Reputation: 469
I am using scipy.integrate.odeint
to solve an ODE (diffusion equation) in both space and time dimensions. The space derivatives I express via finite differences, so that the whole problem is a time problem.
The solver works but it seems to automatically adjust the time intervals and total times (while the number of steps stays constant). When I compare the result to a simple FCTS scheme which does not adjust the time intervals, it always looks different.
I realized that the actual time steps odeint
uses are returned via infodict['tcur']
. Does this mean I always have to plot the resulting solution against these times? And why is that explained differently in the SciPy documentation? (In the example they plot against the argument t
, i.e., the initial times I pass to odeint
.)
Edit:
In the end, this was an error in my code. I passed the indices of the time steps to the odeint
routine instead of the time steps itself. Anyways, thanks for the explanation.
Upvotes: 3
Views: 3940
Reputation: 4434
There are two time steps used by odeint
:
The sampling step, which is the interval in which the integrator returns results to you. This is controlled by you and usually you will select this equidistantly.
The integration step, which is the discretization of time used by the integration algorithm. This is automatically adjusted to ensure that the (estimated) integration error is not too high. It is also chosen such that the sampling steps are exactly stepped upon (so you get an output there). One sampling step consists of a varying number of integration steps, but at least one. In most cases, integration steps are something that happens under the hood of the integrator and are nothing you have to deal with.
The solver works but it seems to automatically adjust the time intervals and total times (while the number of steps stays constant).
This should not be the case.
The total time and sampling steps should always be what you specified in the argument t
.
Your results being different from those of the FCTS scheme could as well be the fault of the latter.
One simple sanity check you may want to make is to reduce the accuracy threshold (rtol
and atol
), which will result in a smaller integration step (unless your sampling step is very small).
This should not considerably affect your results.
I realized that the actual time steps
odeint
uses are returned viainfodict['tcur']
. Does this mean I always have to plot the resulting solution against these times?
No, in most cases, infodict['tcur']
will be longer than your solution because there are more integration steps than sampling steps.
The SciPy documentation is correct.
Upvotes: 5