Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/p4est_3d_dgsem/elixir_advection_amr.jl
5586 views
1
# The same setup as tree_3d_dgsem/elixir_advection_amr.jl
2
# to verify the P4estMesh implementation against TreeMesh
3
4
using OrdinaryDiffEqLowStorageRK
5
using Trixi
6
7
###############################################################################
8
# semidiscretization of the linear advection equation
9
10
advection_velocity = (0.2, -0.7, 0.5)
11
equations = LinearScalarAdvectionEquation3D(advection_velocity)
12
13
initial_condition = initial_condition_gauss
14
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)
15
16
coordinates_min = (-5.0, -5.0, -5.0)
17
coordinates_max = (5.0, 5.0, 5.0)
18
trees_per_dimension = (1, 1, 1)
19
20
# Note that it is not necessary to use mesh polydeg lower than the solver polydeg
21
# on a Cartesian mesh.
22
# See https://doi.org/10.1007/s10915-018-00897-9, Section 6.
23
mesh = P4estMesh(trees_per_dimension, polydeg = 1,
24
coordinates_min = coordinates_min, coordinates_max = coordinates_max,
25
initial_refinement_level = 4,
26
periodicity = true)
27
28
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver;
29
boundary_conditions = boundary_condition_periodic)
30
31
###############################################################################
32
# ODE solvers, callbacks etc.
33
34
tspan = (0.0, 0.3)
35
ode = semidiscretize(semi, tspan)
36
37
summary_callback = SummaryCallback()
38
39
analysis_interval = 100
40
analysis_callback = AnalysisCallback(semi, interval = analysis_interval,
41
extra_analysis_integrals = (entropy,))
42
43
alive_callback = AliveCallback(analysis_interval = analysis_interval)
44
45
save_solution = SaveSolutionCallback(interval = 100,
46
save_initial_solution = true,
47
save_final_solution = true,
48
solution_variables = cons2prim)
49
50
amr_controller = ControllerThreeLevel(semi, IndicatorMax(semi, variable = first),
51
base_level = 4,
52
med_level = 5, med_threshold = 0.1,
53
max_level = 6, max_threshold = 0.6)
54
amr_callback = AMRCallback(semi, amr_controller,
55
interval = 5,
56
adapt_initial_condition = true,
57
adapt_initial_condition_only_refine = true)
58
59
stepsize_callback = StepsizeCallback(cfl = 1.2)
60
61
callbacks = CallbackSet(summary_callback,
62
analysis_callback,
63
alive_callback,
64
save_solution,
65
amr_callback,
66
stepsize_callback)
67
68
###############################################################################
69
# run the simulation
70
71
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
72
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
73
ode_default_options()..., callback = callbacks);
74
75