Skip to content

Commit

Permalink
Implement variable_bounds directly as Dictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
bennibolm committed Sep 27, 2023
1 parent 6329934 commit bd4ede1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
27 changes: 14 additions & 13 deletions src/solvers/dgsem_tree/containers_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1325,16 +1325,16 @@ mutable struct ContainerSubcellLimiterIDP2D{uEltype <: Real}
alpha::Array{uEltype, 3} # [i, j, element]
alpha1::Array{uEltype, 3}
alpha2::Array{uEltype, 3}
variable_bounds::Vector{Array{uEltype, 3}}
variable_bounds::Dict{String, Array{uEltype, 3}}
# internal `resize!`able storage
_alpha::Vector{uEltype}
_alpha1::Vector{uEltype}
_alpha2::Vector{uEltype}
_variable_bounds::Vector{Vector{uEltype}}
_variable_bounds::Dict{String, Vector{uEltype}}
end

function ContainerSubcellLimiterIDP2D{uEltype}(capacity::Integer, n_nodes,
number_bounds) where {uEltype <: Real}
bound_keys) where {uEltype <: Real}
nan_uEltype = convert(uEltype, NaN)

# Initialize fields with defaults
Expand All @@ -1345,12 +1345,12 @@ 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, 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))
_variable_bounds = Dict{String, Vector{uEltype}}()
variable_bounds = Dict{String, Array{uEltype, 3}}()
for key in bound_keys
_variable_bounds[key] = fill(nan_uEltype, n_nodes * n_nodes * capacity)
variable_bounds[key] = unsafe_wrap(Array, pointer(_variable_bounds[key]),
(n_nodes, n_nodes, capacity))
end

return ContainerSubcellLimiterIDP2D{uEltype}(alpha, alpha1, alpha2,
Expand Down Expand Up @@ -1380,10 +1380,11 @@ function Base.resize!(container::ContainerSubcellLimiterIDP2D, capacity)
(n_nodes, n_nodes + 1, capacity))

@unpack _variable_bounds = container
for i in 1:length(_variable_bounds)
resize!(_variable_bounds[i], n_nodes * n_nodes * capacity)
container.variable_bounds[i] = unsafe_wrap(Array, pointer(_variable_bounds[i]),
(n_nodes, n_nodes, capacity))
for (key, _) in _variable_bounds
resize!(_variable_bounds[key], n_nodes * n_nodes * capacity)
container.variable_bounds[key] = unsafe_wrap(Array,
pointer(_variable_bounds[key]),
(n_nodes, n_nodes, capacity))
end

return nothing
Expand Down
9 changes: 2 additions & 7 deletions src/solvers/dgsem_tree/subcell_limiters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,9 @@ function SubcellLimiterIDP(equations::AbstractEquations, basis;
positivity_correction_factor = 0.1)
positivity = (length(positivity_variables_cons) > 0)

bounds_order = Dict()
counter = 1
for index in positivity_variables_cons
bounds_order = Dict(bounds_order..., "$(index)_min" => counter)
counter += 1
end
bound_keys = Tuple("$(i)_min" for i in positivity_variables_cons)

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

SubcellLimiterIDP{typeof(positivity_correction_factor), typeof(cache)}(positivity,
positivity_variables_cons,
Expand Down
9 changes: 4 additions & 5 deletions src/solvers/dgsem_tree/subcell_limiters_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

# this method is used when the limiter is constructed as for shock-capturing volume integrals
function create_cache(limiter::Type{SubcellLimiterIDP}, equations::AbstractEquations{2},
basis::LobattoLegendreBasis, bounds_order)
basis::LobattoLegendreBasis, bound_keys)
subcell_limiter_coefficients = Trixi.ContainerSubcellLimiterIDP2D{real(basis)
}(0,
nnodes(basis),
length(bounds_order))
bound_keys)

return (; subcell_limiter_coefficients, bounds_order)
return (; subcell_limiter_coefficients)
end

function (limiter::SubcellLimiterIDP)(u::AbstractArray{<:Any, 4}, semi, dg::DGSEM, t,
Expand Down Expand Up @@ -63,8 +63,7 @@ end
@unpack variable_bounds = limiter.cache.subcell_limiter_coefficients

(; variable_bounds) = limiter.cache.subcell_limiter_coefficients
(; bounds_order) = limiter.cache
var_min = variable_bounds[bounds_order["$(variable)_min"]]
var_min = variable_bounds["$(variable)_min"]

@threaded for element in eachelement(dg, semi.cache)
inverse_jacobian = cache.elements.inverse_jacobian[element]
Expand Down

0 comments on commit bd4ede1

Please sign in to comment.