Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/src/solvers/dgsem/compute_u_mean.jl
5591 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
# `compute_u_mean` used in:
9
# (Stage-) Callbacks `EntropyBoundedLimiter` and `PositivityPreservingLimiterZhangShu`
10
11
# positional arguments `mesh` and `cache` passed in to match signature of 2D/3D functions
12
@inline function compute_u_mean(u::AbstractArray{<:Any, 3}, element,
13
mesh::AbstractMesh{1}, equations, dg::DGSEM, cache)
14
@unpack weights = dg.basis
15
16
u_mean = zero(get_node_vars(u, equations, dg, 1, element))
17
for i in eachnode(dg)
18
u_node = get_node_vars(u, equations, dg, i, element)
19
u_mean += u_node * weights[i]
20
end
21
# normalize with the total volume
22
# note that the reference element is [-1,1], thus the weights sum to 2
23
return 0.5f0 * u_mean
24
end
25
26
@inline function compute_u_mean(u::AbstractArray{<:Any, 4}, element,
27
mesh::AbstractMesh{2}, equations, dg::DGSEM, cache)
28
@unpack weights = dg.basis
29
@unpack inverse_jacobian = cache.elements
30
31
node_volume = zero(real(mesh))
32
total_volume = zero(node_volume)
33
34
u_mean = zero(get_node_vars(u, equations, dg, 1, 1, element))
35
for j in eachnode(dg), i in eachnode(dg)
36
volume_jacobian = abs(inv(get_inverse_jacobian(inverse_jacobian, mesh,
37
i, j, element)))
38
node_volume = weights[i] * weights[j] * volume_jacobian
39
total_volume += node_volume
40
41
u_node = get_node_vars(u, equations, dg, i, j, element)
42
u_mean += u_node * node_volume
43
end
44
return u_mean / total_volume # normalize with the total volume
45
end
46
47
@inline function compute_u_mean(u::AbstractArray{<:Any, 5}, element,
48
mesh::AbstractMesh{3}, equations, dg::DGSEM, cache)
49
@unpack weights = dg.basis
50
@unpack inverse_jacobian = cache.elements
51
52
node_volume = zero(real(mesh))
53
total_volume = zero(node_volume)
54
55
u_mean = zero(get_node_vars(u, equations, dg, 1, 1, 1, element))
56
for k in eachnode(dg), j in eachnode(dg), i in eachnode(dg)
57
volume_jacobian = abs(inv(get_inverse_jacobian(inverse_jacobian, mesh,
58
i, j, k, element)))
59
node_volume = weights[i] * weights[j] * weights[k] * volume_jacobian
60
total_volume += node_volume
61
62
u_node = get_node_vars(u, equations, dg, i, j, k, element)
63
u_mean += u_node * node_volume
64
end
65
return u_mean / total_volume # normalize with the total volume
66
end
67
end # @muladd
68
69