GCC Code Coverage Report


Directory: ./
File: include/output.hpp
Date: 2024-04-18 12:22:13
Exec Total Coverage
Lines: 0 1 0.0%
Functions: 0 0 -%
Branches: 0 0 -%

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