# Integratror interface skips timesteps in DifferentialEquations.jl?

Hello,
I have a question about the integrator interface of the DifferentialEquations package. I want to step through the solution process of a set of coupled ODEs (to wich I want to add a nonlinearity that I can’t use a callback for).
My issue is the following: the documentation gives the possibility of solving the integration problem step by step via

``````for i in integrator
end
``````

However, it only exposes every second integration step. Why is this? How can I get access to every integration step?

Here is some sample code to demonstrate this:

``````using DifferentialEquations
#using CairoMakie for plotting

function dynamics!(du,u,p,t)
du[1] = 1.
end

begin
u0 = [0.]
t = 1.
dt = 0.1
tspan = (0., t)

prob = ODEProblem(dynamics!, u0, tspan, dt = dt);
integrator = init(prob, Euler(), save_everystep=true)

for i in integrator #simulation loop
@show i, integrator.iter
step!(integrator)
end
usol = [x[1] for x in integrator.sol.u]
end

""" #for plotting
begin
f= Figure()
ax = Axis(f[1,1])
lines!(integrator.sol.t,usol, label = "u")
axislegend(ax)
display(f)
end
"""
``````

The output of the above code is the following:

``````(i, integrator.iter) = (t: 0.1; u: [0.1], 1)
(i, integrator.iter) = (t: 0.30000000000000004; u: [0.30000000000000004], 3)
(i, integrator.iter) = (t: 0.5; u: [0.5], 5)
(i, integrator.iter) = (t: 0.7; u: [0.7], 7)
(i, integrator.iter) = (t: 0.8999999999999999; u: [0.8999999999999999], 9)
``````

As one can see, the integrator only exposes uneven integration steps. Why only uneven steps? Is there an option to expose all integration steps?

`step!(integrator)` is advancing the integrator by a step. Remove that line and everything will work.

1 Like