Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/test/test_t8code_3d.jl
2055 views
1
module TestExamplesT8codeMesh3D
2
3
using Test
4
using Trixi
5
6
include("test_trixi.jl")
7
8
EXAMPLES_DIR = joinpath(examples_dir(), "t8code_3d_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 "T8codeMesh3D" begin
16
@trixi_testset "test t8code mesh from p8est connectivity" begin
17
@test begin
18
using Trixi: Trixi, T8codeMesh
19
# Here we use the connectivity constructor from `P4est.jl` since the
20
# method dispatch works only on `Ptr{p8est_connectivity}` which
21
# actually is `Ptr{P4est.LibP4est.p8est_connectivity}`.
22
conn = Trixi.P4est.LibP4est.p8est_connectivity_new_brick(2, 3, 4, 1, 1, 1)
23
mesh = T8codeMesh(conn)
24
Trixi.p8est_connectivity_destroy(conn)
25
all(size(mesh.tree_node_coordinates) .== (3, 2, 2, 2, 24))
26
end
27
end
28
29
# This test is identical to the one in `test_p4est_3d.jl`.
30
@trixi_testset "elixir_advection_basic.jl" begin
31
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_basic.jl"),
32
# Expected errors are exactly the same as with TreeMesh!
33
l2=[0.00016263963870641478],
34
linf=[0.0014537194925779984])
35
# Ensure that we do not have excessive memory allocations
36
# (e.g., from type instabilities)
37
let
38
t = sol.t[end]
39
u_ode = sol.u[end]
40
du_ode = similar(u_ode)
41
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
42
end
43
end
44
45
# This test is identical to the one in `test_p4est_3d.jl`.
46
@trixi_testset "elixir_advection_unstructured_curved.jl" begin
47
@test_trixi_include(joinpath(EXAMPLES_DIR,
48
"elixir_advection_unstructured_curved.jl"),
49
l2=[0.0004750004258546538],
50
linf=[0.026527551737137167])
51
# Ensure that we do not have excessive memory allocations
52
# (e.g., from type instabilities)
53
let
54
t = sol.t[end]
55
u_ode = sol.u[end]
56
du_ode = similar(u_ode)
57
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
58
end
59
end
60
61
# This test is identical to the one in `test_p4est_3d.jl`.
62
@trixi_testset "elixir_advection_nonconforming.jl" begin
63
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_nonconforming.jl"),
64
l2=[0.00253595715323843],
65
linf=[0.016486952252155795])
66
# Ensure that we do not have excessive memory allocations
67
# (e.g., from type instabilities)
68
let
69
t = sol.t[end]
70
u_ode = sol.u[end]
71
du_ode = similar(u_ode)
72
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
73
end
74
end
75
76
# This test is identical to the one in `test_p4est_3d.jl` besides minor
77
# deviations from the expected error norms.
78
@trixi_testset "elixir_advection_amr.jl" begin
79
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_amr.jl"),
80
# Expected errors are exactly the same as with TreeMesh!
81
l2=[1.1302812803902801e-5],
82
linf=[0.0007889950196294793])
83
# Ensure that we do not have excessive memory allocations
84
# (e.g., from type instabilities)
85
let
86
t = sol.t[end]
87
u_ode = sol.u[end]
88
du_ode = similar(u_ode)
89
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
90
end
91
end
92
93
# This test is identical to the one in `test_p4est_3d.jl` besides minor
94
# deviations from the expected error norms.
95
@trixi_testset "elixir_advection_amr_unstructured_curved.jl" begin
96
@test_trixi_include(joinpath(EXAMPLES_DIR,
97
"elixir_advection_amr_unstructured_curved.jl"),
98
l2=[2.0535121347526814e-5],
99
linf=[0.0010586603797777504],
100
tspan=(0.0, 1.0),)
101
# Ensure that we do not have excessive memory allocations
102
# (e.g., from type instabilities)
103
let
104
t = sol.t[end]
105
u_ode = sol.u[end]
106
du_ode = similar(u_ode)
107
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
108
end
109
end
110
111
# This test differs from the one in `test_p4est_3d.jl` in the latitudinal and
112
# longitudinal dimensions.
113
@trixi_testset "elixir_advection_cubed_sphere.jl" begin
114
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_cubed_sphere.jl"),
115
l2=[0.002006918015656413],
116
linf=[0.027655117058380085])
117
# Ensure that we do not have excessive memory allocations
118
# (e.g., from type instabilities)
119
let
120
t = sol.t[end]
121
u_ode = sol.u[end]
122
du_ode = similar(u_ode)
123
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
124
end
125
end
126
127
# This test is identical to the one in `test_p4est_3d.jl`.
128
@trixi_testset "elixir_advection_restart.jl" begin
129
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_restart.jl"),
130
l2=[0.002590388934758452],
131
linf=[0.01840757696885409])
132
# Ensure that we do not have excessive memory allocations
133
# (e.g., from type instabilities)
134
let
135
t = sol.t[end]
136
u_ode = sol.u[end]
137
du_ode = similar(u_ode)
138
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
139
end
140
end
141
142
# This test is identical to the one in `test_p4est_3d.jl`.
143
@trixi_testset "elixir_euler_source_terms_nonconforming_unstructured_curved.jl" begin
144
@test_trixi_include(joinpath(EXAMPLES_DIR,
145
"elixir_euler_source_terms_nonconforming_unstructured_curved.jl"),
146
l2=[
147
4.070355207909268e-5,
148
4.4993257426833716e-5,
149
5.10588457841744e-5,
150
5.102840924036687e-5,
151
0.00019986264001630542
152
],
153
linf=[
154
0.0016987332417202072,
155
0.003622956808262634,
156
0.002029576258317789,
157
0.0024206977281964193,
158
0.008526972236273522
159
],
160
tspan=(0.0, 0.01))
161
# Ensure that we do not have excessive memory allocations
162
# (e.g., from type instabilities)
163
let
164
t = sol.t[end]
165
u_ode = sol.u[end]
166
du_ode = similar(u_ode)
167
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
168
end
169
end
170
171
# This test is identical to the one in `test_p4est_3d.jl`.
172
@trixi_testset "elixir_euler_source_terms_nonperiodic.jl" begin
173
@test_trixi_include(joinpath(EXAMPLES_DIR,
174
"elixir_euler_source_terms_nonperiodic.jl"),
175
l2=[
176
0.0015106060984283647,
177
0.0014733349038567685,
178
0.00147333490385685,
179
0.001473334903856929,
180
0.0028149479453087093
181
],
182
linf=[
183
0.008070806335238156,
184
0.009007245083113125,
185
0.009007245083121784,
186
0.009007245083102688,
187
0.01562861968368434
188
],
189
tspan=(0.0, 1.0))
190
# Ensure that we do not have excessive memory allocations
191
# (e.g., from type instabilities)
192
let
193
t = sol.t[end]
194
u_ode = sol.u[end]
195
du_ode = similar(u_ode)
196
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
197
end
198
end
199
200
# This test is identical to the one in `test_p4est_3d.jl`.
201
@trixi_testset "elixir_euler_free_stream.jl" begin
202
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_free_stream.jl"),
203
l2=[
204
5.162664597942288e-15,
205
1.941857343642486e-14,
206
2.0232366394187278e-14,
207
2.3381518645408552e-14,
208
7.083114561232324e-14
209
],
210
linf=[
211
7.269740365245525e-13,
212
3.289868377720495e-12,
213
4.440087186807773e-12,
214
3.8686831516088205e-12,
215
9.412914891981927e-12
216
],
217
tspan=(0.0, 0.03))
218
# Ensure that we do not have excessive memory allocations
219
# (e.g., from type instabilities)
220
let
221
t = sol.t[end]
222
u_ode = sol.u[end]
223
du_ode = similar(u_ode)
224
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
225
end
226
end
227
228
# This test is identical to the one in `test_p4est_3d.jl`.
229
@trixi_testset "elixir_euler_free_stream_extruded.jl" begin
230
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_free_stream_extruded.jl"),
231
l2=[
232
8.444868392439035e-16,
233
4.889826056731442e-15,
234
2.2921260987087585e-15,
235
4.268460455702414e-15,
236
1.1356712092620279e-14
237
],
238
linf=[
239
7.749356711883593e-14,
240
2.8792246364872653e-13,
241
1.1121659149182506e-13,
242
3.3228975127030935e-13,
243
9.592326932761353e-13
244
],
245
tspan=(0.0, 0.1), atol=5.0e-13,)
246
# Ensure that we do not have excessive memory allocations
247
# (e.g., from type instabilities)
248
let
249
t = sol.t[end]
250
u_ode = sol.u[end]
251
du_ode = similar(u_ode)
252
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
253
end
254
end
255
256
# This test is identical to the one in `test_p4est_3d.jl`.
257
@trixi_testset "elixir_euler_ec.jl" begin
258
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_ec.jl"),
259
l2=[
260
0.010380390326164493,
261
0.006192950051354618,
262
0.005970674274073704,
263
0.005965831290564327,
264
0.02628875593094754
265
],
266
linf=[
267
0.3326911600075694,
268
0.2824952141320467,
269
0.41401037398065543,
270
0.45574161423218573,
271
0.8099577682187109
272
],
273
tspan=(0.0, 0.2),)
274
# Ensure that we do not have excessive memory allocations
275
# (e.g., from type instabilities)
276
let
277
t = sol.t[end]
278
u_ode = sol.u[end]
279
du_ode = similar(u_ode)
280
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
281
end
282
end
283
284
# This test is identical to the one in `test_p4est_3d.jl` besides minor
285
# deviations in the expected error norms.
286
@trixi_testset "elixir_euler_sedov.jl" begin
287
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_sedov.jl"),
288
l2=[
289
7.82070951e-02,
290
4.33260474e-02,
291
4.33260474e-02,
292
4.33260474e-02,
293
3.75260911e-01
294
],
295
linf=[
296
7.45329845e-01,
297
3.21754792e-01,
298
3.21754792e-01,
299
3.21754792e-01,
300
4.76151527e+00
301
],
302
tspan=(0.0, 0.3),)
303
# Ensure that we do not have excessive memory allocations
304
# (e.g., from type instabilities)
305
let
306
t = sol.t[end]
307
u_ode = sol.u[end]
308
du_ode = similar(u_ode)
309
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
310
end
311
end
312
313
@trixi_testset "elixir_euler_convergence_pure_fv.jl" begin
314
using Trixi: Trixi
315
@test_trixi_include(joinpath(pkgdir(Trixi, "examples", "tree_3d_dgsem"),
316
"elixir_euler_convergence_pure_fv.jl"),
317
l2=[
318
0.037182410351406,
319
0.032062252638283974,
320
0.032062252638283974,
321
0.03206225263828395,
322
0.12228177813586687
323
],
324
linf=[
325
0.0693648413632646,
326
0.0622101894740843,
327
0.06221018947408474,
328
0.062210189474084965,
329
0.24196451799555962
330
],
331
mesh=T8codeMesh((4, 4, 4), polydeg = 3,
332
coordinates_min = (0.0, 0.0, 0.0),
333
coordinates_max = (2.0, 2.0, 2.0)),
334
# Remove SaveSolution callback
335
callbacks=CallbackSet(summary_callback,
336
analysis_callback, alive_callback,
337
stepsize_callback))
338
# Ensure that we do not have excessive memory allocations
339
# (e.g., from type instabilities)
340
let
341
t = sol.t[end]
342
u_ode = sol.u[end]
343
du_ode = similar(u_ode)
344
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
345
end
346
end
347
348
# This test is identical to the one in `test_p4est_3d.jl`.
349
@trixi_testset "elixir_euler_baroclinic_instability.jl" begin
350
@test_trixi_include(joinpath(EXAMPLES_DIR,
351
"elixir_euler_baroclinic_instability.jl"),
352
l2=[
353
6.725093801700048e-7,
354
0.00021710076010951073,
355
0.0004386796338203878,
356
0.00020836270267103122,
357
0.07601887903440395
358
],
359
linf=[
360
1.9107530539574924e-5,
361
0.02980358831035801,
362
0.048476331898047564,
363
0.02200137344113612,
364
4.848310144356219
365
],
366
tspan=(0.0, 1e2),
367
# Decrease tolerance of adaptive time stepping to get similar results across different systems
368
abstol=1.0e-9, reltol=1.0e-9,)
369
# Ensure that we do not have excessive memory allocations
370
# (e.g., from type instabilities)
371
let
372
t = sol.t[end]
373
u_ode = sol.u[end]
374
du_ode = similar(u_ode)
375
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
376
end
377
end
378
379
@trixi_testset "elixir_euler_weak_blast_wave_amr.jl" begin
380
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_weak_blast_wave_amr.jl"),
381
l2=[
382
0.010014531529951328,
383
0.0176268986746271,
384
0.01817514447099777,
385
0.018271085903740675,
386
0.15193033077438198
387
],
388
linf=[
389
0.2898958869606375,
390
0.529717119064458,
391
0.5567193302705906,
392
0.570663236219957,
393
3.5496520808512027
394
],
395
tspan=(0.0, 0.025),)
396
# Ensure that we do not have excessive memory allocations
397
# (e.g., from type instabilities)
398
let
399
t = sol.t[end]
400
u_ode = sol.u[end]
401
du_ode = similar(u_ode)
402
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
403
end
404
# Check for conservation
405
state_integrals = Trixi.integrate(sol.u[2], semi)
406
initial_state_integrals = analysis_callback.affect!.initial_state_integrals
407
408
@test isapprox(state_integrals[1], initial_state_integrals[1], atol = 1e-13)
409
@test isapprox(state_integrals[2], initial_state_integrals[2], atol = 1e-13)
410
@test isapprox(state_integrals[3], initial_state_integrals[3], atol = 1e-13)
411
@test isapprox(state_integrals[4], initial_state_integrals[4], atol = 1e-13)
412
@test isapprox(state_integrals[5], initial_state_integrals[5], atol = 1e-13)
413
end
414
end
415
416
# Clean up afterwards: delete Trixi.jl output directory
417
@test_nowarn rm(outdir, recursive = true)
418
419
end # module
420
421