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

Unexpected behavior with PresetTimeCallback #1022

Closed
aelmokadem opened this issue Mar 7, 2024 · 0 comments · Fixed by SciML/DiffEqCallbacks.jl#210
Closed

Unexpected behavior with PresetTimeCallback #1022

aelmokadem opened this issue Mar 7, 2024 · 0 comments · Fixed by SciML/DiffEqCallbacks.jl#210
Labels

Comments

@aelmokadem
Copy link

aelmokadem commented Mar 7, 2024

When defining callback events with PresetTimeCallback, I see strange behaviors that is different whether I include the 0 timepoint in the event times or define the callback event in ODEProblem or solve.

When 0 is included in the event times and the callback is defined within ODEProblem, the middle event is missed.
When 0 is included in the event times and the callback is defined within solve, all events are missed.

function mod(du, u, p, t)
    du[1] = -p[1]*u[1]
end

p = [1.0]
u0 = [10.0]
tspan = (0.0,72.0)

#dosetimes = [0.0:24.0:tspan[2];]
times1 = 0.0:24.0:tspan[2]
times2 = 24.0:24.0:tspan[2]
affect!(integrator) = integrator.u[1] += 10.0
cb1 = PresetTimeCallback(times1, affect!)
cb2 = PresetTimeCallback(times2, affect!)

# solve

prob1 = ODEProblem(mod, u0, tspan, p, callback=cb1)
prob2 = ODEProblem(mod, u0, tspan, p)

sol1 = solve(prob1)
sol2 = solve(prob2, callback=cb1)

plot(sol1, label="0 included in discrete times and callback defined in ODEProblem")
plot!(sol2, label="0 included in discrete times and callback defined in solve")
Screenshot 2024-03-07 at 10 31 09 AM

When 0 is removed from the event times and the callback is defined within ODEProblem, things look as expected.
When 0 is removed from the event times and the callback is defined within solve, all events are missed.

## remove 0 timepoint from callback times

prob1 = ODEProblem(mod, u0, tspan, p, callback=cb2)
prob2 = ODEProblem(mod, u0, tspan, p)

sol1 = solve(prob1)
sol2 = solve(prob2, callback=cb2)

plot(sol1, label="0 not included in discrete times and callback defined in ODEProblem")
plot!(sol2, label="0 not included in discrete times and callback defined in solve")
Screenshot 2024-03-07 at 10 32 35 AM
Pkg.status()
  [0c46a032] DifferentialEquations v7.13.0
  [91a5bcdd] Plots v1.40.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant