Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/tree_3d_dgsem/elixir_euler_amr.jl
2055 views
1
using OrdinaryDiffEqLowStorageRK
2
using Trixi
3
4
###############################################################################
5
# semidiscretization of the compressible Euler equations
6
7
equations = CompressibleEulerEquations3D(1.4)
8
9
"""
10
initial_condition_density_pulse(x, t, equations::CompressibleEulerEquations3D)
11
12
A Gaussian pulse in the density with constant velocity and pressure; reduces the
13
compressible Euler equations to the linear advection equations.
14
"""
15
function initial_condition_density_pulse(x, t, equations::CompressibleEulerEquations3D)
16
rho = 1 + exp(-(x[1]^2 + x[2]^2 + x[3]^2)) / 2
17
v1 = 1
18
v2 = 1
19
v3 = 1
20
rho_v1 = rho * v1
21
rho_v2 = rho * v2
22
rho_v3 = rho * v3
23
p = 1
24
rho_e = p / (equations.gamma - 1) + 1 / 2 * rho * (v1^2 + v2^2 + v3^2)
25
return SVector(rho, rho_v1, rho_v2, rho_v3, rho_e)
26
end
27
initial_condition = initial_condition_density_pulse
28
# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of
29
# `const flux_lax_friedrichs = FluxLaxFriedrichs(), i.e., `FluxLaxFriedrichs(max_abs_speed = max_abs_speed_naive)`.
30
# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.
31
# Thus, we exchanged in PR#2458 the default wave speed used in the LLF flux to `max_abs_speed`.
32
# To ensure that every example still runs we specify explicitly `FluxLaxFriedrichs(max_abs_speed_naive)`.
33
# We remark, however, that the now default `max_abs_speed` is in general recommended due to compliance with the
34
# `StepsizeCallback` (CFL-Condition) and less diffusion.
35
solver = DGSEM(polydeg = 3, surface_flux = FluxLaxFriedrichs(max_abs_speed_naive))
36
37
coordinates_min = (-5.0, -5.0, -5.0)
38
coordinates_max = (5.0, 5.0, 5.0)
39
mesh = TreeMesh(coordinates_min, coordinates_max,
40
initial_refinement_level = 4,
41
n_cells_max = 10_000)
42
43
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver)
44
45
###############################################################################
46
# ODE solvers, callbacks etc.
47
48
tspan = (0.0, 10.0)
49
ode = semidiscretize(semi, tspan)
50
51
summary_callback = SummaryCallback()
52
53
analysis_interval = 100
54
analysis_callback = AnalysisCallback(semi, interval = analysis_interval,
55
extra_analysis_integrals = (entropy,))
56
57
alive_callback = AliveCallback(analysis_interval = analysis_interval)
58
59
save_restart = SaveRestartCallback(interval = 100,
60
save_final_restart = true)
61
62
save_solution = SaveSolutionCallback(interval = 100,
63
save_initial_solution = true,
64
save_final_solution = true,
65
solution_variables = cons2prim)
66
67
amr_controller = ControllerThreeLevel(semi, IndicatorMax(semi, variable = first),
68
base_level = 4,
69
med_level = 5, med_threshold = 1.05,
70
max_level = 6, max_threshold = 1.3)
71
amr_callback = AMRCallback(semi, amr_controller,
72
interval = 5,
73
adapt_initial_condition = true,
74
adapt_initial_condition_only_refine = true)
75
76
stepsize_callback = StepsizeCallback(cfl = 0.9)
77
78
callbacks = CallbackSet(summary_callback,
79
analysis_callback, alive_callback,
80
save_restart, save_solution,
81
amr_callback, stepsize_callback);
82
83
###############################################################################
84
# run the simulation
85
86
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
87
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
88
ode_default_options()..., callback = callbacks);
89
90