-
-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DifferentialEquations.jl does not save fields of custom types after the callback function #117
Comments
The plot reveals you hit a bug in the interpolation. Hold up and I'll have a solution soon. |
I don't know if that plot if from a different problem (the time goes from 0 to 30 and the discontinuity is at a different spot?), but I ran your code and saw the same wobblyness in the plot. This problem occured when there's a value which was both in Another thing that I had to handle though is the fact that discontinuities in the derivative mess with the interpolation. The fix is to save both before and after applying a discontinuous change. I fixed up the code to do this here: https://gist.github.com/ChrisRackauckas/fc2b439e3e35b22b145a836ab57d42ce which gives the solution: (with the patch applied, using Event HandlingThat makes me think I led you astray. I'm sorry! These are details that the event handling framework takes care of for you, so maybe I should have had you define an event instead! Here's the event-handling way. For events, you define a function which is const tstop = [5]
function event_f(t,u) # Event when event_f(t,u) == 0
t ∉ tstop
end Then you say what you want. This is the discontinuous change you defined before: function apply_event!(u,cache)
for c in cache
c.f1 = 1.5
end
end The const rootfind_event_loc = false
const interp_points = 0
callback = @ode_callback begin
@ode_event event_f apply_event! rootfind_event_loc interp_points
end The first part The code using events in its entirety can be found here: https://gist.github.com/ChrisRackauckas/44bd64d39255fd2a31ed0731c66401a1 and produces the following plot: I'll add this example to DiffEqTutorials.jl. |
Hi @ChrisRackauckas, Thank you very much! Don't need to apologize, it was my fault since I did not describe the problem deeply enough. I will port the code to use those events. My only question is: inside the |
Not yet, but that's in the plan: (Feel free to comment there on the kinds of things you need in events and callbacks!) If you need it right now, I can help you get it going. It should be as simple as making |
hi @ChrisRackauckas, When I finish this simulator, I can make a PR. My workaround was very simple: I created a global variable |
Fixed by the new callbacks + cache iterators. |
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.jl
does 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:
Hence, I was expecting that
u[1]
becomes different ofu[2]
fort > 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:
The 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.
The text was updated successfully, but these errors were encountered: