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_euler_positivity.jl
2055 views
1
using OrdinaryDiffEqLowStorageRK
2
using Trixi
3
4
###############################################################################
5
# semidiscretization of the compressible Euler equations
6
gamma = 1.4
7
equations = CompressibleEulerEquations2D(gamma)
8
9
"""
10
initial_condition_sedov_blast_wave(x, t, equations::CompressibleEulerEquations2D)
11
12
The Sedov blast wave setup based on Flash
13
- https://flash.rochester.edu/site/flashcode/user_support/flash_ug_devel/node187.html#SECTION010114000000000000000
14
"""
15
function initial_condition_sedov_blast_wave(x, t, equations::CompressibleEulerEquations2D)
16
# Set up polar coordinates
17
RealT = eltype(x)
18
inicenter = SVector(0, 0)
19
x_norm = x[1] - inicenter[1]
20
y_norm = x[2] - inicenter[2]
21
r = sqrt(x_norm^2 + y_norm^2)
22
23
# Setup based on https://flash.rochester.edu/site/flashcode/user_support/flash_ug_devel/node187.html#SECTION010114000000000000000
24
r0 = 0.21875f0 # = 3.5 * smallest dx (for domain length=4 and max-ref=6)
25
# r0 = 0.5 # = more reasonable setup
26
E = 1
27
p0_inner = 3 * (equations.gamma - 1) * E / (3 * convert(RealT, pi) * r0^2)
28
p0_outer = convert(RealT, 1.0e-5) # = true Sedov setup
29
# p0_outer = 1.0e-3 # = more reasonable setup
30
31
# Calculate primitive variables
32
rho = 1
33
v1 = 0
34
v2 = 0
35
p = r > r0 ? p0_outer : p0_inner
36
37
return prim2cons(SVector(rho, v1, v2, p), equations)
38
end
39
initial_condition = initial_condition_sedov_blast_wave
40
41
# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of
42
# `const flux_lax_friedrichs = FluxLaxFriedrichs(), i.e., `FluxLaxFriedrichs(max_abs_speed = max_abs_speed_naive)`.
43
# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.
44
# Thus, we exchanged in PR#2458 the default wave speed used in the LLF flux to `max_abs_speed`.
45
# To ensure that every example still runs we specify explicitly `FluxLaxFriedrichs(max_abs_speed_naive)`.
46
# We remark, however, that the now default `max_abs_speed` is in general recommended due to compliance with the
47
# `StepsizeCallback` (CFL-Condition) and less diffusion.
48
surface_flux = FluxLaxFriedrichs(max_abs_speed_naive)
49
volume_flux = flux_ranocha
50
basis = LobattoLegendreBasis(3)
51
indicator_sc = IndicatorHennemannGassner(equations, basis,
52
alpha_max = 0.5,
53
alpha_min = 0.001,
54
alpha_smooth = true,
55
variable = density_pressure)
56
volume_integral = VolumeIntegralShockCapturingHG(indicator_sc;
57
volume_flux_dg = volume_flux,
58
volume_flux_fv = surface_flux)
59
solver = DGSEM(basis, surface_flux, volume_integral)
60
61
coordinates_min = (-2.0, -2.0)
62
coordinates_max = (2.0, 2.0)
63
mesh = TreeMesh(coordinates_min, coordinates_max,
64
initial_refinement_level = 6,
65
n_cells_max = 100_000)
66
67
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver)
68
69
###############################################################################
70
# ODE solvers, callbacks etc.
71
72
tspan = (0.0, 4.0)
73
ode = semidiscretize(semi, tspan)
74
75
summary_callback = SummaryCallback()
76
77
analysis_interval = 500
78
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
79
80
alive_callback = AliveCallback(analysis_interval = analysis_interval)
81
82
save_solution = SaveSolutionCallback(interval = 100,
83
save_initial_solution = true,
84
save_final_solution = true,
85
solution_variables = cons2prim)
86
87
amr_indicator = IndicatorLöhner(semi,
88
variable = density_pressure)
89
amr_controller = ControllerThreeLevel(semi, amr_indicator,
90
base_level = 4,
91
med_level = 0, med_threshold = 0.1, # med_level = current level
92
max_level = 6, max_threshold = 0.3)
93
amr_callback = AMRCallback(semi, amr_controller,
94
interval = 2,
95
adapt_initial_condition = true,
96
adapt_initial_condition_only_refine = true)
97
98
stepsize_callback = StepsizeCallback(cfl = 0.8)
99
100
callbacks = CallbackSet(summary_callback,
101
analysis_callback, alive_callback,
102
save_solution,
103
amr_callback, stepsize_callback)
104
105
stage_limiter! = PositivityPreservingLimiterZhangShu(thresholds = (5.0e-6, 5.0e-6),
106
variables = (Trixi.density, pressure))
107
108
###############################################################################
109
# run the simulation
110
111
sol = solve(ode, CarpenterKennedy2N54(stage_limiter!, williamson_condition = false);
112
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
113
ode_default_options()..., callback = callbacks);
114
115