From 1ba20926010e7882e5ecbc4d45999558a859dea7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Rueda-Ram=C3=ADrez?= Date: Wed, 18 Oct 2023 17:11:19 +0200 Subject: [PATCH 01/11] First attempt to enable save solution with time intervals for SimpleIntegratorSSP --- Project.toml | 1 + .../elixir_euler_shockcapturing_subcell.jl | 2 +- src/Trixi.jl | 1 + src/time_integration/methods_SSP.jl | 26 ++++++++++++++----- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Project.toml b/Project.toml index d318389a6d2..a61928ca33e 100644 --- a/Project.toml +++ b/Project.toml @@ -42,6 +42,7 @@ TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f" Triangulate = "f7e6ffb2-c36d-4f8f-a77e-16e897189344" TriplotBase = "981d1d27-644d-49a2-9326-4793e63143c3" TriplotRecipes = "808ab39a-a642-4abf-81ff-4cb34ebbffa3" +DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" [weakdeps] Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" diff --git a/examples/tree_2d_dgsem/elixir_euler_shockcapturing_subcell.jl b/examples/tree_2d_dgsem/elixir_euler_shockcapturing_subcell.jl index 6b69e4db563..2b9dd466f0d 100644 --- a/examples/tree_2d_dgsem/elixir_euler_shockcapturing_subcell.jl +++ b/examples/tree_2d_dgsem/elixir_euler_shockcapturing_subcell.jl @@ -68,7 +68,7 @@ analysis_callback = AnalysisCallback(semi, interval=analysis_interval) alive_callback = AliveCallback(analysis_interval=analysis_interval) -save_solution = SaveSolutionCallback(interval=100, +save_solution = SaveSolutionCallback(dt=0.1, save_initial_solution=true, save_final_solution=true, solution_variables=cons2prim) diff --git a/src/Trixi.jl b/src/Trixi.jl index b65d03e7975..67621ad8fce 100644 --- a/src/Trixi.jl +++ b/src/Trixi.jl @@ -70,6 +70,7 @@ using TriplotBase: TriplotBase using TriplotRecipes: DGTriPseudocolor @reexport using SimpleUnPack: @unpack using SimpleUnPack: @pack! +using DataStructures: BinaryHeap, FasterForward # finite difference SBP operators using SummationByPartsOperators: AbstractDerivativeOperator, diff --git a/src/time_integration/methods_SSP.jl b/src/time_integration/methods_SSP.jl index a0ed889968a..8fb58213f2b 100644 --- a/src/time_integration/methods_SSP.jl +++ b/src/time_integration/methods_SSP.jl @@ -50,17 +50,19 @@ struct SimpleSSPRK33{StageCallbacks} <: SimpleAlgorithmSSP end # This struct is needed to fake https://github.com/SciML/OrdinaryDiffEq.jl/blob/0c2048a502101647ac35faabd80da8a5645beac7/src/integrators/type.jl#L1 -mutable struct SimpleIntegratorSSPOptions{Callback} +mutable struct SimpleIntegratorSSPOptions{Callback, TStops} callback::Callback # callbacks; used in Trixi adaptive::Bool # whether the algorithm is adaptive; ignored dtmax::Float64 # ignored maxiters::Int # maximal number of time steps - tstops::Vector{Float64} # tstops from https://diffeq.sciml.ai/v6.8/basics/common_solver_opts/#Output-Control-1; ignored + tstops::TStops # tstops from https://diffeq.sciml.ai/v6.8/basics/common_solver_opts/#Output-Control-1; ignored end function SimpleIntegratorSSPOptions(callback, tspan; maxiters = typemax(Int), kwargs...) - SimpleIntegratorSSPOptions{typeof(callback)}(callback, false, Inf, maxiters, - [last(tspan)]) + tstops_internal = BinaryHeap{eltype(tspan)}(FasterForward()) + push!(tstops_internal, last(tspan)) + SimpleIntegratorSSPOptions{typeof(callback), typeof(tstops_internal)}(callback, false, Inf, maxiters, + tstops_internal) end # This struct is needed to fake https://github.com/SciML/OrdinaryDiffEq.jl/blob/0c2048a502101647ac35faabd80da8a5645beac7/src/integrators/type.jl#L77 @@ -73,6 +75,7 @@ mutable struct SimpleIntegratorSSP{RealT <: Real, uType, Params, Sol, F, Alg, du::uType r0::uType t::RealT + tdir::RealT dt::RealT # current time step dtcache::RealT # ignored iter::Int # current number of time steps (iteration) @@ -84,6 +87,16 @@ mutable struct SimpleIntegratorSSP{RealT <: Real, uType, Params, Sol, F, Alg, finalstep::Bool # added for convenience end +""" + add_tstop!(integrator::SimpleIntegratorSSP, t) +Add +""" +function add_tstop!(integrator::SimpleIntegratorSSP, t) + integrator.tdir * (t - integrator.t) < zero(integrator.t) && + error("Tried to add a tstop that is behind the current time. This is strictly forbidden") + push!(integrator.opts.tstops, integrator.tdir * t) +end + # Forward integrator.stats.naccept to integrator.iter (see GitHub PR#771) function Base.getproperty(integrator::SimpleIntegratorSSP, field::Symbol) if field === :stats @@ -108,8 +121,9 @@ function solve(ode::ODEProblem, alg = SimpleSSPRK33()::SimpleAlgorithmSSP; du = similar(u) r0 = similar(u) t = first(ode.tspan) + tdir = sign(ode.tspan[end] - ode.tspan[1]) iter = 0 - integrator = SimpleIntegratorSSP(u, du, r0, t, dt, zero(dt), iter, ode.p, + integrator = SimpleIntegratorSSP(u, du, r0, t, tdir, dt, zero(dt), iter, ode.p, (prob = ode,), ode.f, alg, SimpleIntegratorSSPOptions(callback, ode.tspan; kwargs...), false) @@ -216,7 +230,7 @@ end # stop the time integration function terminate!(integrator::SimpleIntegratorSSP) integrator.finalstep = true - empty!(integrator.opts.tstops) + #empty!(integrator.opts.tstops) end # used for AMR From e05363d74ac684fce05b944029e62872b30939af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Rueda-Ram=C3=ADrez?= Date: Thu, 19 Oct 2023 09:44:15 +0200 Subject: [PATCH 02/11] Importing `add_tstop!` --- src/Trixi.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Trixi.jl b/src/Trixi.jl index 67621ad8fce..62d66f62b4d 100644 --- a/src/Trixi.jl +++ b/src/Trixi.jl @@ -37,7 +37,7 @@ using SciMLBase: CallbackSet, DiscreteCallback, import SciMLBase: get_du, get_tmp_cache, u_modified!, AbstractODEIntegrator, init, step!, check_error, get_proposed_dt, set_proposed_dt!, - terminate!, remake + terminate!, remake, add_tstop! using CodeTracking: CodeTracking using ConstructionBase: ConstructionBase using DiffEqCallbacks: PeriodicCallback, PeriodicCallbackAffect From 64e97843e51dc436e889aebcf46f669242f20b1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Rueda-Ram=C3=ADrez?= Date: Thu, 19 Oct 2023 11:10:31 +0200 Subject: [PATCH 03/11] First working version of SimpleIntegratorSSP with SaveSolutionCallback using time intervals --- Project.toml | 1 + src/Trixi.jl | 3 ++- src/time_integration/methods_SSP.jl | 16 +++++++++++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Project.toml b/Project.toml index a61928ca33e..28a5b1d66d2 100644 --- a/Project.toml +++ b/Project.toml @@ -43,6 +43,7 @@ Triangulate = "f7e6ffb2-c36d-4f8f-a77e-16e897189344" TriplotBase = "981d1d27-644d-49a2-9326-4793e63143c3" TriplotRecipes = "808ab39a-a642-4abf-81ff-4cb34ebbffa3" DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" +OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" [weakdeps] Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" diff --git a/src/Trixi.jl b/src/Trixi.jl index 62d66f62b4d..530b61d2ac5 100644 --- a/src/Trixi.jl +++ b/src/Trixi.jl @@ -37,7 +37,8 @@ using SciMLBase: CallbackSet, DiscreteCallback, import SciMLBase: get_du, get_tmp_cache, u_modified!, AbstractODEIntegrator, init, step!, check_error, get_proposed_dt, set_proposed_dt!, - terminate!, remake, add_tstop! + terminate!, remake, add_tstop!, has_tstop, first_tstop +using OrdinaryDiffEq: modify_dt_for_tstops! using CodeTracking: CodeTracking using ConstructionBase: ConstructionBase using DiffEqCallbacks: PeriodicCallback, PeriodicCallbackAffect diff --git a/src/time_integration/methods_SSP.jl b/src/time_integration/methods_SSP.jl index 8fb58213f2b..ac70e3c870b 100644 --- a/src/time_integration/methods_SSP.jl +++ b/src/time_integration/methods_SSP.jl @@ -60,7 +60,7 @@ end function SimpleIntegratorSSPOptions(callback, tspan; maxiters = typemax(Int), kwargs...) tstops_internal = BinaryHeap{eltype(tspan)}(FasterForward()) - push!(tstops_internal, last(tspan)) + push!(tstops_internal, 2 * last(tspan)) SimpleIntegratorSSPOptions{typeof(callback), typeof(tstops_internal)}(callback, false, Inf, maxiters, tstops_internal) end @@ -85,6 +85,8 @@ mutable struct SimpleIntegratorSSP{RealT <: Real, uType, Params, Sol, F, Alg, alg::Alg opts::SimpleIntegratorSSPOptions finalstep::Bool # added for convenience + dtchangeable::Bool + force_stepfail::Bool end """ @@ -94,9 +96,15 @@ Add function add_tstop!(integrator::SimpleIntegratorSSP, t) integrator.tdir * (t - integrator.t) < zero(integrator.t) && error("Tried to add a tstop that is behind the current time. This is strictly forbidden") + if length(integrator.opts.tstops) > 1 + pop!(integrator.opts.tstops) + end push!(integrator.opts.tstops, integrator.tdir * t) end +has_tstop(integrator::SimpleIntegratorSSP) = !isempty(integrator.opts.tstops) +first_tstop(integrator::SimpleIntegratorSSP) = first(integrator.opts.tstops) + # Forward integrator.stats.naccept to integrator.iter (see GitHub PR#771) function Base.getproperty(integrator::SimpleIntegratorSSP, field::Symbol) if field === :stats @@ -126,7 +134,7 @@ function solve(ode::ODEProblem, alg = SimpleSSPRK33()::SimpleAlgorithmSSP; integrator = SimpleIntegratorSSP(u, du, r0, t, tdir, dt, zero(dt), iter, ode.p, (prob = ode,), ode.f, alg, SimpleIntegratorSSPOptions(callback, ode.tspan; - kwargs...), false) + kwargs...), false, true, false) # resize container resize!(integrator.p, nelements(integrator.p.solver, integrator.p.cache)) @@ -169,6 +177,8 @@ function solve!(integrator::SimpleIntegratorSSP) terminate!(integrator) end + modify_dt_for_tstops!(integrator) + @. integrator.r0 = integrator.u for stage in eachindex(alg.c) t_stage = integrator.t + integrator.dt * alg.c[stage] @@ -190,7 +200,7 @@ function solve!(integrator::SimpleIntegratorSSP) integrator.iter += 1 integrator.t += integrator.dt - + # handle callbacks if callbacks isa CallbackSet for cb in callbacks.discrete_callbacks From 05fcaaa8d8d7d6f44dfd8a307729b2242d37f3bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Rueda-Ram=C3=ADrez?= Date: Thu, 19 Oct 2023 11:16:06 +0200 Subject: [PATCH 04/11] Improved formatting and updated reference solution for test --- src/time_integration/methods_SSP.jl | 13 ++++++++----- test/test_tree_2d_euler.jl | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/time_integration/methods_SSP.jl b/src/time_integration/methods_SSP.jl index ac70e3c870b..424c25ec398 100644 --- a/src/time_integration/methods_SSP.jl +++ b/src/time_integration/methods_SSP.jl @@ -61,8 +61,10 @@ end function SimpleIntegratorSSPOptions(callback, tspan; maxiters = typemax(Int), kwargs...) tstops_internal = BinaryHeap{eltype(tspan)}(FasterForward()) push!(tstops_internal, 2 * last(tspan)) - SimpleIntegratorSSPOptions{typeof(callback), typeof(tstops_internal)}(callback, false, Inf, maxiters, - tstops_internal) + SimpleIntegratorSSPOptions{typeof(callback), typeof(tstops_internal)}(callback, + false, Inf, + maxiters, + tstops_internal) end # This struct is needed to fake https://github.com/SciML/OrdinaryDiffEq.jl/blob/0c2048a502101647ac35faabd80da8a5645beac7/src/integrators/type.jl#L77 @@ -96,7 +98,7 @@ Add function add_tstop!(integrator::SimpleIntegratorSSP, t) integrator.tdir * (t - integrator.t) < zero(integrator.t) && error("Tried to add a tstop that is behind the current time. This is strictly forbidden") - if length(integrator.opts.tstops) > 1 + if length(integrator.opts.tstops) > 1 pop!(integrator.opts.tstops) end push!(integrator.opts.tstops, integrator.tdir * t) @@ -134,7 +136,8 @@ function solve(ode::ODEProblem, alg = SimpleSSPRK33()::SimpleAlgorithmSSP; integrator = SimpleIntegratorSSP(u, du, r0, t, tdir, dt, zero(dt), iter, ode.p, (prob = ode,), ode.f, alg, SimpleIntegratorSSPOptions(callback, ode.tspan; - kwargs...), false, true, false) + kwargs...), + false, true, false) # resize container resize!(integrator.p, nelements(integrator.p.solver, integrator.p.cache)) @@ -200,7 +203,7 @@ function solve!(integrator::SimpleIntegratorSSP) integrator.iter += 1 integrator.t += integrator.dt - + # handle callbacks if callbacks isa CallbackSet for cb in callbacks.discrete_callbacks diff --git a/test/test_tree_2d_euler.jl b/test/test_tree_2d_euler.jl index 1b8a261a60d..e5db2764eaa 100644 --- a/test/test_tree_2d_euler.jl +++ b/test/test_tree_2d_euler.jl @@ -65,8 +65,8 @@ EXAMPLES_DIR = pkgdir(Trixi, "examples", "tree_2d_dgsem") @trixi_testset "elixir_euler_shockcapturing_subcell.jl" begin @test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_shockcapturing_subcell.jl"), - l2 = [0.08508147906199143, 0.04510299017724501, 0.045103019801950375, 0.6930704343869766], - linf = [0.31123546471463326, 0.5616274869594462, 0.5619692712224448, 2.88670199345138]) + l2 = [0.08508152653623638, 0.04510301725066843, 0.04510304668512745, 0.6930705064715306], + linf = [0.31136518019691406, 0.5617651935473419, 0.5621200790240503, 2.8866869108596056]) end @trixi_testset "elixir_euler_blast_wave.jl" begin From 71f5c7ad348efe48c10b4a79f505645c0fe9a3ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Rueda-Ram=C3=ADrez?= Date: Thu, 19 Oct 2023 12:48:21 +0200 Subject: [PATCH 05/11] Modified initialization of tstops to ensure a stop at the end of the simulation --- src/time_integration/methods_SSP.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/time_integration/methods_SSP.jl b/src/time_integration/methods_SSP.jl index 424c25ec398..7865e1d0963 100644 --- a/src/time_integration/methods_SSP.jl +++ b/src/time_integration/methods_SSP.jl @@ -60,6 +60,7 @@ end function SimpleIntegratorSSPOptions(callback, tspan; maxiters = typemax(Int), kwargs...) tstops_internal = BinaryHeap{eltype(tspan)}(FasterForward()) + push!(tstops_internal, last(tspan)) push!(tstops_internal, 2 * last(tspan)) SimpleIntegratorSSPOptions{typeof(callback), typeof(tstops_internal)}(callback, false, Inf, From df34188653685d968dee8c8a8651a404a1e2d354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Rueda-Ram=C3=ADrez?= Date: Mon, 23 Oct 2023 11:44:54 +0200 Subject: [PATCH 06/11] Added missing docstring --- src/time_integration/methods_SSP.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/time_integration/methods_SSP.jl b/src/time_integration/methods_SSP.jl index 7865e1d0963..effe5a85de5 100644 --- a/src/time_integration/methods_SSP.jl +++ b/src/time_integration/methods_SSP.jl @@ -94,7 +94,7 @@ end """ add_tstop!(integrator::SimpleIntegratorSSP, t) -Add +Add a time stop during the time integration process. """ function add_tstop!(integrator::SimpleIntegratorSSP, t) integrator.tdir * (t - integrator.t) < zero(integrator.t) && From d04fd98125dee4ff54f544ecdc2c7ce504c8f98d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Rueda-Ram=C3=ADrez?= Date: Mon, 23 Oct 2023 12:02:24 +0200 Subject: [PATCH 07/11] Removed OrdinaryDiffEq from Trixi's dependencies --- Project.toml | 1 - src/Trixi.jl | 2 +- src/time_integration/methods_SSP.jl | 24 ++++++++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 28a5b1d66d2..a61928ca33e 100644 --- a/Project.toml +++ b/Project.toml @@ -43,7 +43,6 @@ Triangulate = "f7e6ffb2-c36d-4f8f-a77e-16e897189344" TriplotBase = "981d1d27-644d-49a2-9326-4793e63143c3" TriplotRecipes = "808ab39a-a642-4abf-81ff-4cb34ebbffa3" DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" -OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" [weakdeps] Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" diff --git a/src/Trixi.jl b/src/Trixi.jl index 530b61d2ac5..ea96ad694b4 100644 --- a/src/Trixi.jl +++ b/src/Trixi.jl @@ -38,7 +38,7 @@ import SciMLBase: get_du, get_tmp_cache, u_modified!, AbstractODEIntegrator, init, step!, check_error, get_proposed_dt, set_proposed_dt!, terminate!, remake, add_tstop!, has_tstop, first_tstop -using OrdinaryDiffEq: modify_dt_for_tstops! + using CodeTracking: CodeTracking using ConstructionBase: ConstructionBase using DiffEqCallbacks: PeriodicCallback, PeriodicCallbackAffect diff --git a/src/time_integration/methods_SSP.jl b/src/time_integration/methods_SSP.jl index effe5a85de5..f13a8b84ac8 100644 --- a/src/time_integration/methods_SSP.jl +++ b/src/time_integration/methods_SSP.jl @@ -247,6 +247,30 @@ function terminate!(integrator::SimpleIntegratorSSP) #empty!(integrator.opts.tstops) end +""" + modify_dt_for_tstops!(integrator::SimpleIntegratorSSP) +Modify the time-step size to match the time stops specified in integrator.opts.tstops. +To avoid adding OrdinaryDiffEq to Trixi's dependencies, this routine is a copy of +https://github.com/SciML/OrdinaryDiffEq.jl/blob/d76335281c540ee5a6d1bd8bb634713e004f62ee/src/integrators/integrator_utils.jl#L38-L54 +""" +function modify_dt_for_tstops!(integrator::SimpleIntegratorSSP) + if has_tstop(integrator) + tdir_t = integrator.tdir * integrator.t + tdir_tstop = first_tstop(integrator) + if integrator.opts.adaptive + integrator.dt = integrator.tdir * + min(abs(integrator.dt), abs(tdir_tstop - tdir_t)) # step! to the end + elseif iszero(integrator.dtcache) && integrator.dtchangeable + integrator.dt = integrator.tdir * abs(tdir_tstop - tdir_t) + elseif integrator.dtchangeable && !integrator.force_stepfail + # always try to step! with dtcache, but lower if a tstop + # however, if force_stepfail then don't set to dtcache, and no tstop worry + integrator.dt = integrator.tdir * + min(abs(integrator.dtcache), abs(tdir_tstop - tdir_t)) # step! to the end + end + end +end + # used for AMR function Base.resize!(integrator::SimpleIntegratorSSP, new_size) resize!(integrator.u, new_size) From 7aa515b5ca79a237067360fb454d1f19defe0041 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Rueda-Ram=C3=ADrez?= Date: Mon, 23 Oct 2023 12:24:03 +0200 Subject: [PATCH 08/11] Empty tstops BinaryHeap during the call to `terminate!(integrator::SimpleIntegratorSSP)` --- src/time_integration/methods_SSP.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/time_integration/methods_SSP.jl b/src/time_integration/methods_SSP.jl index 09d4e91a434..2b598e1ae3b 100644 --- a/src/time_integration/methods_SSP.jl +++ b/src/time_integration/methods_SSP.jl @@ -249,7 +249,7 @@ end # stop the time integration function terminate!(integrator::SimpleIntegratorSSP) integrator.finalstep = true - #empty!(integrator.opts.tstops) + extract_all!(tstops_internal) end """ From 4322f5b53ec6b56c96114405a8f82553d8b335e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Rueda-Ram=C3=ADrez?= Date: Mon, 23 Oct 2023 13:05:12 +0200 Subject: [PATCH 09/11] Fixed bug and added explanatory comments --- src/Trixi.jl | 2 +- src/time_integration/methods_SSP.jl | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Trixi.jl b/src/Trixi.jl index aa947d00510..dd9fda5d324 100644 --- a/src/Trixi.jl +++ b/src/Trixi.jl @@ -71,7 +71,7 @@ using TriplotBase: TriplotBase using TriplotRecipes: DGTriPseudocolor @reexport using SimpleUnPack: @unpack using SimpleUnPack: @pack! -using DataStructures: BinaryHeap, FasterForward +using DataStructures: BinaryHeap, FasterForward, extract_all! # finite difference SBP operators using SummationByPartsOperators: AbstractDerivativeOperator, diff --git a/src/time_integration/methods_SSP.jl b/src/time_integration/methods_SSP.jl index 2b598e1ae3b..2234293a1ed 100644 --- a/src/time_integration/methods_SSP.jl +++ b/src/time_integration/methods_SSP.jl @@ -65,7 +65,10 @@ end function SimpleIntegratorSSPOptions(callback, tspan; maxiters = typemax(Int), kwargs...) tstops_internal = BinaryHeap{eltype(tspan)}(FasterForward()) + # We add last(tspan) to make sure that the time integration stops at the end time push!(tstops_internal, last(tspan)) + # We add 2 * last(tspan) because add_tstop!(integrator, t) is only called by DiffEqCallbacks.jl if tstops contains a time that is larger than t + # (https://github.com/SciML/DiffEqCallbacks.jl/blob/025dfe99029bd0f30a2e027582744528eb92cd24/src/iterative_and_periodic.jl#L92) push!(tstops_internal, 2 * last(tspan)) SimpleIntegratorSSPOptions{typeof(callback), typeof(tstops_internal)}(callback, false, Inf, @@ -99,11 +102,14 @@ end """ add_tstop!(integrator::SimpleIntegratorSSP, t) -Add a time stop during the time integration process. +Add a time stop during the time integration process. +This function is called after the periodic SaveSolutionCallback to specify the next stop to save the solution. """ function add_tstop!(integrator::SimpleIntegratorSSP, t) integrator.tdir * (t - integrator.t) < zero(integrator.t) && error("Tried to add a tstop that is behind the current time. This is strictly forbidden") + # We need to remove the first entry of tstops when a new entry is added. + # Otherwise, the simulation gets stuck at the previous tstop and dt is adjusted to zero. if length(integrator.opts.tstops) > 1 pop!(integrator.opts.tstops) end @@ -226,6 +232,10 @@ function solve!(integrator::SimpleIntegratorSSP) end end + # Empty the tstops array. + # This cannot be done in terminate!(integrator::SimpleIntegratorSSP) because DiffEqCallbacks.PeriodicCallbackAffect would return at error. + extract_all!(integrator.opts.tstops) + for stage_callback in alg.stage_callbacks finalize_callback(stage_callback, integrator.p) end @@ -249,7 +259,6 @@ end # stop the time integration function terminate!(integrator::SimpleIntegratorSSP) integrator.finalstep = true - extract_all!(tstops_internal) end """ From 772a3889711b82cddaa5ae2e17a851a233e74499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Rueda-Ram=C3=ADrez?= Date: Mon, 23 Oct 2023 15:03:55 +0200 Subject: [PATCH 10/11] Updated Project.toml --- Project.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 34ddd3e4a76..2deb14217a2 100644 --- a/Project.toml +++ b/Project.toml @@ -6,6 +6,7 @@ version = "0.5.47-pre" [deps] CodeTracking = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2" ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9" +DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" DiffEqCallbacks = "459566f4-90b8-5000-8ac3-15dfb0a30def" EllipsisNotation = "da5c29d0-fa7d-589e-88eb-ea29b0a81949" FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b" @@ -42,7 +43,6 @@ TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f" Triangulate = "f7e6ffb2-c36d-4f8f-a77e-16e897189344" TriplotBase = "981d1d27-644d-49a2-9326-4793e63143c3" TriplotRecipes = "808ab39a-a642-4abf-81ff-4cb34ebbffa3" -DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" [weakdeps] Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" @@ -53,6 +53,7 @@ TrixiMakieExt = "Makie" [compat] CodeTracking = "1.0.5" ConstructionBase = "1.3" +DataStructures = "0.18.15" DiffEqCallbacks = "2.25" EllipsisNotation = "1.0" FillArrays = "0.13.2, 1" From a3fb5e5ee872bbaf688da75bea9a2559e8eb3e94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Rueda-Ram=C3=ADrez?= Date: Tue, 12 Dec 2023 18:44:05 +0100 Subject: [PATCH 11/11] format --- test/test_tree_2d_euler.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_tree_2d_euler.jl b/test/test_tree_2d_euler.jl index 212fded51bc..65899cd5263 100644 --- a/test/test_tree_2d_euler.jl +++ b/test/test_tree_2d_euler.jl @@ -217,13 +217,13 @@ end 0.08508152653623638, 0.04510301725066843, 0.04510304668512745, - 0.6930705064715306 + 0.6930705064715306, ], linf=[ 0.31136518019691406, 0.5617651935473419, 0.5621200790240503, - 2.8866869108596056 + 2.8866869108596056, ]) # Ensure that we do not have excessive memory allocations # (e.g., from type instabilities)