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_shockcapturing_subcell.jl
2055 views
1
using Trixi
2
3
###############################################################################
4
# semidiscretization of the compressible Euler equations
5
6
equations = CompressibleEulerEquations2D(1.4)
7
8
"""
9
initial_condition_blast_wave(x, t, equations::CompressibleEulerEquations2D)
10
11
A medium blast wave (modified to lower density and higher pressure) taken from
12
- Sebastian Hennemann, Gregor J. Gassner (2020)
13
A provably entropy stable subcell shock capturing approach for high order split form DG
14
[arXiv: 2008.12044](https://arxiv.org/abs/2008.12044)
15
"""
16
function initial_condition_blast_wave(x, t, equations::CompressibleEulerEquations2D)
17
# Modified From Hennemann & Gassner JCP paper 2020 (Sec. 6.3) -> modified to lower density, higher pressure
18
# Set up polar coordinates
19
RealT = eltype(x)
20
inicenter = SVector(0, 0)
21
x_norm = x[1] - inicenter[1]
22
y_norm = x[2] - inicenter[2]
23
r = sqrt(x_norm^2 + y_norm^2)
24
phi = atan(y_norm, x_norm)
25
sin_phi, cos_phi = sincos(phi)
26
27
# Calculate primitive variables "normal" medium blast wave
28
rho = r > 0.5f0 ? RealT(0.1) : RealT(0.2691) # rho = r > 0.5 ? 1 : 1.1691
29
v1 = r > 0.5f0 ? zero(RealT) : RealT(0.1882) * cos_phi
30
v2 = r > 0.5f0 ? zero(RealT) : RealT(0.1882) * sin_phi
31
p = r > 0.5f0 ? RealT(1.0E-1) : RealT(1.245) # p = r > 0.5 ? 1.0E-3 : 1.245
32
33
return prim2cons(SVector(rho, v1, v2, p), equations)
34
end
35
initial_condition = initial_condition_blast_wave
36
37
# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of
38
# `const flux_lax_friedrichs = FluxLaxFriedrichs(), i.e., `FluxLaxFriedrichs(max_abs_speed = max_abs_speed_naive)`.
39
# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.
40
# Thus, we exchanged in PR#2458 the default wave speed used in the LLF flux to `max_abs_speed`.
41
# To ensure that every example still runs we specify explicitly `FluxLaxFriedrichs(max_abs_speed_naive)`.
42
# We remark, however, that the now default `max_abs_speed` is in general recommended due to compliance with the
43
# `StepsizeCallback` (CFL-Condition) and less diffusion.
44
surface_flux = FluxLaxFriedrichs(max_abs_speed_naive)
45
volume_flux = flux_ranocha
46
basis = LobattoLegendreBasis(3)
47
limiter_idp = SubcellLimiterIDP(equations, basis;
48
positivity_variables_cons = ["rho"],
49
positivity_correction_factor = 0.5)
50
volume_integral = VolumeIntegralSubcellLimiting(limiter_idp;
51
volume_flux_dg = volume_flux,
52
volume_flux_fv = surface_flux)
53
solver = DGSEM(basis, surface_flux, volume_integral)
54
55
coordinates_min = (-2.0, -2.0)
56
coordinates_max = (2.0, 2.0)
57
mesh = TreeMesh(coordinates_min, coordinates_max,
58
initial_refinement_level = 5,
59
n_cells_max = 100_000)
60
61
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver)
62
63
###############################################################################
64
# ODE solvers, callbacks etc.
65
66
tspan = (0.0, 1.0)
67
ode = semidiscretize(semi, tspan)
68
69
summary_callback = SummaryCallback()
70
71
analysis_interval = 100
72
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
73
74
alive_callback = AliveCallback(analysis_interval = analysis_interval)
75
76
save_solution = SaveSolutionCallback(dt = 0.1,
77
save_initial_solution = true,
78
save_final_solution = true,
79
solution_variables = cons2prim,
80
extra_node_variables = (:limiting_coefficient,))
81
82
stepsize_callback = StepsizeCallback(cfl = 0.6)
83
84
callbacks = CallbackSet(summary_callback,
85
analysis_callback, alive_callback,
86
save_solution,
87
stepsize_callback)
88
89
###############################################################################
90
# run the simulation
91
92
stage_callbacks = (SubcellLimiterIDPCorrection(), BoundsCheckCallback(save_errors = false))
93
94
sol = Trixi.solve(ode, Trixi.SimpleSSPRK33(stage_callbacks = stage_callbacks);
95
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
96
ode_default_options()..., callback = callbacks);
97
98