Skip to content

Commit

Permalink
Rename Limiters and Containers
Browse files Browse the repository at this point in the history
  • Loading branch information
bennibolm committed Jul 5, 2023
1 parent 9d6d6f5 commit 7cb8597
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 91 deletions.
8 changes: 4 additions & 4 deletions examples/tree_2d_dgsem/elixir_euler_shockcapturing_subcell.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ initial_condition = initial_condition_blast_wave
surface_flux = flux_lax_friedrichs
volume_flux = flux_ranocha
basis = LobattoLegendreBasis(3)
indicator_sc = IndicatorIDP(equations, basis;
positivity_variables_cons=[1],
positivity_correction_factor=0.5)
volume_integral = VolumeIntegralSubcellLimiting(indicator_sc;
limiter_idp = SubcellLimiterIDP(equations, basis;
positivity_variables_cons=[1],
positivity_correction_factor=0.5)
volume_integral = VolumeIntegralSubcellLimiting(limiter_idp;
volume_flux_dg=volume_flux,
volume_flux_fv=surface_flux)
solver = DGSEM(basis, surface_flux, volume_integral)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,12 @@ surface_flux = flux_lax_friedrichs
volume_flux = flux_ranocha
basis = LobattoLegendreBasis(3)

indicator_sc = IndicatorIDP(equations, basis;
positivity_variables_cons=[(i+3 for i in eachcomponent(equations))...])
limiter_idp = SubcellLimiterIDP(equations, basis;
positivity_variables_cons=[(i+3 for i in eachcomponent(equations))...])

volume_integral=VolumeIntegralSubcellLimiting(indicator_sc; volume_flux_dg=volume_flux,
volume_flux_fv=surface_flux)
volume_integral = VolumeIntegralSubcellLimiting(limiter_idp;
volume_flux_dg=volume_flux,
volume_flux_fv=surface_flux)

solver = DGSEM(basis, surface_flux, volume_integral)

Expand Down
2 changes: 1 addition & 1 deletion src/Trixi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export DG,
VolumeIntegralFluxDifferencing,
VolumeIntegralPureLGLFiniteVolume,
VolumeIntegralShockCapturingHG, IndicatorHennemannGassner,
VolumeIntegralSubcellLimiting, IndicatorIDP,
VolumeIntegralSubcellLimiting, SubcellLimiterIDP,
VolumeIntegralUpwind,
SurfaceIntegralWeakForm, SurfaceIntegralStrongForm,
SurfaceIntegralUpwind,
Expand Down
12 changes: 6 additions & 6 deletions src/callbacks_stage/a_posteriori_limiter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
APosterioriLimiter()
Perform antidiffusive stage for the a posteriori IDP limiter called with
[`VolumeIntegralSubcellLimiting`](@ref) using [`IndicatorIDP`](@ref).
[`VolumeIntegralSubcellLimiting`](@ref) using [`SubcellLimiterIDP`](@ref).
!!! warning "Experimental implementation"
This is an experimental feature and may change in future releases.
Expand All @@ -34,20 +34,20 @@ end
function (limiter!::APosterioriLimiter)(u_ode, semi, t, dt,
volume_integral::VolumeIntegralSubcellLimiting)
@trixi_timeit timer() "a posteriori limiter" limiter!(u_ode, semi, t, dt,
volume_integral.indicator)
volume_integral.limiter)
end

function (limiter!::APosterioriLimiter)(u_ode, semi, t, dt, indicator::IndicatorIDP)
function (limiter!::APosterioriLimiter)(u_ode, semi, t, dt, limiter::SubcellLimiterIDP)
mesh, equations, solver, cache = mesh_equations_solver_cache(semi)

u = wrap_array(u_ode, mesh, equations, solver, cache)

# Calculate blending factor alpha in [0,1]
# f_ij = alpha_ij * f^(FV)_ij + (1 - alpha_ij) * f^(DG)_ij
# = f^(FV)_ij + (1 - alpha_ij) * f^(antidiffusive)_ij
@trixi_timeit timer() "blending factors" solver.volume_integral.indicator(u, semi,
solver, t,
dt)
@trixi_timeit timer() "blending factors" solver.volume_integral.limiter(u, semi,
solver, t,
dt)

perform_idp_correction!(u, dt, mesh, equations, solver, cache)

Expand Down
2 changes: 1 addition & 1 deletion src/callbacks_stage/a_posteriori_limiter_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@inline function perform_idp_correction!(u, dt, mesh::TreeMesh2D, equations, dg, cache)
@unpack inverse_weights = dg.basis
@unpack antidiffusive_flux1, antidiffusive_flux2 = cache.container_antidiffusive_flux
@unpack alpha1, alpha2 = dg.volume_integral.indicator.cache.container_shock_capturing
@unpack alpha1, alpha2 = dg.volume_integral.limiter.cache.container_subcell_limiter

@threaded for element in eachelement(dg, cache)
# Sign switch as in apply_jacobian!
Expand Down
18 changes: 9 additions & 9 deletions src/solvers/dg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,27 +175,27 @@ function Base.show(io::IO, ::MIME"text/plain",
end

"""
VolumeIntegralSubcellLimiting(indicator;
VolumeIntegralSubcellLimiting(limiter;
volume_flux_dg, volume_flux_fv)
A subcell limiting volume integral type for DG methods based on subcell blending approaches
with a low-order FV method. Used with indicator [`IndicatorIDP`](@ref).
with a low-order FV method. Used with limiter [`SubcellLimiterIDP`](@ref).
!!! warning "Experimental implementation"
This is an experimental feature and may change in future releases.
"""
struct VolumeIntegralSubcellLimiting{VolumeFluxDG, VolumeFluxFV, Indicator} <:
struct VolumeIntegralSubcellLimiting{VolumeFluxDG, VolumeFluxFV, Limiter} <:
AbstractVolumeIntegral
volume_flux_dg::VolumeFluxDG
volume_flux_fv::VolumeFluxFV
indicator::Indicator
limiter::Limiter
end

function VolumeIntegralSubcellLimiting(indicator; volume_flux_dg,
function VolumeIntegralSubcellLimiting(limiter; volume_flux_dg,
volume_flux_fv)
VolumeIntegralSubcellLimiting{typeof(volume_flux_dg), typeof(volume_flux_fv),
typeof(indicator)}(volume_flux_dg, volume_flux_fv,
indicator)
typeof(limiter)}(volume_flux_dg, volume_flux_fv,
limiter)
end

function Base.show(io::IO, mime::MIME"text/plain",
Expand All @@ -208,8 +208,8 @@ function Base.show(io::IO, mime::MIME"text/plain",
summary_header(io, "VolumeIntegralSubcellLimiting")
summary_line(io, "volume flux DG", integral.volume_flux_dg)
summary_line(io, "volume flux FV", integral.volume_flux_fv)
summary_line(io, "indicator", integral.indicator |> typeof |> nameof)
show(increment_indent(io), mime, integral.indicator)
summary_line(io, "limiter", integral.limiter |> typeof |> nameof)
show(increment_indent(io), mime, integral.limiter)
summary_footer(io)
end
end
Expand Down
32 changes: 16 additions & 16 deletions src/solvers/dgsem_tree/containers_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ function Base.resize!(fluxes::ContainerAntidiffusiveFlux2D, capacity)
end

# Container data structure (structure-of-arrays style) for variables used for IDP limiting
mutable struct ContainerShockCapturingIndicatorIDP2D{uEltype <: Real}
mutable struct ContainerSubcellLimiterIDP2D{uEltype <: Real}
alpha::Array{uEltype, 3} # [i, j, element]
alpha1::Array{uEltype, 3}
alpha2::Array{uEltype, 3}
Expand All @@ -1333,8 +1333,8 @@ mutable struct ContainerShockCapturingIndicatorIDP2D{uEltype <: Real}
_variable_bounds::Vector{Vector{uEltype}}
end

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

# Initialize fields with defaults
Expand All @@ -1353,36 +1353,36 @@ function ContainerShockCapturingIndicatorIDP2D{uEltype}(capacity::Integer, n_nod
(n_nodes, n_nodes, capacity))
end

return ContainerShockCapturingIndicatorIDP2D{uEltype}(alpha, alpha1, alpha2,
variable_bounds,
_alpha, _alpha1, _alpha2,
_variable_bounds)
return ContainerSubcellLimiterIDP2D{uEltype}(alpha, alpha1, alpha2,
variable_bounds,
_alpha, _alpha1, _alpha2,
_variable_bounds)
end

nnodes(indicator::ContainerShockCapturingIndicatorIDP2D) = size(indicator.alpha, 1)
nnodes(container::ContainerSubcellLimiterIDP2D) = size(container.alpha, 1)

# Only one-dimensional `Array`s are `resize!`able in Julia.
# Hence, we use `Vector`s as internal storage and `resize!`
# them whenever needed. Then, we reuse the same memory by
# `unsafe_wrap`ping multi-dimensional `Array`s around the
# internal storage.
function Base.resize!(indicator::ContainerShockCapturingIndicatorIDP2D, capacity)
n_nodes = nnodes(indicator)
function Base.resize!(container::ContainerSubcellLimiterIDP2D, capacity)
n_nodes = nnodes(container)

@unpack _alpha, _alpha1, _alpha2 = indicator
@unpack _alpha, _alpha1, _alpha2 = container
resize!(_alpha, n_nodes * n_nodes * capacity)
indicator.alpha = unsafe_wrap(Array, pointer(_alpha), (n_nodes, n_nodes, capacity))
container.alpha = unsafe_wrap(Array, pointer(_alpha), (n_nodes, n_nodes, capacity))
resize!(_alpha1, (n_nodes + 1) * n_nodes * capacity)
indicator.alpha1 = unsafe_wrap(Array, pointer(_alpha1),
container.alpha1 = unsafe_wrap(Array, pointer(_alpha1),
(n_nodes + 1, n_nodes, capacity))
resize!(_alpha2, n_nodes * (n_nodes + 1) * capacity)
indicator.alpha2 = unsafe_wrap(Array, pointer(_alpha2),
container.alpha2 = unsafe_wrap(Array, pointer(_alpha2),
(n_nodes, n_nodes + 1, capacity))

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

Expand Down
10 changes: 5 additions & 5 deletions src/solvers/dgsem_tree/dg_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -556,20 +556,20 @@ function calc_volume_integral!(du, u,
nonconservative_terms, equations,
volume_integral::VolumeIntegralSubcellLimiting,
dg::DGSEM, cache)
@unpack indicator = volume_integral
@unpack limiter = volume_integral

@threaded for element in eachelement(dg, cache)
subcell_limiting_kernel!(du, u, element, mesh,
nonconservative_terms, equations,
volume_integral, indicator,
volume_integral, limiter,
dg, cache)
end
end

@inline function subcell_limiting_kernel!(du, u,
element, mesh::TreeMesh{2},
nonconservative_terms::False, equations,
volume_integral, indicator::IndicatorIDP,
volume_integral, limiter::SubcellLimiterIDP,
dg::DGSEM, cache)
@unpack inverse_weights = dg.basis
@unpack volume_flux_dg, volume_flux_fv = volume_integral
Expand All @@ -594,7 +594,7 @@ end

# antidiffusive flux
calcflux_antidiffusive!(fhat1, fhat2, fstar1_L, fstar2_L, u, mesh,
nonconservative_terms, equations, indicator, dg, element,
nonconservative_terms, equations, limiter, dg, element,
cache)

# Calculate volume integral contribution of low-order FV flux
Expand Down Expand Up @@ -689,7 +689,7 @@ end
# Calculate the antidiffusive flux `antidiffusive_flux` as the subtraction between `fhat` and `fstar`.
@inline function calcflux_antidiffusive!(fhat1, fhat2, fstar1, fstar2, u, mesh,
nonconservative_terms, equations,
indicator::IndicatorIDP, dg, element, cache)
limiter::SubcellLimiterIDP, dg, element, cache)
@unpack antidiffusive_flux1, antidiffusive_flux2 = cache.container_antidiffusive_flux

for j in eachnode(dg), i in 2:nnodes(dg)
Expand Down
53 changes: 30 additions & 23 deletions src/solvers/dgsem_tree/indicators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,17 @@ const IndicatorLoehner = IndicatorLöhner
return num / den
end

abstract type AbstractSubcellLimiter end

function create_cache(typ::Type{LimiterType},
semi) where {LimiterType <: AbstractSubcellLimiter}
create_cache(typ, mesh_equations_solver_cache(semi)...)
end

"""
IndicatorIDP(equations::AbstractEquations, basis;
positivity_variables_cons = [],
positivity_correction_factor = 0.1)
SubcellLimiterIDP(equations::AbstractEquations, basis;
positivity_variables_cons = [],
positivity_correction_factor = 0.1)
Subcell invariant domain preserving (IDP) limiting used with [`VolumeIntegralSubcellLimiting`](@ref)
including:
Expand All @@ -239,33 +246,33 @@ The bounds are calculated using the low-order FV solution. The positivity limite
!!! warning "Experimental implementation"
This is an experimental feature and may change in future releases.
"""
struct IndicatorIDP{RealT <: Real, Cache} <: AbstractIndicator
struct SubcellLimiterIDP{RealT <: Real, Cache} <: AbstractSubcellLimiter
positivity::Bool
positivity_variables_cons::Vector{Int} # Positivity for conservative variables
positivity_correction_factor::RealT
cache::Cache
end

# this method is used when the indicator is constructed as for shock-capturing volume integrals
function IndicatorIDP(equations::AbstractEquations, basis;
positivity_variables_cons = [],
positivity_correction_factor = 0.1)
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(IndicatorIDP, equations, basis, number_bounds)
cache = create_cache(SubcellLimiterIDP, equations, basis, number_bounds)

IndicatorIDP{typeof(positivity_correction_factor), typeof(cache)}(positivity,
positivity_variables_cons,
positivity_correction_factor,
cache)
SubcellLimiterIDP{typeof(positivity_correction_factor), typeof(cache)}(positivity,
positivity_variables_cons,
positivity_correction_factor,
cache)
end

function Base.show(io::IO, indicator::IndicatorIDP)
@nospecialize indicator # reduce precompilation time
@unpack positivity = indicator
function Base.show(io::IO, limiter::SubcellLimiterIDP)
@nospecialize limiter # reduce precompilation time
@unpack positivity = limiter

print(io, "IndicatorIDP(")
print(io, "SubcellLimiterIDP(")
if !(positivity)
print(io, "No limiter selected => pure DG method")
else
Expand All @@ -276,27 +283,27 @@ function Base.show(io::IO, indicator::IndicatorIDP)
print(io, ")")
end

function Base.show(io::IO, ::MIME"text/plain", indicator::IndicatorIDP)
@nospecialize indicator # reduce precompilation time
@unpack positivity = indicator
function Base.show(io::IO, ::MIME"text/plain", limiter::SubcellLimiterIDP)
@nospecialize limiter # reduce precompilation time
@unpack positivity = limiter

if get(io, :compact, false)
show(io, indicator)
show(io, limiter)
else
if !(positivity)
setup = ["limiter" => "No limiter selected => pure DG method"]
else
setup = ["limiter" => ""]
if positivity
string = "positivity with conservative variables $(indicator.positivity_variables_cons)"
string = "positivity with conservative variables $(limiter.positivity_variables_cons)"
setup = [setup..., "" => string]
setup = [
setup...,
"" => " positivity correction factor = $(indicator.positivity_correction_factor)",
"" => " positivity correction factor = $(limiter.positivity_correction_factor)",
]
end
end
summary_box(io, "IndicatorIDP", setup)
summary_box(io, "SubcellLimiterIDP", setup)
end
end

Expand Down
Loading

0 comments on commit 7cb8597

Please sign in to comment.