From 824f7a8a5e433c8deb29245bf9a79c3558bce397 Mon Sep 17 00:00:00 2001 From: Daniel Doehring Date: Thu, 28 Nov 2024 18:20:38 +0100 Subject: [PATCH] Time StepCallbacks for custom integrators (#2182) --- src/time_integration/methods_2N.jl | 14 ++++++++------ src/time_integration/methods_3Sstar.jl | 14 ++++++++------ src/time_integration/methods_SSP.jl | 15 +++++++++------ 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/time_integration/methods_2N.jl b/src/time_integration/methods_2N.jl index 1143e4ecb93..fb2847e1c91 100644 --- a/src/time_integration/methods_2N.jl +++ b/src/time_integration/methods_2N.jl @@ -189,13 +189,15 @@ function step!(integrator::SimpleIntegrator2N) integrator.iter += 1 integrator.t += integrator.dt - # handle callbacks - if callbacks isa CallbackSet - foreach(callbacks.discrete_callbacks) do cb - if cb.condition(integrator.u, integrator.t, integrator) - cb.affect!(integrator) + @trixi_timeit timer() "Step-Callbacks" begin + # handle callbacks + if callbacks isa CallbackSet + foreach(callbacks.discrete_callbacks) do cb + if cb.condition(integrator.u, integrator.t, integrator) + cb.affect!(integrator) + end + return nothing end - return nothing end end diff --git a/src/time_integration/methods_3Sstar.jl b/src/time_integration/methods_3Sstar.jl index a3ab023b64b..f197ef60902 100644 --- a/src/time_integration/methods_3Sstar.jl +++ b/src/time_integration/methods_3Sstar.jl @@ -265,13 +265,15 @@ function step!(integrator::SimpleIntegrator3Sstar) integrator.iter += 1 integrator.t += integrator.dt - # handle callbacks - if callbacks isa CallbackSet - foreach(callbacks.discrete_callbacks) do cb - if cb.condition(integrator.u, integrator.t, integrator) - cb.affect!(integrator) + @trixi_timeit timer() "Step-Callbacks" begin + # handle callbacks + if callbacks isa CallbackSet + foreach(callbacks.discrete_callbacks) do cb + if cb.condition(integrator.u, integrator.t, integrator) + cb.affect!(integrator) + end + return nothing end - return nothing end end diff --git a/src/time_integration/methods_SSP.jl b/src/time_integration/methods_SSP.jl index ffbc325c82a..33d1f164138 100644 --- a/src/time_integration/methods_SSP.jl +++ b/src/time_integration/methods_SSP.jl @@ -39,7 +39,7 @@ struct SimpleSSPRK33{StageCallbacks} <: SimpleAlgorithmSSP c = SVector(0.0, 1.0, 1 / 2) # Butcher tableau - # c | a + # c | A # 0 | # 1 | 1 # 1/2 | 1/4 1/4 @@ -208,11 +208,14 @@ function solve!(integrator::SimpleIntegratorSSP) integrator.iter += 1 integrator.t += integrator.dt - # handle callbacks - if callbacks isa CallbackSet - foreach(callbacks.discrete_callbacks) do cb - if cb.condition(integrator.u, integrator.t, integrator) - cb.affect!(integrator) + @trixi_timeit timer() "Step-Callbacks" begin + # handle callbacks + if callbacks isa CallbackSet + foreach(callbacks.discrete_callbacks) do cb + if cb.condition(integrator.u, integrator.t, integrator) + cb.affect!(integrator) + end + return nothing end end end