Presentation Overview of Numerical Integrator for ODE
The library ponio is a collection of time integrators for solving ODE and PDE written in C++. This library aims to be the easiest to use without compromising on performance.
SOON
conda install ponio
git clone https://github.com/hpc-maths/ponio.git
cd ponio
pixi install
pixi build
In this section, we will present how to solve the Lorenz equations, defined:
The ponio library solve a problem written of the form:
The following steps describe how to solve this problem with ponio. It is important to note that these steps are generally the same whatever the equations we want to solve.
First of all, you have to specify the data type that represents a state state_t
). This type needs to support arithmetic operations (addition and multiplication by a scalar), that why we use a std::valarray<double>
in this example.
using state_t = std::valarray<double>;
To integrate a differential equation numerically, one also has to define the rhs of the equation ()
operator), a function or a lambda function with a certain parameter structure (time and a state). Hence, the straightforward way would be to just define a lambda function, e.g:
const double sigma = 10.;
const double rho = 28.;
const double beta = 8./3.;
auto lorenz_rhs = [=]( double /* t */, state_t&& u ) -> state_t
{
return {
sigma * ( u[1] - u[0] ),
rho * u[0] - u[1] - u[0] * u[2],
u[0] * u[1] - beta * u[2]
};
};
Numerical integration works iteratively, that means you start at a state
state_t u_ini = {1., 1., 1.};
double dt = 0.01;
ponio::time_span<double> t_span = { 0., 20. };
Even if you will use an adaptive time step method to solve the ODE, in ponio you should define an initial time step
dt
.
The time span can contains intermediate value where the time stepper should pass.
The function ponio::solve
, which be used to solve the ODE, returns the state at final time, but maybe you want some information on state at each iteration. To do this, ponio library offers some observers. For the sake of simplicity we will prestent the file observer which write data in columns, the first one is the current time, the following columns are state (3 columns for the state of Lorenz equation), and the last one is the time step. The ponio library offers literal operators to create a file observer from a string which contains the filename of output file.
using namespace observer;
auto obs = "sol.txt"_fobs
Now you are ready to solve your problem with an explicit Runge-Kutta method, see algorithm overview. In this example we will use the classical Runge-Kutta scheme of 4th order.
ponio::solver( lorenz_rhs, ponio::runge_kutta::rk_44(), u_ini, t_span, dt, obs);
- Documentation
- Github repository
- Demos
- Notebooks examples
- List of methods and their analysis (personal webpage of main developer)
This project is licensed under the BSD license.
See LICENSE for more information.