Molecular Dynamics Simulation  1.0
TemperatureSensorInterceptor.cpp
Go to the documentation of this file.
2 
3 #include "io/logger/Logger.h"
5 
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 }
21 
22 void TemperatureSensorInterceptor::operator()(size_t iteration, Simulation& simulation) {
23  const double current_temperature = thermostat->getCurrentContainerTemperature(simulation.particle_container);
24 
25  csv_writer->writeRow({iteration, current_temperature});
26 }
27 
28 void TemperatureSensorInterceptor::onSimulationEnd(size_t iteration, Simulation& simulation) {
29  const double current_temperature = thermostat->getCurrentContainerTemperature(simulation.particle_container);
30 
31  csv_writer->writeRow({iteration, current_temperature});
32 }
33 
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 }
40 
41 TemperatureSensorInterceptor::operator std::string() const { return ""; }
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
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.
Class to run a simulation.
Definition: Simulation.h:20
std::unique_ptr< ParticleContainer > particle_container
Reference to the ParticleContainer on whose content the simulation is performed.
Definition: Simulation.h:50
const SimulationParams & params
Reference to the simulation parameters object.
Definition: Simulation.h:45
void onSimulationStart(Simulation &simulation) override
This function is empty as the thermostat doesnt need initialization.
std::unique_ptr< CSVWriter > csv_writer
void operator()(size_t iteration, Simulation &simulation) override
This function is called on every nth iteration. It scales the temperature of the particles in accorda...
std::shared_ptr< Thermostat > thermostat
The thermostat that is used to scale the temperature.
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.
void logSummary(int depth) const override
Logs the summary of the thermostat.