Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/t8code_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 = T8codeMesh(mesh_file, 2; polydeg = 4,
81
mapping = mapping_twist,
82
initial_refinement_level = 1)
83
84
boundary_condition = BoundaryConditionDirichlet(initial_condition)
85
boundary_conditions = Dict(:all => boundary_condition)
86
87
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
88
boundary_conditions = boundary_conditions)
89
90
###############################################################################
91
# ODE solvers, callbacks etc.
92
93
tspan = (0.0, 0.15)
94
ode = semidiscretize(semi, tspan)
95
96
summary_callback = SummaryCallback()
97
98
analysis_interval = 100
99
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
100
101
alive_callback = AliveCallback(analysis_interval = analysis_interval)
102
103
save_solution = SaveSolutionCallback(interval = 100,
104
save_initial_solution = true,
105
save_final_solution = true,
106
solution_variables = cons2prim)
107
108
amr_indicator = IndicatorLöhner(semi,
109
variable = density_pressure)
110
111
amr_controller = ControllerThreeLevel(semi, amr_indicator,
112
base_level = 1,
113
med_level = 3, med_threshold = 0.05,
114
max_level = 5, max_threshold = 0.1)
115
amr_callback = AMRCallback(semi, amr_controller,
116
interval = 5,
117
adapt_initial_condition = true,
118
adapt_initial_condition_only_refine = true,
119
dynamic_load_balancing = false)
120
# We disable `dynamic_load_balancing` for now, since t8code does not support
121
# partitioning for coarsening yet. That is, a complete family of elements always
122
# stays on rank and is not split up due to partitioning. Without this feature
123
# dynamic AMR simulations are not perfectly deterministic regarding to
124
# convergent tests. Once this feature is available in t8code load balancing is
125
# enabled again.
126
127
cfl = 0.5
128
stepsize_callback = StepsizeCallback(cfl = cfl)
129
130
glm_speed_callback = GlmSpeedCallback(glm_scale = 0.5, cfl = cfl)
131
132
callbacks = CallbackSet(summary_callback,
133
analysis_callback,
134
alive_callback,
135
save_solution,
136
amr_callback,
137
stepsize_callback,
138
glm_speed_callback)
139
140
###############################################################################
141
# run the simulation
142
143
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
144
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
145
ode_default_options()..., callback = callbacks);
146
147