Skip to content
This repository was archived by the owner on Apr 21, 2026. It is now read-only.

Commit 6b55c42

Browse files
committed
Test successive callbacks in same integration step
1 parent 3a9a2ca commit 6b55c42

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

test/downstream/community_callback_tests.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,34 @@ sol = solve(prob, DFBDF())
230230
# test that the callback flipping p caused u[2] to get flipped.
231231
first_t = findfirst(isequal(0.5), sol.t)
232232
@test sol.u[first_t][2] == -sol.u[first_t + 1][2]
233+
234+
# https://github.com/SciML/DiffEqBase.jl/issues/1231
235+
@testset "Successive callbacks in same integration step" begin
236+
cb = ContinuousCallback(
237+
(u, t, integrator) -> t - 0e-8,
238+
(integrator) -> push!(record, 0)
239+
)
240+
241+
vcb = VectorContinuousCallback(
242+
(out, u, t, integrator) -> out .= (t - 1e-8, t - 2e-8),
243+
(integrator, event_index) -> push!(record, event_index),
244+
2
245+
)
246+
247+
f(u, p, t) = 1.0
248+
u0 = 0.0
249+
250+
# Forward propagation with successive events
251+
record = []
252+
tspan = (-1.0, 1.0)
253+
prob = ODEProblem(f, u0, tspan)
254+
sol = solve(prob, Tsit5(), dt = 2.0, callback = CallbackSet(cb, vcb))
255+
@test record == [0, 1, 2]
256+
257+
# Backward propagation with successive events
258+
record = []
259+
tspan = (1.0, -1.0)
260+
prob = ODEProblem(f, u0, tspan)
261+
sol = solve(prob, Tsit5(), dt = 2.0, callback = CallbackSet(cb, vcb))
262+
@test record == [2, 1, 0]
263+
end

0 commit comments

Comments
 (0)