Stop integration in odeint with stiff ode

五迷三道 提交于 2019-12-04 18:14:15

Currently, this is not easily possible with odeint. If you can use the range library here you can combine a for_each and a find_if algorithm.

Otherwise you need to write the loop yourself, which is also not that difficult and should be similar to this:

auto stepper = make_dense_output< rosenbrock4< double > >( 1.0e-12 , 1.0e-12 );
auto ode = make_pair( stiff_system() , stiff_system_jacobi() );

double t = 0.0;
double const end_time = 50.0;
double const dt = 0.01;
vector_type x( 2 , 1.0 );
const double y_min = 1.0;

stepper.initialize( x , t , dt );
cout << t << " " << x[0] << " " << x[1] << endl; // or some other output
t += dt;
while( t < end_time )
{
    if( t > stepper.current_time() )
    {
        // perform a real step
        stepper.do_step( ode );
    }
    else  
    {
        // perform a dense output step
        stepper.calc_state( t , x );
        cout << t << " " << x[0] << " " << x[1] << endl; // or some other output
        t += dt;
    }
    if( x[1] < y_min ) // or some other condition
    {
        cout << "Bound reached." << endl;
        break;
    }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!