Path: blob/main/src/callbacks_step/callbacks_step.jl
2055 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# overload this function for specific callbacks which use element element variables8# that should be saved9function get_element_variables!(element_variables, u, mesh, equations, solver, cache,10callback; kwargs...)11return nothing12end1314@inline function get_element_variables!(element_variables, u_ode,15semi::AbstractSemidiscretization,16cb::DiscreteCallback;17kwargs...)18mesh, equations, solver, cache = mesh_equations_solver_cache(semi)19u = wrap_array(u_ode, mesh, equations, solver, cache)20get_element_variables!(element_variables, u, mesh, equations, solver, cache,21cb.affect!; kwargs...)22end2324@inline function isfinished(integrator)25# Checking for floating point equality is OK here as `DifferentialEquations.jl`26# sets the time exactly to the final time in the last iteration27return integrator.t == last(integrator.sol.prob.tspan) ||28isempty(integrator.opts.tstops) ||29integrator.iter == integrator.opts.maxiters30end3132# `include` callback definitions in the order that we currently prefer33# when combining them into a `CallbackSet` which is called *after* a complete step34# The motivation is as follows: The first callbacks belong to the current time step iteration:35# * `SummaryCallback` controls, among other things, timers and should thus be first36# * `SteadyStateCallback` may mark a time step as the last step, which is needed by other callbacks37# * `AnalysisCallback` may also do some checks that mark a step as the last one38# * `AliveCallback` belongs to `AnalysisCallback` and should thus be nearby39# * `SaveRestartCallback`, `SaveSolutionCallback`, and `TimeSeriesCallback` should save the current40# solution state before it is potentially degraded by AMR41# * `VisualizationCallback` similarly should be called before the mesh is adapted42#43# From here on, the remaining callbacks essentially already belong to the next time step iteration:44# * `AMRCallback` really belongs to the next time step already, as it should be the "first" callback45# in a time step loop (however, callbacks are always executed *after* a step, thus it comes near46# the end here)47# * `StepsizeCallback` must come after AMR to accommodate potential changes in the minimum cell size48# * `GlmSpeedCallback` must come after computing time step size because it affects the value of c_h49# * `LBMCollisionCallback` must come after computing time step size because it is already part of50# the next time step calculation51include("summary.jl")52include("steady_state.jl")53include("analysis.jl")54include("alive.jl")55include("save_restart.jl")56include("save_solution.jl")57include("time_series.jl")58include("visualization.jl")59include("averaging.jl")6061include("amr.jl")62include("stepsize.jl")63include("glm_speed.jl")64include("lbm_collision.jl")65include("euler_acoustics_coupling.jl")6667# The `TrivialCallback` purposely does nothing: It allows to quickly disable specific callbacks68# when using `trixi_include` or `test_trixi_include`69include("trivial.jl")7071# DGMulti callbacks72include("analysis_dgmulti.jl")73end # @muladd747576