Boost 在odeint中设置当前状态
我想在boost::odeint中设置步进器的当前状态 我有以下MWE:Boost 在odeint中设置当前状态,boost,differential-equations,odeint,Boost,Differential Equations,Odeint,我想在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) {
#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.initialize(x, stepper.current_time(), 0.01);
绝对可以。在这种情况下,内部状态设置正确 这也适用于自适应积分器和辛积分器吗?
stepper.initialize(x, stepper.current_time(), 0.01);