将运行时参数传递给odeint积分器 [英] Passing runtime parameters to odeint integrator

查看:109
本文介绍了将运行时参数传递给odeint积分器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用odeint Boost积分器查看Kerr时空中的测地线.这需要为各种参数值运行积分器(我具有初始条件和初始动量矢量,因此系统的角动量会根据我的启动方式而变化)

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.

我要注意的第一件事(在我的Kerr系统中,不是Lorenz)是在某些初始条件下,我在t = 0时间点后得到NaN(尽管毫无疑问,这暗示着某个地方存在更深的错误).为了进一步探讨这一点,我希望能够更改系统的参数而不必每次都重新编译.这等效于想要更改,例如R或sigma而无需重新编译.据我所知,除了在这里的第二个代码块

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

因为我缺乏C ++知识,所以我不太了解.

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.

推荐答案

您可以将运行时参数传递给定义ODE的系统函数:

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

这篇关于将运行时参数传递给odeint积分器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆