Molecular Dynamics Simulation  1.0
CheckPointWriter.cpp
Go to the documentation of this file.
1 #include "CheckPointWriter.h"
2 
3 #include <spdlog/fmt/bundled/core.h>
4 
5 #include <fstream>
6 
8 
9 const std::filesystem::path CheckPointWriter::writeFile(const SimulationParams& params, size_t iteration,
10  const std::vector<Particle>& particles) const {
11  auto file_name = params.output_dir_path / fmt::format("MD_CHKPT_{:08d}.chkpt", iteration);
12 
13  MetaDataDataType meta_data{params.input_file_path.string(), params.input_file_hash, params.end_time, params.delta_t, iteration};
14 
15  CheckPointFileType::ParticleData_type xsd_particles{};
16 
17  xsd_particles.particle().reserve(particles.size());
18 
19  for (const Particle& particle : particles) {
20  xsd_particles.particle().push_back(InternalToXSDTypeAdapter::convertToParticle(particle));
21  }
22 
23  CheckPointFileType checkpointfile(meta_data, xsd_particles);
24 
25  std::ofstream file(file_name);
26  CheckPoint(file, checkpointfile);
27  file.close();
28 
29  return file_name;
30 }
const std::filesystem::path writeFile(const SimulationParams &params, size_t iteration, const std::vector< Particle > &particles) const override
Writes the data of the given ParticleContainer to a .vtu file.
static ParticleType convertToParticle(const Particle &particle)
Class to represent a particle.
Definition: Particle.h:26
Contains all parameters needed to run a simulation.
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.
std::filesystem::path input_file_path
Path to the input file of the simulation.
std::size_t input_file_hash
Hash of the input file of the simulation.
double end_time
End time of the simulation.