ODE solver gives correct results only if time interval is small

Dear all,

I have a quick question about ODE solvers.

As shown below, TV_mm is solved by a bunch of ODEs, and finally we got how TV_mm change as time goes by as shown below, I want to know the value of TV_mm at time = 50,

The problem is,

  • if I directly solve the ODEs from T0 = 0 to T=50, I got the green line, and a wrong big value of TV_mm at T=50.

  • If I solve the ODEs piece-wisely from t=0 to T1=25, then solve from T1=25 to T=50, I got the purple line as shown above. The result of TV_mm at T=50 is closer to the correct answer but still off.

  • If I solve the ODE piece-wisely from time = 0 to 1, 1 to 2, 2 to 3, … you know set 1 as the time interval, then I got the red line as shown above, this line is smooth and at T=50 it gives the correct TV_mm value.

I have used LSODA and DVERK as the ODE solvers (I have changed the ATOL and RTOL values but does not help), the results are the same as shown above. ODE solvers did not throw any error messages. But it seems like the errors are accumulated during solving, and the ODE solvers did not aware that.

Just curious, has anyone encounter similar ODE issues, such that you have to decrease the time interval in order to get correct results?
If so, usually what do you do to detect such issues and prevent it from happening?

Many thanks!

Have you tried to change the length of the first step or the maximum step?
Have you tried to normalize the quantity such that they are not of the order 10^5?

I will try to do this changes, well first normalize, and then try to set the length of the first step, as a last resort the maximum step.

1 Like

Thank you @egio !

For the Y vs T, is there some criterion for the magnitude of Y and the time T?
Like, in this case, the time T is the order of 10, Y is the order of 10^5, should Y also be normalized such that it is about the order of 10, something like that?

About the length of the first step of ODE solver, is there some criterion as how to roughly determine this first step’s size?

I am not familiar with TV_mm and the omniscient Google only brings up pages that have nothing to do with a system of ODEs. Could you describe the physical/chemical/mathematical problem?

1 Like

Without knowing anything of the problem you’re trying to solve, I would say:

  • Does tightening the tolerances improve your predictions? for LSODA and other ODEPACK solvers, typical tolerances are RTOL<1.0e-4. “Reference” accuracy is achieved with say, RTOL = 1.0e-08 or sqrt(epsilon(0.0_wp)). ATOL depends on your variables and is as important, because internal error control is done as

\varepsilon = RTOL\cdot |y_i| + ATOL

so if ATOL is too large, RTOL will have no effect

  • LSODA includes automatic switching between a stiff and a non-stiff method. The non-stiff method in LSODA is not very accurate, so if your problem is stiff i.e. chemistry ([mol]?), you should use a stiff method e.g. LSODE or VODE

  • Another wild guess: to restart the solution in ODEPACK solvers, you need to do some work (i.e., reset to ISTATE=3 among other things). It may be worth doublechecking very carefully that the solution, and all necessary flags, are correctly reinitialized between subsequent calls to the solver

1 Like