From 5e81530998d642f6053159765f3f99f0fb449867 Mon Sep 17 00:00:00 2001 From: bennibolm Date: Wed, 8 Nov 2023 12:42:29 +0100 Subject: [PATCH] Implement suggestions --- ...ck_bubble_shockcapturing_subcell_minmax.jl | 5 ++- ...ubble_shockcapturing_subcell_positivity.jl | 5 ++- src/equations/equations.jl | 24 ++++++++++--- src/solvers/dgsem_tree/subcell_limiters.jl | 35 ++++++------------- 4 files changed, 34 insertions(+), 35 deletions(-) diff --git a/examples/tree_2d_dgsem/elixir_eulermulti_shock_bubble_shockcapturing_subcell_minmax.jl b/examples/tree_2d_dgsem/elixir_eulermulti_shock_bubble_shockcapturing_subcell_minmax.jl index 9c8754ab4d..3159a2066a 100644 --- a/examples/tree_2d_dgsem/elixir_eulermulti_shock_bubble_shockcapturing_subcell_minmax.jl +++ b/examples/tree_2d_dgsem/elixir_eulermulti_shock_bubble_shockcapturing_subcell_minmax.jl @@ -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) diff --git a/examples/tree_2d_dgsem/elixir_eulermulti_shock_bubble_shockcapturing_subcell_positivity.jl b/examples/tree_2d_dgsem/elixir_eulermulti_shock_bubble_shockcapturing_subcell_positivity.jl index 6e321ca5e9..7856c9bafb 100644 --- a/examples/tree_2d_dgsem/elixir_eulermulti_shock_bubble_shockcapturing_subcell_positivity.jl +++ b/examples/tree_2d_dgsem/elixir_eulermulti_shock_bubble_shockcapturing_subcell_positivity.jl @@ -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, diff --git a/src/equations/equations.jl b/src/equations/equations.jl index 0e77b92e04..bccb7c4614 100644 --- a/src/equations/equations.jl +++ b/src/equations/equations.jl @@ -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. @@ -211,8 +227,8 @@ 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 @@ -220,8 +236,8 @@ 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 diff --git a/src/solvers/dgsem_tree/subcell_limiters.jl b/src/solvers/dgsem_tree/subcell_limiters.jl index 228acdac4a..055e7ce24a 100644 --- a/src/solvers/dgsem_tree/subcell_limiters.jl +++ b/src/solvers/dgsem_tree/subcell_limiters.jl @@ -14,8 +14,8 @@ 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) @@ -23,8 +23,8 @@ 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`. @@ -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 @@ -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