Passing runtime parameters to odeint integrator

一笑奈何 提交于 2019-12-02 02:52:32

问题


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.


回答1:


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 );



回答2:


I ran into a similar problem. What I did was defined global vars so that my function could access the variable I passed via argvs. Let me know if you need example.



来源:https://stackoverflow.com/questions/33856910/passing-runtime-parameters-to-odeint-integrator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!