Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/test/test_tree_2d_eulermulti.jl
2055 views
1
module TestExamples2DEulerMulticomponent
2
3
using Test
4
using Trixi
5
6
include("test_trixi.jl")
7
8
EXAMPLES_DIR = joinpath(examples_dir(), "tree_2d_dgsem")
9
10
@testset "Compressible Euler Multicomponent" begin
11
@trixi_testset "Testing entropy2cons and cons2entropy" begin
12
using ForwardDiff
13
using Trixi: Trixi, CompressibleEulerMulticomponentEquations2D, cons2entropy,
14
entropy2cons, SVector
15
gammas = (1.1546412974182538, 1.1171560258914812, 1.097107661471476,
16
1.0587601652669245, 1.6209889683979308, 1.6732209755396386,
17
1.2954303574165822)
18
gas_constants = (5.969461071171914, 3.6660802003290183, 6.639008614675539,
19
8.116604827140456, 6.190706056680031, 1.6795013743693712,
20
2.197737590916966)
21
equations = CompressibleEulerMulticomponentEquations2D(gammas = SVector{length(gammas)}(gammas...),
22
gas_constants = SVector{length(gas_constants)}(gas_constants...))
23
u = [-1.7433292819144075, 0.8844413258376495, 0.6050737175812364,
24
0.8261998359817043, 1.0801186290896465, 0.505654488367698,
25
0.6364415555805734, 0.851669392285058, 0.31219606420306223,
26
1.0930477805612038]
27
w = cons2entropy(u, equations)
28
# test that the entropy variables match the gradients of the total entropy
29
@test w ForwardDiff.gradient(u -> Trixi.total_entropy(u, equations), u)
30
# test that `entropy2cons` is the inverse of `cons2entropy`
31
@test entropy2cons(w, equations) u
32
end
33
34
# NOTE: Some of the L2/Linf errors are comparably large. This is due to the fact that some of the
35
# simulations are set up with dimensional states. For example, the reference pressure in SI
36
# units is 101325 Pa, i.e., pressure has values of O(10^5)
37
38
@trixi_testset "elixir_eulermulti_shock_bubble.jl" begin
39
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_eulermulti_shock_bubble.jl"),
40
l2=[
41
73.78467629094177,
42
0.9174752929795251,
43
57942.83587826468,
44
0.1828847253029943,
45
0.011127037850925347
46
],
47
linf=[
48
196.81051991521073,
49
7.8456811648529605,
50
158891.88930113698,
51
0.811379581519794,
52
0.08011973559187913
53
],
54
tspan=(0.0, 0.001))
55
# Ensure that we do not have excessive memory allocations
56
# (e.g., from type instabilities)
57
let
58
t = sol.t[end]
59
u_ode = sol.u[end]
60
du_ode = similar(u_ode)
61
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
62
end
63
end
64
65
@trixi_testset "elixir_eulermulti_shock_bubble_shockcapturing_subcell_positivity.jl" begin
66
rm(joinpath("out", "deviations.txt"), force = true)
67
@test_trixi_include(joinpath(EXAMPLES_DIR,
68
"elixir_eulermulti_shock_bubble_shockcapturing_subcell_positivity.jl"),
69
l2=[
70
81.52845664909304,
71
2.5455678559421346,
72
63229.190712645846,
73
0.19929478404550321,
74
0.011068604228443425
75
],
76
linf=[
77
249.21708417382013,
78
40.33299887640794,
79
174205.0118831558,
80
0.6881458768113586,
81
0.11274401158173972
82
],
83
initial_refinement_level=3,
84
tspan=(0.0, 0.001),
85
save_errors=true)
86
lines = readlines(joinpath("out", "deviations.txt"))
87
@test lines[1] == "# iter, simu_time, rho1_min, rho2_min"
88
# Runs 15 time steps.
89
@test startswith(lines[end], "15")
90
# Ensure that we do not have excessive memory allocations
91
# (e.g., from type instabilities)
92
let
93
t = sol.t[end]
94
u_ode = sol.u[end]
95
du_ode = similar(u_ode)
96
# Larger values for allowed allocations due to usage of custom
97
# integrator which are not *recorded* for the methods from
98
# OrdinaryDiffEq.jl
99
# Corresponding issue: https://github.com/trixi-framework/Trixi.jl/issues/1877
100
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 15000
101
end
102
end
103
104
@trixi_testset "elixir_eulermulti_shock_bubble_shockcapturing_subcell_minmax.jl" begin
105
@test_trixi_include(joinpath(EXAMPLES_DIR,
106
"elixir_eulermulti_shock_bubble_shockcapturing_subcell_minmax.jl"),
107
l2=[
108
73.41054363926742,
109
1.5072038797716156,
110
57405.58964098063,
111
0.17877099207437225,
112
0.010085388785440972
113
],
114
linf=[
115
213.59140793740318,
116
24.57625853486584,
117
152498.21319871658,
118
0.5911106543157919,
119
0.09936092838440383
120
],
121
initial_refinement_level=3,
122
tspan=(0.0, 0.001))
123
# Ensure that we do not have excessive memory allocations
124
# (e.g., from type instabilities)
125
let
126
t = sol.t[end]
127
u_ode = sol.u[end]
128
du_ode = similar(u_ode)
129
# Larger values for allowed allocations due to usage of custom
130
# integrator which are not *recorded* for the methods from
131
# OrdinaryDiffEq.jl
132
# Corresponding issue: https://github.com/trixi-framework/Trixi.jl/issues/1877
133
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 15000
134
end
135
end
136
137
@trixi_testset "elixir_eulermulti_ec.jl" begin
138
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_eulermulti_ec.jl"),
139
l2=[
140
0.050182236154087095,
141
0.050189894464434635,
142
0.2258715597305131,
143
0.06175171559771687
144
],
145
linf=[
146
0.3108124923284472,
147
0.3107380389947733,
148
1.054035804988521,
149
0.29347582879608936
150
])
151
# Ensure that we do not have excessive memory allocations
152
# (e.g., from type instabilities)
153
let
154
t = sol.t[end]
155
u_ode = sol.u[end]
156
du_ode = similar(u_ode)
157
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
158
end
159
end
160
161
@trixi_testset "elixir_eulermulti_es.jl" begin
162
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_eulermulti_es.jl"),
163
l2=[
164
0.0496546258404055,
165
0.04965550099933263,
166
0.22425206549856372,
167
0.004087155041747821,
168
0.008174310083495642,
169
0.016348620166991283,
170
0.032697240333982566
171
],
172
linf=[
173
0.2488251110766228,
174
0.24832493304479406,
175
0.9310354690058298,
176
0.017452870465607374,
177
0.03490574093121475,
178
0.0698114818624295,
179
0.139622963724859
180
])
181
# Ensure that we do not have excessive memory allocations
182
# (e.g., from type instabilities)
183
let
184
t = sol.t[end]
185
u_ode = sol.u[end]
186
du_ode = similar(u_ode)
187
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
188
end
189
end
190
191
@trixi_testset "elixir_eulermulti_convergence_ec.jl" begin
192
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_eulermulti_convergence_ec.jl"),
193
l2=[
194
0.00012290225488326508,
195
0.00012290225488321876,
196
0.00018867397906337653,
197
4.8542321753649044e-5,
198
9.708464350729809e-5
199
],
200
linf=[
201
0.0006722819239133315,
202
0.0006722819239128874,
203
0.0012662292789555885,
204
0.0002843844182700561,
205
0.0005687688365401122
206
])
207
# Ensure that we do not have excessive memory allocations
208
# (e.g., from type instabilities)
209
let
210
t = sol.t[end]
211
u_ode = sol.u[end]
212
du_ode = similar(u_ode)
213
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
214
end
215
end
216
217
@trixi_testset "elixir_eulermulti_convergence_es.jl" begin
218
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_eulermulti_convergence_es.jl"),
219
l2=[
220
2.2661773867001696e-6,
221
2.266177386666318e-6,
222
6.593514692980009e-6,
223
8.836308667348217e-7,
224
1.7672617334696433e-6
225
],
226
linf=[
227
1.4713170997993075e-5,
228
1.4713170997104896e-5,
229
5.115618808515521e-5,
230
5.3639516094383666e-6,
231
1.0727903218876733e-5
232
])
233
# Ensure that we do not have excessive memory allocations
234
# (e.g., from type instabilities)
235
let
236
t = sol.t[end]
237
u_ode = sol.u[end]
238
du_ode = similar(u_ode)
239
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
240
end
241
end
242
243
@trixi_testset "elixir_eulermulti_convergence_es.jl with flux_chandrashekar" begin
244
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_eulermulti_convergence_es.jl"),
245
l2=[
246
1.8621737639352465e-6,
247
1.862173764098385e-6,
248
5.942585713809631e-6,
249
6.216263279534722e-7,
250
1.2432526559069443e-6
251
],
252
linf=[
253
1.6235495582606063e-5,
254
1.6235495576388814e-5,
255
5.854523678827661e-5,
256
5.790274858807898e-6,
257
1.1580549717615796e-5
258
],
259
volume_flux=flux_chandrashekar)
260
# Ensure that we do not have excessive memory allocations
261
# (e.g., from type instabilities)
262
let
263
t = sol.t[end]
264
u_ode = sol.u[end]
265
du_ode = similar(u_ode)
266
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
267
end
268
end
269
end
270
271
end # module
272
273