Skip to content

Commit

Permalink
Pass variable as strings instead of indices
Browse files Browse the repository at this point in the history
  • Loading branch information
bennibolm committed Nov 7, 2023
1 parent 7604822 commit f6836b0
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ volume_flux = flux_ranocha
polydeg = 3
basis = LobattoLegendreBasis(polydeg)
limiter_idp = SubcellLimiterIDP(equations, basis;
positivity_variables_cons = [1],
positivity_variables_nonlinear = (pressure,),
positivity_variables_cons = ["rho"],
positivity_variables_nonlinear = [pressure],
positivity_correction_factor = 0.1,
spec_entropy = false,
max_iterations_newton = 10,
Expand Down
2 changes: 1 addition & 1 deletion examples/structured_2d_dgsem/elixir_euler_double_mach.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ polydeg = 4
basis = LobattoLegendreBasis(polydeg)

limiter_idp = SubcellLimiterIDP(equations, basis;
local_minmax_variables_cons = [1],
local_minmax_variables_cons = ["rho"],
spec_entropy = true,
positivity_correction_factor = 0.1,
max_iterations_newton = 100,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ volume_flux = flux_ranocha
polydeg = 3
basis = LobattoLegendreBasis(polydeg)
limiter_idp = SubcellLimiterIDP(equations, basis;
positivity_variables_cons = [1],
positivity_variables_nonlinear = (pressure,),
positivity_variables_cons = ["rho"],
positivity_variables_nonlinear = [pressure],
positivity_correction_factor = 0.1,
spec_entropy = false,
smoothness_indicator = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ polydeg = 5
basis = LobattoLegendreBasis(polydeg)

limiter_idp = SubcellLimiterIDP(equations, basis;
local_minmax_variables_cons = [1],
local_minmax_variables_cons = ["rho"],
spec_entropy = true,
max_iterations_newton = 100,
bar_states = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ volume_flux = flux_ranocha
polydeg = 3
basis = LobattoLegendreBasis(polydeg)
limiter_idp = SubcellLimiterIDP(equations, basis;
local_minmax_variables_cons = [1],
local_minmax_variables_cons = ["rho"],
spec_entropy = true,
bar_states = false)
volume_integral = VolumeIntegralSubcellLimiting(limiter_idp;
Expand Down
2 changes: 1 addition & 1 deletion examples/tree_2d_dgsem/elixir_euler_astro_jet_subcell.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ basis = LobattoLegendreBasis(polydeg)

# shock capturing necessary for this tough example
limiter_idp = SubcellLimiterIDP(equations, basis;
local_minmax_variables_cons = [1],
local_minmax_variables_cons = ["rho"],
spec_entropy = true,
bar_states = true,
max_iterations_newton = 25)
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;
local_minmax_variables_cons = [1],
local_minmax_variables_cons = ["rho"],
math_entropy = true,
bar_states = false,
smoothness_indicator = true)
Expand Down
4 changes: 2 additions & 2 deletions examples/tree_2d_dgsem/elixir_euler_convergence_IDP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ volume_flux = flux_ranocha
polydeg = 3
basis = LobattoLegendreBasis(polydeg)
limiter_idp = SubcellLimiterIDP(equations, basis;
positivity_variables_cons = [1],
positivity_variables_nonlinear = (pressure,),
positivity_variables_cons = ["rho"],
positivity_variables_nonlinear = [pressure],
positivity_correction_factor = 0.1,
spec_entropy = false,
max_iterations_newton = 10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ polydeg = 3
basis = LobattoLegendreBasis(polydeg)

limiter_idp = SubcellLimiterIDP(equations, basis;
positivity_variables_cons = [1],
positivity_variables_nonlinear = (pressure,),
positivity_variables_cons = ["rho"],
positivity_variables_nonlinear = [pressure],
spec_entropy = false,
bar_states = true)
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 = [1],
local_minmax_variables_cons = ["rho"],
spec_entropy = true,
smoothness_indicator = false,
bar_states = true)
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,
bar_states = false)
volume_integral = VolumeIntegralSubcellLimiting(limiter_idp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ volume_flux = flux_ranocha
polydeg = 3
basis = LobattoLegendreBasis(polydeg)
limiter_idp = SubcellLimiterIDP(equations, basis;
local_minmax_variables_cons = [1],
positivity_variables_cons = [1],
positivity_variables_nonlinear = (pressure,),
local_minmax_variables_cons = ["rho"],
positivity_variables_cons = ["rho"],
positivity_variables_nonlinear = [pressure],
bar_states = true,
smoothness_indicator = true)
volume_integral = VolumeIntegralSubcellLimiting(limiter_idp;
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))...,
],
spec_entropy = false,
bar_states = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ 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))...,
],
positivity_variables_nonlinear = (),
positivity_variables_nonlinear = [],
positivity_correction_factor = 0.1,
spec_entropy = false,
bar_states = false)
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_variables_nonlinear = [pressure],
positivity_correction_factor = 0.1,
bar_states = false)
Expand Down
40 changes: 31 additions & 9 deletions src/solvers/dgsem_tree/subcell_limiters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ end
SubcellLimiterIDP(equations::AbstractEquations, basis;
local_minmax_variables_cons = [],
positivity_variables_cons = [],
positivity_variables_nonlinear = (),
positivity_variables_nonlinear = [],
positivity_correction_factor = 0.1,
spec_entropy = false,
math_entropy = false,
Expand All @@ -40,6 +40,10 @@ including:
- positivity limiting for conservative (`positivity_variables_cons`) and non-linear variables (`positivity_variables_nonlinear`)
- one-sided limiting for specific and mathematical entropy (`spec_entropy`, `math_entropy`)
Conservative variables to be limited are passed as a strings, e.g. `local_minmax_variables_cons = ["rho"]`
and `positivity_variables_nonlinear = ["rho"]`. For the non-linear variables the specific function is
passed, e.g. `positivity_variables_nonlinear = [pressure]`.
The bounds can be calculated using the `bar_states` or the low-order FV solution. The positivity
limiter uses `positivity_correction_factor` such that `u^new >= positivity_correction_factor * u^FV`.
The Newton-bisection method for the limiting of non-linear variables uses maximal `max_iterations_newton`
Expand Down Expand Up @@ -90,7 +94,7 @@ end
function SubcellLimiterIDP(equations::AbstractEquations, basis;
local_minmax_variables_cons = [],
positivity_variables_cons = [],
positivity_variables_nonlinear = (),
positivity_variables_nonlinear = [],
positivity_correction_factor = 0.1,
spec_entropy = false,
math_entropy = false,
Expand All @@ -108,9 +112,19 @@ function SubcellLimiterIDP(equations::AbstractEquations, basis;
error("Only one of the two can be selected: math_entropy/spec_entropy")
end

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"))
Expand All @@ -122,8 +136,8 @@ function SubcellLimiterIDP(equations::AbstractEquations, basis;
if math_entropy
bound_keys = (bound_keys..., :math_entropy_max)
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
Expand All @@ -143,13 +157,12 @@ function SubcellLimiterIDP(equations::AbstractEquations, basis;
SubcellLimiterIDP{typeof(positivity_correction_factor),
typeof(positivity_variables_nonlinear),
typeof(cache), typeof(IndicatorHG)}(local_minmax,
local_minmax_variables_cons,
local_minmax_variables_cons_,
positivity,
positivity_variables_cons,
positivity_variables_cons_,
positivity_variables_nonlinear,
positivity_correction_factor,
spec_entropy,
math_entropy,
spec_entropy, math_entropy,
bar_states,
cache,
max_iterations_newton,
Expand Down Expand Up @@ -236,6 +249,15 @@ 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

"""
SubcellLimiterMCL(equations::AbstractEquations, basis;
DensityLimiter = true,
Expand Down

0 comments on commit f6836b0

Please sign in to comment.