Orrery
A GPU-accelerated N-body gravitational simulator
Loading...
Searching...
No Matches
run_output.hpp
Go to the documentation of this file.
1#pragma once
2
25
26#include <filesystem>
27#include <optional>
28#include <span>
29
30#include "orrery/core/types.hpp"
34
35namespace orrery::sim {
36
37class Simulation;
38
40class RunOutput {
41public:
42 virtual ~RunOutput() = default;
43
55 virtual void record(const Simulation& simulation, bool is_final) = 0;
56
57protected:
58 // As on the other interfaces in this project: a class with a virtual
59 // destructor suppresses the implicit copy and move operations, and copying
60 // an implementation through a reference to this base would slice it.
61 RunOutput() = default;
62 RunOutput(const RunOutput&) = default;
63 RunOutput(RunOutput&&) = default;
64 RunOutput& operator=(const RunOutput&) = default;
65 RunOutput& operator=(RunOutput&&) = default;
66};
67
73class FileOutput final : public RunOutput {
74public:
86 FileOutput(const Configuration& configuration, std::span<const core::Real> masses);
87
88 void record(const Simulation& simulation, bool is_final) override;
89
91 [[nodiscard]] core::Index frames_written() const noexcept;
92
94 [[nodiscard]] core::Index checkpoints_written() const noexcept { return checkpoints_; }
95
96private:
102 [[nodiscard]] bool due(core::Index step, core::Index stride, bool is_final) const noexcept;
103
104 Configuration configuration_;
105
106 std::optional<TrajectoryWriter> trajectory_;
107 std::optional<DiagnosticsLog> diagnostics_;
108
109 std::filesystem::path checkpoint_path_;
110 core::Index checkpoints_ = 0;
111 bool first_ = true;
112};
113
114} // namespace orrery::sim
FileOutput(const Configuration &configuration, std::span< const core::Real > masses)
Open what configuration asks for.
core::Index frames_written() const noexcept
How many trajectory frames have been written.
core::Index checkpoints_written() const noexcept
How many checkpoints have been written.
Definition run_output.hpp:94
void record(const Simulation &simulation, bool is_final) override
Record the current state of simulation.
virtual void record(const Simulation &simulation, bool is_final)=0
Record the current state of simulation.
A gravitational simulation in progress.
Definition simulation.hpp:56
Everything a run is, as data.
The conserved quantities of a run, as they change, in a format anything can read.
A whole run, as data.
Definition configuration.hpp:332
The trajectory file: what the simulation looked like, frame by frame.
The scalar and index types that every layer of the project agrees on.
std::size_t Index
The type of a particle index and of any count of particles.
Definition types.hpp:45