停止整合僵硬颂歌odeint [英] Stop integration in odeint with stiff ode
问题描述
我要解决一个僵硬颂歌与odeint。我在下面的<一个href=\"http://www.boost.org/doc/libs/1_57_0/libs/numeric/odeint/doc/html/boost_numeric_odeint/tutorial/stiff_systems.html\"相对=nofollow>这个(rosenbrock4_dense_output步进),但是,我的功能,可以迅速成长pretty所以我想停止整合如果x(t)的> XMAX。
I want to solve a stiff ode with odeint. I was following this (rosenbrock4_dense_output stepper) but, my function can grow pretty quickly so I want to stop the integration if x(t)>xMAX.
在此<一个href=\"http://stackoverflow.com/questions/14586059/bound-an-odeint-variable/14588283#14588283\">question,他们有一个解决方案,但因为我是新的C + +我不知道如何使用rosenbrock4_dense_output步进何时实现这一点。
In this question, they have a solution for it but since I'm new with c++ I don't know how to implement this when using a rosenbrock4_dense_output stepper.
我想看看如何具体写了rosenbrock4_dense_output步进。
I would like to see how to write this specifically for rosenbrock4_dense_output stepper.
推荐答案
目前,这是不容易可能的odeint。如果你可以在这里使用范围图书馆 你可以结合的for_each
和 find_if
算法
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;
}
}
这篇关于停止整合僵硬颂歌odeint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!