Orrery
A GPU-accelerated N-body gravitational simulator
Loading...
Searching...
No Matches
tree_walk.hpp
Go to the documentation of this file.
1#pragma once
2
76
77#include <cstdint>
78#include <span>
79
81#include "orrery/core/types.hpp"
82#include "orrery/core/vec3.hpp"
86
87namespace orrery::solvers {
88
95struct WalkCounts {
96 std::uint64_t particle_particle{};
97 std::uint64_t particle_cell{};
98};
99
112[[nodiscard]] core::Vec3 walk_tree(const Octree& tree, core::Vec3Span<const core::Real> positions,
113 std::span<const core::Real> masses, core::Index target,
114 core::Softening softening, AccumulateRange accumulate,
115 WalkCounts& counts) noexcept;
116
128[[nodiscard]] inline core::Vec3 monopole_acceleration(core::Vec3 offset, core::Real mass,
129 core::Softening softening) noexcept {
130 // The same expression as one iteration of the direct kernel, with the
131 // cell's total mass in place of a particle's and its centre of mass in
132 // place of a position. That is what a monopole is, and writing it as
133 // anything else would put a second copy of the force law in the project.
134 const core::Real factor =
136
137 return offset * factor;
138}
139
155[[nodiscard]] inline core::Vec3 quadrupole_acceleration(core::Vec3 offset, const Quadrupole& moment,
156 core::Softening softening) noexcept {
157 const core::Real inverse =
159
160 // Formed from the fifth and seventh powers of one reciprocal square root
161 // rather than from two further calls, because the divide and square root
162 // unit is the bottleneck this project measured in Phase 7 and these are
163 // multiplications.
164 const core::Real inverse_squared = inverse * inverse;
165 const core::Real inverse_fifth = inverse_squared * inverse_squared * inverse;
166 const core::Real inverse_seventh = inverse_fifth * inverse_squared;
167
168 // Q d, with the tensor's symmetry spent: six stored components describe
169 // nine, and the three off-diagonal ones appear twice each.
170 const core::Vec3 contracted{
171 (moment.xx * offset.x) + (moment.xy * offset.y) + (moment.xz * offset.z),
172 (moment.xy * offset.x) + (moment.yy * offset.y) + (moment.yz * offset.z),
173 (moment.xz * offset.x) + (moment.yz * offset.y) + (moment.zz * offset.z)};
174
175 const core::Real quadratic = core::dot(offset, contracted);
176
177 return (contracted * -inverse_fifth) +
178 (offset * (static_cast<core::Real>(2.5) * quadratic * inverse_seventh));
179}
180
181} // namespace orrery::solvers
The softening length of the Plummer kernel above.
Definition softening.hpp:49
The octree of one configuration, built from Morton-sorted particles.
Definition octree.hpp:208
The innermost loop of the direct solver, in more than one instruction set.
core::Vec3(*)(core::Vec3Span< const core::Real > positions, std::span< const core::Real > masses, core::Vec3 target, core::Index begin, core::Index end, core::Softening softening) noexcept AccumulateRange
The signature both kernels have.
Definition direct_kernel.hpp:106
The tree the Barnes-Hut solver walks, and the moments it carries.
Plummer softening, defined once for everything that needs it.
Real softened_inverse_distance(Real separation_squared, Softening softening) noexcept
The factor 1 / sqrt(r^2 + eps^2) of the softened potential.
Definition softening.hpp:82
Real softened_inverse_distance_cubed(Real separation_squared, Softening softening) noexcept
The factor 1 / (r^2 + eps^2)^(3/2) of the softened acceleration.
Definition softening.hpp:95
A view of three component arrays of equal length.
Definition vec3_span.hpp:33
A vector in three-dimensional Euclidean space.
Definition vec3.hpp:26
The traceless second moment of a cell about its centre of mass.
Definition octree.hpp:89
What one walk did, in the two units InteractionCount reports.
Definition tree_walk.hpp:95
core::Vec3 quadrupole_acceleration(core::Vec3 offset, const Quadrupole &moment, core::Softening softening) noexcept
The correction the quadrupole moment adds to the term above.
Definition tree_walk.hpp:155
core::Vec3 walk_tree(const Octree &tree, core::Vec3Span< const core::Real > positions, std::span< const core::Real > masses, core::Index target, core::Softening softening, AccumulateRange accumulate, WalkCounts &counts) noexcept
The acceleration on the particle at target, without the factor of G.
core::Vec3 monopole_acceleration(core::Vec3 offset, core::Real mass, core::Softening softening) noexcept
The acceleration at offset from a cell of the given mass, without the factor of G.
Definition tree_walk.hpp:128
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
A three-component vector for interfaces, not for storage.
constexpr Real squared_norm(Vec3 v) noexcept
The squared length.
Definition vec3.hpp:108
Three parallel component arrays, viewed as one sequence of 3-vectors.