Molecular Dynamics Simulation  1.0
SimulationOverview.cpp
Go to the documentation of this file.
1 #include "SimulationOverview.h"
2 
3 #include <spdlog/fmt/chrono.h>
4 
5 #include <algorithm>
6 #include <chrono>
7 #include <ctime>
8 
9 #include "io/logger/Logger.h"
13 #include "utils/FormatTime.h"
14 
15 void SimulationOverview::logSummary(int depth) const {
16  std::string indent = std::string(depth * 2, ' ');
17 
18  Logger::logger->info("{}╔════════════════════════════════════════", indent);
19  Logger::logger->info("{}╟┤{}Simulation overview: {}", indent, ansi_yellow_bold, ansi_end);
20  Logger::logger->info("{}║ Input file: {}", indent, params.input_file_path.string());
21  Logger::logger->info("{}║ Output directory: {}", indent, params.output_dir_path.string());
22  Logger::logger->info("{}║ Simulation time: {}", indent, format_seconds_total(total_time_seconds));
23  Logger::logger->info("{}║ Number of iterations: {}", indent, total_iterations);
24  Logger::logger->info("{}║ Number of particles left: {}", indent, resulting_particles.size());
25  Logger::logger->info("{}╟┤{}Interceptor Logs: {}", indent, ansi_yellow_bold, ansi_end);
26 
27  if (interceptor_summaries.empty()) {
28  Logger::logger->info("{}║ └No interceptors", indent);
29  } else {
30  for (auto& interceptor_summary : interceptor_summaries) {
31  Logger::logger->info("{}║ ├{}", indent, interceptor_summary);
32  }
33  }
34 
35  Logger::logger->info("{}╚════════════════════════════════════════", indent);
36 }
37 
39 
40 void SimulationOverview::savePerformanceDataCSV(const std::string& filename_prefix) const {
41  // write the results to the file
42  std::time_t now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
43  auto formatted_time = fmt::format("{:%d.%m.%Y-%H:%M:%S}", fmt::localtime(now));
44 
45  CSVWriter csv_writer(
46  params.output_dir_path / "statistics" /
47  (filename_prefix + (filename_prefix.empty() ? "" : "_") + "performance_data_" + formatted_time + ".csv"),
48  {"num_particles", "particle_container", "delta_t", "total_time[s]", "particle_updates_per_second[1/s]", "total_iterations"}, false);
49 
50  // find ParticleUpdateCounterInterceptor
51  auto particle_update_counter = std::find_if(params.interceptors.begin(), params.interceptors.end(), [](auto& interceptor) {
52  return std::dynamic_pointer_cast<ParticleUpdateCounterInterceptor>(interceptor) != nullptr;
53  });
54 
55  auto particle_updates_per_second =
56  particle_update_counter != params.interceptors.end()
58  std::dynamic_pointer_cast<ParticleUpdateCounterInterceptor>(*particle_update_counter)->getParticleUpdatesPerSecond())
59  : "N/A";
60 
61  std::string container_type_string = std::visit([](auto&& arg) { return std::string(arg); }, params.container_type);
62 
63  csv_writer.writeRow(
64  {params.num_particles, container_type_string, params.delta_t, total_time_seconds, particle_updates_per_second, total_iterations});
65 }
std::string format_seconds_total(double total_seconds)
Formats the given seconds into a string of the form "HHh MMm SSs MMMms".
Definition: FormatTime.cpp:34
const std::string ansi_yellow_bold
Definition: Logger.h:11
const std::string ansi_end
Definition: Logger.h:13
void writeRow(const std::vector< serializable_types > &row)
Writes a row to the CSV file.
Definition: CSVWriter.cpp:70
static std::shared_ptr< spdlog::logger > logger
Publically accessible shared pointer to the logger.
Definition: Logger.h:35
std::vector< std::string > interceptor_summaries
Summary of the interceptors that were used during the simulation.
double total_time_seconds
Total time the simulation took to execute in seconds (includes time for writing output files and logg...
void savePerformanceDataCSV() const
Saves the simulation overview to a csv file.
void logSummary(int depth=0) const
Prints a summary of the simulation overview to the logger.
std::vector< Particle > resulting_particles
Resulting particles after the simulation.
size_t total_iterations
Total number of iterations the simulation ran for (includes an initial force calculation)
const SimulationParams & params
Original simulation parameters bevore the simulation.
size_t num_particles
Number of particles in the simulation.
double delta_t
Time step of a single simulation iteration.
std::vector< std::shared_ptr< SimulationInterceptor > > interceptors
List of interceptors to be used in the simulation.
std::filesystem::path output_dir_path
Path to the directory in which to save the simulation output.
std::filesystem::path input_file_path
Path to the input file of the simulation.
std::variant< DirectSumType, LinkedCellsType > container_type
Type of the particle container.
std::string to_string(const Container &container, const std::string &delimiter=", ", const std::array< std::string, 2 > &surround={"[", "]"})
Definition: ArrayUtils.h:97