Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/test/test_paper_self_gravitating_gas_dynamics.jl
2055 views
1
module TestPaperSelfgravitatingGasDynamics
2
3
using Test
4
using Trixi
5
6
include("test_trixi.jl")
7
8
# Start with a clean environment: remove Trixi.jl output directory if it exists
9
outdir = "out"
10
isdir(outdir) && rm(outdir, recursive = true)
11
12
EXAMPLES_DIR = joinpath(examples_dir(), "paper_self_gravitating_gas_dynamics")
13
14
# Numerical examples from the Euler-gravity paper
15
@testset "paper_self_gravitating_gas_dynamics" begin
16
#! format: noindent
17
18
@trixi_testset "elixir_euler_convergence.jl" begin
19
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_convergence.jl"),
20
l2=[
21
0.0001740977055972079,
22
0.0003369355182519592,
23
0.0003369355182518708,
24
0.0006099171220334989
25
],
26
linf=[
27
0.001079347149189669,
28
0.0018836938381321389,
29
0.001883693838132583,
30
0.003971575376718217
31
])
32
# Ensure that we do not have excessive memory allocations
33
# (e.g., from type instabilities)
34
let
35
t = sol.t[end]
36
u_ode = sol.u[end]
37
du_ode = similar(u_ode)
38
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
39
end
40
end
41
42
@trixi_testset "elixir_euler_convergence.jl with polydeg=4" begin
43
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_euler_convergence.jl"),
44
l2=[
45
1.7187201161597772e-5,
46
2.678065111772951e-5,
47
2.678065111783027e-5,
48
4.952504160091526e-5
49
],
50
linf=[
51
0.0001501749544159381,
52
0.00016549482504535362,
53
0.00016549482504601976,
54
0.0004372960291432193
55
],
56
polydeg=4)
57
# Ensure that we do not have excessive memory allocations
58
# (e.g., from type instabilities)
59
let
60
t = sol.t[end]
61
u_ode = sol.u[end]
62
du_ode = similar(u_ode)
63
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
64
end
65
end
66
67
@trixi_testset "elixir_hypdiff_convergence.jl" begin
68
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_hypdiff_convergence.jl"),
69
l2=[
70
0.003154024896093942,
71
0.012394432074951856,
72
0.02185973823794725
73
],
74
linf=[
75
0.01731850928579215,
76
0.07843510773347553,
77
0.11242300176349201
78
])
79
# Ensure that we do not have excessive memory allocations
80
# (e.g., from type instabilities)
81
let
82
t = sol.t[end]
83
u_ode = sol.u[end]
84
du_ode = similar(u_ode)
85
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
86
end
87
end
88
89
@trixi_testset "elixir_hypdiff_convergence.jl with polydeg=4" begin
90
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_hypdiff_convergence.jl"),
91
l2=[
92
0.0002511283012128458,
93
0.0008808243846610255,
94
0.0016313343228567005
95
],
96
linf=[
97
0.0017290715087938668,
98
0.003129184465704738,
99
0.01000728849316701
100
],
101
polydeg=4)
102
# Ensure that we do not have excessive memory allocations
103
# (e.g., from type instabilities)
104
let
105
t = sol.t[end]
106
u_ode = sol.u[end]
107
du_ode = similar(u_ode)
108
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
109
end
110
end
111
112
@trixi_testset "elixir_eulergravity_convergence.jl" begin
113
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_eulergravity_convergence.jl"),
114
l2=[
115
0.00024871265138964204,
116
0.0003370077102132591,
117
0.0003370077102131964,
118
0.0007231525513793697
119
],
120
linf=[
121
0.0015813032944647087,
122
0.0020494288423820173,
123
0.0020494288423824614,
124
0.004793821195083758
125
],
126
tspan=(0.0, 0.1))
127
# Ensure that we do not have excessive memory allocations
128
# (e.g., from type instabilities)
129
let
130
t = sol.t[end]
131
u_ode = sol.u[end]
132
du_ode = similar(u_ode)
133
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
134
end
135
end
136
137
@trixi_testset "elixir_eulergravity_convergence.jl with polydeg=4" begin
138
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_eulergravity_convergence.jl"),
139
l2=[
140
1.9537712148648045e-5,
141
2.7564396197947587e-5,
142
2.7564396197967635e-5,
143
5.688838772067586e-5
144
],
145
linf=[
146
0.00012335710672761735,
147
0.00020086268350816283,
148
0.00020086268350727465,
149
0.0004962155455632278
150
],
151
tspan=(0.0, 0.1), polydeg=4)
152
# Ensure that we do not have excessive memory allocations
153
# (e.g., from type instabilities)
154
let
155
t = sol.t[end]
156
u_ode = sol.u[end]
157
du_ode = similar(u_ode)
158
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
159
end
160
end
161
162
@trixi_testset "elixir_eulergravity_convergence.jl with 1st order RK3S*" begin
163
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_eulergravity_convergence.jl"),
164
l2=[
165
0.00024871265138959434,
166
0.000337007710281087,
167
0.0003370077102811394,
168
0.0007231525515231289
169
],
170
linf=[
171
0.0015813032941613958,
172
0.002049428843978518,
173
0.0020494288439798503,
174
0.004793821198143977
175
],
176
tspan=(0.0, 0.1),
177
timestep_gravity=Trixi.timestep_gravity_erk51_3Sstar!)
178
# Ensure that we do not have excessive memory allocations
179
# (e.g., from type instabilities)
180
let
181
t = sol.t[end]
182
u_ode = sol.u[end]
183
du_ode = similar(u_ode)
184
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
185
end
186
end
187
188
@trixi_testset "elixir_eulergravity_convergence.jl with 3rd order RK3S*" begin
189
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_eulergravity_convergence.jl"),
190
l2=[
191
0.0002487126513894034,
192
0.00033700771023049785,
193
0.00033700771023048245,
194
0.0007231525514158737
195
],
196
linf=[
197
0.0015813032943847727,
198
0.002049428842844314,
199
0.0020494288428452023,
200
0.004793821195971937
201
],
202
tspan=(0.0, 0.1),
203
timestep_gravity=Trixi.timestep_gravity_erk53_3Sstar!)
204
# Ensure that we do not have excessive memory allocations
205
# (e.g., from type instabilities)
206
let
207
t = sol.t[end]
208
u_ode = sol.u[end]
209
du_ode = similar(u_ode)
210
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
211
end
212
end
213
214
@trixi_testset "elixir_eulergravity_jeans_instability.jl" begin
215
@test_trixi_include(joinpath(EXAMPLES_DIR,
216
"elixir_eulergravity_jeans_instability.jl"),
217
l2=[
218
10733.28239179182,
219
13356.0533511341,
220
1.6722844879795038e-6,
221
26833.19833691448
222
],
223
linf=[
224
15193.794080890715,
225
18880.45819785685,
226
6.809726988008751e-6,
227
37971.74113135785
228
],
229
tspan=(0.0, 0.1),
230
atol=4.0e-6)
231
# Ensure that we do not have excessive memory allocations
232
# (e.g., from type instabilities)
233
let
234
t = sol.t[end]
235
u_ode = sol.u[end]
236
du_ode = similar(u_ode)
237
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
238
end
239
end
240
241
@trixi_testset "elixir_eulergravity_jeans_instability.jl with RK3S*" begin
242
@test_trixi_include(joinpath(EXAMPLES_DIR,
243
"elixir_eulergravity_jeans_instability.jl"),
244
l2=[
245
10734.653995035567,
246
13357.709699808021,
247
1.911011743371934e-6,
248
26836.62734552835
249
],
250
linf=[
251
15195.73481107317,
252
18882.799120551972,
253
7.867948710816926e-6,
254
37976.592992473394
255
],
256
tspan=(0.0, 0.1),
257
atol=4.0e-6, # the background field is reatively large, so this corresponds to our usual atol
258
parameters=ParametersEulerGravity(background_density = 1.5e7,
259
gravitational_constant = 6.674e-8,
260
cfl = 2.4,
261
resid_tol = 1.0e-4,
262
n_iterations_max = 1000,
263
timestep_gravity = timestep_gravity_erk52_3Sstar!))
264
# Ensure that we do not have excessive memory allocations
265
# (e.g., from type instabilities)
266
let
267
t = sol.t[end]
268
u_ode = sol.u[end]
269
du_ode = similar(u_ode)
270
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
271
end
272
end
273
274
@trixi_testset "Printing" begin
275
@test_trixi_include(joinpath(EXAMPLES_DIR,
276
"elixir_eulergravity_jeans_instability.jl"),
277
tspan=(0.0, 1.0e-5),
278
parameters=ParametersEulerGravity(background_density = 1.5e7,
279
gravitational_constant = 6.674e-8,
280
cfl = 2.4,
281
resid_tol = 1.0e-4,
282
n_iterations_max = 1000,
283
timestep_gravity = timestep_gravity_erk52_3Sstar!))
284
285
show(stdout, parameters)
286
show(stdout, semi)
287
show(stdout, semi_euler.boundary_conditions)
288
show(stdout, TrivialCallback())
289
show(stdout, equations_euler)
290
# Ensure that we do not have excessive memory allocations
291
# (e.g., from type instabilities)
292
let
293
t = sol.t[end]
294
u_ode = sol.u[end]
295
du_ode = similar(u_ode)
296
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
297
end
298
end
299
300
@trixi_testset "elixir_eulergravity_sedov_blast_wave.jl" begin
301
@test_trixi_include(joinpath(EXAMPLES_DIR,
302
"elixir_eulergravity_sedov_blast_wave.jl"),
303
l2=[
304
0.046315994852653024,
305
0.0650818006233669,
306
0.06508180062336677,
307
0.4896707211656037
308
],
309
linf=[
310
2.3874843337593776,
311
4.07876384374792,
312
4.07876384374792,
313
16.23914384809855
314
],
315
tspan=(0.0, 0.05),)
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
@trixi_testset "elixir_eulergravity_sedov_blast_wave.jl with ref-level=8 and no AMR" begin
327
@test_trixi_include(joinpath(EXAMPLES_DIR,
328
"elixir_eulergravity_sedov_blast_wave.jl"),
329
l2=[
330
0.00289222135995042,
331
0.013724813590853825,
332
0.013724813590853832,
333
0.05822904710548214
334
],
335
linf=[
336
0.26361780693997594,
337
1.3908873830688688,
338
1.3908873830688688,
339
4.066701303607613
340
],
341
tspan=(0.0, 0.005), initial_refinement_level=8,
342
amr_callback=TrivialCallback())
343
# Ensure that we do not have excessive memory allocations
344
# (e.g., from type instabilities)
345
let
346
t = sol.t[end]
347
u_ode = sol.u[end]
348
du_ode = similar(u_ode)
349
@test (@allocated Trixi.rhs!(du_ode, u_ode, semi, t)) < 1000
350
end
351
end
352
end
353
354
# Clean up afterwards: delete Trixi.jl output directory
355
@test_nowarn rm(outdir, recursive = true)
356
357
end #module
358
359