From 73902560c70ecf32597872bbaa878d20e300b97d Mon Sep 17 00:00:00 2001 From: Martijn Visser Date: Tue, 2 Apr 2024 21:25:07 +0200 Subject: [PATCH] PresetTimeCallback: filter out tstop of 0.0 --- src/preset_time.jl | 2 +- test/preset_time.jl | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/preset_time.jl b/src/preset_time.jl index 10cf94fb..4c327b70 100644 --- a/src/preset_time.jl +++ b/src/preset_time.jl @@ -62,7 +62,7 @@ function PresetTimeCallback(tstops, user_affect!; if filter_tstops tdir = integrator.tdir tspan = integrator.sol.prob.tspan - _tstops = tstops[@. tdir * tspan[1] <= tdir * tstops < tdir * tspan[2]] + _tstops = tstops[@. tdir * tspan[1] < tdir * tstops < tdir * tspan[2]] add_tstop!.((integrator,), _tstops) else add_tstop!.((integrator,), tstops) diff --git a/test/preset_time.jl b/test/preset_time.jl index 9949504a..70c550b0 100644 --- a/test/preset_time.jl +++ b/test/preset_time.jl @@ -25,8 +25,11 @@ p = rand(4, 4) startp = copy(p) prob = ODEProblem(some_dynamics, u0, tspan, p) -cb = PresetTimeCallback([0.3, 0.6], integrator -> integrator.p .= rand(4, 4)) -sol = solve(prob, Tsit5(), callback = cb) +cb = PresetTimeCallback([0.0, 0.3, 0.6], integrator -> integrator.p .= rand(4, 4)) +integrator = init(prob, Tsit5(), callback = cb) +@test first_tstop(integrator) == 0.3 +solve!(integrator) +sol = integrator.sol @test 0.3 ∈ sol.t @test 0.6 ∈ sol.t @test p != startp