Skip to content

Commit

Permalink
Merge pull request #215 from visr/gt
Browse files Browse the repository at this point in the history
PresetTimeCallback: filter out tstop of 0.0
  • Loading branch information
ChrisRackauckas authored Apr 11, 2024
2 parents 669dc33 + 7390256 commit de1e035
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/preset_time.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions test/preset_time.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit de1e035

Please sign in to comment.