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] 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