17 const idx n =
y0.size();
21 for (
real t =
t0; t <
t1 - 1
e-14 * std::abs(
t1); t += h) {
22 real dt = std::min(h,
t1 - t);
28 return {std::move(
y0),
t1, steps,
true};
35 const idx n =
y0.size();
39 for (
real t =
t0; t <
t1 - 1
e-14 * std::abs(
t1); t += h) {
40 real dt = std::min(h,
t1 - t);
53 for (
idx i = 0;
i < n; ++
i)
58 return {std::move(
y0),
t1, steps,
true};
70 static constexpr real a21 = 1.0/5.0;
71 static constexpr real a31 = 3.0/40.0,
a32 = 9.0/40.0;
72 static constexpr real a41 = 44.0/45.0,
a42 = -56.0/15.0,
a43 = 32.0/9.0;
73 static constexpr real a51 = 19372.0/6561.0,
a52 = -25360.0/2187.0,
74 a53 = 64448.0/6561.0,
a54 = -212.0/729.0;
75 static constexpr real a61 = 9017.0/3168.0,
a62 = -355.0/33.0,
76 a63 = 46732.0/5247.0,
a64 = 49.0/176.0,
77 a65 = -5103.0/18656.0;
79 static constexpr real b1 = 35.0/384.0,
b3 = 500.0/1113.0,
80 b4 = 125.0/192.0,
b5 = -2187.0/6784.0,
b6 = 11.0/84.0;
82 static constexpr real e1 = 71.0/57600.0,
e3 = -71.0/16695.0,
83 e4 = 71.0/1920.0,
e5 = -17253.0/339200.0,
84 e6 = 22.0/525.0,
e7 = -1.0/40.0;
86 const idx n =
y0.size();
92 bool converged =
true;
96 while (t <
t1 - 1
e-14 * std::abs(
t1)) {
97 if (steps >=
max_steps) { converged =
false;
break; }
98 h = std::min(h,
t1 - t);
109 for (
idx i = 0;
i < n; ++
i)
113 for (
idx i = 0;
i < n; ++
i)
117 for (
idx i = 0;
i < n; ++
i)
122 for (
idx i = 0;
i < n; ++
i)
126 for (
idx i = 0;
i < n; ++
i) {
141 factor = std::max(
real(0.1), std::min(
real(10.0), factor));
145 return {std::move(
y0), t, steps, converged};
164 while (t <
t1 - 1
e-14 * std::abs(
t1)) {
165 real dt = std::min(h,
t1 - t);
168 for (
idx i = 0;
i < n; ++
i)
169 q0[
i] += dt *
v0[
i] + 0.5 * dt * dt *
a_cur[
i];
174 for (
idx i = 0;
i < n; ++
i)
183 return {std::move(q0), std::move(
v0), t, steps};
198 static const real w1 = 1.0 / (2.0 - std::cbrt(2.0));
199 static const real w0 = 1.0 - 2.0 *
w1;
212 while (t <
t1 - 1
e-14 * std::abs(
t1)) {
213 real dt = std::min(h,
t1 - t);
238 return {std::move(q0), std::move(
v0), t, steps};
constexpr idx size() const noexcept
std::function< void(real t, const Vector &q, const Vector &v)> SymplecticCallback
std::function< void(real t, const Vector &y, Vector &dydt)> ODERhsFn
Right-hand side callable: fills dydt = f(t, y) in-place.
ODEResult ode_rk45(ODERhsFn f, Vector y0, real t0, real t1, real rtol=1e-6, real atol=1e-9, real h0=1e-3, idx max_steps=1000000, StepCallback on_step=nullptr)
constexpr T ipow(T x) noexcept
Compute x^N at compile time via repeated squaring.
SymplecticResult ode_yoshida4(AccelFn accel, Vector q0, Vector v0, real t0, real t1, real h, SymplecticCallback on_step=nullptr)
BasicVector< real > Vector
Real-valued dense vector with full backend dispatch (CPU + GPU)
SymplecticResult ode_verlet(AccelFn accel, Vector q0, Vector v0, real t0, real t1, real h, SymplecticCallback on_step=nullptr)
ODEResult ode_rk4(ODERhsFn f, Vector y0, real t0, real t1, real h, StepCallback on_step=nullptr)
Classic 4th-order Runge-Kutta (fixed step).
std::function< void(real t, const Vector &y)> StepCallback
std::function< void(const Vector &q, Vector &acc)> AccelFn
ODEResult ode_euler(ODERhsFn f, Vector y0, real t0, real t1, real h, StepCallback on_step=nullptr)
ODE time integrators: Euler, RK4, adaptive RK45 (Dormand-Prince), and symplectic Velocity Verlet / Yo...
Result returned by general ODE integrators.
Result returned by symplectic integrators.