Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/src/callbacks_step/glm_speed_dg.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
function calc_dt_for_cleaning_speed(cfl::Real, mesh,
9
equations::Union{AbstractIdealGlmMhdEquations,
10
AbstractIdealGlmMhdMulticomponentEquations,
11
AbstractIdealGlmMhdMultiIonEquations},
12
dg::DG, cache)
13
# compute time step for GLM linear advection equation with c_h=1 for the DG discretization on
14
# Cartesian meshes
15
max_scaled_speed_for_c_h = maximum(cache.elements.inverse_jacobian) *
16
ndims(equations)
17
18
if mpi_isparallel()
19
# Base.max instead of max needed, see comment in src/auxiliary/math.jl
20
max_scaled_speed_for_c_h = MPI.Allreduce!(Ref(max_scaled_speed_for_c_h),
21
Base.max,
22
mpi_comm())[]
23
end
24
25
# OBS! This depends on the implementation details of the StepsizeCallback and needs to be adapted
26
# as well if that callback changes.
27
return cfl * 2 / (nnodes(dg) * max_scaled_speed_for_c_h)
28
end
29
30
function calc_dt_for_cleaning_speed(cfl::Real, mesh,
31
equations::Union{AbstractIdealGlmMhdEquations,
32
AbstractIdealGlmMhdMulticomponentEquations,
33
AbstractIdealGlmMhdMultiIonEquations},
34
dg::DGMulti, cache)
35
rd = dg.basis
36
md = mesh.md
37
38
# Compute time step for GLM linear advection equation with c_h=1 for a DGMulti discretization.
39
# Copies implementation behavior of `calc_dt_for_cleaning_speed` for DGSEM discretizations.
40
max_scaled_speed_for_c_h = inv(minimum(md.J)) * ndims(equations)
41
42
if mpi_isparallel()
43
# Base.max instead of max needed, see comment in src/auxiliary/math.jl
44
max_scaled_speed_for_c_h = MPI.Allreduce!(Ref(max_scaled_speed_for_c_h),
45
Base.max,
46
mpi_comm())[]
47
end
48
# This mimics `max_dt` for `TreeMesh`, except that `nnodes(dg)` is replaced by
49
# `polydeg+1`. This is because `nnodes(dg)` returns the total number of
50
# multi-dimensional nodes for DGMulti solver types, while `nnodes(dg)` returns
51
# the number of 1D nodes for `DGSEM` solvers.
52
polydeg = rd.N
53
return cfl * 2 / ((polydeg + 1) * max_scaled_speed_for_c_h)
54
end
55
end # @muladd
56
57