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 4 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 @@ -222,7 +222,7 @@ export SummaryCallback, SteadyStateCallback, AnalysisCallback, AliveCallback,
export load_mesh, load_time

export ControllerThreeLevel, ControllerThreeLevelCombined,
IndicatorLöhner, IndicatorLoehner, IndicatorMax,
IndicatorLöhner, IndicatorLoehner, IndicatorMax, IndicatorClamp
IndicatorNeuralNetwork, NeuralNetworkPerssonPeraire, NeuralNetworkRayHesthaven, NeuralNetworkCNN

export PositivityPreservingLimiterZhangShu
Expand Down
46 changes: 46 additions & 0 deletions src/solvers/dgsem_tree/indicators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,52 @@ function Base.show(io::IO, ::MIME"text/plain", indicator::IndicatorMax)
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

"""
IndicatorNeuralNetwork

Expand Down
36 changes: 35 additions & 1 deletion src/solvers/dgsem_tree/indicators_1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,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, indicator_threaded, basis.weights)
end
jmark marked this conversation as resolved.
Show resolved Hide resolved

function create_cache(typ::Type{IndicatorClamp}, mesh, equations::AbstractEquations{1}, dg::DGSEM, cache)
cache = create_cache(typ, equations, dg.basis)
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::Variable = 0.0
jmark marked this conversation as resolved.
Show resolved Hide resolved
for i in eachnode(dg)
u_local = get_node_vars(u, equations, dg, i, element)
mean += indicator_clamp.variable(u_local, equations) * weights[i]*0.5
end
jmark marked this conversation as resolved.
Show resolved Hide resolved

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

return alpha
end

# this method is used when the indicator is constructed as for shock-capturing volume integrals
# empty cache is default
function create_cache(::Type{<:IndicatorNeuralNetwork},
Expand Down Expand Up @@ -402,4 +436,4 @@ function (indicator_ann::IndicatorNeuralNetwork{NeuralNetworkRayHesthaven})(
return alpha
end

end # @muladd
end # @muladd
33 changes: 33 additions & 0 deletions src/solvers/dgsem_tree/indicators_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,39 @@ function (indicator_max::IndicatorMax)(u::AbstractArray{<:Any,4},
return alpha
jmark marked this conversation as resolved.
Show resolved Hide resolved
end

function create_cache(::Type{IndicatorClamp}, equations::AbstractEquations{2}, basis::LobattoLegendreBasis)
alpha = Vector{real(basis)}()

return (; alpha, indicator_threaded, basis.weights)
end

function create_cache(typ::Type{IndicatorClamp}, mesh, equations::AbstractEquations{2}, dg::DGSEM, cache)
cache = create_cache(typ, equations, dg.basis)
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::Variable = 0.0
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]*0.25
end

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

return alpha
end

# this method is used when the indicator is constructed as for shock-capturing volume integrals
# empty cache is default
function create_cache(::Type{IndicatorNeuralNetwork},
Expand Down
33 changes: 33 additions & 0 deletions src/solvers/dgsem_tree/indicators_3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -246,5 +246,38 @@ function (indicator_max::IndicatorMax)(u::AbstractArray{<:Any,5},
return alpha
jmark marked this conversation as resolved.
Show resolved Hide resolved
end

function create_cache(::Type{IndicatorClamp}, equations::AbstractEquations{3}, basis::LobattoLegendreBasis)

alpha = Vector{real(basis)}()

return (; alpha, indicator_threaded, basis.weights)
end

function create_cache(typ::Type{IndicatorClamp}, mesh, equations::AbstractEquations{3}, dg::DGSEM, cache)
cache = create_cache(typ, equations, dg.basis)
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::Variable = 0.0
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]*0.125
end

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 @@ -408,6 +408,9 @@ isdir(outdir) && rm(outdir, recursive=true)
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)

equations = CompressibleEulerEquations2D(1.4)
basis = LobattoLegendreBasis(3)
indicator_neuralnetwork = IndicatorNeuralNetwork(
Expand Down