Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/src/callbacks_step/callbacks_step.jl
2055 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
# overload this function for specific callbacks which use element element variables
9
# that should be saved
10
function get_element_variables!(element_variables, u, mesh, equations, solver, cache,
11
callback; kwargs...)
12
return nothing
13
end
14
15
@inline function get_element_variables!(element_variables, u_ode,
16
semi::AbstractSemidiscretization,
17
cb::DiscreteCallback;
18
kwargs...)
19
mesh, equations, solver, cache = mesh_equations_solver_cache(semi)
20
u = wrap_array(u_ode, mesh, equations, solver, cache)
21
get_element_variables!(element_variables, u, mesh, equations, solver, cache,
22
cb.affect!; kwargs...)
23
end
24
25
@inline function isfinished(integrator)
26
# Checking for floating point equality is OK here as `DifferentialEquations.jl`
27
# sets the time exactly to the final time in the last iteration
28
return integrator.t == last(integrator.sol.prob.tspan) ||
29
isempty(integrator.opts.tstops) ||
30
integrator.iter == integrator.opts.maxiters
31
end
32
33
# `include` callback definitions in the order that we currently prefer
34
# when combining them into a `CallbackSet` which is called *after* a complete step
35
# The motivation is as follows: The first callbacks belong to the current time step iteration:
36
# * `SummaryCallback` controls, among other things, timers and should thus be first
37
# * `SteadyStateCallback` may mark a time step as the last step, which is needed by other callbacks
38
# * `AnalysisCallback` may also do some checks that mark a step as the last one
39
# * `AliveCallback` belongs to `AnalysisCallback` and should thus be nearby
40
# * `SaveRestartCallback`, `SaveSolutionCallback`, and `TimeSeriesCallback` should save the current
41
# solution state before it is potentially degraded by AMR
42
# * `VisualizationCallback` similarly should be called before the mesh is adapted
43
#
44
# From here on, the remaining callbacks essentially already belong to the next time step iteration:
45
# * `AMRCallback` really belongs to the next time step already, as it should be the "first" callback
46
# in a time step loop (however, callbacks are always executed *after* a step, thus it comes near
47
# the end here)
48
# * `StepsizeCallback` must come after AMR to accommodate potential changes in the minimum cell size
49
# * `GlmSpeedCallback` must come after computing time step size because it affects the value of c_h
50
# * `LBMCollisionCallback` must come after computing time step size because it is already part of
51
# the next time step calculation
52
include("summary.jl")
53
include("steady_state.jl")
54
include("analysis.jl")
55
include("alive.jl")
56
include("save_restart.jl")
57
include("save_solution.jl")
58
include("time_series.jl")
59
include("visualization.jl")
60
include("averaging.jl")
61
62
include("amr.jl")
63
include("stepsize.jl")
64
include("glm_speed.jl")
65
include("lbm_collision.jl")
66
include("euler_acoustics_coupling.jl")
67
68
# The `TrivialCallback` purposely does nothing: It allows to quickly disable specific callbacks
69
# when using `trixi_include` or `test_trixi_include`
70
include("trivial.jl")
71
72
# DGMulti callbacks
73
include("analysis_dgmulti.jl")
74
end # @muladd
75
76