Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/test/test_structured_1d.jl
5582 views
1
module TestExamplesStructuredMesh1D
2
3
using Test
4
using Trixi
5
6
include("test_trixi.jl")
7
8
EXAMPLES_DIR = joinpath(examples_dir(), "structured_1d_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
14
@testset "StructuredMesh1D" begin
15
#! format: noindent
16
17
@trixi_testset "elixir_advection_basic.jl" begin
18
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_basic.jl"),
19
# Expected errors are exactly the same as with TreeMesh!
20
l2=[6.0388296447998465e-6],
21
linf=[3.217887726258972e-5])
22
# Ensure that we do not have excessive memory allocations
23
# (e.g., from type instabilities)
24
@test_allocations(Trixi.rhs!, semi, sol, 1000)
25
end
26
27
@trixi_testset "elixir_advection_basic.jl (Gauss-Legendre)" begin
28
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_basic.jl"),
29
solver=DGSEM(polydeg = 3, basis_type = GaussLegendreBasis,
30
surface_flux = flux_godunov),
31
cfl=0.8,
32
# Expected errors are exactly the same as with TreeMesh!
33
l2=[2.515203865524688e-6],
34
linf=[8.660338936650191e-6])
35
# Ensure that we do not have excessive memory allocations
36
# (e.g., from type instabilities)
37
@test_allocations(Trixi.rhs!, semi, sol, 1000)
38
end
39
40
@trixi_testset "elixir_advection_nonperiodic.jl" begin
41
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_nonperiodic.jl"),
42
l2=[5.641921365468918e-5],
43
linf=[0.00021049780975179733])
44
# Ensure that we do not have excessive memory allocations
45
# (e.g., from type instabilities)
46
@test_allocations(Trixi.rhs!, semi, sol, 1000)
47
end
48
49
@trixi_testset "elixir_advection_nonuniform.jl" begin
50
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_nonuniform.jl"),
51
l2=[0.0006665846145698006], linf=[0.00643334347367408])
52
# Ensure that we do not have excessive memory allocations
53
# (e.g., from type instabilities)
54
@test_allocations(Trixi.rhs!, semi, sol, 1000)
55
end
56
57
@trixi_testset "elixir_advection_shockcapturing.jl" begin
58
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_shockcapturing.jl"),
59
l2=[0.08015029105233593],
60
linf=[0.610709468736576],
61
atol=1.0e-5)
62
# Ensure that we do not have excessive memory allocations
63
# (e.g., from type instabilities)
64
@test_allocations(Trixi.rhs!, semi, sol, 1000)
65
end
66
67
@trixi_testset "elixir_advection_float128.jl" begin
68
using Quadmath: Float128
69
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_float128.jl"),
70
l2=Float128[6.49879312655540217059228636803492411e-09],
71
linf=Float128[5.35548407857266390181158920649552284e-08])
72
# Ensure that we do not have excessive memory allocations
73
# (e.g., from type instabilities)
74
@test_allocations(Trixi.rhs!, semi, sol, 1000)
75
end
76
77
# Testing the third-order paired explicit Runge-Kutta (PERK) method with its optimal CFL number
78
@trixi_testset "elixir_burgers_perk3.jl" begin
79
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_burgers_perk3.jl"),
80
l2=[3.8156922097242205e-6],
81
linf=[2.1962957979626552e-5],
82
atol=1.0e-6)
83
# Ensure that we do not have excessive memory allocations
84
# (e.g., from type instabilities)
85
@test_allocations(Trixi.rhs!, semi, sol, 8000)
86
87
# Test `resize!`
88
integrator = Trixi.init(ode, ode_algorithm, dt = 42.0, callback = callbacks)
89
resize!(integrator, 42)
90
@test length(integrator.u) == 42
91
@test length(integrator.du) == 42
92
@test length(integrator.u_tmp) == 42
93
@test length(integrator.k1) == 42
94
@test length(integrator.kS1) == 42
95
end
96
97
# Testing the third-order paired explicit Runge-Kutta (PERK) method without stepsize callback
98
@trixi_testset "elixir_burgers_perk3.jl(fixed time step)" begin
99
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_burgers_perk3.jl"),
100
dt=2.0e-3,
101
tspan=(0.0, 2.0),
102
save_solution=SaveSolutionCallback(dt = 0.1 + 1.0e-8), # Adding a small epsilon to avoid floating-point precision issues
103
callbacks=CallbackSet(summary_callback, save_solution,
104
analysis_callback, alive_callback),
105
l2=[5.725028892495733e-7],
106
linf=[3.4292579200734252e-6],
107
atol=1e-7)
108
# Ensure that we do not have excessive memory allocations
109
# (e.g., from type instabilities)
110
@test_allocations(Trixi.rhs!, semi, sol, 8000)
111
end
112
113
@trixi_testset "elixir_euler_convergence_nonuniform.jl" begin
114
@test_trixi_include(joinpath(EXAMPLES_DIR,
115
"elixir_euler_convergence_nonuniform.jl"),
116
l2=[
117
6.0145954087568086e-5,
118
4.865396929677369e-5,
119
0.00012525608158029655
120
],
121
linf=[
122
0.00014050847320445925,
123
0.00038307746603916115,
124
0.0006872324329503243
125
])
126
# Ensure that we do not have excessive memory allocations
127
# (e.g., from type instabilities)
128
@test_allocations(Trixi.rhs!, semi, sol, 1000)
129
end
130
131
@trixi_testset "elixir_euler_sedov.jl" begin
132
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_sedov.jl"),
133
l2=[3.67478226e-01, 3.49491179e-01, 8.08910759e-01],
134
linf=[1.58971947e+00, 1.59812384e+00, 1.94732969e+00],
135
tspan=(0.0, 0.3))
136
# Ensure that we do not have excessive memory allocations
137
# (e.g., from type instabilities)
138
@test_allocations(Trixi.rhs!, semi, sol, 1000)
139
end
140
141
@trixi_testset "elixir_euler_sedov_hll_davis.jl" begin
142
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_sedov.jl"),
143
l2=[1.278661029299215, 0.0663853410742763, 0.9585741943783386],
144
linf=[
145
3.1661064228547255,
146
0.16256363944708607,
147
2.667676158812806
148
],
149
tspan=(0.0, 12.5),
150
surface_flux=FluxHLL(min_max_speed_davis))
151
# Ensure that we do not have excessive memory allocations
152
# (e.g., from type instabilities)
153
@test_allocations(Trixi.rhs!, semi, sol, 1000)
154
end
155
156
@trixi_testset "elixir_euler_shu_osher_nonuniform_fvO2.jl" begin
157
@test_trixi_include(joinpath(EXAMPLES_DIR,
158
"elixir_euler_shu_osher_nonuniform_fvO2.jl"),
159
abstol=1e-11, reltol=1e-11,
160
l2=[0.5000856244205995, 1.7958065770030094, 6.50409305116869],
161
linf=[2.981082161129505, 10.10855083991654, 36.26666086388062],
162
tspan=(0.0, 0.1))
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.jl" begin
169
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_source_terms.jl"),
170
# Expected errors are exactly the same as with TreeMesh!
171
l2=[
172
2.2527950196212703e-8,
173
1.8187357193835156e-8,
174
7.705669939973104e-8
175
],
176
linf=[
177
1.6205433861493646e-7,
178
1.465427772462391e-7,
179
5.372255111879554e-7
180
])
181
# Ensure that we do not have excessive memory allocations
182
# (e.g., from type instabilities)
183
@test_allocations(Trixi.rhs!, semi, sol, 1000)
184
end
185
186
@trixi_testset "elixir_euler_source_terms_nonperiodic.jl" begin
187
@test_trixi_include(joinpath(EXAMPLES_DIR,
188
"elixir_euler_source_terms_nonperiodic.jl"),
189
l2=[
190
3.8099996914101204e-6,
191
1.6745575717106341e-6,
192
7.732189531480852e-6
193
],
194
linf=[
195
1.2971473393186272e-5,
196
9.270328934274374e-6,
197
3.092514399671842e-5
198
])
199
# Ensure that we do not have excessive memory allocations
200
# (e.g., from type instabilities)
201
@test_allocations(Trixi.rhs!, semi, sol, 1000)
202
end
203
204
@trixi_testset "elixir_euler_source_terms_nonperiodic.jl (Gauss-Legendre)" begin
205
@test_trixi_include(joinpath(EXAMPLES_DIR,
206
"elixir_euler_source_terms_nonperiodic.jl"),
207
solver=DGSEM(polydeg = 3, basis_type = GaussLegendreBasis,
208
surface_flux = flux_lax_friedrichs),
209
# Identical errors as for the `TreeMesh` version of this example
210
l2=[
211
6.179119971404758e-7,
212
6.831335637140733e-7,
213
1.8153512648336213e-6
214
],
215
linf=[
216
2.3035825069683824e-6,
217
2.7398314812465685e-6,
218
7.132056524916663e-6
219
])
220
# Ensure that we do not have excessive memory allocations
221
# (e.g., from type instabilities)
222
@test_allocations(Trixi.rhs!, semi, sol, 1000)
223
end
224
225
@trixi_testset "elixir_euler_source_terms_nonperiodic_fvO2.jl" begin
226
@test_trixi_include(joinpath(EXAMPLES_DIR,
227
"elixir_euler_source_terms_nonperiodic_fvO2.jl"),
228
l2=[
229
0.0005159476609077155,
230
0.000649450399792432,
231
0.0010602371635625239
232
],
233
linf=[
234
0.0017927309507015377,
235
0.001662532939591621,
236
0.004580416775184837
237
])
238
# Ensure that we do not have excessive memory allocations
239
# (e.g., from type instabilities)
240
@test_allocations(Trixi.rhs!, semi, sol, 1000)
241
242
# Test/cover `:compact` printing
243
show(IOContext(IOBuffer(), :compact => true), MIME"text/plain"(), volume_integral)
244
end
245
246
@trixi_testset "elixir_euler_weak_blast_er.jl" begin
247
@test_trixi_include(joinpath(EXAMPLES_DIR,
248
"elixir_euler_weak_blast_er.jl"),
249
analysis_interval=100,
250
l2=[0.1199630838410044,
251
0.1562196058317499,
252
0.44836353019483344],
253
linf=[
254
0.2255546997256792,
255
0.29412938937652194,
256
0.8558237244455227
257
])
258
# Larger values for allowed allocations due to usage of custom
259
# integrator which are not *recorded* for the methods from
260
# OrdinaryDiffEq.jl
261
# Corresponding issue: https://github.com/trixi-framework/Trixi.jl/issues/1877
262
@test_allocations(Trixi.rhs!, semi, sol, 15_000)
263
264
# test both short and long printing formats
265
@test_nowarn show(relaxation_solver)
266
println()
267
@test_nowarn println(relaxation_solver)
268
println()
269
@test_nowarn display(relaxation_solver)
270
# Test `:compact` printing
271
show(IOContext(IOBuffer(), :compact => true), MIME"text/plain"(), relaxation_solver)
272
end
273
274
@trixi_testset "elixir_linearizedeuler_characteristic_system.jl" begin
275
@test_trixi_include(joinpath(EXAMPLES_DIR,
276
"elixir_linearizedeuler_characteristic_system.jl"),
277
l2=[2.9318078842789714e-6, 0.0, 0.0],
278
linf=[4.291208715723194e-5, 0.0, 0.0])
279
# Ensure that we do not have excessive memory allocations
280
# (e.g., from type instabilities)
281
@test_allocations(Trixi.rhs!, semi, sol, 1000)
282
end
283
284
@trixi_testset "elixir_traffic_flow_lwr_greenlight.jl" begin
285
@test_trixi_include(joinpath(EXAMPLES_DIR,
286
"elixir_traffic_flow_lwr_greenlight.jl"),
287
l2=[0.2005523261652845],
288
linf=[0.5052827913468407])
289
# Ensure that we do not have excessive memory allocations
290
# (e.g., from type instabilities)
291
@test_allocations(Trixi.rhs!, semi, sol, 1000)
292
end
293
294
@trixi_testset "elixir_euler_convergence_pure_fv.jl" begin
295
using Trixi: Trixi
296
@test_trixi_include(joinpath(pkgdir(Trixi, "examples", "tree_1d_dgsem"),
297
"elixir_euler_convergence_pure_fv.jl"),
298
mesh=StructuredMesh(16, (0.0,), (2.0,), periodicity = true),
299
l2=[
300
0.019355699748523896,
301
0.022326984561234497,
302
0.02523665947241734
303
],
304
linf=[
305
0.02895961127645519,
306
0.03293442484199227,
307
0.04246098278632804
308
])
309
# Ensure that we do not have excessive memory allocations
310
# (e.g., from type instabilities)
311
@test_allocations(Trixi.rhs!, semi, sol, 1000)
312
end
313
end
314
315
# Clean up afterwards: delete Trixi.jl output directory
316
@test_nowarn rm(outdir, recursive = true)
317
318
end # module
319
320