-
-
Notifications
You must be signed in to change notification settings - Fork 243
Description
Hi guys!
I am using DifferentialEquations.jl to simulate a satellite with continuous and discrete algorithms. @ChrisRackauckas helped me and the full discussion about it can be found here:
https://discourse.julialang.org/t/get-values-of-symbols-inside-a-function/848
However, I had a problem because I needed to modify custom fields of my new type inside the callback function and use those values in the next integration step. It turns out that DifferentialEquation.jldoes not save those values as I am expecting. Consider the following simplified example:
https://gist.github.com/ronisbr/1cac82902f78cf33ad732df79a5bd369
The dynamic function and callbacks are:
function f(t,u,du)
du[1] = -0.5*u[1] + u.f1
du[2] = -0.5*u[2]
end
callback = @ode_callback begin
if t > 5
u.f1 = 1.5
end
@ode_savevalues
endHence, I was expecting that u[1] becomes different of u[2] for t > 5. However, it does not happen as we can see in the following figure:
@ChrisRackauckas pointed out that in order to make this work, I need modify the callback function as described next:
callback = @ode_callback begin
if t > 5
for c in cache
c.f1 = 1.5
end
end
@ode_savevalues
endThe full code can be seen here:
https://gist.github.com/ronisbr/2883ffd81abcc379a259f13faf2b92ea
Now, the result is:
It does not seem a bug, as @ChrisRackauckas said, but it really should be documented.

