Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/p4est_2d_dgsem/elixir_mhd_rotor.jl
2055 views
1
using OrdinaryDiffEqLowStorageRK
2
using Trixi
3
4
###############################################################################
5
# semidiscretization of the compressible ideal GLM-MHD equations
6
equations = IdealGlmMhdEquations2D(1.4)
7
8
"""
9
initial_condition_rotor(x, t, equations::IdealGlmMhdEquations2D)
10
11
The classical MHD rotor test case. Here, the setup is taken from
12
- Dominik Derigs, Gregor J. Gassner, Stefanie Walch & Andrew R. Winters (2018)
13
Entropy Stable Finite Volume Approximations for Ideal Magnetohydrodynamics
14
[doi: 10.1365/s13291-018-0178-9](https://doi.org/10.1365/s13291-018-0178-9)
15
"""
16
function initial_condition_rotor(x, t, equations::IdealGlmMhdEquations2D)
17
# setup taken from Derigs et al. DMV article (2018)
18
# domain must be [0, 1] x [0, 1], γ = 1.4
19
dx = x[1] - 0.5
20
dy = x[2] - 0.5
21
r = sqrt(dx^2 + dy^2)
22
f = (0.115 - r) / 0.015
23
if r <= 0.1
24
rho = 10.0
25
v1 = -20.0 * dy
26
v2 = 20.0 * dx
27
elseif r >= 0.115
28
rho = 1.0
29
v1 = 0.0
30
v2 = 0.0
31
else
32
rho = 1.0 + 9.0 * f
33
v1 = -20.0 * f * dy
34
v2 = 20.0 * f * dx
35
end
36
v3 = 0.0
37
p = 1.0
38
B1 = 5.0 / sqrt(4.0 * pi)
39
B2 = 0.0
40
B3 = 0.0
41
psi = 0.0
42
return prim2cons(SVector(rho, v1, v2, v3, p, B1, B2, B3, psi), equations)
43
end
44
initial_condition = initial_condition_rotor
45
46
# Up to version 0.13.0, `max_abs_speed_naive` was used as the default wave speed estimate of
47
# `const flux_lax_friedrichs = FluxLaxFriedrichs(), i.e., `FluxLaxFriedrichs(max_abs_speed = max_abs_speed_naive)`.
48
# In the `StepsizeCallback`, though, the less diffusive `max_abs_speeds` is employed which is consistent with `max_abs_speed`.
49
# Thus, we exchanged in PR#2458 the default wave speed used in the LLF flux to `max_abs_speed`.
50
# To ensure that every example still runs we specify explicitly `FluxLaxFriedrichs(max_abs_speed_naive)`.
51
# We remark, however, that the now default `max_abs_speed` is in general recommended due to compliance with the
52
# `StepsizeCallback` (CFL-Condition) and less diffusion.
53
surface_flux = (FluxLaxFriedrichs(max_abs_speed_naive), flux_nonconservative_powell)
54
volume_flux = (flux_hindenlang_gassner, flux_nonconservative_powell)
55
polydeg = 4
56
basis = LobattoLegendreBasis(polydeg)
57
indicator_sc = IndicatorHennemannGassner(equations, basis,
58
alpha_max = 0.5,
59
alpha_min = 0.001,
60
alpha_smooth = true,
61
variable = density_pressure)
62
volume_integral = VolumeIntegralShockCapturingHG(indicator_sc;
63
volume_flux_dg = volume_flux,
64
volume_flux_fv = surface_flux)
65
solver = DGSEM(basis, surface_flux, volume_integral)
66
67
# Affine type mapping to take the [-1,1]^2 domain from the mesh file
68
# and put it onto the rotor domain [0,1]^2 and then warp it with a mapping
69
# as described in https://arxiv.org/abs/2012.12040
70
function mapping_twist(xi, eta)
71
y = 0.5 * (eta + 1.0) +
72
0.05 * cos(1.5 * pi * (2.0 * xi - 1.0)) * cos(0.5 * pi * (2.0 * eta - 1.0))
73
x = 0.5 * (xi + 1.0) + 0.05 * cos(0.5 * pi * (2.0 * xi - 1.0)) * cos(2.0 * pi * y)
74
return SVector(x, y)
75
end
76
77
mesh_file = Trixi.download("https://gist.githubusercontent.com/efaulhaber/63ff2ea224409e55ee8423b3a33e316a/raw/7db58af7446d1479753ae718930741c47a3b79b7/square_unstructured_2.inp",
78
joinpath(@__DIR__, "square_unstructured_2.inp"))
79
80
mesh = P4estMesh{2}(mesh_file,
81
polydeg = 4,
82
mapping = mapping_twist,
83
initial_refinement_level = 1)
84
85
boundary_condition = BoundaryConditionDirichlet(initial_condition)
86
boundary_conditions = Dict(:all => boundary_condition)
87
88
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
89
boundary_conditions = boundary_conditions)
90
91
###############################################################################
92
# ODE solvers, callbacks etc.
93
94
tspan = (0.0, 0.15)
95
ode = semidiscretize(semi, tspan)
96
97
summary_callback = SummaryCallback()
98
99
analysis_interval = 100
100
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
101
102
alive_callback = AliveCallback(analysis_interval = analysis_interval)
103
104
save_solution = SaveSolutionCallback(interval = 100,
105
save_initial_solution = true,
106
save_final_solution = true,
107
solution_variables = cons2prim)
108
109
amr_indicator = IndicatorLöhner(semi,
110
variable = density_pressure)
111
112
amr_controller = ControllerThreeLevel(semi, amr_indicator,
113
base_level = 1,
114
med_level = 3, med_threshold = 0.05,
115
max_level = 5, max_threshold = 0.1)
116
amr_callback = AMRCallback(semi, amr_controller,
117
interval = 5,
118
adapt_initial_condition = true,
119
adapt_initial_condition_only_refine = true)
120
121
cfl = 0.5
122
stepsize_callback = StepsizeCallback(cfl = cfl)
123
124
glm_speed_callback = GlmSpeedCallback(glm_scale = 0.5, cfl = cfl)
125
126
callbacks = CallbackSet(summary_callback,
127
analysis_callback,
128
alive_callback,
129
save_solution,
130
amr_callback,
131
stepsize_callback,
132
glm_speed_callback)
133
134
###############################################################################
135
# run the simulation
136
137
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
138
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
139
ode_default_options()..., callback = callbacks);
140
141