Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/tree_2d_dgsem/elixir_advection_restart_amr.jl
5586 views
1
using OrdinaryDiffEqLowStorageRK
2
using Trixi
3
using Accessors: @reset
4
5
###############################################################################
6
# Define time integration algorithm
7
alg = CarpenterKennedy2N54(williamson_condition = false)
8
# Create a restart file
9
trixi_include(@__MODULE__, joinpath(@__DIR__, "elixir_advection_extended.jl"), alg = alg,
10
tspan = (0.0, 3.0))
11
12
###############################################################################
13
# adapt the parameters that have changed compared to "elixir_advection_extended.jl"
14
15
# Note: If you get a restart file from somewhere else, you need to provide
16
# appropriate setups in the elixir loading a restart file
17
18
restart_filename = joinpath("out", "restart_000000040.h5")
19
mesh = load_mesh(restart_filename)
20
21
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver;
22
boundary_conditions = boundary_condition_periodic)
23
24
tspan = (load_time(restart_filename), 5.0)
25
dt = load_dt(restart_filename)
26
ode = semidiscretize(semi, tspan, restart_filename)
27
28
# Do not overwrite the initial snapshot written by elixir_advection_extended.jl.
29
@reset save_solution.condition.save_initial_solution = false
30
31
# Add AMR callback
32
amr_controller = ControllerThreeLevel(semi, IndicatorMax(semi, variable = first),
33
base_level = 3,
34
med_level = 4, med_threshold = 0.8,
35
max_level = 5, max_threshold = 1.2)
36
amr_callback = AMRCallback(semi, amr_controller,
37
interval = 5,
38
adapt_initial_condition = true,
39
adapt_initial_condition_only_refine = true)
40
callbacks_ext = CallbackSet(amr_callback, callbacks.discrete_callbacks...)
41
42
integrator = init(ode, alg;
43
dt = dt, # solve needs some value here but it will be overwritten by the stepsize_callback
44
ode_default_options()..., callback = callbacks_ext, maxiters = 100_000)
45
46
# Load saved context for adaptive time integrator
47
if integrator.opts.adaptive
48
load_adaptive_time_integrator!(integrator, restart_filename)
49
end
50
51
# Get the last time index and work with that.
52
load_timestep!(integrator, restart_filename)
53
54
###############################################################################
55
# run the simulation
56
57
sol = solve!(integrator)
58
59