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