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