In my code I need to check the status of my integrator, and if it got terminated (because of my own callback) I want to know about that.
But I have some difficulty with the MWE down below. It seems like the retcode does not change after
In this code I check for u if it is positive, and then terminate. But then I change the initial condition and the retcode is still
:Terminated (although the solution is perfectly good).
This may be an issue?
using DifferentialEquations f(u,p,t) = 2*u # the solution is positive or negative depends on the initial condition u_positive(u,t,integrator) = u > 0 terminate_if_u_pos = DiscreteCallback(u_positive, terminate!) prob = ODEProblem(f, 1.0, (0.0, 1.0)) # positive initial condition > positive u > :Terminated integrator = init(prob, Tsit5(), callback=terminate_if_u_pos) sol1 = solve!(integrator) @show sol1.retcode # should be :Terminated # julia> sol1.retcode = :Terminated reinit!(integrator, -1.0) # negative initial condition > negative u > :Success! sol2 = solve!(integrator) @show sol2.retcode # julia> sol2.retcode = :Terminated # but should be :Success like as to following code: prob = ODEProblem(f, -1.0,(0.0, 1.0)) # negative initial condition > negative u > :Success! integrator = init(prob, Tsit5(), callback=terminate_if_u_pos) sol3 = solve!(integrator) @show sol3.retcode # julia> sol3.retcode = :Success
Thanks a lot for the great community!