Header-only ordinary differential equation solvers in C++20.
#include <ode/ode.hpp>
using method_type = ode::explicit_method<ode::runge_kutta_4_tableau<float>>;
using problem_type = ode::initial_value_problem<float, vector3f>;
std::int32_t main(std::int32_t argc, char** argv)
{
const auto sigma = 10.0f;
const auto rho = 28.0f;
const auto beta = 8.0f / 3.0f;
const auto problem = problem_type
{
0.0f, /* t0 */
vector3f(16.0f, 16.0f, 16.0f), /* y0 */
[&] (const float t, const vector3f& y) /* dy/dt = f(t, y) */
{
return vector3f(sigma * (y[1] - y[0]), y[0] * (rho - y[2]) - y[1], y[0] * y[1] - beta * y[2]);
}
};
auto iterator = ode::fixed_step_iterator<method_type, problem_type>(problem, 1.0f /* h */);
while (true)
++iterator;
}
- The
[ |extended_]butcher_tableau
encapsulate the coefficients of a Butcher tableau. - The
type
of a tableau must satisfystd::is_arithmetic<type>
. - The following tableau are currently provided:
- Explicit:
- Forward Euler
- Runge Kutta 4
- Dormand Prince 5
- Explicit:
- The
initial_value_problem
encapsulate the (initial) state of an ordinary differential equation problem. - The
higher_order_initial_value_problem
s may be decomposed into order many coupledinitial_value_problem
s. - The
time_type
of a problem must satisfystd::is_arithmetic<time_type>
. - The
value_type
of a problem must satisfystd::is_default_constructible<value_type>
,std::is_assignable<value_type>
, and additionally provide the following operators.- Add assign:
value += value
. - Add :
value + value -> value
. - Subtract :
value - value -> value
. - Scale :
value * time -> value
.
- Add assign:
- The
explicit_method
s encapsulate the operations to perform a single iteration of the solution to ainitial_value_problem
. - The methods are constructed from
[ |extended_]butcher_tableau
.
- The
[fixed_size|adaptive_size]_iterator
s iterate aexplicit_method
over ainitial_value_problem
. - The
coupled_fixed_size_iterator
s iterate aexplicit_method
over coupledinitial_value_problem
s.
- The library is inspired by Boost.Odeint and OrdinaryDiffEq.jl.