From 632993423c85b14f75a1b846052b2387aca1f6f7 Mon Sep 17 00:00:00 2001 From: bennibolm Date: Wed, 27 Sep 2023 10:38:02 +0200 Subject: [PATCH] Implement order of bounds as Dict --- src/solvers/dgsem_tree/containers_2d.jl | 8 ++++---- src/solvers/dgsem_tree/subcell_limiters.jl | 10 ++++++++-- src/solvers/dgsem_tree/subcell_limiters_2d.jl | 15 +++++++-------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/solvers/dgsem_tree/containers_2d.jl b/src/solvers/dgsem_tree/containers_2d.jl index 9148b936312..fb9599d257e 100644 --- a/src/solvers/dgsem_tree/containers_2d.jl +++ b/src/solvers/dgsem_tree/containers_2d.jl @@ -1334,7 +1334,7 @@ mutable struct ContainerSubcellLimiterIDP2D{uEltype <: Real} end function ContainerSubcellLimiterIDP2D{uEltype}(capacity::Integer, n_nodes, - length) where {uEltype <: Real} + number_bounds) where {uEltype <: Real} nan_uEltype = convert(uEltype, NaN) # Initialize fields with defaults @@ -1345,9 +1345,9 @@ function ContainerSubcellLimiterIDP2D{uEltype}(capacity::Integer, n_nodes, _alpha2 = fill(nan_uEltype, n_nodes * (n_nodes + 1) * capacity) alpha2 = unsafe_wrap(Array, pointer(_alpha2), (n_nodes, n_nodes + 1, capacity)) - _variable_bounds = Vector{Vector{uEltype}}(undef, length) - variable_bounds = Vector{Array{uEltype, 3}}(undef, length) - for i in 1:length + _variable_bounds = Vector{Vector{uEltype}}(undef, number_bounds) + variable_bounds = Vector{Array{uEltype, 3}}(undef, number_bounds) + for i in 1:number_bounds _variable_bounds[i] = fill(nan_uEltype, n_nodes * n_nodes * capacity) variable_bounds[i] = unsafe_wrap(Array, pointer(_variable_bounds[i]), (n_nodes, n_nodes, capacity)) diff --git a/src/solvers/dgsem_tree/subcell_limiters.jl b/src/solvers/dgsem_tree/subcell_limiters.jl index 3a707de3bc7..4928b22596f 100644 --- a/src/solvers/dgsem_tree/subcell_limiters.jl +++ b/src/solvers/dgsem_tree/subcell_limiters.jl @@ -52,9 +52,15 @@ function SubcellLimiterIDP(equations::AbstractEquations, basis; positivity_variables_cons = [], positivity_correction_factor = 0.1) positivity = (length(positivity_variables_cons) > 0) - number_bounds = length(positivity_variables_cons) - cache = create_cache(SubcellLimiterIDP, equations, basis, number_bounds) + bounds_order = Dict() + counter = 1 + for index in positivity_variables_cons + bounds_order = Dict(bounds_order..., "$(index)_min" => counter) + counter += 1 + end + + cache = create_cache(SubcellLimiterIDP, equations, basis, bounds_order) SubcellLimiterIDP{typeof(positivity_correction_factor), typeof(cache)}(positivity, positivity_variables_cons, diff --git a/src/solvers/dgsem_tree/subcell_limiters_2d.jl b/src/solvers/dgsem_tree/subcell_limiters_2d.jl index 09ab84ed11a..16dd3be3959 100644 --- a/src/solvers/dgsem_tree/subcell_limiters_2d.jl +++ b/src/solvers/dgsem_tree/subcell_limiters_2d.jl @@ -6,17 +6,14 @@ #! format: noindent # this method is used when the limiter is constructed as for shock-capturing volume integrals -function create_cache(indicator::Type{SubcellLimiterIDP}, - equations::AbstractEquations{2}, - basis::LobattoLegendreBasis, number_bounds) +function create_cache(limiter::Type{SubcellLimiterIDP}, equations::AbstractEquations{2}, + basis::LobattoLegendreBasis, bounds_order) subcell_limiter_coefficients = Trixi.ContainerSubcellLimiterIDP2D{real(basis) }(0, nnodes(basis), - number_bounds) + length(bounds_order)) - cache = (; subcell_limiter_coefficients) - - return cache + return (; subcell_limiter_coefficients, bounds_order) end function (limiter::SubcellLimiterIDP)(u::AbstractArray{<:Any, 4}, semi, dg::DGSEM, t, @@ -65,7 +62,9 @@ end @unpack variable_bounds = limiter.cache.subcell_limiter_coefficients - var_min = variable_bounds[index] + (; variable_bounds) = limiter.cache.subcell_limiter_coefficients + (; bounds_order) = limiter.cache + var_min = variable_bounds[bounds_order["$(variable)_min"]] @threaded for element in eachelement(dg, semi.cache) inverse_jacobian = cache.elements.inverse_jacobian[element]