Skip to content

Commit

Permalink
Rename minmax limiting to twosided limiting
Browse files Browse the repository at this point in the history
  • Loading branch information
bennibolm committed Feb 19, 2024
1 parent a475855 commit 2e71c82
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ surface_flux = flux_lax_friedrichs
volume_flux = flux_ranocha
basis = LobattoLegendreBasis(3)
limiter_idp = SubcellLimiterIDP(equations, basis;
local_minmax_variables_cons = ["rho"],
local_twosided_variables_cons = ["rho"],
local_onesided_variables_nonlinear = [(Trixi.entropy_math,
max)])
volume_integral = VolumeIntegralSubcellLimiting(limiter_idp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ surface_flux = flux_lax_friedrichs
volume_flux = flux_chandrashekar
basis = LobattoLegendreBasis(3)
limiter_idp = SubcellLimiterIDP(equations, basis;
local_minmax_variables_cons = ["rho"],
local_twosided_variables_cons = ["rho"],
local_onesided_variables_nonlinear = [(Trixi.entropy_spec,
min)])
volume_integral = VolumeIntegralSubcellLimiting(limiter_idp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ volume_flux = flux_ranocha
basis = LobattoLegendreBasis(3)

limiter_idp = SubcellLimiterIDP(equations, basis;
local_minmax_variables_cons = ["rho" * string(i)
for i in eachcomponent(equations)])
local_twosided_variables_cons = ["rho" * string(i)
for i in eachcomponent(equations)])
volume_integral = VolumeIntegralSubcellLimiting(limiter_idp;
volume_flux_dg = volume_flux,
volume_flux_fv = surface_flux)
Expand Down
16 changes: 8 additions & 8 deletions src/callbacks_stage/subcell_bounds_check.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ function init_callback(callback::BoundsCheckCallback, semi, limiter::SubcellLimi
return nothing
end

(; local_minmax, positivity, local_onesided) = limiter
(; local_twosided, positivity, local_onesided) = limiter
(; output_directory) = callback
variables = varnames(cons2cons, semi.equations)

mkpath(output_directory)
open("$output_directory/deviations.txt", "a") do f
print(f, "# iter, simu_time")
if local_minmax
for v in limiter.local_minmax_variables_cons
if local_twosided
for v in limiter.local_twosided_variables_cons
variable_string = string(variables[v])
print(f, ", " * variable_string * "_min, " * variable_string * "_max")
end
Expand All @@ -97,7 +97,7 @@ function init_callback(callback::BoundsCheckCallback, semi, limiter::SubcellLimi
end
if positivity
for v in limiter.positivity_variables_cons
if v in limiter.local_minmax_variables_cons
if v in limiter.local_twosided_variables_cons
continue
end
print(f, ", " * string(variables[v]) * "_min")
Expand Down Expand Up @@ -125,15 +125,15 @@ end

@inline function finalize_callback(callback::BoundsCheckCallback, semi,
limiter::SubcellLimiterIDP)
(; local_minmax, positivity, local_onesided) = limiter
(; local_twosided, positivity, local_onesided) = limiter
(; idp_bounds_delta_global) = limiter.cache
variables = varnames(cons2cons, semi.equations)

println(""^100)
println("Maximum deviation from bounds:")
println(""^100)
if local_minmax
for v in limiter.local_minmax_variables_cons
if local_twosided
for v in limiter.local_twosided_variables_cons
v_string = string(v)
println("$(variables[v]):")
println("- lower bound: ",
Expand All @@ -154,7 +154,7 @@ end
end
if positivity
for v in limiter.positivity_variables_cons
if v in limiter.local_minmax_variables_cons
if v in limiter.local_twosided_variables_cons
continue
end
println(string(variables[v]) * ":\n- positivity: ",
Expand Down
14 changes: 7 additions & 7 deletions src/callbacks_stage/subcell_bounds_check_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@inline function check_bounds(u, mesh::AbstractMesh{2}, equations, solver, cache,
limiter::SubcellLimiterIDP,
time, iter, output_directory, save_errors)
(; local_minmax, positivity, local_onesided) = solver.volume_integral.limiter
(; local_twosided, positivity, local_onesided) = solver.volume_integral.limiter
(; variable_bounds) = limiter.cache.subcell_limiter_coefficients
(; idp_bounds_delta_local, idp_bounds_delta_global) = limiter.cache

Expand All @@ -21,8 +21,8 @@
# Since there are no processors with caches over 128B, we use `n = 128B / size(uEltype)`
stride_size = div(128, sizeof(eltype(u))) # = n

if local_minmax
for v in limiter.local_minmax_variables_cons
if local_twosided
for v in limiter.local_twosided_variables_cons
v_string = string(v)
key_min = Symbol(v_string, "_min")
key_max = Symbol(v_string, "_max")
Expand Down Expand Up @@ -62,7 +62,7 @@
end
if positivity
for v in limiter.positivity_variables_cons
if v in limiter.local_minmax_variables_cons
if v in limiter.local_twosided_variables_cons
continue
end
key = Symbol(string(v), "_min")
Expand Down Expand Up @@ -106,8 +106,8 @@
# Print to output file
open("$output_directory/deviations.txt", "a") do f
print(f, iter, ", ", time)
if local_minmax
for v in limiter.local_minmax_variables_cons
if local_twosided
for v in limiter.local_twosided_variables_cons
v_string = string(v)
print(f, ", ",
idp_bounds_delta_local[Symbol(v_string, "_min")][stride_size],
Expand All @@ -124,7 +124,7 @@
end
if positivity
for v in limiter.positivity_variables_cons
if v in limiter.local_minmax_variables_cons
if v in limiter.local_twosided_variables_cons
continue
end
print(f, ", ",
Expand Down
40 changes: 20 additions & 20 deletions src/solvers/dgsem_tree/subcell_limiters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ end

"""
SubcellLimiterIDP(equations::AbstractEquations, basis;
local_minmax_variables_cons = String[],
local_twosided_variables_cons = String[],
positivity_variables_cons = String[],
positivity_variables_nonlinear = [],
positivity_correction_factor = 0.1,
Expand All @@ -25,12 +25,12 @@ end
Subcell invariant domain preserving (IDP) limiting used with [`VolumeIntegralSubcellLimiting`](@ref)
including:
- Local maximum/minimum Zalesak-type limiting for conservative variables (`local_minmax_variables_cons`)
- Local two-sided Zalesak-type limiting for conservative variables (`local_twosided_variables_cons`)
- Positivity limiting for conservative variables (`positivity_variables_cons`) and nonlinear variables
(`positivity_variables_nonlinear`)
- One-sided limiting for nonlinear variables (e.g., `entropy_spec`, `entropy_math`)
Conservative variables to be limited are passed as a vector of strings, e.g. `local_minmax_variables_cons = ["rho"]`
Conservative variables to be limited are passed as a vector of strings, e.g. `local_twosided_variables_cons = ["rho"]`
and `positivity_variables_cons = ["rho"]`. For nonlinear variables the specific functions are
passed - to ensure posivity use a plain vector, e.g. `positivity_variables_nonlinear = [pressure]`,
for a one-sided limiting pass the variable and the specific bound as a tuple within a vector, e.g.
Expand Down Expand Up @@ -62,8 +62,8 @@ where `d = #dimensions`). See equation (20) of Pazner (2020) and equation (30) o
struct SubcellLimiterIDP{RealT <: Real, LimitingVariablesNonlinear,
LimitingOnesidedVariablesNonlinear, Cache} <:
AbstractSubcellLimiter
local_minmax::Bool
local_minmax_variables_cons::Vector{Int} # Local mininum/maximum principles for conservative variables
local_twosided::Bool
local_twosided_variables_cons::Vector{Int} # Local mininum/maximum principles for conservative variables
positivity::Bool
positivity_variables_cons::Vector{Int} # Positivity for conservative variables
positivity_variables_nonlinear::LimitingVariablesNonlinear # Positivity for nonlinear variables
Expand All @@ -78,15 +78,15 @@ end

# this method is used when the limiter is constructed as for shock-capturing volume integrals
function SubcellLimiterIDP(equations::AbstractEquations, basis;
local_minmax_variables_cons = String[],
local_twosided_variables_cons = String[],
positivity_variables_cons = String[],
positivity_variables_nonlinear = [],
positivity_correction_factor = 0.1,
local_onesided_variables_nonlinear = NTuple{2, Function}[],
max_iterations_newton = 10,
newton_tolerances = (1.0e-12, 1.0e-14),
gamma_constant_newton = 2 * ndims(equations))
local_minmax = (length(local_minmax_variables_cons) > 0)
local_twosided = (length(local_twosided_variables_cons) > 0)
local_onesided = (length(local_onesided_variables_nonlinear) > 0)
positivity = (length(positivity_variables_cons) +
length(positivity_variables_nonlinear) > 0)
Expand All @@ -104,14 +104,14 @@ function SubcellLimiterIDP(equations::AbstractEquations, basis;
end
end

local_minmax_variables_cons_ = get_variable_index.(local_minmax_variables_cons,
equations)
local_twosided_variables_cons_ = get_variable_index.(local_twosided_variables_cons,
equations)
positivity_variables_cons_ = get_variable_index.(positivity_variables_cons,
equations)

bound_keys = ()
if local_minmax
for v in local_minmax_variables_cons_
if local_twosided
for v in local_twosided_variables_cons_
v_string = string(v)
bound_keys = (bound_keys..., Symbol(v_string, "_min"),
Symbol(v_string, "_max"))
Expand All @@ -124,7 +124,7 @@ function SubcellLimiterIDP(equations::AbstractEquations, basis;
end
end
for v in positivity_variables_cons_
if !(v in local_minmax_variables_cons_)
if !(v in local_twosided_variables_cons_)
bound_keys = (bound_keys..., Symbol(string(v), "_min"))
end
end
Expand All @@ -137,7 +137,7 @@ function SubcellLimiterIDP(equations::AbstractEquations, basis;
SubcellLimiterIDP{typeof(positivity_correction_factor),
typeof(positivity_variables_nonlinear),
typeof(local_onesided_variables_nonlinear_),
typeof(cache)}(local_minmax, local_minmax_variables_cons_,
typeof(cache)}(local_twosided, local_twosided_variables_cons_,
positivity, positivity_variables_cons_,
positivity_variables_nonlinear,
positivity_correction_factor,
Expand All @@ -150,14 +150,14 @@ end

function Base.show(io::IO, limiter::SubcellLimiterIDP)
@nospecialize limiter # reduce precompilation time
(; local_minmax, positivity, local_onesided) = limiter
(; local_twosided, positivity, local_onesided) = limiter

print(io, "SubcellLimiterIDP(")
if !(local_minmax || positivity || local_onesided)
if !(local_twosided || positivity || local_onesided)
print(io, "No limiter selected => pure DG method")
else
features = String[]
if local_minmax
if local_twosided
push!(features, "local min/max")
end
if positivity
Expand All @@ -175,19 +175,19 @@ end

function Base.show(io::IO, ::MIME"text/plain", limiter::SubcellLimiterIDP)
@nospecialize limiter # reduce precompilation time
(; local_minmax, positivity, local_onesided) = limiter
(; local_twosided, positivity, local_onesided) = limiter

if get(io, :compact, false)
show(io, limiter)
else
if !(local_minmax || positivity || local_onesided)
if !(local_twosided || positivity || local_onesided)
setup = ["Limiter" => "No limiter selected => pure DG method"]
else
setup = ["Limiter" => ""]
if local_minmax
if local_twosided
setup = [
setup...,
"" => "Local maximum/minimum limiting for conservative variables $(limiter.local_minmax_variables_cons)",
"" => "Local maximum/minimum limiting for conservative variables $(limiter.local_twosided_variables_cons)",
]
end
if positivity
Expand Down
18 changes: 9 additions & 9 deletions src/solvers/dgsem_tree/subcell_limiters_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ function (limiter::SubcellLimiterIDP)(u::AbstractArray{<:Any, 4}, semi, dg::DGSE
# TODO: Do not abuse `reset_du!` but maybe implement a generic `set_zero!`
@trixi_timeit timer() "reset alpha" reset_du!(alpha, dg, semi.cache)

if limiter.local_minmax
@trixi_timeit timer() "local min/max" idp_local_minmax!(alpha, limiter,
u, t, dt, semi)
if limiter.local_twosided
@trixi_timeit timer() "local min/max" idp_local_twosided!(alpha, limiter,
u, t, dt, semi)
end
if limiter.positivity
@trixi_timeit timer() "positivity" idp_positivity!(alpha, limiter, u, dt, semi)
Expand Down Expand Up @@ -281,15 +281,15 @@ end
###############################################################################
# Local minimum/maximum limiting

@inline function idp_local_minmax!(alpha, limiter, u, t, dt, semi)
for variable in limiter.local_minmax_variables_cons
idp_local_minmax!(alpha, limiter, u, t, dt, semi, variable)
@inline function idp_local_twosided!(alpha, limiter, u, t, dt, semi)
for variable in limiter.local_twosided_variables_cons
idp_local_twosided!(alpha, limiter, u, t, dt, semi, variable)
end

return nothing
end

@inline function idp_local_minmax!(alpha, limiter, u, t, dt, semi, variable)
@inline function idp_local_twosided!(alpha, limiter, u, t, dt, semi, variable)
_, _, dg, cache = mesh_equations_solver_cache(semi)
(; antidiffusive_flux1_L, antidiffusive_flux2_L, antidiffusive_flux1_R, antidiffusive_flux2_R) = cache.antidiffusive_fluxes
(; inverse_weights) = dg.basis
Expand Down Expand Up @@ -431,8 +431,8 @@ end
end

# Compute bound
if limiter.local_minmax &&
variable in limiter.local_minmax_variables_cons &&
if limiter.local_twosided &&
variable in limiter.local_twosided_variables_cons &&
var_min[i, j, element] >= positivity_correction_factor * var
# Local limiting is more restrictive that positivity limiting
# => Skip positivity limiting for this node
Expand Down

0 comments on commit 2e71c82

Please sign in to comment.