Orrery
A GPU-accelerated N-body gravitational simulator
Loading...
Searching...
No Matches
softening.hpp
Go to the documentation of this file.
1#pragma once
2
35
36#include <cmath>
37
38#include "orrery/core/types.hpp"
39
40namespace orrery::core {
41
49class Softening {
50public:
56 constexpr Softening() noexcept = default;
57
66 constexpr explicit Softening(Real length) noexcept : squared_(length * length) {}
67
69 [[nodiscard]] constexpr Real squared() const noexcept { return squared_; }
70
71 [[nodiscard]] Real length() const noexcept { return std::sqrt(squared_); }
72
73private:
74 Real squared_{};
75};
76
82[[nodiscard]] inline Real softened_inverse_distance(Real separation_squared,
83 Softening softening) noexcept {
84 return Real{1} / std::sqrt(separation_squared + softening.squared());
85}
86
95[[nodiscard]] inline Real softened_inverse_distance_cubed(Real separation_squared,
96 Softening softening) noexcept {
97 const Real inverse = softened_inverse_distance(separation_squared, softening);
98 return inverse * inverse * inverse;
99}
100
101} // namespace orrery::core
The softening length of the Plummer kernel above.
Definition softening.hpp:49
constexpr Softening() noexcept=default
No softening: exact point masses.
constexpr Real squared() const noexcept
The softening length squared, which is the form every kernel uses.
Definition softening.hpp:69
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
The scalar and index types that every layer of the project agrees on.