c++boostboost-units

Passing runtime parameters to odeint integrator


I would like to use the odeint boost integrator to look at geodesic curves in the Kerr spacetime. This necessitates running an integrator for a variety of parameter values (I have initial conditions and initial momentum vectors so the angular momentum of the system will vary depending how I would like to start it)

I've been following the excellent examples laid out here

http://headmyshoulder.github.io/odeint-v2/examples.html

specifically the Lorenz attractor example.

The first thing I note (in my Kerr system, not the Lorenz) is that for some initial conditions I get NaN after the t=0 time point (though no doubt this suggests a deeper error somewhere). To explore this more I'd like to be able to change the parameters of the system without having to recompile each time. This is equivalent to wanting to change, say R or sigma without recompiling. As far as I can tell there is no direct way to pass extra arguments to the integrate function, except perhaps the second code block here

http://headmyshoulder.github.io/odeint-v2/doc/boost_numeric_odeint/tutorial/harmonic_oscillator.html

which I confess, because of my lack of C++ knowledge, I don't quite understand.

I'd appreciate knowledge of how to take in run time arguments and pass them to this solver so i can just run a bunch of batches without compiling each time.


Solution

  • You can pass runtime parameters to the system function defining your ODE:

    struct ode
    {
        double param;
        ode( double param ) : m_param( param ) {}
    
        void operator()( state_type const& x , state_type& dxdt , time_type t ) const 
        {
            // your ode
        }
    };
    
    integrate_const( stepper {} , ode { 0.1 } , x , t_start , t_end , dt , observer );