Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Simple clamp AMR indicator. #1354

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4bd894a
Added clamp AMR indicator.
Feb 9, 2023
8f250ec
Incorporate review suggestions.
Feb 10, 2023
06da6da
Fixed little typo.
Feb 10, 2023
a978811
Fixed minor issues.
Feb 10, 2023
ac6826d
Fixed some issues.
Feb 13, 2023
6d8d2bd
Fixed more issues.
Feb 14, 2023
d96691b
Added missing comma.
Feb 22, 2023
ff2312f
Merge branch 'main' into feature-clamp-indicator
jmark Mar 1, 2023
b064189
Merge branch 'main' into feature-clamp-indicator
jmark Mar 16, 2023
a705475
Merge branch 'main' into feature-clamp-indicator
jmark Apr 25, 2023
f8b8923
Merge branch 'main' into feature-clamp-indicator
jmark May 5, 2023
c5a129e
Merge branch 'main' into feature-clamp-indicator
jmark Jun 1, 2023
05a85c2
Merge with main.
Sep 23, 2023
c5112d9
Merge branch 'main' into feature-clamp-indicator
May 10, 2024
8007138
Applied formatter.
May 10, 2024
4a18976
Merge branch 'main' into feature-clamp-indicator
jmark May 10, 2024
05b908e
Merge branch 'main' into feature-clamp-indicator
May 23, 2024
0bd5638
Merge branch 'main' into feature-clamp-indicator
sloede Aug 28, 2024
6dc79a7
Update src/solvers/dgsem_tree/indicators_1d.jl
jmark Sep 4, 2024
3bb57ae
Update src/solvers/dgsem_tree/indicators_2d.jl
jmark Sep 4, 2024
9f9746c
Update src/solvers/dgsem_tree/indicators_3d.jl
jmark Sep 4, 2024
f57e33f
Merge branch 'main' into feature-clamp-indicator
jmark Sep 4, 2024
848511b
Update src/solvers/dgsem_tree/indicators_2d.jl
jmark Oct 10, 2024
7db971f
Update src/solvers/dgsem_tree/indicators_3d.jl
jmark Oct 10, 2024
9cb06f7
Update src/solvers/dgsem_tree/indicators_1d.jl
jmark Oct 10, 2024
a4e0715
Merge branch 'main' into feature-clamp-indicator
jmark Oct 10, 2024
3833f41
Merge branch 'feature-clamp-indicator' of github.com:trixi-framework/…
Oct 10, 2024
5f58a09
Applied formatter.
Oct 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Trixi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export load_mesh, load_time, load_timestep, load_timestep!, load_dt,
load_adaptive_time_integrator!

export ControllerThreeLevel, ControllerThreeLevelCombined,
IndicatorLöhner, IndicatorLoehner, IndicatorMax
IndicatorLöhner, IndicatorLoehner, IndicatorMax, IndicatorClamp

export PositivityPreservingLimiterZhangShu

Expand Down
51 changes: 51 additions & 0 deletions src/solvers/dgsem_tree/indicators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,55 @@ function Base.show(io::IO, ::MIME"text/plain", indicator::IndicatorMax)
summary_box(io, "IndicatorMax", setup)
end
end

"""
IndicatorClamp(equations::AbstractEquations, basis; min=0.0, max=1.0, variable)
IndicatorClamp(semi::AbstractSemidiscretization; min=0.0, max=1.0, variable)

A simple indicator returning 1.0 when the element average of `variable` lies within [min,max].
Returns -1.0 otherwise.
"""
struct IndicatorClamp{RealT <: Real, Variable, Cache <: NamedTuple} <: AbstractIndicator
min::RealT
max::RealT
variable::Variable
cache::Cache
end

function IndicatorClamp(equations::AbstractEquations, basis; min = 0.0, max = 1.0,
variable)
cache = create_cache(IndicatorClamp, equations, basis)
IndicatorClamp{typeof(min), typeof(variable), typeof(cache)}(min, max, variable,
cache)
end

function IndicatorClamp(semi::AbstractSemidiscretization; min = 0.0, max = 1.0,
variable)
cache = create_cache(IndicatorClamp, semi)
return IndicatorClamp{typeof(min), typeof(variable), typeof(cache)}(min, max,
variable, cache)
end

function Base.show(io::IO, indicator::IndicatorClamp)
@nospecialize indicator # reduce precompilation time

print(io, "IndicatorClamp(")
print(io, "min=", indicator.min, ", max=", indicator.max, ", variable=",
indicator.variable, ")")
end

function Base.show(io::IO, ::MIME"text/plain", indicator::IndicatorClamp)
@nospecialize indicator # reduce precompilation time

if get(io, :compact, false)
show(io, indicator)
else
setup = [
"indicator variable" => indicator.variable,
"min" => indicator.min,
"max" => indicator.max,
]
summary_box(io, "IndicatorClamp", setup)
end
end
end # @muladd
36 changes: 36 additions & 0 deletions src/solvers/dgsem_tree/indicators_1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,40 @@ function (indicator_max::IndicatorMax)(u::AbstractArray{<:Any, 3},

return alpha
end

function create_cache(::Type{IndicatorClamp}, equations::AbstractEquations{1},
basis::LobattoLegendreBasis)
alpha = Vector{real(basis)}()
return (; alpha, basis.weights)
end

function create_cache(typ::Type{IndicatorClamp}, mesh, equations::AbstractEquations{1},
dg::DGSEM, cache)
cache = create_cache(typ, equations, dg.basis)
end
jmark marked this conversation as resolved.
Show resolved Hide resolved

function (indicator_clamp::IndicatorClamp)(u::AbstractArray{<:Any, 3},
mesh, equations, dg::DGSEM, cache;
kwargs...)
@unpack alpha, weights = indicator_clamp.cache
resize!(alpha, nelements(dg, cache))

@threaded for element in eachelement(dg, cache)
mean = zero(real(dg.basis))

for i in eachnode(dg)
u_local = get_node_vars(u, equations, dg, i, element)
mean += indicator_clamp.variable(u_local, equations) * weights[i]
end
mean *= 0.5 # Divide by reference element length

if indicator_clamp.min <= mean <= indicator_clamp.max
alpha[element] = 1.0
else
alpha[element] = -1.0
end
end

return alpha
end
end # @muladd
37 changes: 37 additions & 0 deletions src/solvers/dgsem_tree/indicators_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,41 @@ function (indicator_max::IndicatorMax)(u::AbstractArray{<:Any, 4},

return alpha
end

function create_cache(::Type{IndicatorClamp}, equations::AbstractEquations{2},
basis::LobattoLegendreBasis)
alpha = Vector{real(basis)}()
return (; alpha, basis.weights)
end

function create_cache(typ::Type{IndicatorClamp}, mesh, equations::AbstractEquations{2},
dg::DGSEM, cache)
cache = create_cache(typ, equations, dg.basis)
jmark marked this conversation as resolved.
Show resolved Hide resolved
end

function (indicator_clamp::IndicatorClamp)(u::AbstractArray{<:Any, 4},
mesh, equations, dg::DGSEM, cache;
kwargs...)
@unpack alpha, weights = indicator_clamp.cache
resize!(alpha, nelements(dg, cache))

@threaded for element in eachelement(dg, cache)
mean = zero(real(dg.basis))

for j in eachnode(dg), i in eachnode(dg)
u_local = get_node_vars(u, equations, dg, i, j, element)
mean += indicator_clamp.variable(u_local, equations) * weights[i] *
weights[j]
end
mean *= 0.25 # Divide by reference element area

if indicator_clamp.min <= mean <= indicator_clamp.max
alpha[element] = 1.0
else
alpha[element] = -1.0
end
end

return alpha
end
end # @muladd
37 changes: 37 additions & 0 deletions src/solvers/dgsem_tree/indicators_3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,41 @@ function (indicator_max::IndicatorMax)(u::AbstractArray{<:Any, 5},

return alpha
end

function create_cache(::Type{IndicatorClamp}, equations::AbstractEquations{3},
basis::LobattoLegendreBasis)
alpha = Vector{real(basis)}()
return (; alpha, basis.weights)
end

function create_cache(typ::Type{IndicatorClamp}, mesh, equations::AbstractEquations{3},
dg::DGSEM, cache)
cache = create_cache(typ, equations, dg.basis)
end
jmark marked this conversation as resolved.
Show resolved Hide resolved

function (indicator_clamp::IndicatorClamp)(u::AbstractArray{<:Any, 5},
mesh, equations, dg::DGSEM, cache;
kwargs...)
@unpack alpha, weights = indicator_clamp.cache
resize!(alpha, nelements(dg, cache))

@threaded for element in eachelement(dg, cache)
mean = zero(real(dg.basis))

for k in eachnode(dg), j in eachnode(dg), i in eachnode(dg)
u_local = get_node_vars(u, equations, dg, i, j, k, element)
mean += indicator_clamp.variable(u_local, equations) * weights[i] *
weights[j] * weights[k]
end
mean *= 0.125 # Divide by reference element volume

if indicator_clamp.min <= mean <= indicator_clamp.max
alpha[element] = 1.0
else
alpha[element] = -1.0
end
end

return alpha
end
end # @muladd
3 changes: 3 additions & 0 deletions test/test_unit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,9 @@ end

indicator_max = IndicatorMax("variable", (; cache = nothing))
@test_nowarn show(stdout, indicator_max)

indicator_clamp = IndicatorClamp(0.0, 1.0, "variable", (; cache = nothing))
@test_nowarn show(stdout, indicator_clamp)
end

@timed_testset "LBM 2D constructor" begin
Expand Down
Loading