Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/src/auxiliary/precompile.jl
5586 views
1
#=
2
The code contained in this file is inspired by an analysis performed
3
using SnoopCompile, although most of it is written manually.
4
5
This kind of analysis was performed using the following code.
6
```julia
7
using SnoopCompile
8
inf_timing = @snoopi tmin=0.01 begin
9
# below is mostly a copy of `examples/2d/elixir_advection_amr.jl`
10
using Trixi
11
using OrdinaryDiffEq
12
13
###############################################################################
14
# semidiscretization of the linear advection equation
15
16
advection_velocity = (1.0, 1.0)
17
equations = LinearScalarAdvectionEquation2D(advection_velocity)
18
show(stdout, equations)
19
show(stdout, MIME"text/plain"(), equations)
20
21
initial_condition = initial_condition_gauss
22
23
surface_flux = flux_lax_friedrichs
24
basis = LobattoLegendreBasis(3)
25
solver = DGSEM(basis, surface_flux)
26
show(stdout, solver)
27
show(stdout, MIME"text/plain"(), solver)
28
29
coordinates_min = (-5, -5)
30
coordinates_max = ( 5, 5)
31
mesh = TreeMesh(coordinates_min, coordinates_max,
32
initial_refinement_level=4,
33
n_cells_max=30_000)
34
show(stdout, mesh)
35
show(stdout, MIME"text/plain"(), mesh)
36
37
semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver)
38
show(stdout, semi)
39
show(stdout, MIME"text/plain"(), semi)
40
41
###############################################################################
42
# ODE solvers, callbacks etc.
43
44
tspan = (0.0, 10.0)
45
ode = semidiscretize(semi, tspan)
46
47
summary_callback = SummaryCallback()
48
show(stdout, summary_callback)
49
show(stdout, MIME"text/plain"(), summary_callback)
50
51
amr_controller = ControllerThreeLevel(semi, IndicatorMax(semi, variable=first),
52
base_level=4,
53
med_level=5, med_threshold=0.1,
54
max_level=6, max_threshold=0.6)
55
amr_callback = AMRCallback(semi, amr_controller,
56
interval=5,
57
adapt_initial_condition=true,
58
adapt_initial_condition_only_refine=true)
59
show(stdout, amr_callback)
60
show(stdout, MIME"text/plain"(), amr_callback)
61
62
stepsize_callback = StepsizeCallback(cfl=1.6)
63
show(stdout, stepsize_callback)
64
show(stdout, MIME"text/plain"(), stepsize_callback)
65
66
save_solution = SaveSolutionCallback(interval=100,
67
save_initial_solution=true,
68
save_final_solution=true,
69
solution_variables=cons2prim)
70
show(stdout, save_solution)
71
show(stdout, MIME"text/plain"(), save_solution)
72
73
save_restart = SaveRestartCallback(interval=100,
74
save_final_restart=true)
75
show(stdout, save_restart)
76
show(stdout, MIME"text/plain"(), save_restart)
77
78
analysis_interval = 100
79
alive_callback = AliveCallback(analysis_interval=analysis_interval)
80
show(stdout, alive_callback)
81
show(stdout, MIME"text/plain"(), alive_callback)
82
analysis_callback = AnalysisCallback(equations, solver,
83
interval=analysis_interval,
84
extra_analysis_integrals=(entropy,))
85
show(stdout, analysis_callback)
86
show(stdout, MIME"text/plain"(), analysis_callback)
87
88
callbacks = CallbackSet(summary_callback,
89
save_restart, save_solution,
90
analysis_callback, alive_callback,
91
amr_callback, stepsize_callback);
92
93
###############################################################################
94
# run the simulation
95
96
u_ode = copy(ode.u0)
97
du_ode = similar(u_ode)
98
Trixi.rhs!(du_ode, u_ode, semi, first(tspan))
99
100
# You could also include a `solve` stage to generate possibly more precompile statements.
101
# sol = Trixi.solve(ode, Trixi.SimpleAlgorithm2N45(),
102
# dt=stepsize_callback(ode), # solve needs some value here but it will be overwritten by the stepsize_callback
103
# save_everystep=false, callback=callbacks);
104
summary_callback() # print the timer summary
105
end
106
pc = SnoopCompile.parcel(inf_timing)
107
SnoopCompile.write("dev/precompile", pc)
108
109
```
110
After running the code above, SnoopCompile has generated the file
111
`dev/precompile/precompile_Trixi.jl`, which contains precompile statements
112
in the function `_precompile_`.
113
More information on this process can be found in the docs of SnoopCompile,
114
in particular at https://timholy.github.io/SnoopCompile.jl/stable/snoopi/.
115
116
This kind of analysis helps finding type-unstable parts of the code, e.g.
117
`init_interfaces` etc. in https://github.com/trixi-framework/Trixi.jl/pull/307.
118
Moreover, it allows to generate precompile statements which reduce the latency
119
by caching type inference results.
120
The latency can be measured by running
121
```bash
122
julia --threads=1 -e '@time using Trixi; @time include(joinpath(examples_dir(), "2d", "elixir_advection_basic.jl"))'
123
```
124
125
We add `@assert` to the precompile statements below to make sure that we don't include
126
failing precompile statements, cf. https://timholy.github.io/SnoopCompile.jl/stable/snoopi/.
127
If any assertions below fail, it is generally safe to just disable the failing call
128
to precompile (or to not include precompile.jl at all).
129
To still get the same latency reductions, you should consider to adapt the failing precompile
130
statements in accordance with the changes in Trixi.jl's source code. Please, feel free to ping
131
the core developers of Trixi.jl to get help with that.
132
=#
133
134
import StaticArrays
135
import SciMLBase
136
137
# manually generated precompile statements
138
function _precompile_manual_()
139
ccall(:jl_generating_output, Cint, ()) == 1 || return nothing
140
141
function equations_types_1d(RealT)
142
return (LinearScalarAdvectionEquation1D{RealT},
143
HyperbolicDiffusionEquations1D{RealT},
144
CompressibleEulerEquations1D{RealT},
145
IdealGlmMhdEquations1D{RealT})
146
end
147
function equations_types_2d(RealT)
148
return (LinearScalarAdvectionEquation2D{RealT},
149
HyperbolicDiffusionEquations2D{RealT},
150
CompressibleEulerEquations2D{RealT},
151
IdealGlmMhdEquations2D{RealT},
152
LatticeBoltzmannEquations2D{RealT, typeof(Trixi.collision_bgk)})
153
end
154
function equations_types_3d(RealT)
155
return (LinearScalarAdvectionEquation3D{RealT},
156
HyperbolicDiffusionEquations3D{RealT},
157
CompressibleEulerEquations3D{RealT},
158
IdealGlmMhdEquations3D{RealT},
159
LatticeBoltzmannEquations3D{RealT, typeof(Trixi.collision_bgk)})
160
end
161
function equations_types(RealT)
162
return (LinearScalarAdvectionEquation1D{RealT},
163
LinearScalarAdvectionEquation2D{RealT},
164
LinearScalarAdvectionEquation3D{RealT},
165
HyperbolicDiffusionEquations1D{RealT},
166
HyperbolicDiffusionEquations2D{RealT},
167
HyperbolicDiffusionEquations3D{RealT},
168
CompressibleEulerEquations1D{RealT},
169
CompressibleEulerEquations2D{RealT},
170
CompressibleEulerEquations3D{RealT},
171
IdealGlmMhdEquations1D{RealT},
172
IdealGlmMhdEquations2D{RealT},
173
IdealGlmMhdEquations3D{RealT},
174
LatticeBoltzmannEquations2D{RealT, typeof(Trixi.collision_bgk)},
175
LatticeBoltzmannEquations3D{RealT, typeof(Trixi.collision_bgk)})
176
end
177
178
function basis_type_dgsem(RealT, nnodes_)
179
return LobattoLegendreBasis{RealT, nnodes_,
180
# VectorT
181
StaticArrays.SVector{nnodes_, RealT},
182
# InverseVandermondeLegendre
183
Matrix{RealT},
184
# DerivativeMatrix
185
#StaticArrays.SArray{Tuple{nnodes_,nnodes_},RealT,2,nnodes_^2},
186
Matrix{RealT}}
187
end
188
189
function mortar_type_dgsem(RealT, nnodes_)
190
return LobattoLegendreMortarL2{RealT, nnodes_,
191
# ForwardMatrix
192
#StaticArrays.SArray{Tuple{nnodes_,nnodes_},RealT,2,nnodes_^2},
193
Matrix{RealT},
194
# ReverseMatrix
195
# StaticArrays.SArray{Tuple{nnodes_,nnodes_},RealT,2,nnodes_^2},
196
Matrix{RealT}}
197
end
198
199
function analyzer_type_dgsem(RealT, nnodes_)
200
polydeg = nnodes_ - 1
201
nnodes_analysis = 2 * polydeg + 1
202
return LobattoLegendreAnalyzer{RealT, nnodes_analysis,
203
# VectorT
204
StaticArrays.SVector{nnodes_analysis, RealT},
205
# Vandermonde
206
Array{RealT, 2}}
207
end
208
209
function adaptor_type_dgsem(RealT, nnodes_)
210
return LobattoLegendreAdaptorL2{RealT, nnodes_,
211
# ForwardMatrix
212
StaticArrays.SArray{Tuple{nnodes_, nnodes_}, RealT,
213
2,
214
nnodes_^2},
215
# Matrix{RealT},
216
# ReverseMatrix
217
StaticArrays.SArray{Tuple{nnodes_, nnodes_}, RealT,
218
2,
219
nnodes_^2}
220
# Matrix{RealT},
221
}
222
end
223
224
# Constructors: mesh
225
for RealT in (Int, Float64)
226
@assert Base.precompile(Tuple{Core.kwftype(typeof(Trixi.Type)),
227
NamedTuple{(:initial_refinement_level, :n_cells_max),
228
Tuple{Int, Int}}, Type{TreeMesh},
229
RealT, RealT})
230
@assert Base.precompile(Tuple{Core.kwftype(typeof(Trixi.Type)),
231
NamedTuple{(:initial_refinement_level, :n_cells_max),
232
Tuple{Int, Int}}, Type{TreeMesh},
233
Tuple{RealT}, Tuple{RealT}})
234
@assert Base.precompile(Tuple{Core.kwftype(typeof(Trixi.Type)),
235
NamedTuple{(:initial_refinement_level, :n_cells_max),
236
Tuple{Int, Int}}, Type{TreeMesh},
237
Tuple{RealT, RealT}, Tuple{RealT, RealT}})
238
@assert Base.precompile(Tuple{Core.kwftype(typeof(Trixi.Type)),
239
NamedTuple{(:initial_refinement_level, :n_cells_max),
240
Tuple{Int, Int}}, Type{TreeMesh},
241
Tuple{RealT, RealT, RealT},
242
Tuple{RealT, RealT, RealT}})
243
end
244
for TreeType in (SerialTree, ParallelTree), NDIMS in 1:3
245
@assert Base.precompile(Tuple{typeof(Trixi.initialize!),
246
TreeMesh{NDIMS, TreeType{NDIMS}, Float64}, Int,
247
Tuple{},
248
Tuple{}})
249
@assert Base.precompile(Tuple{typeof(Trixi.save_mesh_file),
250
TreeMesh{NDIMS, TreeType{NDIMS}, Float64}, String,
251
Int})
252
end
253
254
# Constructors: linear advection
255
for RealT in (Float64,)
256
@assert Base.precompile(Tuple{Type{LinearScalarAdvectionEquation1D}, RealT})
257
@assert Base.precompile(Tuple{Type{LinearScalarAdvectionEquation2D}, RealT, RealT})
258
@assert Base.precompile(Tuple{Type{LinearScalarAdvectionEquation2D},
259
Tuple{RealT, RealT}})
260
@assert Base.precompile(Tuple{Type{LinearScalarAdvectionEquation3D}, RealT, RealT,
261
RealT})
262
@assert Base.precompile(Tuple{Type{LinearScalarAdvectionEquation3D},
263
Tuple{RealT, RealT, RealT}})
264
end
265
266
# Constructors: hyperbolic diffusion
267
for RealT in (Float64,)
268
@assert Base.precompile(Tuple{Type{HyperbolicDiffusionEquations1D}})
269
@assert Base.precompile(Tuple{Type{HyperbolicDiffusionEquations2D}})
270
@assert Base.precompile(Tuple{Type{HyperbolicDiffusionEquations3D}})
271
end
272
273
# Constructors: Euler
274
for RealT in (Float64,)
275
@assert Base.precompile(Tuple{Type{CompressibleEulerEquations1D}, RealT})
276
@assert Base.precompile(Tuple{Type{CompressibleEulerEquations2D}, RealT})
277
@assert Base.precompile(Tuple{Type{CompressibleEulerEquations3D}, RealT})
278
end
279
280
# Constructors: MHD
281
for RealT in (Float64,)
282
@assert Base.precompile(Tuple{Type{IdealGlmMhdEquations1D}, RealT})
283
@assert Base.precompile(Tuple{Type{IdealGlmMhdEquations2D}, RealT})
284
@assert Base.precompile(Tuple{Type{IdealGlmMhdEquations3D}, RealT})
285
end
286
287
# Constructors: LBM
288
for RealT in (Float64,)
289
@assert Base.precompile(Tuple{Core.kwftype(typeof(Trixi.Type)),
290
NamedTuple{(:Ma, :Re), Tuple{RealT, RealT}},
291
Type{LatticeBoltzmannEquations2D}})
292
@assert Base.precompile(Tuple{Core.kwftype(typeof(Trixi.Type)),
293
NamedTuple{(:Ma, :Re), Tuple{RealT, Int}},
294
Type{LatticeBoltzmannEquations2D}})
295
@assert Base.precompile(Tuple{Core.kwftype(typeof(Trixi.Type)),
296
NamedTuple{(:Ma, :Re), Tuple{RealT, RealT}},
297
Type{LatticeBoltzmannEquations3D}})
298
@assert Base.precompile(Tuple{Core.kwftype(typeof(Trixi.Type)),
299
NamedTuple{(:Ma, :Re), Tuple{RealT, Int}},
300
Type{LatticeBoltzmannEquations3D}})
301
end
302
303
# Constructors of the basis are inherently type-unstable since we pass integers
304
# and use their values as parameters of static arrays.
305
# Nevertheless, we can still precompile methods used to construct the bases.
306
Base.precompile(Tuple{Type{LobattoLegendreBasis}, Int})
307
for RealT in (Float64,)
308
Base.precompile(Tuple{Type{LobattoLegendreBasis}, RealT, Int})
309
@assert Base.precompile(Tuple{typeof(Trixi.calc_Dhat), Vector{RealT},
310
Vector{RealT}})
311
@assert Base.precompile(Tuple{typeof(Trixi.calc_Dsplit), Vector{RealT},
312
Vector{RealT}})
313
@assert Base.precompile(Tuple{typeof(Trixi.polynomial_derivative_matrix),
314
Vector{RealT}})
315
@assert Base.precompile(Tuple{typeof(Trixi.polynomial_interpolation_matrix),
316
Vector{RealT}, Vector{RealT}})
317
@assert Base.precompile(Tuple{typeof(Trixi.barycentric_weights), Vector{RealT}})
318
@assert Base.precompile(Tuple{typeof(Trixi.calc_L), RealT, Vector{RealT},
319
Vector{RealT}})
320
@assert Base.precompile(Tuple{typeof(Trixi.lagrange_interpolating_polynomials),
321
RealT, Vector{RealT}, Vector{RealT}})
322
@assert Base.precompile(Tuple{typeof(Trixi.calc_q_and_l), Int, RealT})
323
@assert Base.precompile(Tuple{typeof(Trixi.legendre_polynomial_and_derivative), Int,
324
RealT})
325
@assert Base.precompile(Tuple{typeof(Trixi.vandermonde_legendre), Vector{RealT}})
326
end
327
@assert Base.precompile(Tuple{typeof(Trixi.gauss_lobatto_nodes_weights), Int})
328
@assert Base.precompile(Tuple{typeof(Trixi.gauss_nodes_weights), Int})
329
@assert Base.precompile(Tuple{typeof(Trixi.calc_forward_upper), Int})
330
@assert Base.precompile(Tuple{typeof(Trixi.calc_forward_lower), Int})
331
@assert Base.precompile(Tuple{typeof(Trixi.calc_reverse_upper), Int,
332
Val{:gauss}})
333
@assert Base.precompile(Tuple{typeof(Trixi.calc_reverse_lower), Int,
334
Val{:gauss}})
335
@assert Base.precompile(Tuple{typeof(Trixi.calc_reverse_upper), Int,
336
Val{:gauss_lobatto}})
337
@assert Base.precompile(Tuple{typeof(Trixi.calc_reverse_lower), Int,
338
Val{:gauss_lobatto}})
339
340
# Constructors: mortars, analyzers, adaptors
341
for RealT in (Float64,), polydeg in 1:7
342
nnodes_ = polydeg + 1
343
basis_type = basis_type_dgsem(RealT, nnodes_)
344
@assert Base.precompile(Tuple{typeof(Trixi.MortarL2), basis_type})
345
@assert Base.precompile(Tuple{Type{Trixi.SolutionAnalyzer}, basis_type})
346
@assert Base.precompile(Tuple{Type{Trixi.AdaptorL2}, basis_type})
347
end
348
349
# Constructors: callbacks
350
@assert Base.precompile(Tuple{Core.kwftype(typeof(Trixi.Type)),
351
NamedTuple{(:analysis_interval,), Tuple{Int}},
352
Type{AliveCallback}})
353
for RealT in (Float64,)
354
@assert Base.precompile(Tuple{Core.kwftype(typeof(Trixi.Type)),
355
NamedTuple{(:cfl,), Tuple{RealT}},
356
Type{StepsizeCallback}})
357
@assert Base.precompile(Tuple{Core.kwftype(typeof(Trixi.Type)),
358
NamedTuple{(:glm_scale, :cfl), Tuple{RealT, RealT}},
359
Type{GlmSpeedCallback}})
360
end
361
@assert Base.precompile(Tuple{Core.kwftype(typeof(Trixi.Type)),
362
NamedTuple{(:interval, :save_final_restart),
363
Tuple{Int, Bool}}, Type{SaveRestartCallback}})
364
@assert Base.precompile(Tuple{Core.kwftype(typeof(Trixi.Type)),
365
NamedTuple{(:interval, :save_initial_solution,
366
:save_final_solution, :solution_variables),
367
Tuple{Int, Bool, Bool, typeof(cons2cons)}},
368
Type{SaveSolutionCallback}})
369
@assert Base.precompile(Tuple{Core.kwftype(typeof(Trixi.Type)),
370
NamedTuple{(:interval, :save_initial_solution,
371
:save_final_solution, :solution_variables),
372
Tuple{Int, Bool, Bool, typeof(cons2prim)}},
373
Type{SaveSolutionCallback}})
374
# TODO: AnalysisCallback?
375
# for RealT in (Float64,), polydeg in 1:7
376
# nnodes_ = polydeg + 1
377
# nnodes_analysis = 2*polydeg + 1
378
# @assert Base.precompile(Tuple{Type{AnalysisCallback},RealT,Int,Bool,String,String,Trixi.LobattoLegendreAnalyzer{RealT,nnodes_analysis,Array{RealT,2}},Array{Symbol,1},Tuple{typeof(entropy_timederivative),typeof(entropy)},StaticArrays.SArray{Tuple{1},RealT,1,1}})
379
# We would need to use all special cases instead of
380
# Function,Trixi.AbstractVolumeIntegral
381
# for equations_type in equations_types(RealT)
382
# @assert Base.precompile(Tuple{Core.kwftype(typeof(Trixi.Type)),NamedTuple{(:interval, :extra_analysis_integrals),Tuple{Int,Tuple{typeof(entropy)}}},Type{AnalysisCallback},equations_type,DG{RealT,LobattoLegendreBasis{RealT,nnodes_,StaticArrays.SVector{nnodes_,RealT},Array{RealT,2},StaticArrays.SArray{Tuple{4,2},RealT,2,2*nnodes_},StaticArrays.SArray{Tuple{nnodes_,nnodes_},RealT,2,nnodes_^2}},Trixi.LobattoLegendreMortarL2{RealT,nnodes_,StaticArrays.SArray{Tuple{nnodes_,nnodes_},RealT,2,nnodes_^2}},Function,Trixi.AbstractVolumeIntegral}})
383
# end
384
# end
385
@assert Base.precompile(Tuple{typeof(SummaryCallback)})
386
@assert Base.precompile(Tuple{typeof(summary_box), Base.TTY, String,
387
Vector{Pair{String, Any}}})
388
# TODO: AMRCallback, ControllerThreeLevel, indicators
389
390
# init_elements, interfaces, etc.
391
for RealT in (Float64,), polydeg in 1:7
392
uEltype = RealT
393
nnodes_ = polydeg + 1
394
mortar_type = mortar_type_dgsem(RealT, nnodes_)
395
396
# 1D, serial
397
@assert Base.precompile(Tuple{typeof(Trixi.init_boundaries), Array{Int, 1},
398
TreeMesh{1, Trixi.SerialTree{1}, RealT},
399
Trixi.TreeElementContainer1D{RealT, uEltype},
400
basis_type_dgsem(RealT, nnodes_)})
401
@assert Base.precompile(Tuple{typeof(Trixi.init_interfaces), Array{Int, 1},
402
TreeMesh{1, Trixi.SerialTree{1}, RealT},
403
Trixi.TreeElementContainer1D{RealT, uEltype}})
404
@assert Base.precompile(Tuple{typeof(Trixi.save_mesh_file),
405
TreeMesh{1, Trixi.SerialTree{1}, RealT}, String})
406
407
# 2D, serial
408
@assert Base.precompile(Tuple{typeof(Trixi.init_boundaries), Array{Int, 1},
409
TreeMesh{2, Trixi.SerialTree{2}, RealT},
410
Trixi.TreeElementContainer2D{RealT, uEltype},
411
basis_type_dgsem(RealT, nnodes_)})
412
@assert Base.precompile(Tuple{typeof(Trixi.init_interfaces), Array{Int, 1},
413
TreeMesh{2, Trixi.SerialTree{2}, RealT},
414
Trixi.TreeElementContainer2D{RealT, uEltype}})
415
@assert Base.precompile(Tuple{typeof(Trixi.init_mortars), Array{Int, 1},
416
TreeMesh{2, Trixi.SerialTree{2}, RealT},
417
Trixi.TreeElementContainer2D{RealT, uEltype},
418
mortar_type})
419
@assert Base.precompile(Tuple{typeof(Trixi.save_mesh_file),
420
TreeMesh{2, Trixi.SerialTree{2}, RealT}, String})
421
422
# 2D, parallel
423
@assert Base.precompile(Tuple{typeof(Trixi.init_boundaries), Array{Int, 1},
424
TreeMesh{2, Trixi.ParallelTree{2}, RealT},
425
Trixi.TreeElementContainer2D{RealT, uEltype},
426
basis_type_dgsem(RealT, nnodes_)})
427
@assert Base.precompile(Tuple{typeof(Trixi.init_interfaces), Array{Int, 1},
428
TreeMesh{2, Trixi.ParallelTree{2}, RealT},
429
Trixi.TreeElementContainer2D{RealT, uEltype}})
430
@assert Base.precompile(Tuple{typeof(Trixi.init_mortars), Array{Int, 1},
431
TreeMesh{2, Trixi.ParallelTree{2}, RealT},
432
Trixi.TreeElementContainer2D{RealT, uEltype},
433
mortar_type})
434
@assert Base.precompile(Tuple{typeof(Trixi.init_mpi_interfaces), Array{Int, 1},
435
TreeMesh{2, Trixi.ParallelTree{2}, RealT},
436
Trixi.TreeElementContainer2D{RealT, uEltype}})
437
@assert Base.precompile(Tuple{typeof(Trixi.save_mesh_file),
438
TreeMesh{2, Trixi.ParallelTree{2}, RealT}, String})
439
440
# 3D, serial
441
@assert Base.precompile(Tuple{typeof(Trixi.init_boundaries), Array{Int, 1},
442
TreeMesh{3, Trixi.SerialTree{3}, RealT},
443
Trixi.TreeElementContainer3D{RealT, uEltype},
444
basis_type_dgsem(RealT, nnodes_)})
445
@assert Base.precompile(Tuple{typeof(Trixi.init_interfaces), Array{Int, 1},
446
TreeMesh{3, Trixi.SerialTree{3}, RealT},
447
Trixi.TreeElementContainer3D{RealT, uEltype}})
448
@assert Base.precompile(Tuple{typeof(Trixi.init_mortars), Array{Int, 1},
449
TreeMesh{3, Trixi.SerialTree{3}, RealT},
450
Trixi.TreeElementContainer3D{RealT, uEltype},
451
mortar_type})
452
@assert Base.precompile(Tuple{typeof(Trixi.save_mesh_file),
453
TreeMesh{3, Trixi.SerialTree{3}, RealT}, String})
454
end
455
456
# various `show` methods
457
for RealT in (Float64,)
458
# meshes
459
for NDIMS in 1:3
460
# serial
461
@assert Base.precompile(Tuple{typeof(show), Base.TTY,
462
TreeMesh{NDIMS, Trixi.SerialTree{NDIMS}, RealT}})
463
@assert Base.precompile(Tuple{typeof(show), IOContext{Base.TTY},
464
MIME"text/plain",
465
TreeMesh{NDIMS, Trixi.SerialTree{NDIMS}, RealT}})
466
# parallel
467
@assert Base.precompile(Tuple{typeof(show), Base.TTY,
468
TreeMesh{NDIMS, Trixi.ParallelTree{NDIMS}, RealT}})
469
@assert Base.precompile(Tuple{typeof(show), IOContext{Base.TTY},
470
MIME"text/plain",
471
TreeMesh{NDIMS, Trixi.ParallelTree{NDIMS}, RealT}})
472
end
473
474
# equations
475
for eq_type in equations_types(RealT)
476
@assert Base.precompile(Tuple{typeof(show), Base.TTY, eq_type})
477
@assert Base.precompile(Tuple{typeof(show), IOContext{Base.TTY},
478
MIME"text/plain", eq_type})
479
end
480
481
# mortars, analyzers, adaptors, DG
482
for polydeg in 1:1
483
nnodes_ = polydeg + 1
484
basis_type = basis_type_dgsem(RealT, nnodes_)
485
mortar_type = mortar_type_dgsem(RealT, nnodes_)
486
analyzer_type = analyzer_type_dgsem(RealT, nnodes_)
487
adaptor_type = adaptor_type_dgsem(RealT, nnodes_)
488
489
@assert Base.precompile(Tuple{typeof(show), Base.TTY, basis_type})
490
@assert Base.precompile(Tuple{typeof(show), IOContext{Base.TTY},
491
MIME"text/plain", basis_type})
492
493
@assert Base.precompile(Tuple{typeof(show), Base.TTY, mortar_type})
494
@assert Base.precompile(Tuple{typeof(show), IOContext{Base.TTY},
495
MIME"text/plain", mortar_type})
496
497
@assert Base.precompile(Tuple{typeof(show), Base.TTY, analyzer_type})
498
@assert Base.precompile(Tuple{typeof(show), IOContext{Base.TTY},
499
MIME"text/plain", analyzer_type})
500
501
@assert Base.precompile(Tuple{typeof(show), Base.TTY, adaptor_type})
502
@assert Base.precompile(Tuple{typeof(show), IOContext{Base.TTY},
503
MIME"text/plain", adaptor_type})
504
505
# we could also use more numerical fluxes and volume integral types here
506
@assert Base.precompile(Tuple{typeof(show), Base.TTY,
507
DG{basis_type, mortar_type,
508
typeof(flux_lax_friedrichs),
509
VolumeIntegralWeakForm}})
510
@assert Base.precompile(Tuple{typeof(show), IOContext{Base.TTY},
511
MIME"text/plain",
512
DG{basis_type, mortar_type,
513
typeof(flux_lax_friedrichs),
514
VolumeIntegralWeakForm}})
515
end
516
517
# semidiscretizations
518
@assert Base.precompile(Tuple{typeof(show), IOContext{Base.TTY}, MIME"text/plain",
519
SemidiscretizationHyperbolic})
520
521
# We do not precompile callbacks since they are based on
522
# SciML structures like `DiscreteCallback` that may change their
523
# type signatures in non-breaking releases.
524
end
525
526
@assert Base.precompile(Tuple{typeof(init_mpi)})
527
@assert Base.precompile(Tuple{typeof(init_p4est)})
528
529
# The following precompile statements do not seem to be taken
530
# # `multiply_dimensionwise!` as used in the analysis callback
531
# for RealT in (Float64,)
532
# # 1D version
533
# @assert Base.precompile(Tuple{typeof(multiply_dimensionwise!),Array{RealT, 2},Matrix{RealT},SubArray{RealT, 2, Array{RealT, 3}, Tuple{Base.Slice{Base.OneTo{Int}}, Base.Slice{Base.OneTo{Int}}, Int}, true}})
534
# # 2D version
535
# @assert Base.precompile(Tuple{typeof(multiply_dimensionwise!),Array{RealT, 3},Matrix{RealT},SubArray{RealT, 3, Array{RealT, 4}, Tuple{Base.Slice{Base.OneTo{Int}}, Base.Slice{Base.OneTo{Int}}, Base.Slice{Base.OneTo{Int}}, Int}, true},Array{RealT, 3}})
536
# # 3D version
537
# @assert Base.precompile(Tuple{typeof(multiply_dimensionwise!),Array{RealT, 4},Matrix{RealT},SubArray{RealT, 4, Array{RealT, 5}, Tuple{Base.Slice{Base.OneTo{Int}}, Base.Slice{Base.OneTo{Int}}, Base.Slice{Base.OneTo{Int}}, Base.Slice{Base.OneTo{Int}}, Int}, true},Array{RealT, 4},Array{RealT, 4}})
538
# end
539
540
return nothing
541
end
542
543
# Explicit precompilation including running code
544
using PrecompileTools: @setup_workload, @compile_workload
545
546
@setup_workload begin
547
# Setup code can go here
548
549
@compile_workload begin
550
# Everything inside this block will run at precompile time, saving the
551
# binary code to a cache in newer versions of Julia.
552
DGSEM(3)
553
end
554
end
555
556