Skip to content

Commit

Permalink
add limiter fix for curvilinear meshes
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickersing committed May 17, 2024
1 parent da3af82 commit fed45fc
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/callbacks_stage/positivity_shallow_water_dg2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function limiter_shallow_water!(u, threshold::Real, variable,
equations::ShallowWaterEquationsWetDry2D, dg::DGSEM,
cache)
@unpack weights = dg.basis
@unpack inverse_jacobian = cache.elements

Trixi.@threaded for element in eachelement(dg, cache)
# determine minimum value
Expand All @@ -26,12 +27,16 @@ function limiter_shallow_water!(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(Trixi.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 Expand Up @@ -96,6 +101,7 @@ function limiter_shallow_water!(u, threshold::Real, variable,
equations::ShallowWaterMultiLayerEquations2D, dg::DGSEM,
cache)
@unpack weights = dg.basis
@unpack inverse_jacobian = cache.elements

Trixi.@threaded for element in eachelement(dg, cache)
# Limit layerwise
Expand All @@ -112,12 +118,17 @@ function limiter_shallow_water!(u, threshold::Real, variable,

# compute mean value
u_mean = zero(get_node_vars(u, equations, dg, 1, 1, element))
total_volume = zero(eltype(u))

Check warning on line 121 in src/callbacks_stage/positivity_shallow_water_dg2d.jl

View check run for this annotation

Codecov / codecov/patch

src/callbacks_stage/positivity_shallow_water_dg2d.jl#L121

Added line #L121 was not covered by tests
for j in eachnode(dg), i in eachnode(dg)
volume_jacobian = abs(inv(Trixi.get_inverse_jacobian(inverse_jacobian,

Check warning on line 123 in src/callbacks_stage/positivity_shallow_water_dg2d.jl

View check run for this annotation

Codecov / codecov/patch

src/callbacks_stage/positivity_shallow_water_dg2d.jl#L123

Added line #L123 was not covered by tests
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

Check warning on line 128 in src/callbacks_stage/positivity_shallow_water_dg2d.jl

View check run for this annotation

Codecov / codecov/patch

src/callbacks_stage/positivity_shallow_water_dg2d.jl#L127-L128

Added lines #L127 - L128 were not covered by tests
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

Check warning on line 131 in src/callbacks_stage/positivity_shallow_water_dg2d.jl

View check run for this annotation

Codecov / codecov/patch

src/callbacks_stage/positivity_shallow_water_dg2d.jl#L131

Added line #L131 was not covered by tests

# We compute the value directly with the mean values.
# The waterheight `h` is limited independently in each layer.
Expand Down

0 comments on commit fed45fc

Please sign in to comment.