Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/examples/structured_2d_dgsem/elixir_mhdmultiion_convergence_twospecies.jl
5586 views
1
using OrdinaryDiffEqLowStorageRK
2
using Trixi
3
4
###############################################################################
5
"""
6
electron_pressure_alpha(u, equations::IdealGlmMhdMultiIonEquations2D)
7
Returns a fraction (alpha) of the total ion pressure for the electron pressure.
8
"""
9
function electron_pressure_alpha(u, equations::IdealGlmMhdMultiIonEquations2D)
10
alpha = 0.2
11
prim = cons2prim(u, equations)
12
p_e = zero(u[1])
13
for k in eachcomponent(equations)
14
_, _, _, _, p_k = Trixi.get_component(k, prim, equations)
15
p_e += p_k
16
end
17
return alpha * p_e
18
end
19
# semidiscretization of the ideal multi-ion MHD equations
20
equations = IdealGlmMhdMultiIonEquations2D(gammas = (2.0, 4.0),
21
charge_to_mass = (2.0, 1.0),
22
electron_pressure = electron_pressure_alpha)
23
24
"""
25
Initial (and exact) solution for the the manufactured solution test. Runs with
26
* gammas = (2.0, 4.0),
27
* charge_to_mass = (2.0, 1.0)
28
* Domain size: [-1,1]²
29
"""
30
function initial_condition_manufactured_solution(x, t,
31
equations::IdealGlmMhdMultiIonEquations2D)
32
am = 0.1
33
om = π
34
h = am * sin(om * (x[1] + x[2] - t)) + 2
35
hh1 = am * 0.4 * sin(om * (x[1] + x[2] - t)) + 1
36
hh2 = h - hh1
37
38
u1 = hh1
39
u2 = hh1
40
u3 = hh1
41
u4 = 0.1 * hh1
42
u5 = 2 * hh1^2 + hh1
43
u6 = hh2
44
u7 = hh2
45
u8 = hh2
46
u9 = 0.1 * hh2
47
u10 = 2 * hh2^2 + hh2
48
u11 = 0.25 * h
49
u12 = -0.25 * h
50
u13 = 0.1 * h
51
52
return SVector{nvariables(equations), real(equations)}(u11, u12, u13,
53
u1, u2, u3, u4, u5,
54
u6, u7, u8, u9, u10,
55
0)
56
end
57
58
"""
59
Source term that corresponds to the manufactured solution test. Runs with
60
* gammas = (2.0, 4.0),
61
* charge_to_mass = (2.0, 1.0)
62
* Domain size: [-1,1]²
63
"""
64
function source_terms_manufactured_solution_pe(u, x, t,
65
equations::IdealGlmMhdMultiIonEquations2D)
66
am = 0.1
67
om = pi
68
h1 = am * sin(om * (x[1] + x[2] - t))
69
hx = am * om * cos(om * (x[1] + x[2] - t))
70
71
s1 = (2 * hx) / 5
72
s2 = (38055 * hx * h1^2 + 185541 * hx * h1 + 220190 * hx) / (35000 * h1 + 75000)
73
s3 = (38055 * hx * h1^2 + 185541 * hx * h1 + 220190 * hx) / (35000 * h1 + 75000)
74
s4 = hx / 25
75
s5 = (1835811702576186755 * hx * h1^2 + 8592627463681183181 * hx * h1 +
76
9884050459977240490 * hx) / (652252660543767500 * h1 + 1397684272593787500)
77
s6 = (3 * hx) / 5
78
s7 = (76155 * hx * h1^2 + 295306 * hx * h1 + 284435 * hx) / (17500 * h1 + 37500)
79
s8 = (76155 * hx * h1^2 + 295306 * hx * h1 + 284435 * hx) / (17500 * h1 + 37500)
80
s9 = (3 * hx) / 50
81
s10 = (88755 * hx * h1^2 + 338056 * hx * h1 + 318185 * hx) / (8750 * h1 + 18750)
82
s11 = hx / 4
83
s12 = -hx / 4
84
s13 = hx / 10
85
86
s = SVector{nvariables(equations), real(equations)}(s11, s12, s13,
87
s1, s2, s3, s4, s5,
88
s6, s7, s8, s9, s10,
89
0)
90
S_std = source_terms_lorentz(u, x, t, equations::IdealGlmMhdMultiIonEquations2D)
91
92
return SVector{nvariables(equations), real(equations)}(S_std .+ s)
93
end
94
95
initial_condition = initial_condition_manufactured_solution
96
source_terms = source_terms_manufactured_solution_pe
97
98
volume_flux = (flux_ruedaramirez_etal, flux_nonconservative_ruedaramirez_etal)
99
surface_flux = (FluxLaxFriedrichs(max_abs_speed_naive),
100
flux_nonconservative_central) # Also works with flux_nonconservative_ruedaramirez_etal
101
102
solver = DGSEM(polydeg = 3, surface_flux = surface_flux,
103
volume_integral = VolumeIntegralFluxDifferencing(volume_flux))
104
105
coordinates_min = (-1.0, -1.0)
106
coordinates_max = (1.0, 1.0)
107
108
# To test convergence use:
109
# convergence_test("../examples/structured_2d_dgsem/elixir_mhdmultiion_convergence_twospecies.jl", 3, cells_per_dimension = (2, 2), polydeg = 3)
110
# Mapping as described in https://arxiv.org/abs/2012.12040
111
function mapping(xi_, eta_)
112
# Transform input variables between -1 and 1 onto [0,3]
113
xi = 1.5 * xi_ + 1.5
114
eta = 1.5 * eta_ + 1.5
115
116
y = eta +
117
0.05 * (cospi(1.5 * (2 * xi - 3) / 3) *
118
cospi(0.5 * (2 * eta - 3) / 3))
119
120
x = xi +
121
0.05 * (cospi(0.5 * (2 * xi - 3) / 3) *
122
cospi(2 * (2 * y - 3) / 3))
123
124
# Go back to [-1,1]^3
125
x = x * 2 / 3 - 1
126
y = y * 2 / 3 - 1
127
128
return SVector(x, y)
129
end
130
cells_per_dimension = (2, 2)
131
mesh = StructuredMesh(cells_per_dimension, mapping;
132
periodicity = true)
133
134
# # Alternatively, you can test with a TreeMesh
135
# # convergence_test("../examples/structured_2d_dgsem/elixir_mhdmultiion_convergence_twospecies.jl", 3, initial_refinement_level = 1, polydeg = 3)
136
# initial_refinement_level = 1
137
# mesh = TreeMesh(coordinates_min, coordinates_max,
138
# initial_refinement_level = initial_refinement_level,
139
# n_cells_max = 1_000_000,
140
# periodicity = true)
141
142
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
143
source_terms = source_terms,
144
boundary_conditions = boundary_condition_periodic)
145
146
###############################################################################
147
# ODE solvers, callbacks etc.
148
149
tspan = (0.0, 1.0)
150
ode = semidiscretize(semi, tspan)
151
152
summary_callback = SummaryCallback()
153
154
analysis_interval = 100
155
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
156
alive_callback = AliveCallback(analysis_interval = analysis_interval)
157
158
save_solution = SaveSolutionCallback(interval = 1000,
159
save_initial_solution = true,
160
save_final_solution = true,
161
solution_variables = cons2prim)
162
163
cfl = 0.5
164
stepsize_callback = StepsizeCallback(cfl = cfl)
165
166
glm_speed_callback = GlmSpeedCallback(glm_scale = 0.5, cfl = cfl)
167
168
callbacks = CallbackSet(summary_callback,
169
analysis_callback, alive_callback,
170
save_solution,
171
stepsize_callback,
172
glm_speed_callback)
173
174
###############################################################################
175
# run the simulation
176
177
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),
178
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
179
save_everystep = false, callback = callbacks);
180
181