Skip to content

Commit

Permalink
Pass variables as strings instead of ints
Browse files Browse the repository at this point in the history
  • Loading branch information
bennibolm committed Nov 7, 2023
1 parent 953926a commit 3afa4c1
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 12 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 = [1])
local_minmax_variables_cons = ["rho"])
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 @@ -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 = [1])
local_minmax_variables_cons = ["rho"])
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 @@ -39,7 +39,7 @@ surface_flux = flux_lax_friedrichs
volume_flux = flux_ranocha
basis = LobattoLegendreBasis(3)
limiter_idp = SubcellLimiterIDP(equations, basis;
positivity_variables_cons = [1],
positivity_variables_cons = ["rho"],
positivity_correction_factor = 0.5)
volume_integral = VolumeIntegralSubcellLimiting(limiter_idp;
volume_flux_dg = volume_flux,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ basis = LobattoLegendreBasis(3)

limiter_idp = SubcellLimiterIDP(equations, basis;
local_minmax_variables_cons = [
(i + 3 for i in eachcomponent(equations))...,
("rho" * string(i) for i in eachcomponent(equations))...,
])
volume_integral = VolumeIntegralSubcellLimiting(limiter_idp;
volume_flux_dg = volume_flux,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ basis = LobattoLegendreBasis(3)

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

volume_integral = VolumeIntegralSubcellLimiting(limiter_idp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ volume_flux = (flux_derigs_etal, flux_nonconservative_powell_local_symmetric)
basis = LobattoLegendreBasis(3)

limiter_idp = SubcellLimiterIDP(equations, basis;
positivity_variables_cons = [1],
positivity_variables_cons = ["rho"],
positivity_correction_factor = 0.5)
volume_integral = VolumeIntegralSubcellLimiting(limiter_idp;
volume_flux_dg = volume_flux,
Expand Down
33 changes: 28 additions & 5 deletions src/solvers/dgsem_tree/subcell_limiters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ 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"]`.
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 @@ -59,25 +62,36 @@ function SubcellLimiterIDP(equations::AbstractEquations, basis;
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

bound_keys = ()
if local_minmax
for v in local_minmax_variables_cons
for v in local_minmax_variables_cons_
v_string = string(v)
bound_keys = (bound_keys..., Symbol(v_string, "_min"),
Symbol(v_string, "_max"))
end
end
for v in positivity_variables_cons
if !(v in local_minmax_variables_cons)
for v in positivity_variables_cons_
if !(v in local_minmax_variables_cons_)
bound_keys = (bound_keys..., Symbol(string(v), "_min"))
end
end

cache = create_cache(SubcellLimiterIDP, equations, basis, bound_keys)

SubcellLimiterIDP{typeof(positivity_correction_factor),
typeof(cache)}(local_minmax, local_minmax_variables_cons,
positivity, positivity_variables_cons,
typeof(cache)}(local_minmax, local_minmax_variables_cons_,
positivity, positivity_variables_cons_,
positivity_correction_factor, cache)
end

Expand Down Expand Up @@ -138,4 +152,13 @@ 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
2 changes: 1 addition & 1 deletion test/test_unit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ end
indicator_hg = IndicatorHennemannGassner(1.0, 0.0, true, "variable", "cache")
@test_nowarn show(stdout, indicator_hg)

limiter_idp = SubcellLimiterIDP(true, [1], true, [1], 0.1, "cache")
limiter_idp = SubcellLimiterIDP(true, ["rho"], true, ["rho"], 0.1, "cache")
@test_nowarn show(stdout, limiter_idp)

# TODO: TrixiShallowWater: move unit test
Expand Down

0 comments on commit 3afa4c1

Please sign in to comment.