Skip to content

Commit

Permalink
First working version of SimpleIntegratorSSP with SaveSolutionCallbac…
Browse files Browse the repository at this point in the history
…k using time intervals
  • Loading branch information
amrueda committed Oct 19, 2023
1 parent e05363d commit 64e9784
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion src/Trixi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 13 additions & 3 deletions src/time_integration/methods_SSP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

"""
Expand All @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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]
Expand All @@ -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
Expand Down

0 comments on commit 64e9784

Please sign in to comment.