Path: blob/main/src/callbacks_step/glm_speed_dg.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: noindent67function calc_dt_for_cleaning_speed(cfl::Real, mesh,8equations::Union{AbstractIdealGlmMhdEquations,9AbstractIdealGlmMhdMulticomponentEquations,10AbstractIdealGlmMhdMultiIonEquations},11dg::DG, cache)12# compute time step for GLM linear advection equation with c_h=1 for the DG discretization on13# Cartesian meshes14max_scaled_speed_for_c_h = maximum(cache.elements.inverse_jacobian) *15ndims(equations)1617if mpi_isparallel()18# Base.max instead of max needed, see comment in src/auxiliary/math.jl19max_scaled_speed_for_c_h = MPI.Allreduce!(Ref(max_scaled_speed_for_c_h),20Base.max,21mpi_comm())[]22end2324# OBS! This depends on the implementation details of the StepsizeCallback and needs to be adapted25# as well if that callback changes.26return cfl * 2 / (nnodes(dg) * max_scaled_speed_for_c_h)27end2829function calc_dt_for_cleaning_speed(cfl::Real, mesh,30equations::Union{AbstractIdealGlmMhdEquations,31AbstractIdealGlmMhdMulticomponentEquations,32AbstractIdealGlmMhdMultiIonEquations},33dg::DGMulti, cache)34rd = dg.basis35md = mesh.md3637# Compute time step for GLM linear advection equation with c_h=1 for a DGMulti discretization.38# Copies implementation behavior of `calc_dt_for_cleaning_speed` for DGSEM discretizations.39max_scaled_speed_for_c_h = inv(minimum(md.J)) * ndims(equations)4041if mpi_isparallel()42# Base.max instead of max needed, see comment in src/auxiliary/math.jl43max_scaled_speed_for_c_h = MPI.Allreduce!(Ref(max_scaled_speed_for_c_h),44Base.max,45mpi_comm())[]46end47# This mimics `max_dt` for `TreeMesh`, except that `nnodes(dg)` is replaced by48# `polydeg+1`. This is because `nnodes(dg)` returns the total number of49# multi-dimensional nodes for DGMulti solver types, while `nnodes(dg)` returns50# the number of 1D nodes for `DGSEM` solvers.51polydeg = rd.N52return cfl * 2 / ((polydeg + 1) * max_scaled_speed_for_c_h)53end54end # @muladd555657