Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/tree_3d_dgsem/elixir_mhd_convergence.jl
5586 views
1
using Trixi
2
using OrdinaryDiffEqLowStorageRK
3
4
###############################################################################
5
# semidiscretization of the compressible ideal GLM-MHD equations
6
7
gamma() = 2.0 # required to make solution below working!
8
equations = IdealGlmMhdEquations3D(gamma())
9
10
"""
11
initial_condition_convergence(x, t, equations::IdealGlmMhdEquations3D)
12
13
Manufactured solution for the 3D(only!) compressible ideal GLM-MHD equations.
14
Proposed in
15
- Marvin Bohm, Andrew R Winters, Gregor J Gassner, Dominik Derigs, Florian Hindenlang, Joachim Saur (2020):
16
An entropy stable nodal discontinuous Galerkin method for the resistive MHD equations.
17
Part I: Theory and numerical verification
18
[10.1016/j.jcp.2018.06.027](https://doi.org/10.1016/j.jcp.2018.06.027)
19
"""
20
@inline function initial_condition_convergence(x, t, equations::IdealGlmMhdEquations3D)
21
h = 0.5f0 * sinpi(2 * (x[1] + x[2] + x[3] - t)) + 2
22
23
u_1 = h
24
u_2 = h
25
u_3 = h
26
u_4 = 0
27
u_5 = 2 * h^2 + h
28
29
u_6 = h
30
u_7 = -h
31
u_8 = 0
32
u_9 = 0
33
34
return SVector(u_1, u_2, u_3, u_4, u_5, u_6, u_7, u_8, u_9)
35
end
36
37
"""
38
source_terms_convergence(x, t, equations::IdealGlmMhdEquations3D)
39
40
Manufactured solution for the 3D(only!) compressible ideal GLM-MHD equations.
41
Proposed in
42
- Marvin Bohm, Andrew R Winters, Gregor J Gassner, Dominik Derigs, Florian Hindenlang, Joachim Saur (2020):
43
An entropy stable nodal discontinuous Galerkin method for the resistive MHD equations.
44
Part I: Theory and numerical verification
45
[10.1016/j.jcp.2018.06.027](https://doi.org/10.1016/j.jcp.2018.06.027)
46
47
For the version without parabolic terms see the implementation in FLUXO:
48
https://github.com/project-fluxo/fluxo/blob/c7e0cc9b7fd4569dcab67bbb6e5a25c0a84859f1/src/equation/mhd/equation.f90#L1539-L1554
49
"""
50
function source_terms_convergence(u, x, t, equations::IdealGlmMhdEquations3D)
51
h = 0.5f0 * sinpi(2 * (x[1] + x[2] + x[3] - t)) + 2
52
h_x = pi * cospi(2 * (x[1] + x[2] + x[3] - t))
53
54
s_1 = h_x
55
s_2 = h_x + 4 * h * h_x
56
s_3 = h_x + 4 * h * h_x
57
s_4 = 4 * h * h_x
58
s_5 = h_x + 12 * h * h_x
59
s_6 = h_x
60
s_7 = -h_x
61
s_8 = 0
62
s_9 = 0
63
64
return SVector(s_1, s_2, s_3, s_4, s_5, s_6, s_7, s_8, s_9)
65
end
66
67
surface_flux = (flux_hll, flux_nonconservative_powell)
68
volume_flux = (flux_hindenlang_gassner, flux_nonconservative_powell)
69
70
polydeg = 3
71
basis = LobattoLegendreBasis(polydeg)
72
73
volume_integral = VolumeIntegralFluxDifferencing(volume_flux)
74
solver = DGSEM(basis, surface_flux, volume_integral)
75
76
coordinates_min = (0.0, 0.0, 0.0)
77
coordinates_max = (1.0, 1.0, 1.0)
78
79
mesh = TreeMesh(coordinates_min, coordinates_max,
80
initial_refinement_level = 2,
81
periodicity = true,
82
n_cells_max = 100_000)
83
84
semi = SemidiscretizationHyperbolic(mesh, equations,
85
initial_condition_convergence, solver;
86
source_terms = source_terms_convergence,
87
boundary_conditions = boundary_condition_periodic)
88
89
###############################################################################
90
# ODE solvers, callbacks etc.
91
92
tspan = (0.0, 1.0)
93
ode = semidiscretize(semi, tspan)
94
95
summary_callback = SummaryCallback()
96
97
analysis_interval = 50
98
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
99
100
alive_callback = AliveCallback(analysis_interval = analysis_interval)
101
102
cfl = 1.8
103
stepsize_callback = StepsizeCallback(cfl = cfl)
104
105
glm_speed_callback = GlmSpeedCallback(glm_scale = 0.5, cfl = cfl)
106
107
callbacks = CallbackSet(summary_callback,
108
analysis_callback,
109
alive_callback,
110
stepsize_callback,
111
glm_speed_callback)
112
113
###############################################################################
114
# run the simulation
115
116
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false);
117
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
118
ode_default_options()..., callback = callbacks);
119
120