Skip to content

Commit 9d8eb55

Browse files
Merge pull request #556 from oscardssmith/patch-1
`finalize` callbacks
2 parents 23d434e + da5bf61 commit 9d8eb55

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/integrators/integrator_utils.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ end
221221
end
222222

223223
@inline function postamble!(integrator::SDEIntegrator)
224+
DiffEqBase.finalize!(integrator.opts.callback, integrator.u, integrator.t, integrator)
224225
solution_endpoint_match_cur_integrator!(integrator)
225226
resize!(integrator.sol.t,integrator.saveiter)
226227
resize!(integrator.sol.u,integrator.saveiter)

test/events_test.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,17 @@ tstop = [5.;8.]
5050
condition_dc = (u,t,integrator) -> t in tstop
5151
affect!_dc = (integrator) -> integrator.u .= 1.0
5252
save_positions = (true,true)
53-
callback_dc = DiscreteCallback(condition_dc, affect!_dc, save_positions=save_positions)
53+
times_finalize_called = 0
54+
callback_dc = DiscreteCallback(condition_dc, affect!_dc, save_positions=save_positions,
55+
finalize=(args...)->global times_finalize_called+=1)
5456
sol = solve(prob, SRIW1(), callback=callback_dc, tstops=tstop, saveat=tstop)
5557
@test count(x->x==tstop[1], sol.t) == 2
5658
@test count(x->x==tstop[2], sol.t) == 2
59+
@test times_finalize_called == 1
5760
sol = solve(prob, SRIW1(), callback=callback_dc, tstops=tstop, saveat=prevfloat.(tstop))
5861
@test count(x->x==tstop[1], sol.t) == 2
5962
@test count(x->x==tstop[2], sol.t) == 2
63+
@test times_finalize_called == 2
6064

6165

6266

0 commit comments

Comments
 (0)