Path: blob/main/src/solvers/dgsem/compute_u_mean.jl
5591 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# `compute_u_mean` used in:8# (Stage-) Callbacks `EntropyBoundedLimiter` and `PositivityPreservingLimiterZhangShu`910# positional arguments `mesh` and `cache` passed in to match signature of 2D/3D functions11@inline function compute_u_mean(u::AbstractArray{<:Any, 3}, element,12mesh::AbstractMesh{1}, equations, dg::DGSEM, cache)13@unpack weights = dg.basis1415u_mean = zero(get_node_vars(u, equations, dg, 1, element))16for i in eachnode(dg)17u_node = get_node_vars(u, equations, dg, i, element)18u_mean += u_node * weights[i]19end20# normalize with the total volume21# note that the reference element is [-1,1], thus the weights sum to 222return 0.5f0 * u_mean23end2425@inline function compute_u_mean(u::AbstractArray{<:Any, 4}, element,26mesh::AbstractMesh{2}, equations, dg::DGSEM, cache)27@unpack weights = dg.basis28@unpack inverse_jacobian = cache.elements2930node_volume = zero(real(mesh))31total_volume = zero(node_volume)3233u_mean = zero(get_node_vars(u, equations, dg, 1, 1, element))34for j in eachnode(dg), i in eachnode(dg)35volume_jacobian = abs(inv(get_inverse_jacobian(inverse_jacobian, mesh,36i, j, element)))37node_volume = weights[i] * weights[j] * volume_jacobian38total_volume += node_volume3940u_node = get_node_vars(u, equations, dg, i, j, element)41u_mean += u_node * node_volume42end43return u_mean / total_volume # normalize with the total volume44end4546@inline function compute_u_mean(u::AbstractArray{<:Any, 5}, element,47mesh::AbstractMesh{3}, equations, dg::DGSEM, cache)48@unpack weights = dg.basis49@unpack inverse_jacobian = cache.elements5051node_volume = zero(real(mesh))52total_volume = zero(node_volume)5354u_mean = zero(get_node_vars(u, equations, dg, 1, 1, 1, element))55for k in eachnode(dg), j in eachnode(dg), i in eachnode(dg)56volume_jacobian = abs(inv(get_inverse_jacobian(inverse_jacobian, mesh,57i, j, k, element)))58node_volume = weights[i] * weights[j] * weights[k] * volume_jacobian59total_volume += node_volume6061u_node = get_node_vars(u, equations, dg, i, j, k, element)62u_mean += u_node * node_volume63end64return u_mean / total_volume # normalize with the total volume65end66end # @muladd676869