在odeint设置当前状态 [英] Set current state in odeint

查看:200
本文介绍了在odeint设置当前状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置 current_state 步进中的boost :: odeint。

I would like to set the current_state of a stepper in boost::odeint.

我有以下MWE:

#include <queue>
#include <boost/numeric/odeint.hpp>
#include <array>

typedef std::array< double , 2 > state_type;

void eqsys(const state_type &x, state_type &dxdt, double t) {
    dxdt[0] = 0.3*x[1];
    dxdt[1] = 4*x[0];
}

int main() {
    int steps=0;
    auto stepper=make_dense_output(1.0e-6,1.0e-6,boost::numeric::odeint::runge_kutta_dopri5< state_type >() );
    state_type x={2,2};
    double stoptime=10;

    stepper.initialize(x,0,0.01);

    while(true){
        //Run stepper
        while( stepper.current_time()<stoptime && steps<10000 ) {
            stepper.do_step(eqsys);
            ++steps;
        }
        x=stepper.current_state();
        x[0]=2;
        stepper.set_current_state(x);
        stoptime+=10;
    }
}

stepper.set_current_state(X); 是不工作的人。是否有一个命令,我可以用它来完成这项工作?

The line stepper.set_current_state(x); is the one that doesn't work. Is there a command I can use to accomplish this?

我知道我很可能只是用:

I realize I could probably just use:

stepper.initialize(x, stepper.current_time(), 0.01);

不过是目前还不清楚,如果这真的是最好的策略,或者如果我失去了步进的一些内部状态(如当前步长或错误的估计),这将是更好地保持。

but's it's unclear if this is really the best strategy, or if I'm losing some internal state of the stepper (such as the current stepsize or error estimate) which it would be better to keep.

推荐答案

使用

stepper.initialize(x, stepper.current_time(), 0.01);

是绝对OK。在这种情况下,内部状态的正确设置。

is absolutely ok. The internal state is the set correctly in this case.

这篇关于在odeint设置当前状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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