Skip to content

Commit 8be1ca5

Browse files
Merge pull request #2809 from dcourteville/fix_backward_callback
Add tests for event detection when step is exactly on event date
2 parents 8fdc610 + e7bd6c6 commit 8be1ca5

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/OrdinaryDiffEqCore/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Accessors = "0.1.36"
5151
Adapt = "3.0, 4"
5252
ArrayInterface = "7"
5353
DataStructures = "0.18"
54-
DiffEqBase = "6.169.1"
54+
DiffEqBase = "6.182.0"
5555
DiffEqDevTools = "2.44.4"
5656
DocStringExtensions = "0.9"
5757
EnumX = "1"

test/integrators/ode_event_tests.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ callback = ContinuousCallback(condition, affect!)
2222
sol = solve(prob, Tsit5(), callback = callback)
2323
@test length(sol) < 20
2424

25+
# Force integrator to step on event
26+
sol = solve(prob, Tsit5(), callback = callback, tstops = [-2.95])
27+
@test sol(-2.95, continuity = :right) sol(-2.95, continuity = :left) + 2
28+
2529
condition = function (out, u, t, integrator) # Event when event_f(u,t,k) == 0
2630
out[1] = -t - 2.95
2731
end
@@ -36,6 +40,10 @@ callback = VectorContinuousCallback(condition, affect!, 1)
3640

3741
sol = solve(prob, Tsit5(), callback = callback)
3842

43+
# Force integrator to step on event
44+
sol = solve(prob, Tsit5(), callback = callback, tstops = [-2.95])
45+
@test sol(-2.95, continuity = :right) sol(-2.95, continuity = :left) + 2
46+
3947
f = function (du, u, p, t)
4048
du[1] = -u[1] + sin(t)
4149
end
@@ -54,6 +62,10 @@ callback = ContinuousCallback(condition, affect!)
5462

5563
sol = solve(prob, Tsit5(), callback = callback, abstol = 1e-8, reltol = 1e-6)
5664

65+
# Force integrator to step on event
66+
sol = solve(prob, Tsit5(), callback = callback, abstol = 1e-8, reltol = 1e-6, tstops = [2.95])
67+
@test sol(2.95, continuity = :right)[1] sol(2.95, continuity = :left)[1] + 2
68+
5769
condition = function (out, u, t, integrator) # Event when event_f(u,t,k) == 0
5870
out[1] = t - 2.95
5971
end
@@ -68,6 +80,10 @@ callback = VectorContinuousCallback(condition, affect!, 1)
6880

6981
sol = solve(prob, Tsit5(), callback = callback, abstol = 1e-8, reltol = 1e-6)
7082

83+
# Force integrator to step on event
84+
sol = solve(prob, Tsit5(), callback = callback, abstol = 1e-8, reltol = 1e-6, tstops = [2.95])
85+
@test sol(2.95, continuity = :right)[1] sol(2.95, continuity = :left)[1] + 2
86+
7187
f = function (du, u, p, t)
7288
du[1] = u[2]
7389
du[2] = -9.81

0 commit comments

Comments
 (0)