-
-
Notifications
You must be signed in to change notification settings - Fork 122
Closed
Labels
Description
Describe the bug π
When multiple distinct callbacks occur in an single time step during backward integration, the integrator will step to the last occurring callback (in the integration direction) instead of the first.
This is caused by this date comparison that doesn't account for integration direction :
I will open a pull request with the fix.
Minimal Reproducible Example π
using OrdinaryDiffEq, Test
cb = ContinuousCallback(
(u, t, integrator) -> t - 0e-8,
(integrator) -> push!(record, 0)
)
vcb = VectorContinuousCallback(
(out, u, t, integrator) -> out .= (t - 1e-8, t - 2e-8),
(integrator, event_index) -> push!(record, event_index),
2
)
f(u, p, t) = 1.0
u0 = 0.0
# Forward propagation with successive events
record = []
tspan = (-1.0, 1.0)
prob = ODEProblem(f, u0, tspan)
sol = solve(prob, Tsit5(), dt=2.0, callback=CallbackSet(cb, vcb))
@test record == [0,1,2]
# Backward propagation with successive events
record = []
tspan = (1.0, -1.0)
prob = ODEProblem(f, u0, tspan)
sol = solve(prob, Tsit5(), dt=2.0, callback=CallbackSet(cb, vcb))
@test record == [2,1,0] # FailEnvironment (please complete the following information):
- Output of
using Pkg; Pkg.status()
[1dea7af3] OrdinaryDiffEq v6.104.0