Skip to content

Commit 4010727

Browse files
Example Zhang-Shu Positivity-Preserving Limiter for MHD (#2637)
* Example Zhang-Shu Positivity-Preserving Limiter for MHD * coveragge * mv * rm
1 parent 413d75f commit 4010727

File tree

2 files changed

+135
-0
lines changed

2 files changed

+135
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
using OrdinaryDiffEqSSPRK
2+
using Trixi
3+
4+
###############################################################################
5+
# semidiscretization of the ideal MHD equations
6+
gamma = 2
7+
equations = IdealGlmMhdEquations1D(gamma)
8+
9+
"""
10+
initial_condition_briowu_shock_tube_mod(x, t, equations::IdealGlmMhdEquations1D)
11+
12+
Compound shock tube test case for one dimensional ideal MHD equations.
13+
It is basically an MHD extension of the Sod shock tube.
14+
Taken from Section V of the article with a modified lower right pressure (1e-3 instead of 0.1)
15+
- Brio and Wu (1988)
16+
An Upwind Differencing Scheme for the Equations of Ideal Magnetohydrodynamics
17+
[DOI: 10.1016/0021-9991(88)90120-9](https://doi.org/10.1016/0021-9991(88)90120-9)
18+
"""
19+
function initial_condition_briowu_shock_tube_mod(x, t, equations::IdealGlmMhdEquations1D)
20+
# domain must be set to [0, 1], γ = 2, final time = 0.12
21+
RealT = eltype(x)
22+
rho = x[1] < 0.5f0 ? 1.0f0 : 0.125f0
23+
v1 = 0
24+
v2 = 0
25+
v3 = 0
26+
p = x[1] < 0.5f0 ? one(RealT) : RealT(1e-3) # 1e-3 instead of 0.1
27+
B1 = 0.75f0
28+
B2 = x[1] < 0.5f0 ? 1 : -1
29+
B3 = 0
30+
return prim2cons(SVector(rho, v1, v2, v3, p, B1, B2, B3), equations)
31+
end
32+
initial_condition = initial_condition_briowu_shock_tube_mod
33+
34+
boundary_conditions = BoundaryConditionDirichlet(initial_condition)
35+
36+
surface_flux = flux_hlle
37+
volume_flux = flux_derigs_etal
38+
basis = LobattoLegendreBasis(4)
39+
40+
indicator_sc = IndicatorHennemannGassner(equations, basis,
41+
alpha_max = 0.5,
42+
alpha_min = 0.001,
43+
alpha_smooth = true,
44+
variable = density_pressure)
45+
volume_integral = VolumeIntegralShockCapturingHG(indicator_sc;
46+
volume_flux_dg = volume_flux,
47+
volume_flux_fv = surface_flux)
48+
solver = DGSEM(basis, surface_flux, volume_integral)
49+
50+
coordinates_min = 0.0
51+
coordinates_max = 1.0
52+
mesh = TreeMesh(coordinates_min, coordinates_max,
53+
initial_refinement_level = 4,
54+
n_cells_max = 10_000,
55+
periodicity = false)
56+
57+
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
58+
boundary_conditions = boundary_conditions)
59+
60+
###############################################################################
61+
# ODE solvers, callbacks etc.
62+
63+
tspan = (0.0, 0.12)
64+
ode = semidiscretize(semi, tspan)
65+
66+
summary_callback = SummaryCallback()
67+
68+
analysis_interval = 100
69+
analysis_callback = AnalysisCallback(semi, interval = analysis_interval,
70+
extra_analysis_errors = (:l2_error_primitive,
71+
:linf_error_primitive))
72+
73+
alive_callback = AliveCallback(analysis_interval = analysis_interval)
74+
75+
save_restart = SaveRestartCallback(interval = 100,
76+
save_final_restart = true)
77+
78+
amr_indicator = IndicatorHennemannGassner(semi,
79+
alpha_max = 0.5,
80+
alpha_min = 0.001,
81+
alpha_smooth = true,
82+
variable = density_pressure)
83+
amr_controller = ControllerThreeLevel(semi, amr_indicator,
84+
base_level = 4,
85+
max_level = 6, max_threshold = 0.01)
86+
amr_callback = AMRCallback(semi, amr_controller,
87+
interval = 5,
88+
adapt_initial_condition = true,
89+
adapt_initial_condition_only_refine = true)
90+
91+
stepsize_callback = StepsizeCallback(cfl = 1.1)
92+
93+
callbacks = CallbackSet(summary_callback,
94+
analysis_callback, alive_callback,
95+
save_restart,
96+
amr_callback, stepsize_callback)
97+
98+
###############################################################################
99+
# run the simulation
100+
101+
# crashes without positivity limiter
102+
stage_limiter! = PositivityPreservingLimiterZhangShu(thresholds = (5.0e-6,),
103+
variables = (pressure,))
104+
105+
sol = solve(ode, SSPRK54(stage_limiter! = stage_limiter!);
106+
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
107+
ode_default_options()..., callback = callbacks);

test/test_tree_1d_mhd.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,34 @@ end
167167
@test_allocations(Trixi.rhs!, semi, sol, 1000)
168168
end
169169

170+
@trixi_testset "elixir_mhd_briowu_shock_tube_mod_positivity.jl" begin
171+
@test_trixi_include(joinpath(EXAMPLES_DIR,
172+
"elixir_mhd_briowu_shock_tube_mod_positivity.jl"),
173+
l2=[
174+
0.17958200783518533,
175+
0.21403217755031365,
176+
0.3528008349880033,
177+
0.0,
178+
0.40156743941762096,
179+
7.603990369710917e-14,
180+
0.34299587882334953,
181+
0.0
182+
],
183+
linf=[
184+
0.5347779567211823,
185+
0.4651105133406562,
186+
0.9873266889381644,
187+
0.0,
188+
1.000540495846343,
189+
8.615330671091215e-14,
190+
1.4425998855617321,
191+
0.0
192+
])
193+
# Ensure that we do not have excessive memory allocations
194+
# (e.g., from type instabilities)
195+
@test_allocations(Trixi.rhs!, semi, sol, 1000)
196+
end
197+
170198
@trixi_testset "elixir_mhd_torrilhon_shock_tube.jl" begin
171199
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_mhd_torrilhon_shock_tube.jl"),
172200
l2=[

0 commit comments

Comments
 (0)