Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/src/auxiliary/precompile.jl
2055 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
(LinearScalarAdvectionEquation1D{RealT},
143
HyperbolicDiffusionEquations1D{RealT},
144
CompressibleEulerEquations1D{RealT},
145
IdealGlmMhdEquations1D{RealT})
146
end
147
function equations_types_2d(RealT)
148
(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
(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
(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
LobattoLegendreBasis{RealT, nnodes_,
180
# VectorT
181
StaticArrays.SVector{nnodes_, RealT},
182
# InverseVandermondeLegendre
183
Matrix{RealT},
184
# BoundaryMatrix
185
#StaticArrays.SArray{Tuple{nnodes_,2},RealT,2,2*nnodes_},
186
Matrix{RealT},
187
# DerivativeMatrix
188
#StaticArrays.SArray{Tuple{nnodes_,nnodes_},RealT,2,nnodes_^2},
189
Matrix{RealT}}
190
end
191
192
function mortar_type_dgsem(RealT, nnodes_)
193
LobattoLegendreMortarL2{RealT, nnodes_,
194
# ForwardMatrix
195
#StaticArrays.SArray{Tuple{nnodes_,nnodes_},RealT,2,nnodes_^2},
196
Matrix{RealT},
197
# ReverseMatrix
198
# StaticArrays.SArray{Tuple{nnodes_,nnodes_},RealT,2,nnodes_^2},
199
Matrix{RealT}}
200
end
201
202
function analyzer_type_dgsem(RealT, nnodes_)
203
polydeg = nnodes_ - 1
204
nnodes_analysis = 2 * polydeg + 1
205
LobattoLegendreAnalyzer{RealT, nnodes_analysis,
206
# VectorT
207
StaticArrays.SVector{nnodes_analysis, RealT},
208
# Vandermonde
209
Array{RealT, 2}}
210
end
211
212
function adaptor_type_dgsem(RealT, nnodes_)
213
LobattoLegendreAdaptorL2{RealT, nnodes_,
214
# ForwardMatrix
215
StaticArrays.SArray{Tuple{nnodes_, nnodes_}, RealT, 2,
216
nnodes_^2},
217
# Matrix{RealT},
218
# ReverseMatrix
219
StaticArrays.SArray{Tuple{nnodes_, nnodes_}, RealT, 2,
220
nnodes_^2}
221
# Matrix{RealT},
222
}
223
end
224
225
# Constructors: mesh
226
for RealT in (Int, Float64)
227
@assert Base.precompile(Tuple{Core.kwftype(typeof(Trixi.Type)),
228
NamedTuple{(:initial_refinement_level, :n_cells_max),
229
Tuple{Int, Int}}, Type{TreeMesh},
230
RealT, RealT})
231
@assert Base.precompile(Tuple{Core.kwftype(typeof(Trixi.Type)),
232
NamedTuple{(:initial_refinement_level, :n_cells_max),
233
Tuple{Int, Int}}, Type{TreeMesh},
234
Tuple{RealT}, Tuple{RealT}})
235
@assert Base.precompile(Tuple{Core.kwftype(typeof(Trixi.Type)),
236
NamedTuple{(:initial_refinement_level, :n_cells_max),
237
Tuple{Int, Int}}, Type{TreeMesh},
238
Tuple{RealT, RealT}, Tuple{RealT, RealT}})
239
@assert Base.precompile(Tuple{Core.kwftype(typeof(Trixi.Type)),
240
NamedTuple{(:initial_refinement_level, :n_cells_max),
241
Tuple{Int, Int}}, Type{TreeMesh},
242
Tuple{RealT, RealT, RealT},
243
Tuple{RealT, RealT, RealT}})
244
end
245
for TreeType in (SerialTree, ParallelTree), NDIMS in 1:3
246
@assert Base.precompile(Tuple{typeof(Trixi.initialize!),
247
TreeMesh{NDIMS, TreeType{NDIMS}, Float64}, Int,
248
Tuple{},
249
Tuple{}})
250
@assert Base.precompile(Tuple{typeof(Trixi.save_mesh_file),
251
TreeMesh{NDIMS, TreeType{NDIMS}, Float64}, String,
252
Int})
253
end
254
255
# Constructors: linear advection
256
for RealT in (Float64,)
257
@assert Base.precompile(Tuple{Type{LinearScalarAdvectionEquation1D}, RealT})
258
@assert Base.precompile(Tuple{Type{LinearScalarAdvectionEquation2D}, RealT, RealT})
259
@assert Base.precompile(Tuple{Type{LinearScalarAdvectionEquation2D},
260
Tuple{RealT, RealT}})
261
@assert Base.precompile(Tuple{Type{LinearScalarAdvectionEquation3D}, RealT, RealT,
262
RealT})
263
@assert Base.precompile(Tuple{Type{LinearScalarAdvectionEquation3D},
264
Tuple{RealT, RealT, RealT}})
265
end
266
267
# Constructors: hyperbolic diffusion
268
for RealT in (Float64,)
269
@assert Base.precompile(Tuple{Type{HyperbolicDiffusionEquations1D}})
270
@assert Base.precompile(Tuple{Type{HyperbolicDiffusionEquations2D}})
271
@assert Base.precompile(Tuple{Type{HyperbolicDiffusionEquations3D}})
272
end
273
274
# Constructors: Euler
275
for RealT in (Float64,)
276
@assert Base.precompile(Tuple{Type{CompressibleEulerEquations1D}, RealT})
277
@assert Base.precompile(Tuple{Type{CompressibleEulerEquations2D}, RealT})
278
@assert Base.precompile(Tuple{Type{CompressibleEulerEquations3D}, RealT})
279
end
280
281
# Constructors: MHD
282
for RealT in (Float64,)
283
@assert Base.precompile(Tuple{Type{IdealGlmMhdEquations1D}, RealT})
284
@assert Base.precompile(Tuple{Type{IdealGlmMhdEquations2D}, RealT})
285
@assert Base.precompile(Tuple{Type{IdealGlmMhdEquations3D}, RealT})
286
end
287
288
# Constructors: LBM
289
for RealT in (Float64,)
290
@assert Base.precompile(Tuple{Core.kwftype(typeof(Trixi.Type)),
291
NamedTuple{(:Ma, :Re), Tuple{RealT, RealT}},
292
Type{LatticeBoltzmannEquations2D}})
293
@assert Base.precompile(Tuple{Core.kwftype(typeof(Trixi.Type)),
294
NamedTuple{(:Ma, :Re), Tuple{RealT, Int}},
295
Type{LatticeBoltzmannEquations2D}})
296
@assert Base.precompile(Tuple{Core.kwftype(typeof(Trixi.Type)),
297
NamedTuple{(:Ma, :Re), Tuple{RealT, RealT}},
298
Type{LatticeBoltzmannEquations3D}})
299
@assert Base.precompile(Tuple{Core.kwftype(typeof(Trixi.Type)),
300
NamedTuple{(:Ma, :Re), Tuple{RealT, Int}},
301
Type{LatticeBoltzmannEquations3D}})
302
end
303
304
# Constructors of the basis are inherently type-unstable since we pass integers
305
# and use their values as parameters of static arrays.
306
# Nevertheless, we can still precompile methods used to construct the bases.
307
Base.precompile(Tuple{Type{LobattoLegendreBasis}, Int})
308
for RealT in (Float64,)
309
Base.precompile(Tuple{Type{LobattoLegendreBasis}, RealT, Int})
310
@assert Base.precompile(Tuple{typeof(Trixi.calc_dhat), Vector{RealT},
311
Vector{RealT}})
312
@assert Base.precompile(Tuple{typeof(Trixi.calc_dsplit), Vector{RealT},
313
Vector{RealT}})
314
@assert Base.precompile(Tuple{typeof(Trixi.polynomial_derivative_matrix),
315
Vector{RealT}})
316
@assert Base.precompile(Tuple{typeof(Trixi.polynomial_interpolation_matrix),
317
Vector{RealT}, Vector{RealT}})
318
@assert Base.precompile(Tuple{typeof(Trixi.barycentric_weights), Vector{RealT}})
319
@assert Base.precompile(Tuple{typeof(Trixi.calc_lhat), RealT, Vector{RealT},
320
Vector{RealT}})
321
@assert Base.precompile(Tuple{typeof(Trixi.lagrange_interpolating_polynomials),
322
RealT, Vector{RealT}, Vector{RealT}})
323
@assert Base.precompile(Tuple{typeof(Trixi.calc_q_and_l), Int, RealT})
324
@assert Base.precompile(Tuple{typeof(Trixi.legendre_polynomial_and_derivative), Int,
325
RealT})
326
@assert Base.precompile(Tuple{typeof(Trixi.vandermonde_legendre), Vector{RealT}})
327
end
328
@assert Base.precompile(Tuple{typeof(Trixi.gauss_lobatto_nodes_weights), Int})
329
@assert Base.precompile(Tuple{typeof(Trixi.gauss_nodes_weights), Int})
330
@assert Base.precompile(Tuple{typeof(Trixi.calc_forward_upper), Int})
331
@assert Base.precompile(Tuple{typeof(Trixi.calc_forward_lower), Int})
332
@assert Base.precompile(Tuple{typeof(Trixi.calc_reverse_upper), Int,
333
Val{:gauss}})
334
@assert Base.precompile(Tuple{typeof(Trixi.calc_reverse_lower), Int,
335
Val{:gauss}})
336
@assert Base.precompile(Tuple{typeof(Trixi.calc_reverse_upper), Int,
337
Val{:gauss_lobatto}})
338
@assert Base.precompile(Tuple{typeof(Trixi.calc_reverse_lower), Int,
339
Val{:gauss_lobatto}})
340
341
# Constructors: mortars, analyzers, adaptors
342
for RealT in (Float64,), polydeg in 1:7
343
nnodes_ = polydeg + 1
344
basis_type = basis_type_dgsem(RealT, nnodes_)
345
@assert Base.precompile(Tuple{typeof(Trixi.MortarL2), basis_type})
346
@assert Base.precompile(Tuple{Type{Trixi.SolutionAnalyzer}, basis_type})
347
@assert Base.precompile(Tuple{Type{Trixi.AdaptorL2}, basis_type})
348
end
349
350
# Constructors: callbacks
351
@assert Base.precompile(Tuple{Core.kwftype(typeof(Trixi.Type)),
352
NamedTuple{(:analysis_interval,), Tuple{Int}},
353
Type{AliveCallback}})
354
for RealT in (Float64,)
355
@assert Base.precompile(Tuple{Core.kwftype(typeof(Trixi.Type)),
356
NamedTuple{(:cfl,), Tuple{RealT}},
357
Type{StepsizeCallback}})
358
@assert Base.precompile(Tuple{Core.kwftype(typeof(Trixi.Type)),
359
NamedTuple{(:glm_scale, :cfl), Tuple{RealT, RealT}},
360
Type{GlmSpeedCallback}})
361
end
362
@assert Base.precompile(Tuple{Core.kwftype(typeof(Trixi.Type)),
363
NamedTuple{(:interval, :save_final_restart),
364
Tuple{Int, Bool}}, Type{SaveRestartCallback}})
365
@assert Base.precompile(Tuple{Core.kwftype(typeof(Trixi.Type)),
366
NamedTuple{(:interval, :save_initial_solution,
367
:save_final_solution, :solution_variables),
368
Tuple{Int, Bool, Bool, typeof(cons2cons)}},
369
Type{SaveSolutionCallback}})
370
@assert Base.precompile(Tuple{Core.kwftype(typeof(Trixi.Type)),
371
NamedTuple{(:interval, :save_initial_solution,
372
:save_final_solution, :solution_variables),
373
Tuple{Int, Bool, Bool, typeof(cons2prim)}},
374
Type{SaveSolutionCallback}})
375
# TODO: AnalysisCallback?
376
# for RealT in (Float64,), polydeg in 1:7
377
# nnodes_ = polydeg + 1
378
# nnodes_analysis = 2*polydeg + 1
379
# @assert Base.precompile(Tuple{Type{AnalysisCallback},RealT,Int,Bool,String,String,Trixi.LobattoLegendreAnalyzer{RealT,nnodes_analysis,Array{RealT,2}},Array{Symbol,1},Tuple{typeof(Trixi.entropy_timederivative),typeof(entropy)},StaticArrays.SArray{Tuple{1},RealT,1,1}})
380
# We would need to use all special cases instead of
381
# Function,Trixi.AbstractVolumeIntegral
382
# for equations_type in equations_types(RealT)
383
# @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}})
384
# end
385
# end
386
@assert Base.precompile(Tuple{typeof(SummaryCallback)})
387
@assert Base.precompile(Tuple{typeof(summary_box), Base.TTY, String,
388
Vector{Pair{String, Any}}})
389
# TODO: AMRCallback, ControllerThreeLevel, indicators
390
391
# init_elements, interfaces, etc.
392
for RealT in (Float64,), polydeg in 1:7
393
uEltype = RealT
394
nnodes_ = polydeg + 1
395
mortar_type = mortar_type_dgsem(RealT, nnodes_)
396
397
# 1D, serial
398
@assert Base.precompile(Tuple{typeof(Trixi.init_boundaries), Array{Int, 1},
399
TreeMesh{1, Trixi.SerialTree{1}, RealT},
400
Trixi.ElementContainer1D{RealT, uEltype}})
401
@assert Base.precompile(Tuple{typeof(Trixi.init_interfaces), Array{Int, 1},
402
TreeMesh{1, Trixi.SerialTree{1}, RealT},
403
Trixi.ElementContainer1D{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.ElementContainer2D{RealT, uEltype}})
411
@assert Base.precompile(Tuple{typeof(Trixi.init_interfaces), Array{Int, 1},
412
TreeMesh{2, Trixi.SerialTree{2}, RealT},
413
Trixi.ElementContainer2D{RealT, uEltype}})
414
@assert Base.precompile(Tuple{typeof(Trixi.init_mortars), Array{Int, 1},
415
TreeMesh{2, Trixi.SerialTree{2}, RealT},
416
Trixi.ElementContainer2D{RealT, uEltype},
417
mortar_type})
418
@assert Base.precompile(Tuple{typeof(Trixi.save_mesh_file),
419
TreeMesh{2, Trixi.SerialTree{2}, RealT}, String})
420
421
# 2D, parallel
422
@assert Base.precompile(Tuple{typeof(Trixi.init_boundaries), Array{Int, 1},
423
TreeMesh{2, Trixi.ParallelTree{2}, RealT},
424
Trixi.ElementContainer2D{RealT, uEltype}})
425
@assert Base.precompile(Tuple{typeof(Trixi.init_interfaces), Array{Int, 1},
426
TreeMesh{2, Trixi.ParallelTree{2}, RealT},
427
Trixi.ElementContainer2D{RealT, uEltype}})
428
@assert Base.precompile(Tuple{typeof(Trixi.init_mortars), Array{Int, 1},
429
TreeMesh{2, Trixi.ParallelTree{2}, RealT},
430
Trixi.ElementContainer2D{RealT, uEltype},
431
mortar_type})
432
@assert Base.precompile(Tuple{typeof(Trixi.init_mpi_interfaces), Array{Int, 1},
433
TreeMesh{2, Trixi.ParallelTree{2}, RealT},
434
Trixi.ElementContainer2D{RealT, uEltype}})
435
@assert Base.precompile(Tuple{typeof(Trixi.save_mesh_file),
436
TreeMesh{2, Trixi.ParallelTree{2}, RealT}, String})
437
438
# 3D, serial
439
@assert Base.precompile(Tuple{typeof(Trixi.init_boundaries), Array{Int, 1},
440
TreeMesh{3, Trixi.SerialTree{3}, RealT},
441
Trixi.ElementContainer3D{RealT, uEltype}})
442
@assert Base.precompile(Tuple{typeof(Trixi.init_interfaces), Array{Int, 1},
443
TreeMesh{3, Trixi.SerialTree{3}, RealT},
444
Trixi.ElementContainer3D{RealT, uEltype}})
445
@assert Base.precompile(Tuple{typeof(Trixi.init_mortars), Array{Int, 1},
446
TreeMesh{3, Trixi.SerialTree{3}, RealT},
447
Trixi.ElementContainer3D{RealT, uEltype},
448
mortar_type})
449
@assert Base.precompile(Tuple{typeof(Trixi.save_mesh_file),
450
TreeMesh{3, Trixi.SerialTree{3}, RealT}, String})
451
end
452
453
# various `show` methods
454
for RealT in (Float64,)
455
# meshes
456
for NDIMS in 1:3
457
# serial
458
@assert Base.precompile(Tuple{typeof(show), Base.TTY,
459
TreeMesh{NDIMS, Trixi.SerialTree{NDIMS}, RealT}})
460
@assert Base.precompile(Tuple{typeof(show), IOContext{Base.TTY},
461
MIME"text/plain",
462
TreeMesh{NDIMS, Trixi.SerialTree{NDIMS}, RealT}})
463
# parallel
464
@assert Base.precompile(Tuple{typeof(show), Base.TTY,
465
TreeMesh{NDIMS, Trixi.ParallelTree{NDIMS}, RealT}})
466
@assert Base.precompile(Tuple{typeof(show), IOContext{Base.TTY},
467
MIME"text/plain",
468
TreeMesh{NDIMS, Trixi.ParallelTree{NDIMS}, RealT}})
469
end
470
471
# equations
472
for eq_type in equations_types(RealT)
473
@assert Base.precompile(Tuple{typeof(show), Base.TTY, eq_type})
474
@assert Base.precompile(Tuple{typeof(show), IOContext{Base.TTY},
475
MIME"text/plain", eq_type})
476
end
477
478
# mortars, analyzers, adaptors, DG
479
for polydeg in 1:1
480
nnodes_ = polydeg + 1
481
basis_type = basis_type_dgsem(RealT, nnodes_)
482
mortar_type = mortar_type_dgsem(RealT, nnodes_)
483
analyzer_type = analyzer_type_dgsem(RealT, nnodes_)
484
adaptor_type = adaptor_type_dgsem(RealT, nnodes_)
485
486
@assert Base.precompile(Tuple{typeof(show), Base.TTY, basis_type})
487
@assert Base.precompile(Tuple{typeof(show), IOContext{Base.TTY},
488
MIME"text/plain", basis_type})
489
490
@assert Base.precompile(Tuple{typeof(show), Base.TTY, mortar_type})
491
@assert Base.precompile(Tuple{typeof(show), IOContext{Base.TTY},
492
MIME"text/plain", mortar_type})
493
494
@assert Base.precompile(Tuple{typeof(show), Base.TTY, analyzer_type})
495
@assert Base.precompile(Tuple{typeof(show), IOContext{Base.TTY},
496
MIME"text/plain", analyzer_type})
497
498
@assert Base.precompile(Tuple{typeof(show), Base.TTY, adaptor_type})
499
@assert Base.precompile(Tuple{typeof(show), IOContext{Base.TTY},
500
MIME"text/plain", adaptor_type})
501
502
# we could also use more numerical fluxes and volume integral types here
503
@assert Base.precompile(Tuple{typeof(show), Base.TTY,
504
DG{basis_type, mortar_type,
505
typeof(flux_lax_friedrichs),
506
VolumeIntegralWeakForm}})
507
@assert Base.precompile(Tuple{typeof(show), IOContext{Base.TTY},
508
MIME"text/plain",
509
DG{basis_type, mortar_type,
510
typeof(flux_lax_friedrichs),
511
VolumeIntegralWeakForm}})
512
end
513
514
# semidiscretizations
515
@assert Base.precompile(Tuple{typeof(show), IOContext{Base.TTY}, MIME"text/plain",
516
SemidiscretizationHyperbolic})
517
518
# We do not precompile callbacks since they are based on
519
# SciML structures like `DiscreteCallback` that may change their
520
# type signatures in non-breaking releases.
521
end
522
523
@assert Base.precompile(Tuple{typeof(init_mpi)})
524
@assert Base.precompile(Tuple{typeof(init_p4est)})
525
526
# The following precompile statements do not seem to be taken
527
# # `multiply_dimensionwise!` as used in the analysis callback
528
# for RealT in (Float64,)
529
# # 1D version
530
# @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}})
531
# # 2D version
532
# @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}})
533
# # 3D version
534
# @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}})
535
# end
536
537
return nothing
538
end
539
540
# Explicit precompilation including running code
541
using PrecompileTools: @setup_workload, @compile_workload
542
543
@setup_workload begin
544
# Setup code can go here
545
546
@compile_workload begin
547
# Everything inside this block will run at precompile time, saving the
548
# binary code to a cache in newer versions of Julia.
549
DGSEM(3)
550
end
551
end
552
553