Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mean value in Zhang-Shu limiter on curved meshes #1945

Merged
merged 16 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/callbacks_stage/positivity_zhang_shu_dg2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
function limiter_zhang_shu!(u, threshold::Real, variable,
mesh::AbstractMesh{2}, equations, dg::DGSEM, cache)
@unpack weights = dg.basis
@unpack inverse_jacobian = cache.elements

@threaded for element in eachelement(dg, cache)
# determine minimum value
Expand All @@ -22,12 +23,16 @@ function limiter_zhang_shu!(u, threshold::Real, variable,

# compute mean value
u_mean = zero(get_node_vars(u, equations, dg, 1, 1, element))
total_volume = zero(eltype(u))
for j in eachnode(dg), i in eachnode(dg)
volume_jacobian = abs(inv(get_inverse_jacobian(inverse_jacobian, mesh,
i, j, element)))
u_node = get_node_vars(u, equations, dg, i, j, element)
u_mean += u_node * weights[i] * weights[j]
u_mean += u_node * weights[i] * weights[j] * volume_jacobian
total_volume += weights[i] * weights[j] * volume_jacobian
end
# note that the reference element is [-1,1]^ndims(dg), thus the weights sum to 2
u_mean = u_mean / 2^ndims(mesh)
# normalize with the total volume
u_mean = u_mean / total_volume

# We compute the value directly with the mean values, as we assume that
# Jensen's inequality holds (e.g. pressure for compressible Euler equations).
Expand Down
11 changes: 8 additions & 3 deletions src/callbacks_stage/positivity_zhang_shu_dg3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
function limiter_zhang_shu!(u, threshold::Real, variable,
mesh::AbstractMesh{3}, equations, dg::DGSEM, cache)
@unpack weights = dg.basis
@unpack inverse_jacobian = cache.elements

@threaded for element in eachelement(dg, cache)
# determine minimum value
Expand All @@ -22,12 +23,16 @@ function limiter_zhang_shu!(u, threshold::Real, variable,

# compute mean value
u_mean = zero(get_node_vars(u, equations, dg, 1, 1, 1, element))
total_volume = zero(eltype(u))
for k in eachnode(dg), j in eachnode(dg), i in eachnode(dg)
volume_jacobian = abs(inv(get_inverse_jacobian(inverse_jacobian, mesh,
i, j, k, element)))
u_node = get_node_vars(u, equations, dg, i, j, k, element)
u_mean += u_node * weights[i] * weights[j] * weights[k]
u_mean += u_node * weights[i] * weights[j] * weights[k] * volume_jacobian
total_volume += weights[i] * weights[j] * weights[k] * volume_jacobian
end
# note that the reference element is [-1,1]^ndims(dg), thus the weights sum to 2
u_mean = u_mean / 2^ndims(mesh)
# normalize with the total volume
u_mean = u_mean / total_volume

# We compute the value directly with the mean values, as we assume that
# Jensen's inequality holds (e.g. pressure for compressible Euler equations).
Expand Down
8 changes: 8 additions & 0 deletions src/solvers/dgsem_structured/dg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ end
end
end

@inline function get_inverse_jacobian(inverse_jacobian,
mesh::Union{StructuredMesh, StructuredMeshView,
UnstructuredMesh2D, P4estMesh,
T8codeMesh},
indices...)
return inverse_jacobian[indices...]
end

include("containers.jl")
include("dg_1d.jl")
include("dg_2d.jl")
Expand Down
6 changes: 6 additions & 0 deletions src/solvers/dgsem_tree/dg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ function volume_jacobian(element, mesh::TreeMesh, cache)
return inv(cache.elements.inverse_jacobian[element])^ndims(mesh)
end

@inline function get_inverse_jacobian(inverse_jacobian, mesh::TreeMesh,
indices...)
element = last(indices)
return inverse_jacobian[element]
end

# Indicators used for shock-capturing and AMR
include("indicators.jl")
include("indicators_1d.jl")
Expand Down
Loading