Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/test/test_dgmulti_1d.jl
2055 views
1
module TestExamplesDGMulti1D
2
3
using Test
4
using Trixi
5
6
include("test_trixi.jl")
7
8
EXAMPLES_DIR = joinpath(examples_dir(), "dgmulti_1d")
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 "DGMulti 1D" begin
15
#! format: noindent
16
17
@trixi_testset "elixir_advection_gauss_sbp.jl " begin
18
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_gauss_sbp.jl"),
19
cells_per_dimension=(8,),
20
l2=[2.9953644500009865e-5],
21
linf=[4.467840577382365e-5])
22
# Ensure that we do not have excessive memory allocations
23
# (e.g., from type instabilities)
24
let
25
t = sol.t[end]
26
u_ode = sol.u[end]
27
du_ode = similar(u_ode)
28
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
29
end
30
end
31
32
@trixi_testset "elixir_burgers_gauss_shock_capturing.jl " begin
33
@test_trixi_include(joinpath(EXAMPLES_DIR,
34
"elixir_burgers_gauss_shock_capturing.jl"),
35
cells_per_dimension=(8,), tspan=(0.0, 0.1),
36
l2=[0.445804588167854],
37
linf=[0.74780611426038])
38
# Ensure that we do not have excessive memory allocations
39
# (e.g., from type instabilities)
40
let
41
t = sol.t[end]
42
u_ode = sol.u[end]
43
du_ode = similar(u_ode)
44
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
45
end
46
end
47
48
@trixi_testset "elixir_euler_flux_diff.jl " begin
49
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_flux_diff.jl"),
50
cells_per_dimension=(16,),
51
# division by sqrt(2.0) corresponds to normalization by the square root of the size of the domain
52
l2=[
53
7.853842541289665e-7,
54
9.609905503440606e-7,
55
2.832322219966481e-6
56
] ./ sqrt(2.0),
57
linf=[
58
1.5003758788711963e-6,
59
1.802998748523521e-6,
60
4.83599270806323e-6
61
])
62
# Ensure that we do not have excessive memory allocations
63
# (e.g., from type instabilities)
64
let
65
t = sol.t[end]
66
u_ode = sol.u[end]
67
du_ode = similar(u_ode)
68
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
69
end
70
end
71
72
@trixi_testset "elixir_euler_shu_osher_gauss_shock_capturing.jl " begin
73
@test_trixi_include(joinpath(EXAMPLES_DIR,
74
"elixir_euler_shu_osher_gauss_shock_capturing.jl"),
75
cells_per_dimension=(64,), tspan=(0.0, 1.0),
76
l2=[
77
1.6967151731067875,
78
6.018445633981826,
79
21.77425594743242
80
],
81
linf=[
82
3.2229876650556477,
83
10.702690533393842,
84
38.37424900889908
85
])
86
# Ensure that we do not have excessive memory allocations
87
# (e.g., from type instabilities)
88
let
89
t = sol.t[end]
90
u_ode = sol.u[end]
91
du_ode = similar(u_ode)
92
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
93
end
94
end
95
96
@trixi_testset "elixir_euler_flux_diff.jl (convergence)" begin
97
using Trixi: convergence_test
98
mean_convergence = convergence_test(@__MODULE__,
99
joinpath(EXAMPLES_DIR,
100
"elixir_euler_flux_diff.jl"), 3)
101
@test isapprox(mean_convergence[:l2],
102
[4.1558759698638434, 3.977911306037128, 4.041421206468769],
103
rtol = 0.05)
104
# Ensure that we do not have excessive memory allocations
105
# (e.g., from type instabilities)
106
let
107
t = sol.t[end]
108
u_ode = sol.u[end]
109
du_ode = similar(u_ode)
110
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
111
end
112
end
113
114
@trixi_testset "elixir_euler_flux_diff.jl (SBP) " begin
115
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_flux_diff.jl"),
116
cells_per_dimension=(16,),
117
approximation_type=SBP(),
118
l2=[
119
6.437827414849647e-6,
120
2.1840558851820947e-6,
121
1.3245669629438228e-5
122
],
123
linf=[
124
2.0715843751295537e-5,
125
8.519520630301258e-6,
126
4.2642194098885255e-5
127
])
128
# Ensure that we do not have excessive memory allocations
129
# (e.g., from type instabilities)
130
let
131
t = sol.t[end]
132
u_ode = sol.u[end]
133
du_ode = similar(u_ode)
134
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
135
end
136
end
137
138
@trixi_testset "elixir_euler_flux_diff.jl (FD SBP)" begin
139
using Trixi: SummationByPartsOperators, derivative_operator
140
global D = derivative_operator(SummationByPartsOperators.MattssonNordström2004(),
141
derivative_order = 1,
142
accuracy_order = 4,
143
xmin = 0.0, xmax = 1.0,
144
N = 16)
145
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_flux_diff.jl"),
146
cells_per_dimension=(4,),
147
approximation_type=D,
148
l2=[
149
1.8684509287853788e-5,
150
1.0641411823379635e-5,
151
5.178010291876143e-5
152
],
153
linf=[
154
6.933493585936645e-5,
155
3.0277366229292113e-5,
156
0.0002220020568932668
157
])
158
show(stdout, semi.solver.basis)
159
show(stdout, MIME"text/plain"(), semi.solver.basis)
160
# Ensure that we do not have excessive memory allocations
161
# (e.g., from type instabilities)
162
let
163
t = sol.t[end]
164
u_ode = sol.u[end]
165
du_ode = similar(u_ode)
166
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
167
end
168
end
169
170
@trixi_testset "elixir_euler_modified_sod.jl" begin
171
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_modified_sod.jl"),
172
cells_per_dimension=(16,),
173
l2=[0.26352391505659767, 0.4528974787813885, 0.9310255091126164],
174
linf=[
175
0.6268146194274395,
176
0.8214003799995101,
177
1.8606901431409795
178
])
179
# Ensure that we do not have excessive memory allocations
180
# (e.g., from type instabilities)
181
let
182
t = sol.t[end]
183
u_ode = sol.u[end]
184
du_ode = similar(u_ode)
185
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
186
end
187
end
188
189
@trixi_testset "elixir_euler_fdsbp_periodic.jl" begin
190
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_fdsbp_periodic.jl"),
191
l2=[
192
9.146929178341782e-7, 1.8997616876521201e-6,
193
3.991417701005622e-6
194
],
195
linf=[
196
1.7321089882393892e-6, 3.3252888869128583e-6,
197
6.525278767988141e-6
198
])
199
show(stdout, semi.solver.basis)
200
show(stdout, MIME"text/plain"(), semi.solver.basis)
201
# Ensure that we do not have excessive memory allocations
202
# (e.g., from type instabilities)
203
let
204
t = sol.t[end]
205
u_ode = sol.u[end]
206
du_ode = similar(u_ode)
207
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
208
end
209
end
210
211
@trixi_testset "DGMulti with periodic SBP unit test" begin
212
using Trixi: periodic_derivative_operator, DGMulti, Line, DGMultiMesh
213
# see https://github.com/trixi-framework/Trixi.jl/pull/1013
214
global D = periodic_derivative_operator(derivative_order = 1,
215
accuracy_order = 4,
216
xmin = -5.0,
217
xmax = 10.0, N = 50)
218
dg = DGMulti(element_type = Line(), approximation_type = D)
219
mesh = DGMultiMesh(dg)
220
@test mapreduce(isapprox, &, mesh.md.xyz, dg.basis.rst)
221
# check to make sure nodes are rescaled to [-1, 1]
222
@test minimum(dg.basis.rst[1]) -1
223
@test maximum(dg.basis.rst[1])≈1 atol=0.35
224
end
225
226
# test non-conservative systems
227
@trixi_testset "elixir_euler_quasi_1d.jl (SBP) " begin
228
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_quasi_1d.jl"),
229
cells_per_dimension=(8,),
230
approximation_type=SBP(),
231
l2=[
232
1.633271343738687e-5,
233
9.575385661756332e-6,
234
1.2700331443128421e-5,
235
0.0
236
],
237
linf=[
238
7.304984704381567e-5,
239
5.2365944135601694e-5,
240
6.469559594934893e-5,
241
0.0
242
])
243
# Ensure that we do not have excessive memory allocations
244
# (e.g., from type instabilities)
245
let
246
t = sol.t[end]
247
u_ode = sol.u[end]
248
du_ode = similar(u_ode)
249
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
250
end
251
end
252
253
@trixi_testset "elixir_euler_quasi_1d.jl (Polynomial) " begin
254
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_quasi_1d.jl"),
255
cells_per_dimension=(8,),
256
approximation_type=Polynomial(),
257
l2=[
258
3.3742251708854453e-6,
259
2.9716405988822176e-6,
260
3.1641250402788772e-6,
261
1.0482169269991052e-6
262
],
263
linf=[
264
8.056816211965412e-6,
265
6.031057946387364e-6,
266
6.90878439346676e-6,
267
1.5199471203874992e-6
268
])
269
# Ensure that we do not have excessive memory allocations
270
# (e.g., from type instabilities)
271
let
272
t = sol.t[end]
273
u_ode = sol.u[end]
274
du_ode = similar(u_ode)
275
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
276
end
277
end
278
end
279
280
# Clean up afterwards: delete Trixi.jl output directory
281
@test_nowarn isdir(outdir) && rm(outdir, recursive = true)
282
283
end # module
284
285