Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/test/test_tree_2d_advection.jl
2055 views
1
module TestExamples2DAdvection
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 "Linear scalar advection" begin
11
#! format: noindent
12
13
@trixi_testset "elixir_advection_basic.jl" begin
14
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_basic.jl"),
15
# Expected errors are exactly the same as in the parallel test!
16
l2=[8.311947673061856e-6],
17
linf=[6.627000273229378e-5])
18
# Ensure that we do not have excessive memory allocations
19
# (e.g., from type instabilities)
20
let
21
t = sol.t[end]
22
u_ode = sol.u[end]
23
du_ode = similar(u_ode)
24
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
25
end
26
end
27
28
@trixi_testset "elixir_advection_extended.jl with polydeg=1" begin
29
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_extended.jl"),
30
l2=[0.02134571266411136],
31
linf=[0.04347734797775926],
32
polydeg=1)
33
# Ensure that we do not have excessive memory allocations
34
# (e.g., from type instabilities)
35
let
36
t = sol.t[end]
37
u_ode = sol.u[end]
38
du_ode = similar(u_ode)
39
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
40
end
41
end
42
43
@trixi_testset "elixir_advection_implicit_sparse_jacobian.jl" begin
44
@test_trixi_include(joinpath(EXAMPLES_DIR,
45
"elixir_advection_implicit_sparse_jacobian.jl"),
46
l2=[0.003003253325111022], linf=[0.004256250998163846])
47
# Ensure that we do not have excessive memory allocations
48
# (e.g., from type instabilities)
49
let
50
t = sol.t[end]
51
u_ode = sol.u[end]
52
du_ode = similar(u_ode)
53
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi_float_type, t)) < 1000
54
end
55
end
56
57
@trixi_testset "elixir_advection_implicit_sparse_jacobian_restart.jl" begin
58
@test_trixi_include(joinpath(EXAMPLES_DIR,
59
"elixir_advection_implicit_sparse_jacobian_restart.jl"),
60
l2=[0.007964280656552015], linf=[0.011267546271397588])
61
# Ensure that we do not have excessive memory allocations
62
# (e.g., from type instabilities)
63
let
64
t = sol.t[end]
65
u_ode = sol.u[end]
66
du_ode = similar(u_ode)
67
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi_float_type, t)) < 1000
68
end
69
end
70
71
@trixi_testset "elixir_advection_implicit_sparse_jacobian_restart.jl (no colorvec)" begin
72
@test_trixi_include(joinpath(EXAMPLES_DIR,
73
"elixir_advection_implicit_sparse_jacobian_restart.jl"),
74
colorvec=nothing,
75
l2=[0.007964280656552015], linf=[0.011267546271397588])
76
# Ensure that we do not have excessive memory allocations
77
# (e.g., from type instabilities)
78
let
79
t = sol.t[end]
80
u_ode = sol.u[end]
81
du_ode = similar(u_ode)
82
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi_float_type, t)) < 1000
83
end
84
end
85
86
@trixi_testset "elixir_advection_restart.jl" begin
87
using OrdinaryDiffEqSSPRK: SSPRK43
88
println("═"^100)
89
println(joinpath(EXAMPLES_DIR, "elixir_advection_timeintegration_adaptive.jl"))
90
trixi_include(@__MODULE__,
91
joinpath(EXAMPLES_DIR,
92
"elixir_advection_timeintegration_adaptive.jl"),
93
alg = SSPRK43(), tspan = (0.0, 10.0))
94
l2_expected, linf_expected = analysis_callback(sol)
95
96
println("═"^100)
97
println(joinpath(EXAMPLES_DIR, "elixir_advection_restart.jl"))
98
# Errors are exactly the same as in the elixir_advection_extended.jl
99
trixi_include(@__MODULE__, joinpath(EXAMPLES_DIR, "elixir_advection_restart.jl"),
100
alg = SSPRK43(),
101
base_elixir = "elixir_advection_timeintegration_adaptive.jl")
102
l2_actual, linf_actual = analysis_callback(sol)
103
104
@test l2_actual == l2_expected
105
@test linf_actual == linf_expected
106
end
107
108
@trixi_testset "elixir_advection_mortar.jl" begin
109
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_mortar.jl"),
110
# Expected errors are exactly the same as in the parallel test!
111
l2=[0.0015188466707237375],
112
linf=[0.008446655719187679])
113
114
# Ensure that we do not have excessive memory allocations
115
# (e.g., from type instabilities)
116
let
117
t = sol.t[end]
118
u_ode = sol.u[end]
119
du_ode = similar(u_ode)
120
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
121
end
122
end
123
124
@trixi_testset "elixir_advection_amr.jl" begin
125
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_amr.jl"),
126
# Expected errors are exactly the same as in the parallel test!
127
l2=[4.913300828257469e-5],
128
linf=[0.00045263895394385967])
129
# Ensure that we do not have excessive memory allocations
130
# (e.g., from type instabilities)
131
let
132
t = sol.t[end]
133
u_ode = sol.u[end]
134
du_ode = similar(u_ode)
135
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
136
end
137
end
138
139
@trixi_testset "elixir_advection_amr_nonperiodic.jl" begin
140
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_amr_nonperiodic.jl"),
141
# Expected errors are exactly the same as in the parallel test!
142
l2=[3.2207388565869075e-5],
143
linf=[0.0007508059772436404])
144
# Ensure that we do not have excessive memory allocations
145
# (e.g., from type instabilities)
146
let
147
t = sol.t[end]
148
u_ode = sol.u[end]
149
du_ode = similar(u_ode)
150
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
151
end
152
end
153
154
@trixi_testset "elixir_advection_amr_solution_independent.jl" begin
155
@test_trixi_include(joinpath(EXAMPLES_DIR,
156
"elixir_advection_amr_solution_independent.jl"),
157
l2=[4.949660644033807e-5],
158
linf=[0.0004867846262313763])
159
# Ensure that we do not have excessive memory allocations
160
# (e.g., from type instabilities)
161
let
162
t = sol.t[end]
163
u_ode = sol.u[end]
164
du_ode = similar(u_ode)
165
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
166
end
167
end
168
169
@trixi_testset "elixir_advection_amr_visualization.jl" begin
170
# To make CI tests work, disable showing a plot window with the GR backend of the Plots package
171
# Xref: https://github.com/jheinen/GR.jl/issues/278
172
# Xref: https://github.com/JuliaPlots/Plots.jl/blob/8cc6d9d48755ba452a2835f9b89d3880e9945377/test/runtests.jl#L103
173
if !isinteractive()
174
restore = get(ENV, "GKSwstype", nothing)
175
ENV["GKSwstype"] = "100"
176
end
177
178
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_amr_visualization.jl"),
179
l2=[0.0007225529919720868],
180
linf=[0.005954447875428925])
181
182
# Restore GKSwstype to previous value (if it was set)
183
if !isinteractive()
184
if isnothing(restore)
185
delete!(ENV, "GKSwstype")
186
else
187
ENV["GKSwstype"] = restore
188
end
189
end
190
end
191
192
@trixi_testset "elixir_advection_timeintegration.jl" begin
193
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_timeintegration.jl"),
194
l2=[2.4976030518356626e-5],
195
linf=[0.0005531580316338533])
196
# Ensure that we do not have excessive memory allocations
197
# (e.g., from type instabilities)
198
let
199
t = sol.t[end]
200
u_ode = sol.u[end]
201
du_ode = similar(u_ode)
202
# Larger values for allowed allocations due to usage of custom
203
# integrator which are not *recorded* for the methods from
204
# OrdinaryDiffEq.jl
205
# Corresponding issue: https://github.com/trixi-framework/Trixi.jl/issues/1877
206
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 15000
207
end
208
end
209
end
210
211
@trixi_testset "elixir_advection_timeintegration.jl with carpenter_kennedy_erk43" begin
212
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_timeintegration.jl"),
213
l2=[2.5314747030031457e-5],
214
linf=[0.0005437136621948904],
215
ode_algorithm=Trixi.CarpenterKennedy2N43(),
216
cfl=1.0)
217
# Ensure that we do not have excessive memory allocations
218
# (e.g., from type instabilities)
219
let
220
t = sol.t[end]
221
u_ode = sol.u[end]
222
du_ode = similar(u_ode)
223
# Larger values for allowed allocations due to usage of custom
224
# integrator which are not *recorded* for the methods from
225
# OrdinaryDiffEq.jl
226
# Corresponding issue: https://github.com/trixi-framework/Trixi.jl/issues/1877
227
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 15000
228
end
229
end
230
231
@trixi_testset "elixir_advection_timeintegration.jl with carpenter_kennedy_erk43 with maxiters=1" begin
232
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_timeintegration.jl"),
233
l2=[1.2135350502911197e-5],
234
linf=[9.999985420537649e-5],
235
ode_algorithm=Trixi.CarpenterKennedy2N43(),
236
cfl=1.0,
237
maxiters=1)
238
# Ensure that we do not have excessive memory allocations
239
# (e.g., from type instabilities)
240
let
241
t = sol.t[end]
242
u_ode = sol.u[end]
243
du_ode = similar(u_ode)
244
# Larger values for allowed allocations due to usage of custom
245
# integrator which are not *recorded* for the methods from
246
# OrdinaryDiffEq.jl
247
# Corresponding issue: https://github.com/trixi-framework/Trixi.jl/issues/1877
248
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 15000
249
end
250
end
251
252
@trixi_testset "elixir_advection_timeintegration.jl with parsani_ketcheson_deconinck_erk94" begin
253
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_timeintegration.jl"),
254
l2=[2.4976673477385313e-5],
255
linf=[0.0005534166916640881],
256
ode_algorithm=Trixi.ParsaniKetchesonDeconinck3Sstar94())
257
# Ensure that we do not have excessive memory allocations
258
# (e.g., from type instabilities)
259
let
260
t = sol.t[end]
261
u_ode = sol.u[end]
262
du_ode = similar(u_ode)
263
# Larger values for allowed allocations due to usage of custom
264
# integrator which are not *recorded* for the methods from
265
# OrdinaryDiffEq.jl
266
# Corresponding issue: https://github.com/trixi-framework/Trixi.jl/issues/1877
267
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 15000
268
end
269
end
270
271
@trixi_testset "elixir_advection_timeintegration.jl with parsani_ketcheson_deconinck_erk32" begin
272
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_timeintegration.jl"),
273
l2=[3.667894656471403e-5],
274
linf=[0.0005799465470165757],
275
ode_algorithm=Trixi.ParsaniKetchesonDeconinck3Sstar32(),
276
cfl=1.0)
277
# Ensure that we do not have excessive memory allocations
278
# (e.g., from type instabilities)
279
let
280
t = sol.t[end]
281
u_ode = sol.u[end]
282
du_ode = similar(u_ode)
283
# Larger values for allowed allocations due to usage of custom
284
# integrator which are not *recorded* for the methods from
285
# OrdinaryDiffEq.jl
286
# Corresponding issue: https://github.com/trixi-framework/Trixi.jl/issues/1877
287
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 15000
288
end
289
end
290
291
@trixi_testset "elixir_advection_timeintegration.jl with parsani_ketcheson_deconinck_erk32 with maxiters=1" begin
292
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_timeintegration.jl"),
293
l2=[1.2198725469737875e-5],
294
linf=[9.977247740793407e-5],
295
ode_algorithm=Trixi.ParsaniKetchesonDeconinck3Sstar32(),
296
cfl=1.0,
297
maxiters=1)
298
# Ensure that we do not have excessive memory allocations
299
# (e.g., from type instabilities)
300
let
301
t = sol.t[end]
302
u_ode = sol.u[end]
303
du_ode = similar(u_ode)
304
# Larger values for allowed allocations due to usage of custom
305
# integrator which are not *recorded* for the methods from
306
# OrdinaryDiffEq.jl
307
# Corresponding issue: https://github.com/trixi-framework/Trixi.jl/issues/1877
308
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 15000
309
end
310
end
311
312
@trixi_testset "elixir_advection_callbacks.jl" begin
313
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_callbacks.jl"),
314
l2=[8.311947673061856e-6],
315
linf=[6.627000273229378e-5])
316
# Ensure that we do not have excessive memory allocations
317
# (e.g., from type instabilities)
318
let
319
t = sol.t[end]
320
u_ode = sol.u[end]
321
du_ode = similar(u_ode)
322
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
323
end
324
end
325
326
# Coverage test for all initial conditions
327
@testset "Linear scalar advection: Tests for initial conditions" begin
328
# Linear scalar advection
329
@trixi_testset "elixir_advection_extended.jl with initial_condition_sin_sin" begin
330
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_extended.jl"),
331
l2=[0.0001420618061089383],
332
linf=[0.0007140570281718439],
333
maxiters=1,
334
initial_condition=Trixi.initial_condition_sin_sin)
335
# Ensure that we do not have excessive memory allocations
336
# (e.g., from type instabilities)
337
let
338
t = sol.t[end]
339
u_ode = sol.u[end]
340
du_ode = similar(u_ode)
341
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
342
end
343
end
344
345
@trixi_testset "elixir_advection_extended.jl with initial_condition_constant" begin
346
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_extended.jl"),
347
l2=[3.8302867746057483e-16],
348
linf=[1.3322676295501878e-15],
349
maxiters=1,
350
initial_condition=initial_condition_constant)
351
# Ensure that we do not have excessive memory allocations
352
# (e.g., from type instabilities)
353
let
354
t = sol.t[end]
355
u_ode = sol.u[end]
356
du_ode = similar(u_ode)
357
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
358
end
359
end
360
361
@trixi_testset "elixir_advection_extended.jl with initial_condition_linear_x_y" begin
362
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_extended.jl"),
363
l2=[2.7276160570381226e-16],
364
linf=[5.10702591327572e-15],
365
maxiters=1,
366
initial_condition=Trixi.initial_condition_linear_x_y,
367
boundary_conditions=Trixi.boundary_condition_linear_x_y,
368
periodicity=false)
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_advection_extended.jl with initial_condition_linear_x" begin
380
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_extended.jl"),
381
l2=[1.5121648229368207e-16],
382
linf=[1.3322676295501878e-15],
383
maxiters=1,
384
initial_condition=Trixi.initial_condition_linear_x,
385
boundary_conditions=Trixi.boundary_condition_linear_x,
386
periodicity=false)
387
# Ensure that we do not have excessive memory allocations
388
# (e.g., from type instabilities)
389
let
390
t = sol.t[end]
391
u_ode = sol.u[end]
392
du_ode = similar(u_ode)
393
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
394
end
395
end
396
397
@trixi_testset "elixir_advection_extended.jl with initial_condition_linear_y" begin
398
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_extended.jl"),
399
l2=[1.714292614252588e-16],
400
linf=[2.220446049250313e-15],
401
maxiters=1,
402
initial_condition=Trixi.initial_condition_linear_y,
403
boundary_conditions=Trixi.boundary_condition_linear_y,
404
periodicity=false)
405
# Ensure that we do not have excessive memory allocations
406
# (e.g., from type instabilities)
407
let
408
t = sol.t[end]
409
u_ode = sol.u[end]
410
du_ode = similar(u_ode)
411
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
412
end
413
end
414
end
415
416
end # module
417
418