Skip to content
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

Integrator.sol.retcode does not update after reinit!(integrator) #861

Closed
Elycoo opened this issue May 3, 2022 · 0 comments · Fixed by SciML/OrdinaryDiffEq.jl#1662 or SciML/Sundials.jl#355

Comments

@Elycoo
Copy link

Elycoo commented May 3, 2022

Hi all,

It seems like the retcode of ODESolution does not change after reinit!, even if in the new initial condition the retcode should be :Success.

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).

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

Link for discourse discussion.

Thanks!

ChrisRackauckas added a commit to SciML/OrdinaryDiffEq.jl that referenced this issue May 14, 2022
ChrisRackauckas added a commit to SciML/Sundials.jl that referenced this issue May 14, 2022
ChrisRackauckas added a commit to SciML/Sundials.jl that referenced this issue May 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant