【问题标题】:Set current state in odeint在 odeint 中设置当前状态
【发布时间】:2013-01-07 04:38:11
【问题描述】:

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

我有以下 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); 行是行不通的。有没有我可以使用的命令来完成这个?

我意识到我可能只是使用:

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

但目前尚不清楚这是否真的是最好的策略,或者我是否会丢失一些最好保留的步进器内部状态(例如当前步长或误差估计)。

【问题讨论】:

    标签: boost differential-equations odeint


    【解决方案1】:

    使用

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

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

    【讨论】:

    • 这是否也适用于自适应积分器和辛积分器?
    猜你喜欢
    • 2017-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-28
    • 1970-01-01
    • 1970-01-01
    • 2016-10-27
    • 2012-04-04
    相关资源
    最近更新 更多