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
5582 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
@test_allocations(Trixi.rhs!, semi, sol, 1000)
25
end
26
27
@trixi_testset "elixir_burgers_gauss_shock_capturing.jl " begin
28
@test_trixi_include(joinpath(EXAMPLES_DIR,
29
"elixir_burgers_gauss_shock_capturing.jl"),
30
cells_per_dimension=(8,), tspan=(0.0, 0.1),
31
l2=[0.445804588167854],
32
linf=[0.74780611426038])
33
# Ensure that we do not have excessive memory allocations
34
# (e.g., from type instabilities)
35
@test_allocations(Trixi.rhs!, semi, sol, 1000)
36
end
37
38
@trixi_testset "elixir_euler_flux_diff.jl " begin
39
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_flux_diff.jl"),
40
cells_per_dimension=(16,),
41
# division by sqrt(2.0) corresponds to normalization by the square root of the size of the domain
42
l2=[
43
7.853842541289665e-7,
44
9.609905503440606e-7,
45
2.832322219966481e-6
46
] ./ sqrt(2.0),
47
linf=[
48
1.5003758788711963e-6,
49
1.802998748523521e-6,
50
4.83599270806323e-6
51
])
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_euler_shu_osher_gauss_shock_capturing.jl " begin
58
@test_trixi_include(joinpath(EXAMPLES_DIR,
59
"elixir_euler_shu_osher_gauss_shock_capturing.jl"),
60
l2=[1.6967163299095107, 6.018450129099115, 21.774272062049693],
61
linf=[3.2229821729393437, 10.702811890261692, 38.37413018581744])
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_euler_flux_diff.jl (convergence)" begin
68
using Trixi: convergence_test
69
eocs, _ = convergence_test(@__MODULE__,
70
joinpath(EXAMPLES_DIR,
71
"elixir_euler_flux_diff.jl"), 3)
72
mean_convergence = Trixi.calc_mean_convergence(eocs)
73
@test isapprox(mean_convergence[:l2],
74
[4.1558759698638434, 3.977911306037128, 4.041421206468769],
75
rtol = 0.05)
76
# Ensure that we do not have excessive memory allocations
77
# (e.g., from type instabilities)
78
@test_allocations(Trixi.rhs!, semi, sol, 1000)
79
end
80
81
@trixi_testset "elixir_euler_flux_diff.jl (SBP) " begin
82
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_flux_diff.jl"),
83
cells_per_dimension=(16,),
84
approximation_type=SBP(),
85
l2=[
86
6.437827414849647e-6,
87
2.1840558851820947e-6,
88
1.3245669629438228e-5
89
],
90
linf=[
91
2.0715843751295537e-5,
92
8.519520630301258e-6,
93
4.2642194098885255e-5
94
])
95
# Ensure that we do not have excessive memory allocations
96
# (e.g., from type instabilities)
97
@test_allocations(Trixi.rhs!, semi, sol, 1000)
98
end
99
100
@trixi_testset "elixir_euler_flux_diff.jl (FD SBP)" begin
101
using Trixi: SummationByPartsOperators, derivative_operator
102
global D = derivative_operator(SummationByPartsOperators.MattssonNordström2004(),
103
derivative_order = 1,
104
accuracy_order = 4,
105
xmin = 0.0, xmax = 1.0,
106
N = 16)
107
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_flux_diff.jl"),
108
cells_per_dimension=(4,),
109
approximation_type=D,
110
l2=[
111
1.8684509287853788e-5,
112
1.0641411823379635e-5,
113
5.178010291876143e-5
114
],
115
linf=[
116
6.933493585936645e-5,
117
3.0277366229292113e-5,
118
0.0002220020568932668
119
])
120
show(stdout, semi.solver.basis)
121
show(stdout, MIME"text/plain"(), semi.solver.basis)
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_euler_modified_sod.jl" begin
128
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_modified_sod.jl"),
129
cells_per_dimension=(16,),
130
l2=[0.26352391505659767, 0.4528974787813885, 0.9310255091126164],
131
linf=[
132
0.6268146194274395,
133
0.8214003799995101,
134
1.8606901431409795
135
])
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_fdsbp_periodic.jl" begin
142
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_fdsbp_periodic.jl"),
143
l2=[
144
9.146929178341782e-7, 1.8997616876521201e-6,
145
3.991417701005622e-6
146
],
147
linf=[
148
1.7321089882393892e-6, 3.3252888869128583e-6,
149
6.525278767988141e-6
150
])
151
show(stdout, semi.solver.basis)
152
show(stdout, MIME"text/plain"(), semi.solver.basis)
153
# Ensure that we do not have excessive memory allocations
154
# (e.g., from type instabilities)
155
@test_allocations(Trixi.rhs!, semi, sol, 1000)
156
end
157
158
@trixi_testset "elixir_euler_cgsbp_periodic.jl" begin
159
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_cgsbp_periodic.jl"),
160
l2=[
161
5.843760898223001e-5, 6.147562272684972e-5,
162
2.47193762401697e-5
163
],
164
linf=[
165
1.3094042977845888e-4, 1.2807952438143033e-4,
166
6.1275164883412e-5
167
])
168
@test_allocations(Trixi.rhs!, semi, sol, 1000)
169
end
170
171
@trixi_testset "DGMulti with periodic SBP unit test" begin
172
using Trixi: periodic_derivative_operator, DGMulti, Line, DGMultiMesh
173
# see https://github.com/trixi-framework/Trixi.jl/pull/1013
174
global D = periodic_derivative_operator(derivative_order = 1,
175
accuracy_order = 4,
176
xmin = -5.0,
177
xmax = 10.0, N = 50)
178
dg = DGMulti(element_type = Line(), approximation_type = D)
179
mesh = DGMultiMesh(dg)
180
@test mapreduce(isapprox, &, mesh.md.xyz, dg.basis.rst)
181
# check to make sure nodes are rescaled to [-1, 1]
182
@test minimum(dg.basis.rst[1]) -1
183
@test maximum(dg.basis.rst[1])≈1 atol=0.35
184
end
185
186
# test non-conservative systems
187
@trixi_testset "elixir_euler_quasi_1d.jl (SBP) " begin
188
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_quasi_1d.jl"),
189
cells_per_dimension=(8,),
190
approximation_type=SBP(),
191
l2=[
192
1.633271343738687e-5,
193
9.575385661756332e-6,
194
1.2700331443128421e-5,
195
0.0
196
],
197
linf=[
198
7.304984704381567e-5,
199
5.2365944135601694e-5,
200
6.469559594934893e-5,
201
0.0
202
])
203
# Ensure that we do not have excessive memory allocations
204
# (e.g., from type instabilities)
205
@test_allocations(Trixi.rhs!, semi, sol, 1000)
206
end
207
208
@trixi_testset "elixir_euler_quasi_1d.jl (Polynomial) " begin
209
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_quasi_1d.jl"),
210
cells_per_dimension=(8,),
211
approximation_type=Polynomial(),
212
l2=[
213
3.3742251708854453e-6,
214
2.9716405988822176e-6,
215
3.1641250402788772e-6,
216
1.0482169269991052e-6
217
],
218
linf=[
219
8.056816211965412e-6,
220
6.031057946387364e-6,
221
6.90878439346676e-6,
222
1.5199471203874992e-6
223
])
224
# Ensure that we do not have excessive memory allocations
225
# (e.g., from type instabilities)
226
@test_allocations(Trixi.rhs!, semi, sol, 1000)
227
end
228
end
229
230
# Clean up afterwards: delete Trixi.jl output directory
231
@test_nowarn isdir(outdir) && rm(outdir, recursive = true)
232
233
end # module
234
235