Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix intern time integration method with fixed time step #1919

Merged
merged 14 commits into from
May 6, 2024
Merged
16 changes: 8 additions & 8 deletions src/time_integration/methods_SSP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ mutable struct SimpleIntegratorSSP{RealT <: Real, uType, Params, Sol, F, Alg,
t::RealT
tdir::RealT
dt::RealT # current time step
dtcache::RealT # ignored
dtcache::RealT # manually set time step
iter::Int # current number of time steps (iteration)
p::Params # will be the semidiscretization from Trixi
sol::Sol # faked
Expand All @@ -102,7 +102,7 @@ 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)
Expand Down Expand Up @@ -145,7 +145,7 @@ function solve(ode::ODEProblem, alg = SimpleSSPRK33()::SimpleAlgorithmSSP;
t = first(ode.tspan)
tdir = sign(ode.tspan[end] - ode.tspan[1])
iter = 0
integrator = SimpleIntegratorSSP(u, du, r0, t, tdir, dt, zero(dt), iter, ode.p,
integrator = SimpleIntegratorSSP(u, du, r0, t, tdir, dt, dt, iter, ode.p,
(prob = ode,), ode.f, alg,
SimpleIntegratorSSPOptions(callback, ode.tspan;
kwargs...),
Expand Down Expand Up @@ -185,15 +185,15 @@ function solve!(integrator::SimpleIntegratorSSP)
error("time step size `dt` is NaN")
end

modify_dt_for_tstops!(integrator)

# if the next iteration would push the simulation beyond the end time, set dt accordingly
if integrator.t + integrator.dt > t_end ||
isapprox(integrator.t + integrator.dt, t_end)
integrator.dt = t_end - integrator.t
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 Down Expand Up @@ -232,7 +232,7 @@ function solve!(integrator::SimpleIntegratorSSP)
end
end

# Empty the tstops array.
# Empty the tstops array.
# This cannot be done in terminate!(integrator::SimpleIntegratorSSP) because DiffEqCallbacks.PeriodicCallbackAffect would return at error.
extract_all!(integrator.opts.tstops)

Expand All @@ -253,12 +253,12 @@ u_modified!(integrator::SimpleIntegratorSSP, ::Bool) = false

# used by adaptive timestepping algorithms in DiffEq
function set_proposed_dt!(integrator::SimpleIntegratorSSP, dt)
integrator.dt = dt
(integrator.dt = dt; integrator.dtcache = dt)
end

# used by adaptive timestepping algorithms in DiffEq
function get_proposed_dt(integrator::SimpleIntegratorSSP)
return integrator.dt
return ifelse(integrator.opts.adaptive, integrator.dt, integrator.dtcache)
end

# stop the time integration
Expand Down
32 changes: 32 additions & 0 deletions test/test_tree_2d_euler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,38 @@ end
end
end

@trixi_testset "elixir_euler_shockcapturing_subcell.jl (fixed time step)" begin
bennibolm marked this conversation as resolved.
Show resolved Hide resolved
# Testing local SSP method without stepsize callback
# Additionally, tests combination with SaveSolutionCallback using time interval
save_solution = SaveSolutionCallback(dt = 0.1 + 1.0e-8)
@test_trixi_include(joinpath(EXAMPLES_DIR,
"elixir_euler_shockcapturing_subcell.jl"),
dt=3.0e-3,
tspan=(0.0, 0.25),
callbacks=CallbackSet(summary_callback, save_solution,
analysis_callback, alive_callback),
l2=[
0.05621775473787103,
0.06928809243501848,
0.0692880359352759,
0.6200493251265817,
],
linf=[
0.29610606271773776,
0.6493038217288114,
0.6493038571824573,
3.077005817249576,
])
# Ensure that we do not have excessive memory allocations
# (e.g., from type instabilities)
let
t = sol.t[end]
u_ode = sol.u[end]
du_ode = similar(u_ode)
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 15000
end
end

@trixi_testset "elixir_euler_blast_wave.jl" begin
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_blast_wave.jl"),
l2=[
Expand Down
Loading