numerics 0.1.0
Loading...
Searching...
No Matches
ode.hpp File Reference

ODE integrators: Euler, RK4, adaptive RK45 (Dormand-Prince), and symplectic Velocity Verlet / Yoshida-4 for Hamiltonian systems. More...

#include "core/types.hpp"
#include "core/vector.hpp"
#include "ode/implicit.hpp"
#include <functional>

Go to the source code of this file.

Classes

struct  num::Step
 
struct  num::SymplecticStep
 
struct  num::ODEResult
 
struct  num::SymplecticResult
 
struct  num::ODEParams
 Parameters for all ODE integrators. Set only the fields you need. More...
 
struct  num::StepEnd
 
class  num::EulerSteps
 
struct  num::EulerSteps::iterator
 
class  num::RK4Steps
 
struct  num::RK4Steps::iterator
 
class  num::RK45Steps
 
struct  num::RK45Steps::iterator
 
class  num::VerletSteps
 
struct  num::VerletSteps::iterator
 
class  num::Yoshida4Steps
 
struct  num::Yoshida4Steps::iterator
 
class  num::RK4_2ndSteps
 
struct  num::RK4_2ndSteps::iterator
 

Namespaces

namespace  num
 

Typedefs

using num::ODERhsFn = std::function< void(real t, const Vector &y, Vector &dydt)>
 
using num::AccelFn = std::function< void(const Vector &q, Vector &acc)>
 
using num::ObserverFn = std::function< void(real t, const Vector &y)>
 
using num::SympObserverFn = std::function< void(real t, const Vector &q, const Vector &v)>
 

Functions

EulerSteps num::euler (ODERhsFn f, Vector y0, ODEParams p={})
 
RK4Steps num::rk4 (ODERhsFn f, Vector y0, ODEParams p={})
 
RK45Steps num::rk45 (ODERhsFn f, Vector y0, ODEParams p={})
 
VerletSteps num::verlet (AccelFn accel, Vector q0, Vector v0, ODEParams p={})
 
Yoshida4Steps num::yoshida4 (AccelFn accel, Vector q0, Vector v0, ODEParams p={})
 
RK4_2ndSteps num::rk4_2nd (AccelFn accel, Vector q0, Vector v0, ODEParams p={})
 
ODEResult num::ode_euler (ODERhsFn f, Vector y0, ODEParams p={}, ObserverFn obs=nullptr)
 Forward Euler, 1st-order, fixed step.
 
ODEResult num::ode_rk4 (ODERhsFn f, Vector y0, ODEParams p={}, ObserverFn obs=nullptr)
 Classic 4th-order Runge-Kutta, fixed step.
 
ODEResult num::ode_rk45 (ODERhsFn f, Vector y0, ODEParams p={}, ObserverFn obs=nullptr)
 Adaptive Dormand-Prince RK45 with FSAL and PI step-size control.
 
SymplecticResult num::ode_verlet (AccelFn accel, Vector q0, Vector v0, ODEParams p={}, SympObserverFn obs=nullptr)
 Velocity Verlet, 2nd-order symplectic, 1 force evaluation per step.
 
SymplecticResult num::ode_yoshida4 (AccelFn accel, Vector q0, Vector v0, ODEParams p={}, SympObserverFn obs=nullptr)
 Yoshida 4th-order symplectic, 3 force evaluations per step.
 
SymplecticResult num::ode_rk4_2nd (AccelFn accel, Vector q0, Vector v0, ODEParams p={}, SympObserverFn obs=nullptr)
 RK4 for second-order systems q'' = accel(q), Nystrom form.
 

Detailed Description

ODE integrators: Euler, RK4, adaptive RK45 (Dormand-Prince), and symplectic Velocity Verlet / Yoshida-4 for Hamiltonian systems.

General ODE solvers advance \( \dot{y} = f(t,y) \):

  • ode_euler – forward Euler, O(h)
  • ode_rk4 – classic 4th-order Runge-Kutta, O(h^4)
  • ode_rk45 – adaptive Dormand-Prince with PI step control, O(h^5)

Symplectic integrators for separable \( H(q,p) = T(p) + V(q) \):

  • ode_verlet – velocity Verlet, 2nd-order symplectic, 1 force eval/step
  • ode_yoshida4 – Yoshida (1990) 4th-order symplectic, 3 force evals/step
  • ode_rk4_2nd – non-symplectic RK4 in Nystrom form, for comparison

Each integrator has a corresponding lazy-range factory (rk4, rk45, verlet, etc.). Iterate with a range-based for to observe intermediate states, or call .run() / use the ode_*() wrappers to obtain only the final result.

Parameters are passed via ODEParams using C++20 designated initializers:

rk45(f, y0, {.tf = 50.0, .rtol = 1e-8, .atol = 1e-10})

Definition in file ode.hpp.