Path: blob/main/src/callbacks_step/lbm_collision.jl
5586 views
# By default, Julia/LLVM does not use fused multiply-add operations (FMAs).1# Since these FMAs can increase the performance of many numerical algorithms,2# we need to opt-in explicitly.3# See https://ranocha.de/blog/Optimizing_EC_Trixi for further details.4@muladd begin5#! format: noindent67"""8LBMCollisionCallback()910Apply the Lattice-Boltzmann method (LBM) collision operator before each time step.11See [`LatticeBoltzmannEquations2D`](@ref) for further details.12"""13function LBMCollisionCallback()14return DiscreteCallback(lbm_collision_callback, lbm_collision_callback,15save_positions = (false, false),16initialize = initialize!)17end1819# Always execute collision step after a time step, but not after the last step20lbm_collision_callback(u, t, integrator) = !isfinished(integrator)2122function Base.show(io::IO,23cb::DiscreteCallback{<:Any, <:typeof(lbm_collision_callback)})24@nospecialize cb # reduce precompilation time2526print(io, "LBMCollisionCallback()")27return nothing28end2930function Base.show(io::IO, ::MIME"text/plain",31cb::DiscreteCallback{<:Any, <:typeof(lbm_collision_callback)})32@nospecialize cb # reduce precompilation time3334if get(io, :compact, false)35show(io, cb)36else37summary_box(io, "LBMCollisionCallback")38end39end4041# Execute collision step once in the very beginning42function initialize!(cb::DiscreteCallback{Condition, Affect!}, u, t,43integrator) where {Condition,44Affect! <: typeof(lbm_collision_callback)}45return cb.affect!(integrator)46end4748# This method is called as callback after the StepsizeCallback during the time integration.49@inline function lbm_collision_callback(integrator)50dt = get_proposed_dt(integrator)51semi = integrator.p52mesh, equations, solver, cache = mesh_equations_solver_cache(semi)53@unpack collision_op = equations5455u_ode = integrator.u56u = wrap_array(u_ode, mesh, equations, solver, cache)5758@trixi_timeit timer() "LBM collision" apply_collision!(u, dt, collision_op, mesh,59equations, solver, cache)6061return nothing62end6364include("lbm_collision_dg2d.jl")65include("lbm_collision_dg3d.jl")66end # @muladd676869