Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/test/test_parabolic_2d.jl
2055 views
1
module TestExamplesParabolic2D
2
3
using Test
4
using Trixi
5
6
include("test_trixi.jl")
7
8
EXAMPLES_DIR = examples_dir()
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
14
@testset "SemidiscretizationHyperbolicParabolic (2D)" begin
15
#! format: noindent
16
17
@trixi_testset "DGMulti 2D rhs_parabolic!" begin
18
using Trixi
19
dg = DGMulti(polydeg = 2, element_type = Quad(), approximation_type = Polynomial(),
20
surface_integral = SurfaceIntegralWeakForm(flux_central),
21
volume_integral = VolumeIntegralWeakForm())
22
cells_per_dimension = (2, 2)
23
mesh = DGMultiMesh(dg, cells_per_dimension)
24
25
# test with polynomial initial condition x^2 * y
26
# test if we recover the exact second derivative
27
initial_condition = (x, t, equations) -> SVector(x[1]^2 * x[2])
28
29
equations = LinearScalarAdvectionEquation2D(1.0, 1.0)
30
equations_parabolic = LaplaceDiffusion2D(1.0, equations)
31
32
semi = SemidiscretizationHyperbolicParabolic(mesh, equations, equations_parabolic,
33
initial_condition, dg)
34
@trixi_test_nowarn show(stdout, semi)
35
@trixi_test_nowarn show(stdout, MIME"text/plain"(), semi)
36
@trixi_test_nowarn show(stdout, boundary_condition_do_nothing)
37
38
@test nvariables(semi) == nvariables(equations)
39
@test Base.ndims(semi) == Base.ndims(mesh)
40
@test Base.real(semi) == Base.real(dg)
41
42
ode = semidiscretize(semi, (0.0, 0.01))
43
u0 = similar(ode.u0)
44
Trixi.compute_coefficients!(u0, 0.0, semi)
45
@test u0 ode.u0
46
47
# test "do nothing" BC just returns first argument
48
@test boundary_condition_do_nothing(u0, nothing) == u0
49
50
(; cache, cache_parabolic, equations_parabolic) = semi
51
(; gradients) = cache_parabolic
52
for dim in eachindex(gradients)
53
fill!(gradients[dim], zero(eltype(gradients[dim])))
54
end
55
56
# unpack VectorOfArray
57
u0 = Base.parent(ode.u0)
58
t = 0.0
59
# pass in `boundary_condition_periodic` to skip boundary flux/integral evaluation
60
parabolic_scheme = semi.solver_parabolic
61
Trixi.calc_gradient!(gradients, u0, t, mesh, equations_parabolic,
62
boundary_condition_periodic, dg, parabolic_scheme,
63
cache, cache_parabolic)
64
(; x, y, xq, yq) = mesh.md
65
@test getindex.(gradients[1], 1) 2 * xq .* yq
66
@test getindex.(gradients[2], 1) xq .^ 2
67
68
u_flux = similar.(gradients)
69
Trixi.calc_viscous_fluxes!(u_flux, u0, gradients, mesh,
70
equations_parabolic,
71
dg, cache, cache_parabolic)
72
@test u_flux[1] gradients[1]
73
@test u_flux[2] gradients[2]
74
75
du = similar(u0)
76
Trixi.calc_divergence!(du, u0, t, u_flux, mesh,
77
equations_parabolic,
78
boundary_condition_periodic,
79
dg, semi.solver_parabolic, cache, cache_parabolic)
80
Trixi.invert_jacobian!(du, mesh, equations_parabolic, dg, cache; scaling = 1.0)
81
@test getindex.(du, 1) 2 * y
82
end
83
84
@trixi_testset "DGMulti: elixir_advection_diffusion.jl" begin
85
@test_trixi_include(joinpath(EXAMPLES_DIR, "dgmulti_2d",
86
"elixir_advection_diffusion.jl"),
87
cells_per_dimension=(4, 4), tspan=(0.0, 0.1),
88
l2=[0.2485803335154642],
89
linf=[1.079606969242132])
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
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
97
end
98
end
99
100
@trixi_testset "DGMulti: elixir_advection_diffusion_periodic.jl" begin
101
@test_trixi_include(joinpath(EXAMPLES_DIR, "dgmulti_2d",
102
"elixir_advection_diffusion_periodic.jl"),
103
cells_per_dimension=(4, 4), tspan=(0.0, 0.1),
104
l2=[0.03180371984888462],
105
linf=[0.2136821621370909])
106
# Ensure that we do not have excessive memory allocations
107
# (e.g., from type instabilities)
108
let
109
t = sol.t[end]
110
u_ode = sol.u[end]
111
du_ode = similar(u_ode)
112
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
113
end
114
end
115
116
@trixi_testset "DGMulti: elixir_advection_diffusion_nonperiodic.jl" begin
117
@test_trixi_include(joinpath(EXAMPLES_DIR, "dgmulti_2d",
118
"elixir_advection_diffusion_nonperiodic.jl"),
119
cells_per_dimension=(4, 4), tspan=(0.0, 0.1),
120
l2=[0.002123168335604323],
121
linf=[0.00963640423513712])
122
# Ensure that we do not have excessive memory allocations
123
# (e.g., from type instabilities)
124
let
125
t = sol.t[end]
126
u_ode = sol.u[end]
127
du_ode = similar(u_ode)
128
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
129
end
130
end
131
132
@trixi_testset "DGMulti: elixir_navierstokes_convergence.jl" begin
133
@test_trixi_include(joinpath(EXAMPLES_DIR, "dgmulti_2d",
134
"elixir_navierstokes_convergence.jl"),
135
cells_per_dimension=(4, 4), tspan=(0.0, 0.1),
136
l2=[
137
0.0015355076237431118,
138
0.003384316785885901,
139
0.0036531858026850757,
140
0.009948436101649498
141
],
142
linf=[
143
0.005522560543588462,
144
0.013425258431728926,
145
0.013962115936715924,
146
0.027483099961148838
147
])
148
# Ensure that we do not have excessive memory allocations
149
# (e.g., from type instabilities)
150
let
151
t = sol.t[end]
152
u_ode = sol.u[end]
153
du_ode = similar(u_ode)
154
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
155
end
156
end
157
158
@trixi_testset "DGMulti: elixir_navierstokes_convergence_curved.jl" begin
159
@test_trixi_include(joinpath(EXAMPLES_DIR, "dgmulti_2d",
160
"elixir_navierstokes_convergence_curved.jl"),
161
cells_per_dimension=(4, 4), tspan=(0.0, 0.1),
162
l2=[
163
0.0042551020940351444,
164
0.011118489080358264,
165
0.011281831362358863,
166
0.035736565778376306
167
],
168
linf=[
169
0.015071709836357083,
170
0.04103131887989486,
171
0.03990424032494211,
172
0.13094018584692968
173
])
174
# Ensure that we do not have excessive memory allocations
175
# (e.g., from type instabilities)
176
let
177
t = sol.t[end]
178
u_ode = sol.u[end]
179
du_ode = similar(u_ode)
180
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
181
end
182
end
183
184
@trixi_testset "DGMulti: elixir_navierstokes_lid_driven_cavity.jl" begin
185
@test_trixi_include(joinpath(EXAMPLES_DIR, "dgmulti_2d",
186
"elixir_navierstokes_lid_driven_cavity.jl"),
187
cells_per_dimension=(4, 4), tspan=(0.0, 0.5),
188
l2=[
189
0.0002215612357465129,
190
0.028318325887331217,
191
0.009509168805093485,
192
0.028267893004691534
193
],
194
linf=[
195
0.0015622793960574644,
196
0.1488665309341318,
197
0.07163235778907852,
198
0.19472797949052278
199
])
200
# Ensure that we do not have excessive memory allocations
201
# (e.g., from type instabilities)
202
let
203
t = sol.t[end]
204
u_ode = sol.u[end]
205
du_ode = similar(u_ode)
206
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
207
end
208
end
209
210
@trixi_testset "TreeMesh2D: elixir_advection_diffusion.jl" begin
211
@test_trixi_include(joinpath(EXAMPLES_DIR, "tree_2d_dgsem",
212
"elixir_advection_diffusion.jl"),
213
initial_refinement_level=2, tspan=(0.0, 0.4), polydeg=5,
214
l2=[4.0915532997994255e-6],
215
linf=[2.3040850347877395e-5])
216
# Ensure that we do not have excessive memory allocations
217
# (e.g., from type instabilities)
218
let
219
t = sol.t[end]
220
u_ode = sol.u[end]
221
du_ode = similar(u_ode)
222
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
223
end
224
end
225
226
@trixi_testset "TreeMesh2D: elixir_advection_diffusion.jl (LDG)" begin
227
@test_trixi_include(joinpath(EXAMPLES_DIR, "tree_2d_dgsem",
228
"elixir_advection_diffusion.jl"),
229
solver_parabolic=ViscousFormulationLocalDG(),
230
initial_refinement_level=2, tspan=(0.0, 0.4), polydeg=5,
231
l2=[6.193056910594806e-6], linf=[4.918855889635143e-5])
232
# Ensure that we do not have excessive memory allocations
233
# (e.g., from type instabilities)
234
let
235
t = sol.t[end]
236
u_ode = sol.u[end]
237
du_ode = similar(u_ode)
238
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
239
end
240
end
241
242
@trixi_testset "TreeMesh2D: elixir_advection_diffusion.jl (Refined mesh)" begin
243
@test_trixi_include(joinpath(EXAMPLES_DIR, "tree_2d_dgsem",
244
"elixir_advection_diffusion.jl"),
245
tspan=(0.0, 0.0))
246
LLID = Trixi.local_leaf_cells(mesh.tree)
247
num_leaves = length(LLID)
248
@assert num_leaves % 8 == 0
249
Trixi.refine!(mesh.tree, LLID[1:Int(num_leaves / 8)])
250
tspan = (0.0, 1.5)
251
semi = SemidiscretizationHyperbolicParabolic(mesh,
252
(equations, equations_parabolic),
253
initial_condition, solver;
254
boundary_conditions = (boundary_conditions,
255
boundary_conditions_parabolic))
256
ode = semidiscretize(semi, tspan)
257
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
258
callbacks = CallbackSet(summary_callback, alive_callback, analysis_callback)
259
sol = solve(ode, RDPK3SpFSAL49(); abstol = time_int_tol, reltol = time_int_tol,
260
ode_default_options()..., callback = callbacks)
261
l2_error, linf_error = analysis_callback(sol)
262
@test l2_error [1.67452550744728e-6]
263
@test linf_error [7.905059166368744e-6]
264
265
# Ensure that we do not have excessive memory allocations
266
# (e.g., from type instabilities)
267
let
268
t = sol.t[end]
269
u_ode = sol.u[end]
270
du_ode = similar(u_ode)
271
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 100
272
@test (@allocated Trixi.rhs_parabolic!(du_ode, u_ode, semi, t)) < 100
273
end
274
end
275
276
@trixi_testset "TreeMesh2D: elixir_advection_diffusion_amr.jl" begin
277
@test_trixi_include(joinpath(EXAMPLES_DIR, "tree_2d_dgsem",
278
"elixir_advection_diffusion_amr.jl"),
279
initial_refinement_level=2,
280
base_level=2,
281
med_level=3,
282
max_level=4,
283
l2=[0.0009662045510830027],
284
linf=[0.006121646998993091])
285
# Ensure that we do not have excessive memory allocations
286
# (e.g., from type instabilities)
287
let
288
t = sol.t[end]
289
u_ode = sol.u[end]
290
du_ode = similar(u_ode)
291
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
292
end
293
end
294
295
@trixi_testset "TreeMesh2D: elixir_advection_diffusion_nonperiodic.jl" begin
296
@test_trixi_include(joinpath(EXAMPLES_DIR, "tree_2d_dgsem",
297
"elixir_advection_diffusion_nonperiodic.jl"),
298
initial_refinement_level=2, tspan=(0.0, 0.1),
299
l2=[0.007646800618485118],
300
linf=[0.10067621050468958])
301
# Ensure that we do not have excessive memory allocations
302
# (e.g., from type instabilities)
303
let
304
t = sol.t[end]
305
u_ode = sol.u[end]
306
du_ode = similar(u_ode)
307
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
308
end
309
end
310
311
@trixi_testset "TreeMesh2D: elixir_advection_diffusion_nonperiodic.jl (LDG)" begin
312
@test_trixi_include(joinpath(EXAMPLES_DIR, "tree_2d_dgsem",
313
"elixir_advection_diffusion_nonperiodic.jl"),
314
initial_refinement_level=2, tspan=(0.0, 0.1),
315
solver_parabolic=ViscousFormulationLocalDG(),
316
l2=[0.007009146246373517], linf=[0.09535203925012649])
317
# Ensure that we do not have excessive memory allocations
318
# (e.g., from type instabilities)
319
let
320
t = sol.t[end]
321
u_ode = sol.u[end]
322
du_ode = similar(u_ode)
323
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
324
end
325
end
326
327
@trixi_testset "TreeMesh2D: elixir_navierstokes_convergence.jl" begin
328
@test_trixi_include(joinpath(EXAMPLES_DIR, "tree_2d_dgsem",
329
"elixir_navierstokes_convergence.jl"),
330
initial_refinement_level=2, tspan=(0.0, 0.1),
331
analysis_callback=AnalysisCallback(semi,
332
interval = analysis_interval,
333
extra_analysis_integrals = (energy_kinetic,
334
energy_internal,
335
enstrophy)),
336
l2=[
337
0.0021116725306624543,
338
0.003432235149083229,
339
0.003874252819605527,
340
0.012469246082535005
341
],
342
linf=[
343
0.012006418939279007,
344
0.03552087120962882,
345
0.02451274749189282,
346
0.11191122588626357
347
])
348
# Ensure that we do not have excessive memory allocations
349
# (e.g., from type instabilities)
350
let
351
t = sol.t[end]
352
u_ode = sol.u[end]
353
du_ode = similar(u_ode)
354
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
355
end
356
end
357
358
@trixi_testset "TreeMesh2D: elixir_navierstokes_convergence.jl (isothermal walls)" begin
359
using Trixi: Trixi
360
@test_trixi_include(joinpath(EXAMPLES_DIR, "tree_2d_dgsem",
361
"elixir_navierstokes_convergence.jl"),
362
initial_refinement_level=2, tspan=(0.0, 0.1),
363
heat_bc_top_bottom=Isothermal((x, t, equations) -> Trixi.temperature(initial_condition_navier_stokes_convergence_test(x,
364
t,
365
equations),
366
equations)),
367
l2=[
368
0.0021036296503840883,
369
0.003435843933397192,
370
0.003867359878114748,
371
0.012670355349293195
372
],
373
linf=[
374
0.01200626179308184,
375
0.03550212518997239,
376
0.025107947320178275,
377
0.11647078036751068
378
])
379
# Ensure that we do not have excessive memory allocations
380
# (e.g., from type instabilities)
381
let
382
t = sol.t[end]
383
u_ode = sol.u[end]
384
du_ode = similar(u_ode)
385
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
386
end
387
end
388
389
@trixi_testset "TreeMesh2D: elixir_navierstokes_convergence.jl (Entropy gradient variables)" begin
390
@test_trixi_include(joinpath(EXAMPLES_DIR, "tree_2d_dgsem",
391
"elixir_navierstokes_convergence.jl"),
392
initial_refinement_level=2, tspan=(0.0, 0.1),
393
gradient_variables=GradientVariablesEntropy(),
394
l2=[
395
0.002140374251729127,
396
0.003425828709496601,
397
0.0038915122887358097,
398
0.012506862342858291
399
],
400
linf=[
401
0.012244412004772665,
402
0.03507559186131113,
403
0.02458089234472249,
404
0.11425600758024679
405
])
406
# Ensure that we do not have excessive memory allocations
407
# (e.g., from type instabilities)
408
let
409
t = sol.t[end]
410
u_ode = sol.u[end]
411
du_ode = similar(u_ode)
412
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
413
end
414
end
415
416
@trixi_testset "TreeMesh2D: elixir_navierstokes_convergence.jl (Entropy gradient variables, isothermal walls)" begin
417
@test_trixi_include(joinpath(EXAMPLES_DIR, "tree_2d_dgsem",
418
"elixir_navierstokes_convergence.jl"),
419
initial_refinement_level=2, tspan=(0.0, 0.1),
420
gradient_variables=GradientVariablesEntropy(),
421
heat_bc_top_bottom=Isothermal((x, t, equations) -> Trixi.temperature(initial_condition_navier_stokes_convergence_test(x,
422
t,
423
equations),
424
equations)),
425
l2=[
426
0.0021349737347923716,
427
0.0034301388278178365,
428
0.0038928324473968836,
429
0.012693611436338
430
],
431
linf=[
432
0.012244236275761766,
433
0.03505406631430898,
434
0.025099598505644406,
435
0.11795616324985403
436
])
437
# Ensure that we do not have excessive memory allocations
438
# (e.g., from type instabilities)
439
let
440
t = sol.t[end]
441
u_ode = sol.u[end]
442
du_ode = similar(u_ode)
443
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
444
end
445
end
446
447
@trixi_testset "TreeMesh2D: elixir_navierstokes_convergence.jl (flux differencing)" begin
448
@test_trixi_include(joinpath(EXAMPLES_DIR, "tree_2d_dgsem",
449
"elixir_navierstokes_convergence.jl"),
450
initial_refinement_level=2, tspan=(0.0, 0.1),
451
volume_integral=VolumeIntegralFluxDifferencing(flux_central),
452
l2=[
453
0.0021116725306612075,
454
0.0034322351490838703,
455
0.0038742528196011594,
456
0.012469246082545557
457
],
458
linf=[
459
0.012006418939262131,
460
0.0355208712096602,
461
0.024512747491999436,
462
0.11191122588669522
463
])
464
# Ensure that we do not have excessive memory allocations
465
# (e.g., from type instabilities)
466
let
467
t = sol.t[end]
468
u_ode = sol.u[end]
469
du_ode = similar(u_ode)
470
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
471
end
472
end
473
474
@trixi_testset "TreeMesh2D: elixir_navierstokes_convergence.jl (Refined mesh)" begin
475
@test_trixi_include(joinpath(EXAMPLES_DIR, "tree_2d_dgsem",
476
"elixir_navierstokes_convergence.jl"),
477
tspan=(0.0, 0.0), initial_refinement_level=3)
478
LLID = Trixi.local_leaf_cells(mesh.tree)
479
num_leaves = length(LLID)
480
@assert num_leaves % 4 == 0
481
Trixi.refine!(mesh.tree, LLID[1:Int(num_leaves / 4)])
482
tspan = (0.0, 0.5)
483
semi = SemidiscretizationHyperbolicParabolic(mesh, (equations, equations_parabolic),
484
initial_condition, solver;
485
boundary_conditions = (boundary_conditions,
486
boundary_conditions_parabolic),
487
source_terms = source_terms_navier_stokes_convergence_test)
488
ode = semidiscretize(semi, tspan)
489
analysis_callback = AnalysisCallback(semi, interval = analysis_interval)
490
callbacks = CallbackSet(summary_callback, alive_callback, analysis_callback)
491
sol = solve(ode, RDPK3SpFSAL49(); abstol = time_int_tol, reltol = time_int_tol,
492
dt = 1e-5,
493
ode_default_options()..., callback = callbacks)
494
l2_error, linf_error = analysis_callback(sol)
495
@test l2_error
496
[0.00024296959174050973;
497
0.00020932631586399853;
498
0.0005390572390981241;
499
0.00026753561391316933]
500
@test linf_error
501
[0.0016210102053486608;
502
0.0025932876486537016;
503
0.0029539073438284817;
504
0.0020771191202548778]
505
# Ensure that we do not have excessive memory allocations
506
# (e.g., from type instabilities)
507
let
508
t = sol.t[end]
509
u_ode = sol.u[end]
510
du_ode = similar(u_ode)
511
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
512
end
513
end
514
515
@trixi_testset "TreeMesh2D: elixir_navierstokes_lid_driven_cavity.jl" begin
516
@test_trixi_include(joinpath(EXAMPLES_DIR, "tree_2d_dgsem",
517
"elixir_navierstokes_lid_driven_cavity.jl"),
518
initial_refinement_level=2, tspan=(0.0, 0.5),
519
l2=[
520
0.00015144571529699053,
521
0.018766076072331623,
522
0.007065070765652574,
523
0.0208399005734258
524
],
525
linf=[
526
0.0014523369373669048,
527
0.12366779944955864,
528
0.05532450997115432,
529
0.16099927805328207
530
])
531
# Ensure that we do not have excessive memory allocations
532
# (e.g., from type instabilities)
533
let
534
t = sol.t[end]
535
u_ode = sol.u[end]
536
du_ode = similar(u_ode)
537
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
538
end
539
end
540
541
@trixi_testset "TreeMesh2D: elixir_navierstokes_shearlayer_amr.jl" begin
542
@test_trixi_include(joinpath(EXAMPLES_DIR, "tree_2d_dgsem",
543
"elixir_navierstokes_shearlayer_amr.jl"),
544
l2=[
545
0.005155557460409018,
546
0.4048446934219344,
547
0.43040068852937047,
548
1.1255130552079322
549
],
550
linf=[
551
0.03287305649809613,
552
1.1656793717431393,
553
1.3917196016246969,
554
8.146587380114653
555
],
556
tspan=(0.0, 0.7))
557
end
558
559
@trixi_testset "TreeMesh2D: elixir_navierstokes_taylor_green_vortex_sutherland.jl" begin
560
@test_trixi_include(joinpath(EXAMPLES_DIR, "tree_2d_dgsem",
561
"elixir_navierstokes_taylor_green_vortex_sutherland.jl"),
562
l2=[
563
0.001452856280034929,
564
0.0007538775539989481,
565
0.0007538775539988681,
566
0.011035506549989587
567
],
568
linf=[
569
0.003291912841311362,
570
0.002986462478096974,
571
0.0029864624780958637,
572
0.0231954665514138
573
],
574
tspan=(0.0, 1.0))
575
end
576
577
@trixi_testset "P4estMesh2D: elixir_advection_diffusion_periodic.jl" begin
578
@test_trixi_include(joinpath(EXAMPLES_DIR, "p4est_2d_dgsem",
579
"elixir_advection_diffusion_periodic.jl"),
580
trees_per_dimension=(1, 1), initial_refinement_level=2,
581
tspan=(0.0, 0.5),
582
l2=[0.0023754695605828443],
583
linf=[0.008154128363741964])
584
# Ensure that we do not have excessive memory allocations
585
# (e.g., from type instabilities)
586
let
587
t = sol.t[end]
588
u_ode = sol.u[end]
589
du_ode = similar(u_ode)
590
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
591
end
592
end
593
594
@trixi_testset "P4estMesh2D: elixir_advection_diffusion_periodic.jl" begin
595
@test_trixi_include(joinpath(EXAMPLES_DIR, "p4est_2d_dgsem",
596
"elixir_advection_diffusion_periodic.jl"),
597
trees_per_dimension=(1, 1), initial_refinement_level=2,
598
tspan=(0.0, 0.5),
599
l2=[0.0023754695605828443],
600
linf=[0.008154128363741964])
601
# Ensure that we do not have excessive memory allocations
602
# (e.g., from type instabilities)
603
let
604
t = sol.t[end]
605
u_ode = sol.u[end]
606
du_ode = similar(u_ode)
607
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
608
end
609
end
610
611
@trixi_testset "P4estMesh2D: elixir_advection_diffusion_periodic_curved.jl" begin
612
@test_trixi_include(joinpath(EXAMPLES_DIR, "p4est_2d_dgsem",
613
"elixir_advection_diffusion_periodic_curved.jl"),
614
trees_per_dimension=(1, 1), initial_refinement_level=2,
615
tspan=(0.0, 0.5),
616
l2=[0.006708147442490916],
617
linf=[0.04807038397976693])
618
# Ensure that we do not have excessive memory allocations
619
# (e.g., from type instabilities)
620
let
621
t = sol.t[end]
622
u_ode = sol.u[end]
623
du_ode = similar(u_ode)
624
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
625
end
626
end
627
628
@trixi_testset "P4estMesh2D: elixir_advection_diffusion_periodic_amr.jl" begin
629
@test_trixi_include(joinpath(EXAMPLES_DIR, "p4est_2d_dgsem",
630
"elixir_advection_diffusion_periodic_amr.jl"),
631
tspan=(0.0, 0.01),
632
l2=[0.014715887539773128],
633
linf=[0.2285802791900049])
634
# Ensure that we do not have excessive memory allocations
635
# (e.g., from type instabilities)
636
let
637
t = sol.t[end]
638
u_ode = sol.u[end]
639
du_ode = similar(u_ode)
640
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
641
end
642
end
643
644
@trixi_testset "P4estMesh2D: elixir_advection_diffusion_nonperiodic_amr.jl" begin
645
@test_trixi_include(joinpath(EXAMPLES_DIR, "p4est_2d_dgsem",
646
"elixir_advection_diffusion_nonperiodic_amr.jl"),
647
tspan=(0.0, 0.01),
648
l2=[0.007934195641974433],
649
linf=[0.11030265194954081])
650
# Ensure that we do not have excessive memory allocations
651
# (e.g., from type instabilities)
652
let
653
t = sol.t[end]
654
u_ode = sol.u[end]
655
du_ode = similar(u_ode)
656
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
657
end
658
end
659
660
@trixi_testset "P4estMesh2D: elixir_advection_diffusion_nonperiodic_curved.jl" begin
661
@test_trixi_include(joinpath(EXAMPLES_DIR, "p4est_2d_dgsem",
662
"elixir_advection_diffusion_nonperiodic_curved.jl"),
663
trees_per_dimension=(1, 1), initial_refinement_level=2,
664
tspan=(0.0, 0.5),
665
l2=[0.00919917034843865],
666
linf=[0.14186297438393505])
667
# Ensure that we do not have excessive memory allocations
668
# (e.g., from type instabilities)
669
let
670
t = sol.t[end]
671
u_ode = sol.u[end]
672
du_ode = similar(u_ode)
673
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
674
end
675
end
676
677
@trixi_testset "P4estMesh2D: elixir_navierstokes_convergence.jl" begin
678
@test_trixi_include(joinpath(EXAMPLES_DIR, "p4est_2d_dgsem",
679
"elixir_navierstokes_convergence.jl"),
680
initial_refinement_level=1, tspan=(0.0, 0.2),
681
l2=[
682
0.0003811978986531135,
683
0.0005874314969137914,
684
0.0009142898787681551,
685
0.0011613918893790497
686
],
687
linf=[
688
0.0021633623985426453,
689
0.009484348273965089,
690
0.0042315720663082534,
691
0.011661660264076446
692
])
693
# Ensure that we do not have excessive memory allocations
694
# (e.g., from type instabilities)
695
let
696
t = sol.t[end]
697
u_ode = sol.u[end]
698
du_ode = similar(u_ode)
699
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
700
end
701
end
702
703
@trixi_testset "P4estMesh2D: elixir_navierstokes_convergence_nonperiodic.jl" begin
704
@test_trixi_include(joinpath(EXAMPLES_DIR, "p4est_2d_dgsem",
705
"elixir_navierstokes_convergence_nonperiodic.jl"),
706
initial_refinement_level=1, tspan=(0.0, 0.2),
707
l2=[
708
0.0004036496258545996,
709
0.0005869762480189079,
710
0.0009148853742181908,
711
0.0011984191532764543
712
],
713
linf=[
714
0.0024993634989209923,
715
0.009487866203496731,
716
0.004505829506103787,
717
0.011634902753554499
718
])
719
# Ensure that we do not have excessive memory allocations
720
# (e.g., from type instabilities)
721
let
722
t = sol.t[end]
723
u_ode = sol.u[end]
724
du_ode = similar(u_ode)
725
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
726
end
727
end
728
729
@trixi_testset "P4estMesh2D: elixir_navierstokes_lid_driven_cavity.jl" begin
730
@test_trixi_include(joinpath(EXAMPLES_DIR, "p4est_2d_dgsem",
731
"elixir_navierstokes_lid_driven_cavity.jl"),
732
initial_refinement_level=2, tspan=(0.0, 0.5),
733
l2=[
734
0.00028716166408816073,
735
0.08101204560401647,
736
0.02099595625377768,
737
0.05008149754143295
738
],
739
linf=[
740
0.014804500261322406,
741
0.9513271652357098,
742
0.7223919625994717,
743
1.4846907331004786
744
])
745
# Ensure that we do not have excessive memory allocations
746
# (e.g., from type instabilities)
747
let
748
t = sol.t[end]
749
u_ode = sol.u[end]
750
du_ode = similar(u_ode)
751
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
752
end
753
end
754
755
@trixi_testset "P4estMesh2D: elixir_navierstokes_lid_driven_cavity_amr.jl" begin
756
@test_trixi_include(joinpath(EXAMPLES_DIR, "p4est_2d_dgsem",
757
"elixir_navierstokes_lid_driven_cavity_amr.jl"),
758
tspan=(0.0, 1.0),
759
l2=[
760
0.0005323841980601085, 0.07892044543547208,
761
0.02909671646389337, 0.11717468256112017
762
],
763
linf=[
764
0.006045292737899444, 0.9233292581786228,
765
0.7982129977236198, 1.6864546235292153
766
])
767
# Ensure that we do not have excessive memory allocations
768
# (e.g., from type instabilities)
769
let
770
t = sol.t[end]
771
u_ode = sol.u[end]
772
du_ode = similar(u_ode)
773
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
774
end
775
end
776
777
@trixi_testset "elixir_navierstokes_NACA0012airfoil_mach08.jl" begin
778
@test_trixi_include(joinpath(EXAMPLES_DIR, "p4est_2d_dgsem",
779
"elixir_navierstokes_NACA0012airfoil_mach08.jl"),
780
l2=[0.000186486564226516,
781
0.0005076712323400374,
782
0.00038074588984354107,
783
0.002128177239782089],
784
linf=[0.5153387072802718,
785
1.199362305026636,
786
0.9077214424040279,
787
5.666071182328691], tspan=(0.0, 0.001),
788
initial_refinement_level=0,)
789
# Ensure that we do not have excessive memory allocations
790
# (e.g., from type instabilities)
791
let
792
t = sol.t[end]
793
u_ode = sol.u[end]
794
du_ode = similar(u_ode)
795
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
796
end
797
798
u_ode = copy(sol.u[end])
799
du_ode = zero(u_ode) # Just a placeholder in this case
800
801
u = Trixi.wrap_array(u_ode, semi)
802
du = Trixi.wrap_array(du_ode, semi)
803
804
drag_p = Trixi.analyze(drag_coefficient, du, u, tspan[2], mesh, equations, solver,
805
semi.cache, semi)
806
lift_p = Trixi.analyze(lift_coefficient, du, u, tspan[2], mesh, equations, solver,
807
semi.cache, semi)
808
809
drag_f = Trixi.analyze(drag_coefficient_shear_force, du, u, tspan[2], mesh,
810
equations, equations_parabolic, solver,
811
semi.cache, semi, semi.cache_parabolic)
812
lift_f = Trixi.analyze(lift_coefficient_shear_force, du, u, tspan[2], mesh,
813
equations, equations_parabolic, solver,
814
semi.cache, semi, semi.cache_parabolic)
815
816
@test isapprox(drag_p, 0.17963843913309516, atol = 1e-13)
817
@test isapprox(lift_p, 0.26462588007949367, atol = 1e-13)
818
819
@test isapprox(drag_f, 1.5427441885921553, atol = 1e-13)
820
@test isapprox(lift_f, 0.005621910087395724, atol = 1e-13)
821
end
822
823
@trixi_testset "elixir_navierstokes_NACA0012airfoil_mach085_restart.jl" begin
824
@test_trixi_include(joinpath(EXAMPLES_DIR, "p4est_2d_dgsem",
825
"elixir_navierstokes_NACA0012airfoil_mach085_restart.jl"),
826
l2=[
827
6.191672324705442e-6,
828
0.00011583392224949682,
829
0.00011897020463459889,
830
0.006467379086802275
831
],
832
linf=[
833
0.0017446176443216936,
834
0.06961708834164942,
835
0.037063246278530367,
836
1.4435072005258793
837
], tspan=(0.0, 0.01),)
838
# Ensure that we do not have excessive memory allocations
839
# (e.g., from type instabilities)
840
let
841
t = sol.t[end]
842
u_ode = sol.u[end]
843
du_ode = similar(u_ode)
844
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
845
end
846
end
847
848
@trixi_testset "P4estMesh2D: elixir_navierstokes_viscous_shock.jl" begin
849
@test_trixi_include(joinpath(EXAMPLES_DIR, "p4est_2d_dgsem",
850
"elixir_navierstokes_viscous_shock.jl"),
851
l2=[
852
0.0002576236264053728,
853
0.00014336949098706463,
854
7.189100338239794e-17,
855
0.00017369905124642074
856
],
857
linf=[
858
0.0016731940983241156,
859
0.0010638640749656147,
860
5.59044079947959e-16,
861
0.001149532023891009
862
])
863
# Ensure that we do not have excessive memory allocations
864
# (e.g., from type instabilities)
865
let
866
t = sol.t[end]
867
u_ode = sol.u[end]
868
du_ode = similar(u_ode)
869
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
870
end
871
end
872
873
@trixi_testset "P4estMesh2D: elixir_navierstokes_viscous_shock_newton_krylov.jl" begin
874
@test_trixi_include(joinpath(EXAMPLES_DIR, "p4est_2d_dgsem",
875
"elixir_navierstokes_viscous_shock_newton_krylov.jl"),
876
tspan=(0.0, 0.1),
877
l2=[
878
3.468233560427797e-5,
879
2.64864594855224e-5,
880
7.879490760481979e-10,
881
2.8748482665365446e-5
882
],
883
linf=[
884
0.00018754529350140103,
885
0.00014045634087878067,
886
9.043610782328732e-9,
887
0.00014499382160382268
888
])
889
# Ensure that we do not have excessive memory allocations
890
# (e.g., from type instabilities)
891
let
892
t = sol.t[end]
893
u_ode = sol.u[end]
894
du_ode = similar(u_ode)
895
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
896
end
897
end
898
899
@trixi_testset "elixir_navierstokes_SD7003airfoil.jl" begin
900
@test_trixi_include(joinpath(EXAMPLES_DIR, "p4est_2d_dgsem",
901
"elixir_navierstokes_SD7003airfoil.jl"),
902
l2=[
903
9.292899618740586e-5,
904
0.0001350510200255721,
905
7.964907891113045e-5,
906
0.0002336568736996096
907
],
908
linf=[
909
0.2845637352223691,
910
0.295808392241858,
911
0.19309201225626166,
912
0.7188927326929244
913
],
914
tspan=(0.0, 5e-3))
915
# Ensure that we do not have excessive memory allocations
916
# (e.g., from type instabilities)
917
let
918
t = sol.t[end]
919
u_ode = sol.u[end]
920
du_ode = similar(u_ode)
921
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
922
end
923
end
924
925
@trixi_testset "elixir_navierstokes_SD7003airfoil.jl (CFL-Interval)" begin
926
@test_trixi_include(joinpath(EXAMPLES_DIR, "p4est_2d_dgsem",
927
"elixir_navierstokes_SD7003airfoil.jl"),
928
l2=[
929
9.292895651912815e-5,
930
0.0001350510066877861,
931
7.964905098170568e-5,
932
0.00023365678706785303
933
],
934
linf=[
935
0.2845614660523972,
936
0.29577255454711177,
937
0.19307666048254143,
938
0.7188872358580256
939
],
940
tspan=(0.0, 5e-3),
941
stepsize_callback=StepsizeCallback(cfl = 2.2, interval = 5))
942
# Ensure that we do not have excessive memory allocations
943
# (e.g., from type instabilities)
944
let
945
t = sol.t[end]
946
u_ode = sol.u[end]
947
du_ode = similar(u_ode)
948
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
949
end
950
end
951
952
@trixi_testset "elixir_navierstokes_vortex_street.jl" begin
953
@test_trixi_include(joinpath(EXAMPLES_DIR, "p4est_2d_dgsem",
954
"elixir_navierstokes_vortex_street.jl"),
955
l2=[
956
0.012420217727434794,
957
0.028935260981567217,
958
0.023078384429351353,
959
0.11317643179072025
960
],
961
linf=[
962
0.4484833725983406,
963
1.268913882714608,
964
0.7071821629898418,
965
3.643975012834931
966
],
967
tspan=(0.0, 1.0))
968
# Ensure that we do not have excessive memory allocations
969
# (e.g., from type instabilities)
970
let
971
t = sol.t[end]
972
u_ode = sol.u[end]
973
du_ode = similar(u_ode)
974
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
975
end
976
end
977
978
@trixi_testset "elixir_navierstokes_poiseuille_flow.jl" begin
979
@test_trixi_include(joinpath(EXAMPLES_DIR, "p4est_2d_dgsem",
980
"elixir_navierstokes_poiseuille_flow.jl"),
981
l2=[
982
0.028671228188785286,
983
0.2136420195921885,
984
0.009953689550858224,
985
0.13216036594768157
986
],
987
linf=[
988
0.30901218409540543,
989
1.3488655161645846,
990
0.1304661713119874,
991
1.2094591729756736],
992
tspan=(0.0, 1.0))
993
# Ensure that we do not have excessive memory allocations
994
# (e.g., from type instabilities)
995
let
996
t = sol.t[end]
997
u_ode = sol.u[end]
998
du_ode = similar(u_ode)
999
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
1000
end
1001
end
1002
1003
@trixi_testset "elixir_navierstokes_kelvin_helmholtz_instability_sc_subcell.jl" begin
1004
@test_trixi_include(joinpath(EXAMPLES_DIR, "tree_2d_dgsem",
1005
"elixir_navierstokes_kelvin_helmholtz_instability_sc_subcell.jl"),
1006
l2=[
1007
0.1987691550257618,
1008
0.1003336666735962,
1009
0.1599420846677608,
1010
0.07314642823482713
1011
],
1012
linf=[
1013
0.8901520920065688,
1014
0.47421178500575756,
1015
0.38859478648621326,
1016
0.3247497921546598
1017
],
1018
tspan=(0.0, 1.0))
1019
# Ensure that we do not have excessive memory allocations
1020
# (e.g., from type instabilities)
1021
let
1022
t = sol.t[end]
1023
u_ode = sol.u[end]
1024
du_ode = similar(u_ode)
1025
# Larger values for allowed allocations due to usage of custom
1026
# integrator which are not *recorded* for the methods from
1027
# OrdinaryDiffEq.jl
1028
# Corresponding issue: https://github.com/trixi-framework/Trixi.jl/issues/1877
1029
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 15000
1030
end
1031
end
1032
1033
@trixi_testset "elixir_navierstokes_freestream_symmetry.jl" begin
1034
@test_trixi_include(joinpath(EXAMPLES_DIR, "p4est_2d_dgsem",
1035
"elixir_navierstokes_freestream_symmetry.jl"),
1036
l2=[
1037
4.37868326434923e-15,
1038
7.002449644031901e-16,
1039
1.0986677074164136e-14,
1040
1.213800745067394e-14
1041
],
1042
linf=[
1043
2.531308496145357e-14,
1044
3.8367543336926215e-15,
1045
4.9960036108132044e-14,
1046
6.705747068735946e-14
1047
])
1048
# Ensure that we do not have excessive memory allocations
1049
# (e.g., from type instabilities)
1050
let
1051
t = sol.t[end]
1052
u_ode = sol.u[end]
1053
du_ode = similar(u_ode)
1054
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
1055
end
1056
end
1057
1058
@trixi_testset "elixir_navierstokes_couette_flow.jl" begin
1059
@test_trixi_include(joinpath(EXAMPLES_DIR, "p4est_2d_dgsem",
1060
"elixir_navierstokes_couette_flow.jl"),
1061
l2=[
1062
0.009585252225488753,
1063
0.007939233099864973,
1064
0.0007617512688442657,
1065
0.027229870237669436
1066
],
1067
linf=[
1068
0.027230029149270862,
1069
0.027230451118692933,
1070
0.0038642959675975713,
1071
0.04738248734987671
1072
])
1073
# Ensure that we do not have excessive memory allocations
1074
# (e.g., from type instabilities)
1075
let
1076
t = sol.t[end]
1077
u_ode = sol.u[end]
1078
du_ode = similar(u_ode)
1079
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
1080
end
1081
end
1082
1083
@trixi_testset "elixir_navierstokes_blast_reflective.jl" begin
1084
@test_trixi_include(joinpath(EXAMPLES_DIR, "p4est_2d_dgsem",
1085
"elixir_navierstokes_blast_reflective.jl"),
1086
l2=[
1087
0.08271777454941344,
1088
0.10020048140682014,
1089
0.10020048140682006,
1090
0.5954017435122945
1091
],
1092
linf=[
1093
0.4785944470287504,
1094
0.7205772140501768,
1095
0.7205772140501767,
1096
3.25120873497427
1097
],
1098
tspan=(0.0, 0.05),
1099
abstol=1e-7, reltol=1e-7)
1100
# Ensure that we do not have excessive memory allocations
1101
# (e.g., from type instabilities)
1102
let
1103
t = sol.t[end]
1104
u_ode = sol.u[end]
1105
du_ode = similar(u_ode)
1106
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
1107
end
1108
end
1109
end
1110
1111
# Clean up afterwards: delete Trixi.jl output directory
1112
@test_nowarn isdir(outdir) && rm(outdir, recursive = true)
1113
1114
end # module
1115
1116