diff --git a/src/preset_time.jl b/src/preset_time.jl index 417386bb..8eeec723 100644 --- a/src/preset_time.jl +++ b/src/preset_time.jl @@ -4,6 +4,8 @@ PresetTimeCallback(tstops, user_affect!; initialize = DiffEqBase.INITIALIZE_DEFAULT, filter_tstops = true, kwargs...) + +PresetTimeCallback(user_affect!::Function, tstops; kwargs...) ``` A callback that adds callback `affect!` calls at preset times. No playing around with @@ -61,4 +63,8 @@ function PresetTimeCallback(tstops, user_affect!; DiscreteCallback(condition, user_affect!; initialize = initialize_preset, kwargs...) end +function PresetTimeCallback(affect!::Function, ts; kwargs...) + PresetTimeCallback(ts, affect!; kwargs...) +end + export PresetTimeCallback diff --git a/test/preset_time.jl b/test/preset_time.jl index be082135..6fbdda7c 100644 --- a/test/preset_time.jl +++ b/test/preset_time.jl @@ -21,6 +21,15 @@ sol = solve(prob, Tsit5(), callback = cb) @test 0.5 ∈ sol.t @test p != startp +# test do syntax +p .= startp # reset startp +cbdoo = PresetTimeCallback(0.5) do integrator + integrator.p .= rand(4, 4) +end +sol = solve(prob, Tsit5(), callback = cbdoo) +@test 0.5 ∈ sol.t +@test p != startp + p = rand(4, 4) startp = copy(p)