Molecular Dynamics Simulation  1.0
Public Member Functions | Private Attributes | List of all members
TemperatureSensorInterceptor Class Reference

#include <TemperatureSensorInterceptor.h>

Inheritance diagram for TemperatureSensorInterceptor:
Inheritance graph
Collaboration diagram for TemperatureSensorInterceptor:
Collaboration graph

Public Member Functions

 TemperatureSensorInterceptor (std::shared_ptr< Thermostat > thermostat, double sample_every_x_percent)
 Construct a new TemperatureSensor Interceptor object. More...
 
void onSimulationStart (Simulation &simulation) override
 This function is empty as the thermostat doesnt need initialization. More...
 
void operator() (size_t iteration, Simulation &simulation) override
 This function is called on every nth iteration. It scales the temperature of the particles in accordance with the thermostat. More...
 
void onSimulationEnd (size_t iteration, Simulation &simulation) override
 This function is empty as the thermostat doesnt need to do anything at the end of the simulation. More...
 
 operator std::string () const override
 The string representation of this interceptor. More...
 
void logSummary (int depth) const override
 Logs the summary of the thermostat. More...
 
- Public Member Functions inherited from SimulationInterceptor
virtual ~SimulationInterceptor ()=default
 Destroy the Simulation Interceptor object. More...
 
void notify (size_t iteration, Simulation &simulation)
 This function is called by the simulation loop on every iteration. Whenever the iteration is a multiple of every_nth_iteration, the operator() function is called. More...
 

Private Attributes

std::unique_ptr< CSVWritercsv_writer
 
std::shared_ptr< Thermostatthermostat
 The thermostat that is used to scale the temperature. More...
 
double sample_every_x_percent
 

Additional Inherited Members

- Protected Attributes inherited from SimulationInterceptor
size_t every_nth_iteration = 1
 

Detailed Description

Definition at line 8 of file TemperatureSensorInterceptor.h.

Constructor & Destructor Documentation

◆ TemperatureSensorInterceptor()

TemperatureSensorInterceptor::TemperatureSensorInterceptor ( std::shared_ptr< Thermostat thermostat,
double  sample_every_x_percent 
)
inlineexplicit

Construct a new TemperatureSensor Interceptor object.

Definition at line 13 of file TemperatureSensorInterceptor.h.

std::shared_ptr< Thermostat > thermostat
The thermostat that is used to scale the temperature.

Member Function Documentation

◆ logSummary()

void TemperatureSensorInterceptor::logSummary ( int  depth) const
overridevirtual

Logs the summary of the thermostat.

Implements SimulationInterceptor.

Definition at line 34 of file TemperatureSensorInterceptor.cpp.

34  {
35  std::string indent = std::string(depth * 2, ' ');
36 
37  Logger::logger->info("{}╟┤{}TemperatureSensor: {}", indent, ansi_orange_bold, ansi_end);
38  Logger::logger->info("{}║ ├Sample every x percent: {}", indent, sample_every_x_percent);
39 }
const std::string ansi_end
Definition: Logger.h:13
const std::string ansi_orange_bold
Definition: Logger.h:10
static std::shared_ptr< spdlog::logger > logger
Publically accessible shared pointer to the logger.
Definition: Logger.h:35

◆ onSimulationEnd()

void TemperatureSensorInterceptor::onSimulationEnd ( size_t  iteration,
Simulation simulation 
)
overridevirtual

This function is empty as the thermostat doesnt need to do anything at the end of the simulation.

Parameters
iterationThe current iteration
simulationThe simulation object

Implements SimulationInterceptor.

Definition at line 28 of file TemperatureSensorInterceptor.cpp.

28  {
29  const double current_temperature = thermostat->getCurrentContainerTemperature(simulation.particle_container);
30 
31  csv_writer->writeRow({iteration, current_temperature});
32 }
std::unique_ptr< ParticleContainer > particle_container
Reference to the ParticleContainer on whose content the simulation is performed.
Definition: Simulation.h:50
std::unique_ptr< CSVWriter > csv_writer

◆ onSimulationStart()

void TemperatureSensorInterceptor::onSimulationStart ( Simulation simulation)
overridevirtual

This function is empty as the thermostat doesnt need initialization.

Parameters
simulationThe simulation object

Implements SimulationInterceptor.

Definition at line 6 of file TemperatureSensorInterceptor.cpp.

6  {
7  bool append = simulation.params.start_iteration != 0;
8 
9  csv_writer = std::make_unique<CSVWriter>(simulation.params.output_dir_path / "statistics" / "temperature.csv", append);
10 
11  csv_writer->initialize({"iteration", "temperature"});
12 
13  auto expected_iterations = static_cast<size_t>(std::ceil(simulation.params.end_time / simulation.params.delta_t) + 1);
14  SimulationInterceptor::every_nth_iteration = std::max(1, static_cast<int>(sample_every_x_percent * expected_iterations / 100));
15 
16  if (simulation.params.start_iteration == 0) {
17  auto current_temperature = thermostat->getCurrentContainerTemperature(simulation.particle_container);
18  csv_writer->writeRow({simulation.params.start_iteration, current_temperature});
19  }
20 }
double delta_t
Time step of a single simulation iteration.
std::filesystem::path output_dir_path
Path to the directory in which to save the simulation output.
size_t start_iteration
Start iteration of the simulation.
double end_time
End time of the simulation.
const SimulationParams & params
Reference to the simulation parameters object.
Definition: Simulation.h:45

◆ operator std::string()

TemperatureSensorInterceptor::operator std::string ( ) const
explicitoverridevirtual

The string representation of this interceptor.

Returns
std::string

This is used to write the final summary of the Interceptors to the console.

Implements SimulationInterceptor.

Definition at line 41 of file TemperatureSensorInterceptor.cpp.

41 { return ""; }

◆ operator()()

void TemperatureSensorInterceptor::operator() ( size_t  iteration,
Simulation simulation 
)
overridevirtual

This function is called on every nth iteration. It scales the temperature of the particles in accordance with the thermostat.

Parameters
iterationThe current iteration
simulationThe simulation object

Implements SimulationInterceptor.

Definition at line 22 of file TemperatureSensorInterceptor.cpp.

22  {
23  const double current_temperature = thermostat->getCurrentContainerTemperature(simulation.particle_container);
24 
25  csv_writer->writeRow({iteration, current_temperature});
26 }

Member Data Documentation

◆ csv_writer

std::unique_ptr<CSVWriter> TemperatureSensorInterceptor::csv_writer
private

Definition at line 57 of file TemperatureSensorInterceptor.h.

◆ sample_every_x_percent

double TemperatureSensorInterceptor::sample_every_x_percent
private

Definition at line 64 of file TemperatureSensorInterceptor.h.

◆ thermostat

std::shared_ptr<Thermostat> TemperatureSensorInterceptor::thermostat
private

The thermostat that is used to scale the temperature.

Definition at line 62 of file TemperatureSensorInterceptor.h.


The documentation for this class was generated from the following files: