Orrery
A GPU-accelerated N-body gravitational simulator
Loading...
Searching...
No Matches
direct_solver.hpp
Go to the documentation of this file.
1#pragma once
2
92
93#include <span>
94#include <string_view>
95
98#include "orrery/core/types.hpp"
103
104namespace orrery::solvers {
105
107class DirectSolver final : public ForceSolver {
108public:
110 DirectSolver() = default;
111
116 explicit DirectSolver(core::Softening softening) noexcept : softening_(softening) {}
117
119 explicit DirectSolver(backend::Executor& executor) noexcept : executor_(&executor) {}
120
130
141 void evaluate(core::Vec3Span<const core::Real> positions, std::span<const core::Real> masses,
142 core::Vec3Span<core::Real> accelerations) override;
143
144 [[nodiscard]] std::string_view name() const noexcept override { return "direct"; }
145
146 [[nodiscard]] core::Softening softening() const noexcept override { return softening_; }
147
148 [[nodiscard]] InteractionCount interaction_count() const noexcept override { return count_; }
149
150 void reset_interaction_count() noexcept override { count_ = {}; }
151
158 [[nodiscard]] const backend::Executor* executor() const noexcept { return executor_; }
159
174 void select_kernel(KernelKind kind) noexcept {
175 kernel_ = kernel_available(kind) ? kind : KernelKind::kScalar;
176 }
177
179 [[nodiscard]] KernelKind kernel() const noexcept { return kernel_; }
180
181private:
182 core::Softening softening_;
183
193 backend::Executor* executor_{nullptr};
194
201 KernelKind kernel_{fastest_available_kernel()};
202
203 InteractionCount count_;
204};
205
206} // namespace orrery::solvers
Something that can run a loop body over a range, possibly in parallel.
Definition executor.hpp:52
The softening length of the Plummer kernel above.
Definition softening.hpp:49
core::Softening softening() const noexcept override
The softening this solver applies.
Definition direct_solver.hpp:146
DirectSolver(core::Softening softening) noexcept
A solver softening at the given length.
Definition direct_solver.hpp:116
void select_kernel(KernelKind kind) noexcept
Ask for a particular kernel, and settle for the scalar one if this machine cannot run it.
Definition direct_solver.hpp:174
DirectSolver(backend::Executor &executor) noexcept
A solver over exact point masses, evaluated through executor.
Definition direct_solver.hpp:119
KernelKind kernel() const noexcept
The kernel this solver will actually use.
Definition direct_solver.hpp:179
InteractionCount interaction_count() const noexcept override
The work done since construction or since the last reset.
Definition direct_solver.hpp:148
void reset_interaction_count() noexcept override
Set every counter back to zero.
Definition direct_solver.hpp:150
DirectSolver(core::Softening softening, backend::Executor &executor) noexcept
A softened solver evaluated through executor.
Definition direct_solver.hpp:128
const backend::Executor * executor() const noexcept
The executor this solver evaluates through, or null if it runs on the calling thread.
Definition direct_solver.hpp:158
std::string_view name() const noexcept override
The solver's name, for benchmark tables and test messages.
Definition direct_solver.hpp:144
DirectSolver()=default
A solver over exact point masses, evaluated on the calling thread.
void evaluate(core::Vec3Span< const core::Real > positions, std::span< const core::Real > masses, core::Vec3Span< core::Real > accelerations) override
Write the acceleration at each position into accelerations.
The innermost loop of the direct solver, in more than one instruction set.
KernelKind
Which implementation of the summation to use.
Definition direct_kernel.hpp:85
@ kScalar
One pair at a time, in index order.
Definition direct_kernel.hpp:91
bool kernel_available(KernelKind kind) noexcept
Whether this build, on this machine, can run kind.
How a kernel asks for a loop to be run in parallel.
What every gravitational force solver in this project provides.
The unit in which the cost of a force evaluation is reported.
Plummer softening, defined once for everything that needs it.
A view of three component arrays of equal length.
Definition vec3_span.hpp:33
What a solver has done since the count was last reset.
Definition interaction_count.hpp:37
The scalar and index types that every layer of the project agrees on.
Three parallel component arrays, viewed as one sequence of 3-vectors.