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
5582 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
@test_allocations(Trixi.rhs!, semi, sol, 1000)
82
end
83
84
@trixi_testset "elixir_advection_nonconforming_flag.jl" begin
85
# This test is identical to the one in `test_p4est_2d.jl`.
86
@test_trixi_include(joinpath(EXAMPLES_DIR,
87
"elixir_advection_nonconforming_flag.jl"),
88
l2=[3.198940059144588e-5],
89
linf=[0.00030636069494005547])
90
# Ensure that we do not have excessive memory allocations
91
# (e.g., from type instabilities)
92
@test_allocations(Trixi.rhs!, semi, sol, 1000)
93
end
94
95
@trixi_testset "elixir_advection_unstructured_flag.jl" begin
96
# This test is identical to the one in `test_p4est_2d.jl`.
97
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_unstructured_flag.jl"),
98
l2=[0.0005379687442422346],
99
linf=[0.007438525029884735])
100
# Ensure that we do not have excessive memory allocations
101
# (e.g., from type instabilities)
102
@test_allocations(Trixi.rhs!, semi, sol, 1000)
103
end
104
105
@trixi_testset "elixir_advection_amr_unstructured_flag.jl" begin
106
@test_trixi_include(joinpath(EXAMPLES_DIR,
107
"elixir_advection_amr_unstructured_flag.jl"),
108
l2=[0.002019623611753929],
109
linf=[0.03542375961299987])
110
# Ensure that we do not have excessive memory allocations
111
# (e.g., from type instabilities)
112
@test_allocations(Trixi.rhs!, semi, sol, 1000)
113
end
114
115
@trixi_testset "elixir_advection_amr_solution_independent.jl" begin
116
# This test is identical to the one in `test_p4est_2d.jl`.
117
@test_trixi_include(joinpath(EXAMPLES_DIR,
118
"elixir_advection_amr_solution_independent.jl"),
119
# Expected errors are exactly the same as with StructuredMesh!
120
l2=[4.949660644033807e-5],
121
linf=[0.0004867846262313763])
122
# Ensure that we do not have excessive memory allocations
123
# (e.g., from type instabilities)
124
@test_allocations(Trixi.rhs!, semi, sol, 1000)
125
end
126
127
@trixi_testset "elixir_advection_restart.jl" begin
128
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_restart.jl"),
129
l2=[4.507575525876275e-6],
130
linf=[6.21489667023134e-5])
131
132
# Ensure that we do not have excessive memory allocations
133
# (e.g., from type instabilities)
134
@test_allocations(Trixi.rhs!, semi, sol, 1000)
135
end
136
137
@trixi_testset "elixir_advection_restart_amr.jl" begin
138
# This test is identical to the one in `test_p4est_2d.jl`.
139
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_restart_amr.jl"),
140
l2=[2.869137983727866e-6],
141
linf=[3.8353423270964804e-5])
142
# Ensure that we do not have excessive memory allocations
143
# (e.g., from type instabilities)
144
@test_allocations(Trixi.rhs!, semi, sol, 1000)
145
end
146
147
@trixi_testset "elixir_euler_source_terms_nonconforming_unstructured_flag.jl" begin
148
# This test is identical to the one in `test_p4est_2d.jl`.
149
@test_trixi_include(joinpath(EXAMPLES_DIR,
150
"elixir_euler_source_terms_nonconforming_unstructured_flag.jl"),
151
l2=[
152
0.0034516244508588046,
153
0.0023420334036925493,
154
0.0024261923964557187,
155
0.004731710454271893
156
],
157
linf=[
158
0.04155789011775046,
159
0.024772109862748914,
160
0.03759938693042297,
161
0.08039824959535657
162
])
163
# Ensure that we do not have excessive memory allocations
164
# (e.g., from type instabilities)
165
@test_allocations(Trixi.rhs!, semi, sol, 1000)
166
end
167
168
@trixi_testset "elixir_euler_source_terms_nonconforming_unstructured_flag.jl (O2 inner reconstruction)" begin
169
@test_trixi_include(joinpath(EXAMPLES_DIR,
170
"elixir_euler_source_terms_nonconforming_unstructured_flag.jl"),
171
solver=DGSEM(polydeg = 3, surface_flux = flux_hll,
172
volume_integral = VolumeIntegralPureLGLFiniteVolumeO2(LobattoLegendreBasis(3),
173
volume_flux_fv = flux_hll,
174
reconstruction_mode = reconstruction_O2_inner,
175
slope_limiter = vanleer)),
176
l2=[
177
0.01872951597687948,
178
0.01146844899089883,
179
0.014258199256512774,
180
0.031637508582254815
181
],
182
linf=[
183
0.057283852256227785,
184
0.03992615300124713,
185
0.04871972163845162,
186
0.11212570929707955
187
])
188
# Ensure that we do not have excessive memory allocations
189
# (e.g., from type instabilities)
190
@test_allocations(Trixi.rhs!, semi, sol, 1000)
191
end
192
193
@trixi_testset "elixir_euler_free_stream.jl" begin
194
# This test is identical to the one in `test_p4est_2d.jl`.
195
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_free_stream.jl"),
196
l2=[
197
2.063350241405049e-15,
198
1.8571016296925367e-14,
199
3.1769447886391905e-14,
200
1.4104095258528071e-14
201
],
202
linf=[1.9539925233402755e-14, 2e-12, 4.8e-12, 4e-12],
203
atol=2.0e-12)
204
# Ensure that we do not have excessive memory allocations
205
# (e.g., from type instabilities)
206
@test_allocations(Trixi.rhs!, semi, sol, 1000)
207
end
208
209
@trixi_testset "elixir_euler_shockcapturing_ec.jl" begin
210
# This test is identical to the one in `test_p4est_2d.jl`.
211
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_shockcapturing_ec.jl"),
212
l2=[
213
9.53984675e-02,
214
1.05633455e-01,
215
1.05636158e-01,
216
3.50747237e-01
217
],
218
linf=[
219
2.94357464e-01,
220
4.07893014e-01,
221
3.97334516e-01,
222
1.08142520e+00
223
],
224
tspan=(0.0, 1.0))
225
# Ensure that we do not have excessive memory allocations
226
# (e.g., from type instabilities)
227
@test_allocations(Trixi.rhs!, semi, sol, 1000)
228
end
229
230
@trixi_testset "elixir_euler_sedov.jl" begin
231
# This test is identical to the one in `test_p4est_2d.jl` besides minor
232
# deviations in the expected error norms.
233
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_sedov.jl"),
234
l2=[
235
3.76149952e-01,
236
2.46970327e-01,
237
2.46970327e-01,
238
1.28889042e+00
239
],
240
linf=[
241
1.22139001e+00,
242
1.17742626e+00,
243
1.17742626e+00,
244
6.20638482e+00
245
],
246
tspan=(0.0, 0.3))
247
# Ensure that we do not have excessive memory allocations
248
# (e.g., from type instabilities)
249
@test_allocations(Trixi.rhs!, semi, sol, 1000)
250
end
251
252
@trixi_testset "elixir_mhd_alfven_wave.jl" begin
253
# This test is identical to the one in `test_p4est_2d.jl`.
254
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_mhd_alfven_wave.jl"),
255
l2=[1.0513414461545583e-5, 1.0517900957166411e-6,
256
1.0517900957304043e-6, 1.511816606372376e-6,
257
1.0443997728645063e-6, 7.879639064990798e-7,
258
7.879639065049896e-7, 1.0628631669056271e-6,
259
4.3382328912336153e-7],
260
linf=[4.255466285174592e-5, 1.0029706745823264e-5,
261
1.0029706747467781e-5, 1.2122265939010224e-5,
262
5.4791097160444835e-6, 5.18922042269665e-6,
263
5.189220422141538e-6, 9.552667261422676e-6,
264
1.4237578427628152e-6])
265
# Ensure that we do not have excessive memory allocations
266
# (e.g., from type instabilities)
267
@test_allocations(Trixi.rhs!, semi, sol, 1000)
268
end
269
270
@trixi_testset "elixir_mhd_rotor.jl" begin
271
# This test is identical to the one in `test_p4est_2d.jl` besides minor
272
# deviations in the expected error norms.
273
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_mhd_rotor.jl"),
274
l2=[0.4419337424073218, 0.8804938551016932, 0.8258185723720365,
275
0.0,
276
0.961220188718187, 0.10397273631386837, 0.15408979488125943,
277
0.0,
278
2.66769410449947e-5],
279
linf=[10.053140536236942, 18.17070117006211, 9.549208389448738,
280
0.0,
281
19.676151923191583, 1.3896544044814965, 1.8153256887969416,
282
0.0,
283
0.0022030404596184786],
284
tspan=(0.0, 0.02))
285
# Ensure that we do not have excessive memory allocations
286
# (e.g., from type instabilities)
287
@test_allocations(Trixi.rhs!, semi, sol, 1000)
288
end
289
290
@trixi_testset "elixir_euler_weak_blast_wave_amr.jl" begin
291
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_weak_blast_wave_amr.jl"),
292
l2=[
293
0.10823279736983638,
294
0.1158152939803735,
295
0.11633970342992006,
296
0.751152651902375
297
],
298
linf=[
299
0.5581611332828653,
300
0.8354026029724041,
301
0.834485181423738,
302
3.923553028014343
303
],
304
tspan=(0.0, 0.1))
305
# Ensure that we do not have excessive memory allocations
306
# (e.g., from type instabilities)
307
@test_allocations(Trixi.rhs!, semi, sol, 1000)
308
# Check for conservation
309
state_integrals = Trixi.integrate(sol.u[2], semi)
310
initial_state_integrals = analysis_callback.affect!.initial_state_integrals
311
312
@test isapprox(state_integrals[1], initial_state_integrals[1], atol = 1e-13)
313
@test isapprox(state_integrals[2], initial_state_integrals[2], atol = 1e-13)
314
@test isapprox(state_integrals[3], initial_state_integrals[3], atol = 1e-13)
315
@test isapprox(state_integrals[4], initial_state_integrals[4], atol = 1e-13)
316
end
317
end
318
319
# Clean up afterwards: delete Trixi.jl output directory
320
@test_nowarn rm(outdir, recursive = true)
321
322
end # module
323
324