Skip to content

Commit

Permalink
Fix names, move constraint outside of BCs
Browse files Browse the repository at this point in the history
  • Loading branch information
charleskawczynski committed Dec 19, 2024
1 parent c6a8d37 commit cc6dd31
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
14 changes: 8 additions & 6 deletions src/Operators/finitedifference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1341,16 +1341,18 @@ cases (discussed in Lin et al (1994)) include setting the 𝜙_min = 0 or 𝜙_m
saturation mixing ratio for water vapor are not considered here in favour of
the generalized local extrema in equation (5a, 5b).
"""
struct LinVanLeerC2F{BCS} <: AdvectionOperator
struct LinVanLeerC2F{BCS, C} <: AdvectionOperator
bcs::BCS
constraint::C
end
abstract type LimiterConstraint end
struct AlgebraicMean <: LimiterConstraint end
struct PositiveDefinite <: LimiterConstraint end
struct MonotoneHarmonic <: LimiterConstraint end
struct MonotoneLocalExtrema <: LimiterConstraint end

LinVanLeerC2F(; kwargs...) = LinVanLeerC2F(NamedTuple(kwargs))
LinVanLeerC2F(; constraint, kwargs...) =
LinVanLeerC2F(NamedTuple(kwargs), constraint)

return_eltype(::LinVanLeerC2F, V, A, dt) =
Geometry.Contravariant3Vector{eltype(eltype(V))}
Expand Down Expand Up @@ -1395,16 +1397,16 @@ function compute_Δ𝛼_linvanleer(a⁻, a⁰, a⁺, v, dt, ::AlgebraicMean)
return ((a⁰ - a⁻) + (a⁺ - a⁰)) / 2 * (1 - sign(v) * v * dt)
end

function slope_limited_product(v, a⁻, a⁻⁻, a⁺, a⁺⁺, dt, method)
function slope_limited_product(v, a⁻, a⁻⁻, a⁺, a⁺⁺, dt, constraint)
# Following Lin et al. (1994)
# https://doi.org/10.1175/1520-0493(1994)122<1575:ACOTVL>2.0.CO;2
if v >= 0
# Eqn (2,5a,5b,5c)
Δ𝛼 = compute_Δ𝛼_linvanleer(a⁻⁻, a⁻, a⁺, v, dt, method)
Δ𝛼 = compute_Δ𝛼_linvanleer(a⁻⁻, a⁻, a⁺, v, dt, constraint)
return v (a⁻ RecursiveApply.rdiv(Δ𝛼, 2))
else
# Eqn (2,5a,5b,5c)
Δ𝛼 = compute_Δ𝛼_linvanleer(a⁻, a⁺, a⁺⁺, v, dt, method)
Δ𝛼 = compute_Δ𝛼_linvanleer(a⁻, a⁺, a⁺⁺, v, dt, constraint)
return v (a⁺ RecursiveApply.rdiv(Δ𝛼, 2))
end
end
Expand All @@ -1431,7 +1433,7 @@ Base.@propagate_inbounds function stencil_interior(
Geometry.LocalGeometry(space, idx, hidx),
)
return Geometry.Contravariant3Vector(
slope_limited_product(vᶠ, a⁻, a⁻⁻, a⁺, a⁺⁺, dt, op.bcs.method),
slope_limited_product(vᶠ, a⁻, a⁻⁻, a⁺, a⁺⁺, dt, op.constraint),
)
end

Expand Down
8 changes: 4 additions & 4 deletions test/Operators/finitedifference/convergence_column.jl
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ end
SLMethod = Operators.LinVanLeerC2F(
bottom = Operators.FirstOrderOneSided(),
top = Operators.FirstOrderOneSided(),
method = Operators.Mono5(),
constraint = Operators.MonotoneLocalExtrema(),
)

divf2c = Operators.DivergenceF2C()
Expand Down Expand Up @@ -771,10 +771,10 @@ end
# c = sin(z), scalar field defined at the centers
c = sin.(centers)

SLMethod = Operators.LinVanLeerC2F(
SLMethod = Operators.LinVanLeerC2F(;
bottom = Operators.FirstOrderOneSided(),
top = Operators.FirstOrderOneSided(),
method = Operators.MonotoneHarmonic(),
constraint = Operators.MonotoneHarmonic(),
)

divf2c = Operators.DivergenceF2C()
Expand Down Expand Up @@ -830,7 +830,7 @@ end
SLMethod = Operators.LinVanLeerC2F(
bottom = Operators.FirstOrderOneSided(),
top = Operators.FirstOrderOneSided(),
method = Operators.PosDef(),
constraint = Operators.PositiveDefinite(),
)

divf2c = Operators.DivergenceF2C()
Expand Down

0 comments on commit cc6dd31

Please sign in to comment.