Bound an odeint variable

后端 未结 2 1559
慢半拍i
慢半拍i 2021-01-14 03:15

I\'m using odeint to simulate a system wherein there are several variables which should not go less than zero.

Is there an appropriate way to bound a variable in ode

2条回答
  •  独厮守ぢ
    2021-01-14 03:44

    There is no such possibility in odeint. And I guess there are no algorithms which could do that. You must somehow encode the bound in your ODE.

    If you only want to find a bound during the evolution of your system use a loop like

    while( t < tmax )
    {
        stepper.do_step( ode , x , t , dt );
        t += dt;
        if( check_bound( x , t ) ) break;
    }
    

    Two side nodes, maybe this is the case for your problem:

    1. There are special algorithms for ODEs with have conservation laws where the algorithm ensures that the conservation law holds, see the symplectic solvers for example.

    2. If you bound is already encode in some way in your ODE and the bound is anyhow reached you must shorten the stepsize of the solver.

提交回复
热议问题