From 08b47f2bedeb9cd488322e2295d4cba38e4e0fab Mon Sep 17 00:00:00 2001 From: LasNikas Date: Fri, 19 Apr 2024 12:20:01 +0200 Subject: [PATCH] remove update bool --- src/callbacks/update.jl | 24 ++++++++++-------------- test/callbacks/update.jl | 17 ----------------- 2 files changed, 10 insertions(+), 31 deletions(-) diff --git a/src/callbacks/update.jl b/src/callbacks/update.jl index 5bbf6fe9d..d370783b7 100644 --- a/src/callbacks/update.jl +++ b/src/callbacks/update.jl @@ -1,6 +1,5 @@ struct UpdateCallback{I} - interval :: I - update :: Bool + interval::I end """ @@ -14,7 +13,7 @@ regular intervals at `dt` in terms of integration time. - `interval`: Update quantities at the end of every `interval` time steps (default `interval=1`) - `dt`: Update quantities in regular intervals of `dt` in terms of integration time """ -function UpdateCallback(; update=true, interval::Integer=-1, dt=0.0) +function UpdateCallback(; interval::Integer=-1, dt=0.0) if dt > 0 && interval !== -1 throw(ArgumentError("Setting both interval and dt is not supported!")) end @@ -24,13 +23,13 @@ function UpdateCallback(; update=true, interval::Integer=-1, dt=0.0) interval = Float64(dt) # Update every time step (default) - elseif update && interval == -1 + elseif interval == -1 interval = 1 end - update_callback! = UpdateCallback(interval, update) + update_callback! = UpdateCallback(interval) - if dt > 0 && update + if dt > 0 # Add a `tstop` every `dt`, and save the final solution. return PeriodicCallback(update_callback!, dt, initialize=initial_update!, @@ -52,18 +51,18 @@ function initial_update!(cb, u, t, integrator) initial_update!(cb.affect!, u, t, integrator) end -initial_update!(cb::UpdateCallback, u, t, integrator) = cb.update && cb(integrator) +initial_update!(cb::UpdateCallback, u, t, integrator) = cb(integrator) # condition function (update_callback!::UpdateCallback)(u, t, integrator) - (; interval, update) = update_callback! + (; interval) = update_callback! # With error-based step size control, some steps can be rejected. Thus, # `integrator.iter >= integrator.stats.naccept` # (total #steps) (#accepted steps) # We need to check the number of accepted steps since callbacks are not # activated after a rejected step. - return update && (integrator.stats.naccept % interval == 0) + return integrator.stats.naccept % interval == 0 end # affect @@ -93,8 +92,7 @@ end function Base.show(io::IO, cb::DiscreteCallback{<:Any, <:UpdateCallback}) @nospecialize cb # reduce precompilation time - print(io, "UpdateCallback(interval=", (cb.affect!.update ? cb.affect!.interval : "-"), - ")") + print(io, "UpdateCallback(interval=", cb.affect!.interval, ")") end function Base.show(io::IO, @@ -113,8 +111,7 @@ function Base.show(io::IO, ::MIME"text/plain", else update_cb = cb.affect! setup = [ - "interval" => update_cb.update ? update_cb.interval : "-", - "update" => update_cb.update ? "yes" : "no", + "interval" => update_cb.interval, ] summary_box(io, "UpdateCallback", setup) end @@ -131,7 +128,6 @@ function Base.show(io::IO, ::MIME"text/plain", update_cb = cb.affect!.affect! setup = [ "dt" => update_cb.interval, - "update" => update_cb.update ? "yes" : "no", ] summary_box(io, "UpdateCallback", setup) end diff --git a/test/callbacks/update.jl b/test/callbacks/update.jl index 5515b94a6..180f0bb97 100644 --- a/test/callbacks/update.jl +++ b/test/callbacks/update.jl @@ -11,7 +11,6 @@ │ UpdateCallback │ │ ══════════════ │ │ interval: ……………………………………………………… 1 │ - │ update: …………………………………………………………… yes │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" @test repr("text/plain", callback0) == show_box @@ -25,7 +24,6 @@ │ UpdateCallback │ │ ══════════════ │ │ interval: ……………………………………………………… 11 │ - │ update: …………………………………………………………… yes │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" @test repr("text/plain", callback1) == show_box @@ -39,23 +37,8 @@ │ UpdateCallback │ │ ══════════════ │ │ dt: ……………………………………………………………………… 1.2 │ - │ update: …………………………………………………………… yes │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" @test repr("text/plain", callback2) == show_box - - callback3 = UpdateCallback(update=false) - - show_compact = "UpdateCallback(interval=-)" - @test repr(callback3) == show_compact - - show_box = """ - ┌──────────────────────────────────────────────────────────────────────────────────────────────────┐ - │ UpdateCallback │ - │ ══════════════ │ - │ interval: ……………………………………………………… - │ - │ update: …………………………………………………………… no │ - └──────────────────────────────────────────────────────────────────────────────────────────────────┘""" - @test repr("text/plain", callback3) == show_box end @testset "Illegal Input" begin