Skip to content

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

@Elycoo

Description

@Elycoo

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions