Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/test/test_t8code_2d.jl
2055 views
1
module TestExamplesT8codeMesh2D
2
3
using Test
4
using Trixi
5
6
include("test_trixi.jl")
7
8
EXAMPLES_DIR = joinpath(examples_dir(), "t8code_2d_dgsem")
9
10
# Start with a clean environment: remove Trixi.jl output directory if it exists
11
outdir = "out"
12
isdir(outdir) && rm(outdir, recursive = true)
13
mkdir(outdir)
14
15
@testset "T8codeMesh2D" begin
16
#! format: noindent
17
18
@trixi_testset "test load mesh from path" begin
19
using Trixi: T8codeMesh
20
mktempdir() do path
21
@test_throws "Unknown file extension: .unknown_ext" begin
22
mesh = T8codeMesh(touch(joinpath(path, "dummy.unknown_ext")), 2)
23
end
24
end
25
end
26
27
@trixi_testset "test check_for_negative_volumes" begin
28
# This test actually checks if a "negative volume" error is thrown.
29
# Since t8code currently applies a correction on-the-fly this test
30
# is kinda broken. The correction feature in t8code, however, is planned
31
# to be removed in near to midterm future. Thus, this test is kept. It will
32
# fail once the internal correction is removed and can then be restored
33
# to its original form.
34
35
# @test_throws "Discovered negative volumes" begin
36
@test begin
37
using Trixi: Trixi, T8codeMesh
38
# Unstructured mesh with six cells which have left-handed node ordering.
39
mesh_file = Trixi.download("https://gist.githubusercontent.com/jmark/bfe0d45f8e369298d6cc637733819013/raw/cecf86edecc736e8b3e06e354c494b2052d41f7a/rectangle_with_negative_volumes.msh",
40
joinpath(EXAMPLES_DIR,
41
"rectangle_with_negative_volumes.msh"))
42
43
# This call should throw a warning about negative volumes detected.
44
mesh = T8codeMesh(mesh_file, 2)
45
true
46
end
47
end
48
49
@trixi_testset "test t8code mesh from p4est connectivity" begin
50
@test begin
51
using Trixi: Trixi, T8codeMesh
52
# Here we use the connectivity constructor from `P4est.jl` since the
53
# method dispatch works only on `Ptr{p4est_connectivity}` which
54
# actually is `Ptr{P4est.LibP4est.p4est_connectivity}`.
55
conn = Trixi.P4est.LibP4est.p4est_connectivity_new_brick(2, 3, 1, 1)
56
mesh = T8codeMesh(conn)
57
Trixi.p4est_connectivity_destroy(conn)
58
all(size(mesh.tree_node_coordinates) .== (2, 2, 2, 6))
59
end
60
end
61
62
@trixi_testset "test t8code mesh from ABAQUS HOHQMesh file" begin
63
@test begin
64
using Trixi: Trixi, T8codeMesh
65
# Unstructured ABAQUS mesh file created with HOHQMesh..
66
file_path = Trixi.download("https://gist.githubusercontent.com/jmark/9e0da4306e266617eeb19bc56b0e7feb/raw/e6856e1deb648a807f6bb6d6dcacff9e55d94e2a/round_2d_tank.inp",
67
joinpath(EXAMPLES_DIR, "round_2d_tank.inp"))
68
mesh = T8codeMesh(file_path, 2)
69
all(size(mesh.tree_node_coordinates) .== (2, 4, 4, 340))
70
end
71
end
72
73
@trixi_testset "elixir_advection_basic.jl" begin
74
# This test is identical to the one in `test_p4est_2d.jl`.
75
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_basic.jl"),
76
# Expected errors are exactly the same as with TreeMesh!
77
l2=[8.311947673061856e-6],
78
linf=[6.627000273229378e-5])
79
# Ensure that we do not have excessive memory allocations
80
# (e.g., from type instabilities)
81
let
82
t = sol.t[end]
83
u_ode = sol.u[end]
84
du_ode = similar(u_ode)
85
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
86
end
87
end
88
89
@trixi_testset "elixir_advection_nonconforming_flag.jl" begin
90
# This test is identical to the one in `test_p4est_2d.jl`.
91
@test_trixi_include(joinpath(EXAMPLES_DIR,
92
"elixir_advection_nonconforming_flag.jl"),
93
l2=[3.198940059144588e-5],
94
linf=[0.00030636069494005547])
95
# Ensure that we do not have excessive memory allocations
96
# (e.g., from type instabilities)
97
let
98
t = sol.t[end]
99
u_ode = sol.u[end]
100
du_ode = similar(u_ode)
101
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
102
end
103
end
104
105
@trixi_testset "elixir_advection_unstructured_flag.jl" begin
106
# This test is identical to the one in `test_p4est_2d.jl`.
107
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_unstructured_flag.jl"),
108
l2=[0.0005379687442422346],
109
linf=[0.007438525029884735])
110
# Ensure that we do not have excessive memory allocations
111
# (e.g., from type instabilities)
112
let
113
t = sol.t[end]
114
u_ode = sol.u[end]
115
du_ode = similar(u_ode)
116
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
117
end
118
end
119
120
@trixi_testset "elixir_advection_amr_unstructured_flag.jl" begin
121
@test_trixi_include(joinpath(EXAMPLES_DIR,
122
"elixir_advection_amr_unstructured_flag.jl"),
123
l2=[0.002019623611753929],
124
linf=[0.03542375961299987])
125
# Ensure that we do not have excessive memory allocations
126
# (e.g., from type instabilities)
127
let
128
t = sol.t[end]
129
u_ode = sol.u[end]
130
du_ode = similar(u_ode)
131
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
132
end
133
end
134
135
@trixi_testset "elixir_advection_amr_solution_independent.jl" begin
136
# This test is identical to the one in `test_p4est_2d.jl`.
137
@test_trixi_include(joinpath(EXAMPLES_DIR,
138
"elixir_advection_amr_solution_independent.jl"),
139
# Expected errors are exactly the same as with StructuredMesh!
140
l2=[4.949660644033807e-5],
141
linf=[0.0004867846262313763])
142
# Ensure that we do not have excessive memory allocations
143
# (e.g., from type instabilities)
144
let
145
t = sol.t[end]
146
u_ode = sol.u[end]
147
du_ode = similar(u_ode)
148
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
149
end
150
end
151
152
@trixi_testset "elixir_advection_restart.jl" begin
153
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_restart.jl"),
154
l2=[4.507575525876275e-6],
155
linf=[6.21489667023134e-5])
156
157
# Ensure that we do not have excessive memory allocations
158
# (e.g., from type instabilities)
159
let
160
t = sol.t[end]
161
u_ode = sol.u[end]
162
du_ode = similar(u_ode)
163
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
164
end
165
end
166
167
@trixi_testset "elixir_advection_restart_amr.jl" begin
168
# This test is identical to the one in `test_p4est_2d.jl`.
169
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_restart_amr.jl"),
170
l2=[2.869137983727866e-6],
171
linf=[3.8353423270964804e-5])
172
# Ensure that we do not have excessive memory allocations
173
# (e.g., from type instabilities)
174
let
175
t = sol.t[end]
176
u_ode = sol.u[end]
177
du_ode = similar(u_ode)
178
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
179
end
180
end
181
182
@trixi_testset "elixir_euler_source_terms_nonconforming_unstructured_flag.jl" begin
183
# This test is identical to the one in `test_p4est_2d.jl`.
184
@test_trixi_include(joinpath(EXAMPLES_DIR,
185
"elixir_euler_source_terms_nonconforming_unstructured_flag.jl"),
186
l2=[
187
0.0034516244508588046,
188
0.0023420334036925493,
189
0.0024261923964557187,
190
0.004731710454271893
191
],
192
linf=[
193
0.04155789011775046,
194
0.024772109862748914,
195
0.03759938693042297,
196
0.08039824959535657
197
])
198
# Ensure that we do not have excessive memory allocations
199
# (e.g., from type instabilities)
200
let
201
t = sol.t[end]
202
u_ode = sol.u[end]
203
du_ode = similar(u_ode)
204
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
205
end
206
end
207
208
@trixi_testset "elixir_euler_free_stream.jl" begin
209
# This test is identical to the one in `test_p4est_2d.jl`.
210
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_free_stream.jl"),
211
l2=[
212
2.063350241405049e-15,
213
1.8571016296925367e-14,
214
3.1769447886391905e-14,
215
1.4104095258528071e-14
216
],
217
linf=[1.9539925233402755e-14, 2e-12, 4.8e-12, 4e-12],
218
atol=2.0e-12,)
219
# Ensure that we do not have excessive memory allocations
220
# (e.g., from type instabilities)
221
let
222
t = sol.t[end]
223
u_ode = sol.u[end]
224
du_ode = similar(u_ode)
225
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
226
end
227
end
228
229
@trixi_testset "elixir_euler_shockcapturing_ec.jl" begin
230
# This test is identical to the one in `test_p4est_2d.jl`.
231
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_shockcapturing_ec.jl"),
232
l2=[
233
9.53984675e-02,
234
1.05633455e-01,
235
1.05636158e-01,
236
3.50747237e-01
237
],
238
linf=[
239
2.94357464e-01,
240
4.07893014e-01,
241
3.97334516e-01,
242
1.08142520e+00
243
],
244
tspan=(0.0, 1.0))
245
# Ensure that we do not have excessive memory allocations
246
# (e.g., from type instabilities)
247
let
248
t = sol.t[end]
249
u_ode = sol.u[end]
250
du_ode = similar(u_ode)
251
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
252
end
253
end
254
255
@trixi_testset "elixir_euler_sedov.jl" begin
256
# This test is identical to the one in `test_p4est_2d.jl` besides minor
257
# deviations in the expected error norms.
258
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_sedov.jl"),
259
l2=[
260
3.76149952e-01,
261
2.46970327e-01,
262
2.46970327e-01,
263
1.28889042e+00
264
],
265
linf=[
266
1.22139001e+00,
267
1.17742626e+00,
268
1.17742626e+00,
269
6.20638482e+00
270
],
271
tspan=(0.0, 0.3))
272
# Ensure that we do not have excessive memory allocations
273
# (e.g., from type instabilities)
274
let
275
t = sol.t[end]
276
u_ode = sol.u[end]
277
du_ode = similar(u_ode)
278
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
279
end
280
end
281
282
@trixi_testset "elixir_mhd_alfven_wave.jl" begin
283
# This test is identical to the one in `test_p4est_2d.jl`.
284
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_mhd_alfven_wave.jl"),
285
l2=[1.0513414461545583e-5, 1.0517900957166411e-6,
286
1.0517900957304043e-6, 1.511816606372376e-6,
287
1.0443997728645063e-6, 7.879639064990798e-7,
288
7.879639065049896e-7, 1.0628631669056271e-6,
289
4.3382328912336153e-7],
290
linf=[4.255466285174592e-5, 1.0029706745823264e-5,
291
1.0029706747467781e-5, 1.2122265939010224e-5,
292
5.4791097160444835e-6, 5.18922042269665e-6,
293
5.189220422141538e-6, 9.552667261422676e-6,
294
1.4237578427628152e-6])
295
# Ensure that we do not have excessive memory allocations
296
# (e.g., from type instabilities)
297
let
298
t = sol.t[end]
299
u_ode = sol.u[end]
300
du_ode = similar(u_ode)
301
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
302
end
303
end
304
305
@trixi_testset "elixir_mhd_rotor.jl" begin
306
# This test is identical to the one in `test_p4est_2d.jl` besides minor
307
# deviations in the expected error norms.
308
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_mhd_rotor.jl"),
309
l2=[0.4419337424073218, 0.8804938551016932, 0.8258185723720365,
310
0.0,
311
0.961220188718187, 0.10397273631386837, 0.15408979488125943,
312
0.0,
313
2.66769410449947e-5],
314
linf=[10.053140536236942, 18.17070117006211, 9.549208389448738,
315
0.0,
316
19.676151923191583, 1.3896544044814965, 1.8153256887969416,
317
0.0,
318
0.0022030404596184786],
319
tspan=(0.0, 0.02))
320
# Ensure that we do not have excessive memory allocations
321
# (e.g., from type instabilities)
322
let
323
t = sol.t[end]
324
u_ode = sol.u[end]
325
du_ode = similar(u_ode)
326
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
327
end
328
end
329
330
@trixi_testset "elixir_euler_weak_blast_wave_amr.jl" begin
331
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_weak_blast_wave_amr.jl"),
332
l2=[
333
0.10823279736983638,
334
0.1158152939803735,
335
0.11633970342992006,
336
0.751152651902375
337
],
338
linf=[
339
0.5581611332828653,
340
0.8354026029724041,
341
0.834485181423738,
342
3.923553028014343
343
],
344
tspan=(0.0, 0.1),)
345
# Ensure that we do not have excessive memory allocations
346
# (e.g., from type instabilities)
347
let
348
t = sol.t[end]
349
u_ode = sol.u[end]
350
du_ode = similar(u_ode)
351
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
352
end
353
# Check for conservation
354
state_integrals = Trixi.integrate(sol.u[2], semi)
355
initial_state_integrals = analysis_callback.affect!.initial_state_integrals
356
357
@test isapprox(state_integrals[1], initial_state_integrals[1], atol = 1e-13)
358
@test isapprox(state_integrals[2], initial_state_integrals[2], atol = 1e-13)
359
@test isapprox(state_integrals[3], initial_state_integrals[3], atol = 1e-13)
360
@test isapprox(state_integrals[4], initial_state_integrals[4], atol = 1e-13)
361
end
362
end
363
364
# Clean up afterwards: delete Trixi.jl output directory
365
@test_nowarn rm(outdir, recursive = true)
366
367
end # module
368
369