c++ - 将运行时参数传递给 odeint 集成器

标签 c++ boost boost-units

我想使用 odeint boost 积分器查看克尔时空中的测地线曲线。这需要为各种参数值运行积分器(我有初始条件和初始动量 vector ,因此系统的角动量将根据我想如何启动它而变化)

我一直在关注此处列出的优秀示例

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

特别是洛伦兹吸引子示例。

我注意到的第一件事(在我的 Kerr 系统中,而不是 Lorenz)是对于某些初始条件,我在 t=0 时间点之后得到 NaN(尽管毫无疑问这表明某处存在更深层次的错误)。为了进一步探索这一点,我希望能够更改系统的参数,而不必每次都重新编译。这相当于想要更改,比如 R 或 sigma 而无需重新编译。据我所知,没有直接的方法可以将额外的参数传递给集成函数,除了这里的第二个代码块

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

我承认,由于我缺乏C++知识,我不是很明白。

我很想知道如何获取运行时参数并将它们传递给这个求解器,这样我就可以运行一堆批处理而无需每次都进行编译。

最佳答案

您可以将运行时参数传递给定义 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 );

关于c++ - 将运行时参数传递给 odeint 集成器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33856910/

相关文章:

c++ - Visual Studio 2013 Express - 资源编辑不可用

c++ - boost spirit x3 : parse into structs

c++ - 从子状态机延迟事件

c++ - 异步服务器在没有明显原因的情况下停止从客户端获取数据

c++ - 将 printf 与 boost::units::quantity 值一起使用

c++ - 如何将 boost::units::metric::hour_base_unit 转换为 boost::units::si::time?

c++ - 为什么将数组作为 "int *& name"传递?

c++ - Qt 5 迁移 - 无法打开包含文件 : 'ui_mainwindow.h'

c++ - 如何在 Boost Unit 中正确定义派生单位

c++ - std::map 是否自动平衡自身