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