Skip to content

Commit

Permalink
Rename operator to min_or_max
Browse files Browse the repository at this point in the history
  • Loading branch information
bennibolm committed Feb 27, 2024
1 parent e7acae2 commit 967e5bd
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 46 deletions.
12 changes: 6 additions & 6 deletions src/callbacks_stage/subcell_bounds_check.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ function init_callback(callback::BoundsCheckCallback, semi, limiter::SubcellLimi
end
end
if local_onesided
for (variable, operator) in limiter.local_onesided_variables_nonlinear
print(f, ", " * string(variable) * "_" * string(operator))
for (variable, min_or_max) in limiter.local_onesided_variables_nonlinear
print(f, ", " * string(variable) * "_" * string(min_or_max))
end
end
if positivity
Expand Down Expand Up @@ -143,13 +143,13 @@ end
end
end
if local_onesided
for (variable, operator) in limiter.local_onesided_variables_nonlinear
for (variable, min_or_max) in limiter.local_onesided_variables_nonlinear
variable_string = string(variable)
operator_string = string(operator)
minmax_string = string(min_or_max)
println("$variable_string:")
println("- $operator_string bound: ",
println("- $minmax_string bound: ",
idp_bounds_delta_global[Symbol(variable_string, "_",
operator_string)])
minmax_string)])
end
end
if positivity
Expand Down
16 changes: 9 additions & 7 deletions src/callbacks_stage/subcell_bounds_check_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,19 @@
end
end
if local_onesided
foreach(limiter.local_onesided_variables_nonlinear) do (variable, operator)
key = Symbol(string(variable), "_", string(operator))
factor = operator === max ? 1.0 : -1.0
foreach(limiter.local_onesided_variables_nonlinear) do (variable, min_or_max)
key = Symbol(string(variable), "_", string(min_or_max))
deviation_threaded = idp_bounds_delta_local[key]
@threaded for element in eachelement(solver, cache)
deviation = deviation_threaded[stride_size * Threads.threadid()]
for j in eachnode(solver), i in eachnode(solver)
v = variable(get_node_vars(u, equations, solver, i, j, element),
equations)
deviation = max(deviation,
factor * (v - variable_bounds[key][i, j, element]))
if min_or_max === max
deviation = max(deviation, v - variable_bounds[key][i, j, element])
else # min_or_max === min
deviation = max(deviation, variable_bounds[key][i, j, element] - v)
end
end
deviation_threaded[stride_size * Threads.threadid()] = deviation
end
Expand Down Expand Up @@ -116,10 +118,10 @@
end
end
if local_onesided
for (variable, operator) in limiter.local_onesided_variables_nonlinear
for (variable, min_or_max) in limiter.local_onesided_variables_nonlinear
print(f, ", ",
idp_bounds_delta_local[Symbol(string(variable), "_",
string(operator))][stride_size])
string(min_or_max))][stride_size])
end
end
if positivity
Expand Down
16 changes: 8 additions & 8 deletions src/solvers/dgsem_tree/subcell_limiters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ function SubcellLimiterIDP(equations::AbstractEquations, basis;
# When passing `min` or `max` in the elixir the specific function of Base is used.
# To speed up the simulation, we replace it with `Trixi.min` and `Trixi.max` respectively.
local_onesided_variables_nonlinear_ = Tuple{Function, Function}[]
for (variable, operator) in local_onesided_variables_nonlinear
if operator === Base.max
for (variable, min_or_max) in local_onesided_variables_nonlinear
if min_or_max === Base.max
push!(local_onesided_variables_nonlinear_, tuple(variable, max))
elseif operator === Base.min
elseif min_or_max === Base.min
push!(local_onesided_variables_nonlinear_, tuple(variable, min))
else
error("Operator $operator is not a valid input. Use `max` or `min` instead.")
error("Parameter $min_or_max is not a valid input. Use `max` or `min` instead.")
end
end

Expand All @@ -122,9 +122,9 @@ function SubcellLimiterIDP(equations::AbstractEquations, basis;
end
end
if local_onesided
for (variable, operator) in local_onesided_variables_nonlinear_
for (variable, min_or_max) in local_onesided_variables_nonlinear_
bound_keys = (bound_keys...,
Symbol(string(variable), "_", string(operator)))
Symbol(string(variable), "_", string(min_or_max)))
end
end
for v in positivity_variables_cons_
Expand Down Expand Up @@ -203,8 +203,8 @@ function Base.show(io::IO, ::MIME"text/plain", limiter::SubcellLimiterIDP)
]
end
if local_onesided
for (variable, operator) in limiter.local_onesided_variables_nonlinear
setup = [setup..., "" => "Local $operator limiting for $variable"]
for (variable, min_or_max) in limiter.local_onesided_variables_nonlinear
setup = [setup..., "" => "Local $min_or_max limiting for $variable"]
end
end
setup = [
Expand Down
50 changes: 25 additions & 25 deletions src/solvers/dgsem_tree/subcell_limiters_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ end
return nothing
end

@inline function calc_bounds_onesided!(var_minmax, minmax, variable, u, t, semi)
@inline function calc_bounds_onesided!(var_minmax, min_or_max, variable, u, t, semi)
mesh, equations, dg, cache = mesh_equations_solver_cache(semi)
# Calc bounds inside elements
@threaded for element in eachelement(dg, cache)
# Reset bounds
for j in eachnode(dg), i in eachnode(dg)
if minmax === max
if min_or_max === max
var_minmax[i, j, element] = typemin(eltype(var_minmax))
else
var_minmax[i, j, element] = typemax(eltype(var_minmax))
Expand All @@ -191,32 +191,32 @@ end
# Calculate bounds at Gauss-Lobatto nodes using u
for j in eachnode(dg), i in eachnode(dg)
var = variable(get_node_vars(u, equations, dg, i, j, element), equations)
var_minmax[i, j, element] = minmax(var_minmax[i, j, element], var)
var_minmax[i, j, element] = min_or_max(var_minmax[i, j, element], var)

if i > 1
var_minmax[i - 1, j, element] = minmax(var_minmax[i - 1, j, element],
var)
var_minmax[i - 1, j, element] = min_or_max(var_minmax[i - 1, j, element],
var)
end
if i < nnodes(dg)
var_minmax[i + 1, j, element] = minmax(var_minmax[i + 1, j, element],
var)
var_minmax[i + 1, j, element] = min_or_max(var_minmax[i + 1, j, element],
var)
end
if j > 1
var_minmax[i, j - 1, element] = minmax(var_minmax[i, j - 1, element],
var)
var_minmax[i, j - 1, element] = min_or_max(var_minmax[i, j - 1, element],
var)
end
if j < nnodes(dg)
var_minmax[i, j + 1, element] = minmax(var_minmax[i, j + 1, element],
var)
var_minmax[i, j + 1, element] = min_or_max(var_minmax[i, j + 1, element],
var)
end
end
end

# Values at element boundary
calc_bounds_onesided_interface!(var_minmax, minmax, variable, u, t, semi, mesh)
calc_bounds_onesided_interface!(var_minmax, min_or_max, variable, u, t, semi, mesh)
end

@inline function calc_bounds_onesided_interface!(var_minmax, minmax, variable, u, t,
@inline function calc_bounds_onesided_interface!(var_minmax, min_or_max, variable, u, t,
semi, mesh::TreeMesh2D)
_, equations, dg, cache = mesh_equations_solver_cache(semi)
(; boundary_conditions) = semi
Expand All @@ -240,10 +240,10 @@ end
var_right = variable(get_node_vars(u, equations, dg, index_right..., right),
equations)

var_minmax[index_right..., right] = minmax(var_minmax[index_right...,
right], var_left)
var_minmax[index_left..., left] = minmax(var_minmax[index_left..., left],
var_right)
var_minmax[index_right..., right] = min_or_max(var_minmax[index_right...,
right], var_left)
var_minmax[index_left..., left] = min_or_max(var_minmax[index_left..., left],
var_right)
end
end

Expand All @@ -270,16 +270,16 @@ end
index..., element)
var_outer = variable(u_outer, equations)

var_minmax[index..., element] = minmax(var_minmax[index..., element],
var_outer)
var_minmax[index..., element] = min_or_max(var_minmax[index..., element],
var_outer)
end
end

return nothing
end

###############################################################################
# Local two-sided limiting for conservative variables
# Local two-sided limiting of conservative variables

@inline function idp_local_twosided!(alpha, limiter, u, t, dt, semi)
for variable in limiter.local_twosided_variables_cons
Expand Down Expand Up @@ -354,19 +354,19 @@ end
# Local one-sided limiting of nonlinear variables

@inline function idp_local_onesided!(alpha, limiter, u, t, dt, semi)
for (variable, operator) in limiter.local_onesided_variables_nonlinear
idp_local_onesided!(alpha, limiter, u, t, dt, semi, variable, operator)
for (variable, min_or_max) in limiter.local_onesided_variables_nonlinear
idp_local_onesided!(alpha, limiter, u, t, dt, semi, variable, min_or_max)
end

return nothing
end

@inline function idp_local_onesided!(alpha, limiter, u, t, dt, semi, variable::F,
minmax) where {F}
min_or_max) where {F}
_, equations, dg, cache = mesh_equations_solver_cache(semi)
(; variable_bounds) = limiter.cache.subcell_limiter_coefficients
var_minmax = variable_bounds[Symbol(string(variable), "_", string(minmax))]
calc_bounds_onesided!(var_minmax, minmax, variable, u, t, semi)
var_minmax = variable_bounds[Symbol(string(variable), "_", string(min_or_max))]
calc_bounds_onesided!(var_minmax, min_or_max, variable, u, t, semi)

# Perform Newton's bisection method to find new alpha
@threaded for element in eachelement(dg, cache)
Expand Down

0 comments on commit 967e5bd

Please sign in to comment.