Skip to content

Commit

Permalink
Implement suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
bennibolm committed Nov 8, 2023
1 parent fd3d531 commit 5e81530
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,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_minmax_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
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ volume_flux = flux_ranocha
basis = LobattoLegendreBasis(3)

limiter_idp = SubcellLimiterIDP(equations, basis;
positivity_variables_cons = [
("rho" * string(i) for i in eachcomponent(equations))...,
])
positivity_variables_cons = ["rho" * string(i)
for i in eachcomponent(equations)])

volume_integral = VolumeIntegralSubcellLimiting(limiter_idp;
volume_flux_dg = volume_flux,
Expand Down
24 changes: 20 additions & 4 deletions src/equations/equations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@ Common choices of the `conversion_function` are [`cons2cons`](@ref) and
"""
function varnames end

"""
get_variable_index(variable, equations, conversion_function = cons2cons)
Return the index of `variable` in `varnames(conversion_function, equations)` if available.
Otherwise, return an error.
"""
@inline function get_variable_index(variable, equations,
conversion_function = cons2cons)
index = findfirst(==(variable), varnames(conversion_function, equations))
if isnothing(index)
error("$variable is no valid variable.")
end

return index
end

# Add methods to show some information on systems of equations.
function Base.show(io::IO, equations::AbstractEquations)
# Since this is not performance-critical, we can use `@nospecialize` to reduce latency.
Expand Down Expand Up @@ -211,17 +227,17 @@ end
"""
NonConservativeLocal()
Struct used for multiple dispatch on non-conservative flux functions in the format of "local * symmetric".
When the argument `nonconservative_type` is of type `NonConservativeLocal`,
Struct used for multiple dispatch on non-conservative flux functions in the format of "local * symmetric".
When the argument `nonconservative_type` is of type `NonConservativeLocal`,
the function returns the local part of the non-conservative term.
"""
struct NonConservativeLocal end

"""
NonConservativeSymmetric()
Struct used for multiple dispatch on non-conservative flux functions in the format of "local * symmetric".
When the argument `nonconservative_type` is of type `NonConservativeSymmetric`,
Struct used for multiple dispatch on non-conservative flux functions in the format of "local * symmetric".
When the argument `nonconservative_type` is of type `NonConservativeSymmetric`,
the function returns the symmetric part of the non-conservative term.
"""
struct NonConservativeSymmetric end
Expand Down
35 changes: 10 additions & 25 deletions src/solvers/dgsem_tree/subcell_limiters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ end

"""
SubcellLimiterIDP(equations::AbstractEquations, basis;
local_minmax_variables_cons = [],
positivity_variables_cons = [],
local_minmax_variables_cons = String[],
positivity_variables_cons = String[],
positivity_correction_factor = 0.1)
Subcell invariant domain preserving (IDP) limiting used with [`VolumeIntegralSubcellLimiting`](@ref)
including:
- Local maximum/minimum Zalesak-type limiting for conservative variables (`local_minmax_variables_cons`)
- Positivity limiting for conservative variables (`positivity_variables_cons`)
Conservative variables to be limited are passed as a strings, e.g. `local_minmax_variables_cons = ["rho"]`
and `positivity_variables_nonlinear = ["rho"]`.
Conservative variables to be limited are passed as a vector of strings, e.g. `local_minmax_variables_cons = ["rho"]`
and `positivity_variables_cons = ["rho"]`.
The bounds are calculated using the low-order FV solution. The positivity limiter uses
`positivity_correction_factor` such that `u^new >= positivity_correction_factor * u^FV`.
Expand Down Expand Up @@ -56,22 +56,16 @@ 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 = [],
positivity_variables_cons = [],
local_minmax_variables_cons = String[],
positivity_variables_cons = String[],
positivity_correction_factor = 0.1)
local_minmax = (length(local_minmax_variables_cons) > 0)
positivity = (length(positivity_variables_cons) > 0)

variables = varnames(cons2cons, equations)
local_minmax_variables_cons_ = Vector{Int}(undef,
length(local_minmax_variables_cons))
positivity_variables_cons_ = Vector{Int}(undef, length(positivity_variables_cons))
for (i, variable) in enumerate(local_minmax_variables_cons)
local_minmax_variables_cons_[i] = get_variable_index(variable, variables)
end
for (i, variable) in enumerate(positivity_variables_cons)
positivity_variables_cons_[i] = get_variable_index(variable, variables)
end
local_minmax_variables_cons_ = get_variable_index.(local_minmax_variables_cons,
equations)
positivity_variables_cons_ = get_variable_index.(positivity_variables_cons,
equations)

bound_keys = ()
if local_minmax
Expand Down Expand Up @@ -152,13 +146,4 @@ function get_node_variables!(node_variables, limiter::SubcellLimiterIDP,

return nothing
end

@inline function get_variable_index(variable, variable_names)
for (i_, variable_) in enumerate(variable_names)
if variable == variable_
return i_
end
end
error("$variable is no valid variable.")
end
end # @muladd

0 comments on commit 5e81530

Please sign in to comment.