Line |
Branch |
Exec |
Source |
1 |
|
|
#pragma once |
2 |
|
|
|
3 |
|
|
#include <H5Cpp.h> |
4 |
|
|
#include <cstddef> |
5 |
|
|
#include <filesystem> |
6 |
|
|
#include <fstream> |
7 |
|
|
#include <string> |
8 |
|
|
#include <thread> |
9 |
|
|
#include <vector> |
10 |
|
|
#include <yaml-cpp/yaml.h> |
11 |
|
|
|
12 |
|
|
#include "trajectories.hpp" |
13 |
|
|
#include "types.hpp" |
14 |
|
|
|
15 |
|
|
class System; |
16 |
|
|
struct Stage; |
17 |
|
|
struct Particle; |
18 |
|
|
class Integrator; |
19 |
|
|
class Observables; |
20 |
|
|
class Simulation; |
21 |
|
|
class Timeseries; |
22 |
|
|
|
23 |
|
|
class Teebuf : public std::streambuf { |
24 |
|
|
std::streambuf *sbuf1; |
25 |
|
|
std::streambuf *sbuf2; |
26 |
|
|
|
27 |
|
|
public: |
28 |
|
|
Teebuf(std::streambuf *sbuf1, std::streambuf *sbuf2); |
29 |
|
|
int overflow(int c); |
30 |
|
|
int sync(); |
31 |
|
|
}; |
32 |
|
|
|
33 |
|
|
class Output { |
34 |
|
|
void writeStats(Simulation *simulation, const std::string &filename); |
35 |
|
|
|
36 |
|
|
virtual void writeObservables(Observables *observables, int stage) = 0; |
37 |
|
|
virtual void writeTimeseries(Timeseries *timeseries, int stage) = 0; |
38 |
|
|
|
39 |
|
|
protected: |
40 |
|
|
std::filesystem::path outputPath; |
41 |
|
|
bool dryrun; |
42 |
|
|
std::ofstream logFile; |
43 |
|
|
Teebuf *tee; |
44 |
|
|
std::streambuf *clogbuf; |
45 |
|
|
|
46 |
|
|
public: |
47 |
|
|
Output(const std::filesystem::path &outputPath, bool dryrun); |
48 |
|
|
virtual ~Output(); |
49 |
|
|
|
50 |
|
|
void emitConfig(const YAML::Node &config); |
51 |
|
|
void writeParticles(const std::vector<Particle> &particles, const std::string &filename); |
52 |
|
|
virtual void write(Simulation *simulation); |
53 |
|
|
// If you want trajectories in the data files, call this method *every step*! |
54 |
|
|
virtual void writeTrajectoryFrame(Trajectories *trajectories, System *system, int stage); |
55 |
|
|
}; |
56 |
|
|
|
57 |
|
|
class H5MDOutput : public Output { |
58 |
|
|
H5::H5File file; |
59 |
|
|
|
60 |
|
✗ |
struct TrajectoryQuantityProps { |
61 |
|
|
H5::PredType type; |
62 |
|
|
size_t dim; |
63 |
|
|
H5::DataSet dataset = H5::DataSet(); |
64 |
|
|
void *data = nullptr; |
65 |
|
|
}; |
66 |
|
|
|
67 |
|
|
struct { |
68 |
|
|
std::vector<Vec> r; |
69 |
|
|
std::vector<ArrayI> box; |
70 |
|
|
std::vector<Vec> v; |
71 |
|
|
std::vector<Vec> F; |
72 |
|
|
std::vector<Vec> Fext; |
73 |
|
|
std::vector<Vec> Fint; |
74 |
|
|
std::vector<Vec> rRand; |
75 |
|
|
std::vector<double> m; |
76 |
|
|
std::vector<int> species; |
77 |
|
|
} trajectoryBuffers; |
78 |
|
|
|
79 |
|
|
std::map<std::string, TrajectoryQuantityProps> trajectoryQuantities; |
80 |
|
|
std::thread trajectoryWriter; |
81 |
|
|
|
82 |
|
|
void initFile(const std::filesystem::path &path, const std::string &filename); |
83 |
|
|
void writeMeta(); |
84 |
|
|
void initParticlesGroup(Trajectories *trajectories, System *system); |
85 |
|
|
|
86 |
|
|
void writeObservables(Observables *observables, int stage); |
87 |
|
|
void writeTimeseries(Timeseries *timeseries, int stage); |
88 |
|
|
|
89 |
|
|
public: |
90 |
|
|
H5MDOutput(const std::filesystem::path &outputPath, bool dryrun); |
91 |
|
|
~H5MDOutput(); |
92 |
|
|
|
93 |
|
|
void write(Simulation *simulation); |
94 |
|
|
void writeTrajectoryFrame(Trajectories *trajectories, System *system, int stage); |
95 |
|
|
}; |
96 |
|
|
|
97 |
|
|
class ASCIIOutput : public Output { |
98 |
|
|
void writeObservables(Observables *observables, int stage); |
99 |
|
|
void writeTimeseries(Timeseries *timeseries, int stage); |
100 |
|
|
|
101 |
|
|
public: |
102 |
|
|
ASCIIOutput(const std::filesystem::path &outputPath, bool dryrun); |
103 |
|
|
}; |
104 |
|
|
|