|
SpECTRE
v2026.04.01
|
For ODE integration, we suggest using the boost libraries whenever possible. More...
For ODE integration, we suggest using the boost libraries whenever possible.
Here we describe briefly the suggested setup to use a boost ODE integrator in SpECTRE. The boost utilities have a number of more elaborate features, including features that may result in simpler function calls than the specific recipes below. For full documentation, see the Boost odeint documentation: https://www.boost.org/doc/libs/1_72_0/libs/numeric/odeint/doc/html/boost_numeric_odeint/
The integration methods can be used largely as in the boost documentation. We summarize the salient points necessary to get an example running. The main steps in using a boost integrator are:
For most cases the Dormand-Prince fifth order controlled, dense-output stepper is recommended. That stepper is used in the section "SpECTRE vectors or `std::array` thereof in boost integrators" below.
Let us consider a simple oscillator system, which we'll declare as a lambda:
Note that the first argument is a const lvalue reference to the state type, std::array<double, 2>, the second argument is an lvalue reference for the time derivatives that is written to by the system function, and the final argument is the current time.
The construction and initialization of the stepper is simple:
Finally, we can perform the steps and examine the output,
The dense-output and controlled-step-size ODE integrators in boost comply with a somewhat different interface, as significantly more state information must be managed. The result is a somewhat simpler, but more opaque, interface to the user code.
Once again, we start by constructing the system we'd like to integrate,
The constructor for dense steppers takes optional arguments for tolerance, and dense steppers need to be initialized.
It is important to take note of the tolerance arguments, as the defaults are 1.0e-6, which is often looser than we want for calculations in SpECTRE.
We then perform the step supplying the system function, and can retrieve the dense output state with calc_state, which returns by reference by the second argument.
The additional template specializations present in the OdeIntegration.hpp file ensure that the boost ODE methods work transparently for SpECTRE vectors as well. We'll run through a brief example to emphasize the functionality.