Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/src/callbacks_step/lbm_collision.jl
5586 views
1
# By default, Julia/LLVM does not use fused multiply-add operations (FMAs).
2
# Since these FMAs can increase the performance of many numerical algorithms,
3
# we need to opt-in explicitly.
4
# See https://ranocha.de/blog/Optimizing_EC_Trixi for further details.
5
@muladd begin
6
#! format: noindent
7
8
"""
9
LBMCollisionCallback()
10
11
Apply the Lattice-Boltzmann method (LBM) collision operator before each time step.
12
See [`LatticeBoltzmannEquations2D`](@ref) for further details.
13
"""
14
function LBMCollisionCallback()
15
return DiscreteCallback(lbm_collision_callback, lbm_collision_callback,
16
save_positions = (false, false),
17
initialize = initialize!)
18
end
19
20
# Always execute collision step after a time step, but not after the last step
21
lbm_collision_callback(u, t, integrator) = !isfinished(integrator)
22
23
function Base.show(io::IO,
24
cb::DiscreteCallback{<:Any, <:typeof(lbm_collision_callback)})
25
@nospecialize cb # reduce precompilation time
26
27
print(io, "LBMCollisionCallback()")
28
return nothing
29
end
30
31
function Base.show(io::IO, ::MIME"text/plain",
32
cb::DiscreteCallback{<:Any, <:typeof(lbm_collision_callback)})
33
@nospecialize cb # reduce precompilation time
34
35
if get(io, :compact, false)
36
show(io, cb)
37
else
38
summary_box(io, "LBMCollisionCallback")
39
end
40
end
41
42
# Execute collision step once in the very beginning
43
function initialize!(cb::DiscreteCallback{Condition, Affect!}, u, t,
44
integrator) where {Condition,
45
Affect! <: typeof(lbm_collision_callback)}
46
return cb.affect!(integrator)
47
end
48
49
# This method is called as callback after the StepsizeCallback during the time integration.
50
@inline function lbm_collision_callback(integrator)
51
dt = get_proposed_dt(integrator)
52
semi = integrator.p
53
mesh, equations, solver, cache = mesh_equations_solver_cache(semi)
54
@unpack collision_op = equations
55
56
u_ode = integrator.u
57
u = wrap_array(u_ode, mesh, equations, solver, cache)
58
59
@trixi_timeit timer() "LBM collision" apply_collision!(u, dt, collision_op, mesh,
60
equations, solver, cache)
61
62
return nothing
63
end
64
65
include("lbm_collision_dg2d.jl")
66
include("lbm_collision_dg3d.jl")
67
end # @muladd
68
69