Orrery
A GPU-accelerated N-body gravitational simulator
Loading...
Searching...
No Matches
simulation.hpp
Go to the documentation of this file.
1#pragma once
2
41
42#include <memory>
43
47#include "orrery/core/types.hpp"
50
51namespace orrery::sim {
52
53class RunOutput;
54
57public:
65 Simulation(core::ParticleData particles, std::unique_ptr<solvers::ForceSolver> solver,
66 std::unique_ptr<integrators::Integrator> integrator, core::Real timestep,
67 std::unique_ptr<backend::Executor> executor = nullptr,
68 std::unique_ptr<RunOutput> output = nullptr);
69
71
72 Simulation(const Simulation&) = delete;
73 Simulation& operator=(const Simulation&) = delete;
74 Simulation(Simulation&&) noexcept;
75 Simulation& operator=(Simulation&&) noexcept;
76
81 void step();
82
89 void run(core::Index steps);
90
101 void restore(core::ParticleData particles, core::Index step,
102 bool accelerations_are_current = false);
103
104 [[nodiscard]] core::Index step_index() const noexcept { return step_; }
105
107 [[nodiscard]] core::Real time() const noexcept {
108 return static_cast<core::Real>(step_) * timestep_;
109 }
110
111 [[nodiscard]] core::Real timestep() const noexcept { return timestep_; }
112
113 [[nodiscard]] const core::ParticleData& particles() const noexcept { return particles_; }
114
115 [[nodiscard]] const solvers::ForceSolver& solver() const noexcept { return *solver_; }
116
117 [[nodiscard]] const integrators::Integrator& integrator() const noexcept {
118 return *integrator_;
119 }
120
131 [[nodiscard]] core::Diagnostics measure() const;
132
133private:
135 std::unique_ptr<backend::Executor> executor_;
136
137 std::unique_ptr<solvers::ForceSolver> solver_;
138 std::unique_ptr<integrators::Integrator> integrator_;
139 std::unique_ptr<RunOutput> output_;
140
141 core::ParticleData particles_;
142 core::Real timestep_;
143 core::Index step_ = 0;
144};
145
146} // namespace orrery::sim
Storage for a set of point masses in structure-of-arrays layout.
Definition particle_data.hpp:43
Somewhere for a run to report itself to.
Definition run_output.hpp:40
void step()
Advance by one step and count it.
core::Real time() const noexcept
The simulated time, step * timestep.
Definition simulation.hpp:107
void run(core::Index steps)
Record the current state, then take steps steps, recording as the output asks.
Simulation(core::ParticleData particles, std::unique_ptr< solvers::ForceSolver > solver, std::unique_ptr< integrators::Integrator > integrator, core::Real timestep, std::unique_ptr< backend::Executor > executor=nullptr, std::unique_ptr< RunOutput > output=nullptr)
Take ownership of a configuration and the machinery to advance it.
void restore(core::ParticleData particles, core::Index step, bool accelerations_are_current=false)
Replace the state and the step counter, as a resume does.
core::Diagnostics measure() const
Measure the conserved quantities of the current state.
The conserved quantities, which are how this project knows it is right.
How a kernel asks for a loop to be run in parallel.
What every gravitational force solver in this project provides.
The interface every time integrator presents, and the contract about accelerations that makes the che...
The particle store: one contiguous array per component.
Every conserved quantity of a configuration, measured at one instant.
Definition diagnostics.hpp:52
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