From f6836b05c8c16945e4e7f4d2491a29aaee74ccd6 Mon Sep 17 00:00:00 2001 From: bennibolm Date: Tue, 7 Nov 2023 16:23:30 +0100 Subject: [PATCH] Pass variable as strings instead of indices --- ...elixir_euler_convergence_wavingflag_IDP.jl | 4 +- .../elixir_euler_double_mach.jl | 2 +- .../elixir_euler_free_stream_sc_subcell.jl | 4 +- .../elixir_euler_shock_upstream_sc_subcell.jl | 2 +- .../elixir_euler_source_terms_sc_subcell.jl | 2 +- .../elixir_euler_astro_jet_subcell.jl | 2 +- .../elixir_euler_blast_wave_sc_subcell.jl | 2 +- .../elixir_euler_convergence_IDP.jl | 4 +- ...kelvin_helmholtz_instability_sc_subcell.jl | 4 +- ...lixir_euler_sedov_blast_wave_sc_subcell.jl | 2 +- .../elixir_euler_shockcapturing_subcell.jl | 2 +- .../elixir_euler_source_terms_sc_subcell.jl | 6 +-- ...ck_bubble_shockcapturing_subcell_minmax.jl | 2 +- ...ubble_shockcapturing_subcell_positivity.jl | 4 +- .../elixir_mhd_shockcapturing_subcell.jl | 2 +- src/solvers/dgsem_tree/subcell_limiters.jl | 40 ++++++++++++++----- 16 files changed, 53 insertions(+), 31 deletions(-) diff --git a/examples/structured_2d_dgsem/elixir_euler_convergence_wavingflag_IDP.jl b/examples/structured_2d_dgsem/elixir_euler_convergence_wavingflag_IDP.jl index 57c2d2a780..e7435e4712 100644 --- a/examples/structured_2d_dgsem/elixir_euler_convergence_wavingflag_IDP.jl +++ b/examples/structured_2d_dgsem/elixir_euler_convergence_wavingflag_IDP.jl @@ -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, diff --git a/examples/structured_2d_dgsem/elixir_euler_double_mach.jl b/examples/structured_2d_dgsem/elixir_euler_double_mach.jl index d306b70cb7..c855f448fd 100644 --- a/examples/structured_2d_dgsem/elixir_euler_double_mach.jl +++ b/examples/structured_2d_dgsem/elixir_euler_double_mach.jl @@ -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, diff --git a/examples/structured_2d_dgsem/elixir_euler_free_stream_sc_subcell.jl b/examples/structured_2d_dgsem/elixir_euler_free_stream_sc_subcell.jl index 639fb92875..6f81e38574 100644 --- a/examples/structured_2d_dgsem/elixir_euler_free_stream_sc_subcell.jl +++ b/examples/structured_2d_dgsem/elixir_euler_free_stream_sc_subcell.jl @@ -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, diff --git a/examples/structured_2d_dgsem/elixir_euler_shock_upstream_sc_subcell.jl b/examples/structured_2d_dgsem/elixir_euler_shock_upstream_sc_subcell.jl index def69ecc28..303cfa71de 100644 --- a/examples/structured_2d_dgsem/elixir_euler_shock_upstream_sc_subcell.jl +++ b/examples/structured_2d_dgsem/elixir_euler_shock_upstream_sc_subcell.jl @@ -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) diff --git a/examples/structured_2d_dgsem/elixir_euler_source_terms_sc_subcell.jl b/examples/structured_2d_dgsem/elixir_euler_source_terms_sc_subcell.jl index 53c07261c3..1f88427d3e 100644 --- a/examples/structured_2d_dgsem/elixir_euler_source_terms_sc_subcell.jl +++ b/examples/structured_2d_dgsem/elixir_euler_source_terms_sc_subcell.jl @@ -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; diff --git a/examples/tree_2d_dgsem/elixir_euler_astro_jet_subcell.jl b/examples/tree_2d_dgsem/elixir_euler_astro_jet_subcell.jl index 3bf4f230d4..47988bfef0 100644 --- a/examples/tree_2d_dgsem/elixir_euler_astro_jet_subcell.jl +++ b/examples/tree_2d_dgsem/elixir_euler_astro_jet_subcell.jl @@ -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) diff --git a/examples/tree_2d_dgsem/elixir_euler_blast_wave_sc_subcell.jl b/examples/tree_2d_dgsem/elixir_euler_blast_wave_sc_subcell.jl index fab3a86e53..2307a6d139 100644 --- a/examples/tree_2d_dgsem/elixir_euler_blast_wave_sc_subcell.jl +++ b/examples/tree_2d_dgsem/elixir_euler_blast_wave_sc_subcell.jl @@ -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) diff --git a/examples/tree_2d_dgsem/elixir_euler_convergence_IDP.jl b/examples/tree_2d_dgsem/elixir_euler_convergence_IDP.jl index eccf13c6d2..66d6e77629 100644 --- a/examples/tree_2d_dgsem/elixir_euler_convergence_IDP.jl +++ b/examples/tree_2d_dgsem/elixir_euler_convergence_IDP.jl @@ -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, diff --git a/examples/tree_2d_dgsem/elixir_euler_kelvin_helmholtz_instability_sc_subcell.jl b/examples/tree_2d_dgsem/elixir_euler_kelvin_helmholtz_instability_sc_subcell.jl index 8f07b7ca92..5f482668cb 100644 --- a/examples/tree_2d_dgsem/elixir_euler_kelvin_helmholtz_instability_sc_subcell.jl +++ b/examples/tree_2d_dgsem/elixir_euler_kelvin_helmholtz_instability_sc_subcell.jl @@ -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; diff --git a/examples/tree_2d_dgsem/elixir_euler_sedov_blast_wave_sc_subcell.jl b/examples/tree_2d_dgsem/elixir_euler_sedov_blast_wave_sc_subcell.jl index b460b7a507..1848c71b6e 100644 --- a/examples/tree_2d_dgsem/elixir_euler_sedov_blast_wave_sc_subcell.jl +++ b/examples/tree_2d_dgsem/elixir_euler_sedov_blast_wave_sc_subcell.jl @@ -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) diff --git a/examples/tree_2d_dgsem/elixir_euler_shockcapturing_subcell.jl b/examples/tree_2d_dgsem/elixir_euler_shockcapturing_subcell.jl index d8fce68592..0335597960 100644 --- a/examples/tree_2d_dgsem/elixir_euler_shockcapturing_subcell.jl +++ b/examples/tree_2d_dgsem/elixir_euler_shockcapturing_subcell.jl @@ -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; diff --git a/examples/tree_2d_dgsem/elixir_euler_source_terms_sc_subcell.jl b/examples/tree_2d_dgsem/elixir_euler_source_terms_sc_subcell.jl index 6d5281fcbc..5d9a90003d 100644 --- a/examples/tree_2d_dgsem/elixir_euler_source_terms_sc_subcell.jl +++ b/examples/tree_2d_dgsem/elixir_euler_source_terms_sc_subcell.jl @@ -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; 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 4a8a70b566..22e111c5a9 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 @@ -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) 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 5f6cdb1e9c..03670c4c6a 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 @@ -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) diff --git a/examples/tree_2d_dgsem/elixir_mhd_shockcapturing_subcell.jl b/examples/tree_2d_dgsem/elixir_mhd_shockcapturing_subcell.jl index 84361ef4f8..e1f60f7225 100644 --- a/examples/tree_2d_dgsem/elixir_mhd_shockcapturing_subcell.jl +++ b/examples/tree_2d_dgsem/elixir_mhd_shockcapturing_subcell.jl @@ -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) diff --git a/src/solvers/dgsem_tree/subcell_limiters.jl b/src/solvers/dgsem_tree/subcell_limiters.jl index 6a10f92b89..303f56950f 100644 --- a/src/solvers/dgsem_tree/subcell_limiters.jl +++ b/src/solvers/dgsem_tree/subcell_limiters.jl @@ -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, @@ -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` @@ -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, @@ -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")) @@ -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 @@ -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, @@ -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,