Open ufechner7 opened 3 years ago
This code is working:
for i in 1:round(t_end/dt)
step!(integrator, dt, true)
u = integrator.u
t = integrator.t
@show u[18], t
end
Lets say only the documentation is wrong. It says:
step!(integrator,dt[,stop_at_tdt=false])
at https://diffeq.sciml.ai/stable/basics/integrator/#SciMLBase.step!
.
Perhaps it would also be good to add the working example above to the documentation. Because if it is not added the only thing you see is:
for (u,t) in tuples(integrator)
@show u,t
end
Which does not work together with the option stop_at_tdt=true.
What do you mean that doesn't work?
Look at the initial example. It gives wrong output, it does not respect dt.
In
for i in 1:5
step!(integrator, dt, true)
for (u,t) in tuples(integrator)
@show u[18], t
end
end
You're explicitly telling it to only use dt
in the first step, and then after you've solved to the end of the interval using adaptive time stepping, use dt
4 more times.
using OrdinaryDiffEq
prob = ODEProblem((u,p,t)->1.01u,1.01,(0.0,1.0))
integrator = init(prob,Tsit5())
for (u,t) in tuples(integrator)
@show u,t
end
(u, t) = (1.1169134682731792, 0.09962249330449434)
(u, t) = (1.4319565770427753, 0.34563506464944166)
(u, t) = (2.002298156149145, 0.6775695999548759)
(u, t) = (2.7730568905500066, 1.0)
It iterates as documented, and because it does what's documented it causes your "issue".
That is very confusing. Why should the command:
tuples(integrator)
actually cause the integration to continue? My understanding of this command is that it just collects the result of the last integration.
It's an iterator that iterates by stepping.
using OrdinaryDiffEq
prob = ODEProblem((u,p,t)->1.01u,1.01,(0.0,1.0))
integrator = init(prob,Tsit5())
for integ in integrator
@show integ.t
end
integ.t = 0.09962249330449434
integ.t = 0.34563506464944166
integ.t = 0.6775695999548759
integ.t = 1.0
It's the standard Julia construct for stepping. I don't understand why you were using stepping to view terms when you didn't want stepping.
My understand of this command is that it just collects the result of the last integration.
No, it's an iterator, defined in the iteration section as an iterator.
This type also implements an iterator interface, so one can step n times (or to the last tstop) using the take iterator:
for i in take(integrator,n) end
One can loop to the end by using solve!(integrator) or using the iterator interface:
for i in integrator end
In addition, some helper iterators are provided to help monitor the solution. For example, the tuples iterator lets you view the values:
for (u,t) in tuples(integrator)
@show u,t
end
and the intervals iterator lets you view the full interval
etc. It's all about different iterators to control and view stepping behavior in nice ways.
Anyway, I think it would be helpful to add an example like this:
dt = 0.1
t_en = 10.0
for i in 1:round(t_end/dt)
step!(integrator, dt, true)
u = integrator.u
t = integrator.t
@show u, t
end
to the documentation.
Agreed.
TimeChoiceIterator
might be a little more natural though?
for (u,t) in TimeChoiceIterator(integrator,0:dt:tend)
@show u,t
end
might be the nicest way.
But does this do the integration step-by-step with the possibility to update parameters after each step?
Yes, it iterates to the next t
and gives you control in the middle of the loop.
for (u,t) in TimeChoiceIterator(integrator,0:dt:tend)
@show u,t
integrator.p = ... # modify the parameter before continuing
end
Great!
The following code gives an unexpected output:
Output:
I would expect the results at 0.5, 1, 1.5, 2.0 and 2.5 seconds simulation time.
Full example: https://github.com/ufechner7/KiteViewer/blob/sim/src/RTSim_bug.jl