【发布时间】:2013-01-22 18:43:04
【问题描述】:
假设我有以下boost::odeint 代码:
#include <iostream>
#include <boost/array.hpp>
#include <boost/numeric/odeint.hpp>
using namespace std;
using namespace boost::numeric::odeint;
const double sigma = 10.0;
const double R = 28.0;
const double b = 8.0 / 3.0;
typedef boost::array< double , 3 > state_type;
void lorenz( const state_type &x , state_type &dxdt , double t ){
dxdt[0] = sigma * ( x[1] - x[0] );
dxdt[1] = R * x[0] - x[1] - x[0] * x[2];
dxdt[2] = -b * x[2] + x[0] * x[1];
}
void write_lorenz( const state_type &x , const double t ){
cout << t << '\t' << x[0] << '\t' << x[1] << '\t' << x[2] << endl;
}
int main(int argc, char **argv){
state_type x = { 10.0 , 1.0 , 1.0 }; // initial conditions
cout<<"Steps: "<<integrate( lorenz , x , 0.0 , 25.0 , 0.1 , write_lorenz )<<endl;
}
如何修改代码以使集成在一定数量的步骤后中断?我正在运行大量集成,并希望避免在集成任何特定系统上花费太多时间。
我曾考虑过使用integrate_n_steps(),但这可能意味着集成会持续到我感兴趣的结束时间。
【问题讨论】:
-
所以你想修正实时花费,而不是步数?休息后,你期待什么?放弃集成或输出类似的东西?
-
@hwlau,我想放弃集成。按固定数量的步骤或按执行时间进行切割都可以,但我希望程序在中断后继续运行:只有积分器应该停止。
标签: c++ boost differential-equations odeint