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

Removing some advection schemes #3659

Merged
merged 4 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
1 change: 0 additions & 1 deletion src/Advection/Advection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ include("vector_invariant_upwinding.jl")
include("vector_invariant_advection.jl")
include("vector_invariant_cross_upwinding.jl")
include("vector_invariant_self_upwinding.jl")
include("vector_invariant_velocity_upwinding.jl")

include("flat_advective_fluxes.jl")
include("topologically_conditional_interpolation.jl")
Expand Down
1 change: 0 additions & 1 deletion src/Advection/vector_invariant_advection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ const VectorInvariantKineticEnergyUpwinding = VectorInvariant{<:Any, <:Any,
# VectorInvariant{N, FT, M, Z, ZS, V, K, D, U (upwinding)
const VectorInvariantCrossVerticalUpwinding = VectorInvariant{<:Any, <:Any, <:Any, <:Any, <:Any, <:Any, <:Any, <:AbstractUpwindBiasedAdvectionScheme, <:CrossAndSelfUpwinding}
const VectorInvariantSelfVerticalUpwinding = VectorInvariant{<:Any, <:Any, <:Any, <:Any, <:Any, <:Any, <:Any, <:AbstractUpwindBiasedAdvectionScheme, <:OnlySelfUpwinding}
const VectorInvariantVelocityVerticalUpwinding = VectorInvariant{<:Any, <:Any, <:Any, <:Any, <:Any, <:Any, <:Any, <:AbstractUpwindBiasedAdvectionScheme, <:VelocityUpwinding}

Base.summary(a::VectorInvariant) = string("Vector Invariant, Dimension-by-dimension reconstruction")
Base.summary(a::MultiDimensionalVectorInvariant) = string("Vector Invariant, Multidimensional reconstruction")
Expand Down
26 changes: 0 additions & 26 deletions src/Advection/vector_invariant_upwinding.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,8 @@ CrossAndSelfUpwinding(; cross_scheme = CenteredSecondOrder(),
δv²_stencil = FunctionStencil(v_smoothness),
) = CrossAndSelfUpwinding(extract_centered_scheme(cross_scheme), divergence_stencil, δu²_stencil, δv²_stencil)

"""
VelocityUpwinding(; cross_scheme = CenteredSecondOrder())

Upwinding treatment for Divergence fluxes and Kinetic Energy gradient in the Vector Invariant formulation, whereas only
the terms corresponding to the transporting velocity are upwinded. (i.e., terms in `u` in the zonal momentum equation and
terms in `v` in the meridional momentum equation). Contrarily to `OnlySelfUpwinding`, the reconstruction (and hence the
upwinding) is done _inside_ the gradient operator, i.e., velocities are reconstructed instead of velocity derivatives.

Keyword arguments
=================

- `cross_scheme`: Advection scheme used for cross-reconstructed terms (tangential velocities)
in the kinetic energy gradient and the divergence flux. Defaults to `CenteredSecondOrder()`.
"""
VelocityUpwinding(; cross_scheme = CenteredSecondOrder()) = VelocityUpwinding(extract_centered_scheme(cross_scheme))

Base.summary(a::OnlySelfUpwinding) = "OnlySelfUpwinding"
Base.summary(a::CrossAndSelfUpwinding) = "CrossAndSelfUpwinding"
Base.summary(a::VelocityUpwinding) = "VelocityUpwinding"

Base.show(io::IO, a::OnlySelfUpwinding) =
print(io, summary(a), " \n",
Expand Down Expand Up @@ -139,12 +122,3 @@ Adapt.adapt_structure(to, scheme::CrossAndSelfUpwinding) =
Adapt.adapt(to, scheme.divergence_stencil),
Adapt.adapt(to, scheme.δu²_stencil),
Adapt.adapt(to, scheme.δv²_stencil))

Base.show(io::IO, a::VelocityUpwinding) =
print(io, summary(a), " \n",
"KE gradient and Divergence flux cross terms reconstruction: ", "\n",
"└── $(summary(a.cross_scheme))")

Adapt.adapt_structure(to, scheme::VelocityUpwinding) =
VelocityUpwinding(Adapt.adapt(to, scheme.cross_scheme))

97 changes: 0 additions & 97 deletions src/Advection/vector_invariant_velocity_upwinding.jl

This file was deleted.

29 changes: 6 additions & 23 deletions src/Advection/weno_interpolants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -212,22 +212,11 @@ end
return :($(elem...),)
end

# JSWENO α weights dᵣ / (βᵣ + ε)²
@inline function metaprogrammed_js_alpha_loop(buffer)
elem = Vector(undef, buffer)
for stencil = 1:buffer
elem[stencil] = :(@inbounds FT(coeff(scheme, Val($(stencil-1)))) / (β[$stencil] + FT(ε))^ƞ)
end

return :($(elem...),)
end

for buffer in [2, 3, 4, 5, 6]
@eval begin
@inline beta_sum(scheme::WENO{$buffer}, β₁, β₂) = @inbounds $(metaprogrammed_beta_sum(buffer))
@inline beta_loop(scheme::WENO{$buffer}, ψ, func) = @inbounds $(metaprogrammed_beta_loop(buffer))
@inline zweno_alpha_loop(scheme::WENO{$buffer}, β, τ, coeff, FT) = @inbounds $(metaprogrammed_zweno_alpha_loop(buffer))
@inline js_alpha_loop(scheme::WENO{$buffer}, β, coeff, FT) = @inbounds $(metaprogrammed_js_alpha_loop(buffer))
end
end

Expand All @@ -253,12 +242,9 @@ for (side, coeff) in zip([:left, :right], (:Cl, :Cr))
@inbounds begin
β = beta_loop(scheme, ψ, $biased_β)

if scheme isa ZWENO
τ = global_smoothness_indicator(Val(N), β)
α = zweno_alpha_loop(scheme, β, τ, $coeff, FT)
else
α = js_alpha_loop(scheme, β, $coeff, FT)
end
τ = global_smoothness_indicator(Val(N), β)
α = zweno_alpha_loop(scheme, β, τ, $coeff, FT)

return α ./ sum(α)
end
end
Expand All @@ -274,12 +260,9 @@ for (side, coeff) in zip([:left, :right], (:Cl, :Cr))

β = beta_sum(scheme, βᵤ, βᵥ)

if scheme isa ZWENO
τ = global_smoothness_indicator(Val(N), β)
α = zweno_alpha_loop(scheme, β, τ, $coeff, FT)
else
α = js_alpha_loop(scheme, β, $coeff, FT)
end
τ = global_smoothness_indicator(Val(N), β)
α = zweno_alpha_loop(scheme, β, τ, $coeff, FT)

return α ./ sum(α)
end
end
Expand Down
69 changes: 29 additions & 40 deletions src/Advection/weno_reconstruction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
##### Weighted Essentially Non-Oscillatory (WENO) advection scheme
#####

struct WENO{N, FT, XT, YT, ZT, WF, PP, CA, SI} <: AbstractUpwindBiasedAdvectionScheme{N, FT}
struct WENO{N, FT, XT, YT, ZT, PP, CA, SI} <: AbstractUpwindBiasedAdvectionScheme{N, FT}

"Coefficient for ENO reconstruction on x-faces"
coeff_xᶠᵃᵃ::XT
Expand All @@ -25,24 +25,23 @@ struct WENO{N, FT, XT, YT, ZT, WF, PP, CA, SI} <: AbstractUpwindBiasedAdvectionS
"Reconstruction scheme used for symmetric interpolation"
advecting_velocity_scheme :: SI

function WENO{N, FT, WF}(coeff_xᶠᵃᵃ::XT, coeff_xᶜᵃᵃ::XT,
coeff_yᵃᶠᵃ::YT, coeff_yᵃᶜᵃ::YT,
coeff_zᵃᵃᶠ::ZT, coeff_zᵃᵃᶜ::ZT,
bounds::PP, buffer_scheme::CA,
advecting_velocity_scheme :: SI) where {N, FT, XT, YT, ZT, WF, PP, CA, SI}
function WENO{N, FT}(coeff_xᶠᵃᵃ::XT, coeff_xᶜᵃᵃ::XT,
coeff_yᵃᶠᵃ::YT, coeff_yᵃᶜᵃ::YT,
coeff_zᵃᵃᶠ::ZT, coeff_zᵃᵃᶜ::ZT,
bounds::PP, buffer_scheme::CA,
advecting_velocity_scheme :: SI) where {N, FT, XT, YT, ZT, PP, CA, SI}

return new{N, FT, XT, YT, ZT, WF, PP, CA, SI}(coeff_xᶠᵃᵃ, coeff_xᶜᵃᵃ,
coeff_yᵃᶠᵃ, coeff_yᵃᶜᵃ,
coeff_zᵃᵃᶠ, coeff_zᵃᵃᶜ,
bounds, buffer_scheme, advecting_velocity_scheme)
return new{N, FT, XT, YT, ZT, PP, CA, SI}(coeff_xᶠᵃᵃ, coeff_xᶜᵃᵃ,
coeff_yᵃᶠᵃ, coeff_yᵃᶜᵃ,
coeff_zᵃᵃᶠ, coeff_zᵃᵃᶜ,
bounds, buffer_scheme, advecting_velocity_scheme)
end
end

"""
WENO([FT=Float64;]
order = 5,
grid = nothing,
zweno = true,
bounds = nothing)

Construct a weighted essentially non-oscillatory advection scheme of order `order`.
Expand All @@ -52,8 +51,6 @@ Keyword arguments

- `order`: The order of the WENO advection scheme. Default: 5
- `grid`: (defaults to `nothing`)
- `zweno`: When `true` implement a Z-WENO formulation for the WENO weights calculation.
(defaults to `true`)

Examples
========
Expand All @@ -62,8 +59,6 @@ julia> using Oceananigans

julia> WENO()
WENO reconstruction order 5
Smoothness formulation:
└── Z-weno
Boundary scheme:
└── WENO reconstruction order 3
Symmetric scheme:
Expand All @@ -88,8 +83,6 @@ julia> grid = RectilinearGrid(size = (Nx, Nz), halo = (4, 4), topology=(Periodic

julia> WENO(grid; order=7)
WENO reconstruction order 7
Smoothness formulation:
└── Z-weno
Boundary scheme:
└── WENO reconstruction order 5
Symmetric scheme:
Expand All @@ -103,7 +96,6 @@ WENO reconstruction order 7
function WENO(FT::DataType=Float64;
order = 5,
grid = nothing,
zweno = true,
bounds = nothing)

if !(grid isa Nothing)
Expand All @@ -119,11 +111,11 @@ function WENO(FT::DataType=Float64;
N = Int((order + 1) ÷ 2)

weno_coefficients = compute_reconstruction_coefficients(grid, FT, :WENO; order = N)
buffer_scheme = WENO(FT; grid, order = order - 2, zweno, bounds)
buffer_scheme = WENO(FT; grid, order = order - 2, bounds)
advecting_velocity_scheme = Centered(FT; grid, order = order - 1)
end

return WENO{N, FT, zweno}(weno_coefficients..., bounds, buffer_scheme, advecting_velocity_scheme)
return WENO{N, FT}(weno_coefficients..., bounds, buffer_scheme, advecting_velocity_scheme)
end

WENO(grid, FT::DataType=Float64; kwargs...) = WENO(FT; grid, kwargs...)
Expand All @@ -133,15 +125,12 @@ WENOThirdOrder(grid=nothing, FT::DataType=Float64; kwargs...) = WENO(grid, FT;
WENOFifthOrder(grid=nothing, FT::DataType=Float64; kwargs...) = WENO(grid, FT; order=5, kwargs...)

# Flavours of WENO
const ZWENO = WENO{<:Any, <:Any, <:Any, <:Any, <:Any, true}
const PositiveWENO = WENO{<:Any, <:Any, <:Any, <:Any, <:Any, <:Any, <:Tuple}
const PositiveWENO = WENO{<:Any, <:Any, <:Any, <:Any, <:Any, <:Tuple}

Base.summary(a::WENO{N}) where N = string("WENO reconstruction order ", N*2-1)

Base.show(io::IO, a::WENO{N, FT, RX, RY, RZ, WF, PP}) where {N, FT, RX, RY, RZ, WF, PP} =
Base.show(io::IO, a::WENO{N, FT, RX, RY, RZ, PP}) where {N, FT, RX, RY, RZ, PP} =
print(io, summary(a), " \n",
" Smoothness formulation: ", "\n",
" └── $(WF ? "Z-weno" : "JS-weno") \n",
a.bounds isa Nothing ? "" : " Bounds : \n └── $(a.bounds) \n",
" Boundary scheme: ", "\n",
" └── ", summary(a.buffer_scheme) , "\n",
Expand All @@ -152,21 +141,21 @@ Base.show(io::IO, a::WENO{N, FT, RX, RY, RZ, WF, PP}) where {N, FT, RX, RY, RZ,
" ├── Y $(RY == Nothing ? "regular" : "stretched") \n",
" └── Z $(RZ == Nothing ? "regular" : "stretched")" )

Adapt.adapt_structure(to, scheme::WENO{N, FT, XT, YT, ZT, WF, PP}) where {N, FT, XT, YT, ZT, WF, PP} =
WENO{N, FT, WF}(Adapt.adapt(to, scheme.coeff_xᶠᵃᵃ), Adapt.adapt(to, scheme.coeff_xᶜᵃᵃ),
Adapt.adapt(to, scheme.coeff_yᵃᶠᵃ), Adapt.adapt(to, scheme.coeff_yᵃᶜᵃ),
Adapt.adapt(to, scheme.coeff_zᵃᵃᶠ), Adapt.adapt(to, scheme.coeff_zᵃᵃᶜ),
Adapt.adapt(to, scheme.bounds),
Adapt.adapt(to, scheme.buffer_scheme),
Adapt.adapt(to, scheme.advecting_velocity_scheme))

on_architecture(to, scheme::WENO{N, FT, XT, YT, ZT, WF, PP}) where {N, FT, XT, YT, ZT, WF, PP} =
WENO{N, FT, WF}(on_architecture(to, scheme.coeff_xᶠᵃᵃ), on_architecture(to, scheme.coeff_xᶜᵃᵃ),
on_architecture(to, scheme.coeff_yᵃᶠᵃ), on_architecture(to, scheme.coeff_yᵃᶜᵃ),
on_architecture(to, scheme.coeff_zᵃᵃᶠ), on_architecture(to, scheme.coeff_zᵃᵃᶜ),
on_architecture(to, scheme.bounds),
on_architecture(to, scheme.buffer_scheme),
on_architecture(to, scheme.advecting_velocity_scheme))
Adapt.adapt_structure(to, scheme::WENO{N, FT, XT, YT, ZT, PP}) where {N, FT, XT, YT, ZT, PP} =
WENO{N, FT}(Adapt.adapt(to, scheme.coeff_xᶠᵃᵃ), Adapt.adapt(to, scheme.coeff_xᶜᵃᵃ),
Adapt.adapt(to, scheme.coeff_yᵃᶠᵃ), Adapt.adapt(to, scheme.coeff_yᵃᶜᵃ),
Adapt.adapt(to, scheme.coeff_zᵃᵃᶠ), Adapt.adapt(to, scheme.coeff_zᵃᵃᶜ),
Adapt.adapt(to, scheme.bounds),
Adapt.adapt(to, scheme.buffer_scheme),
Adapt.adapt(to, scheme.advecting_velocity_scheme))

on_architecture(to, scheme::WENO{N, FT, XT, YT, ZT, PP}) where {N, FT, XT, YT, ZT, PP} =
WENO{N, FT}(on_architecture(to, scheme.coeff_xᶠᵃᵃ), on_architecture(to, scheme.coeff_xᶜᵃᵃ),
on_architecture(to, scheme.coeff_yᵃᶠᵃ), on_architecture(to, scheme.coeff_yᵃᶜᵃ),
on_architecture(to, scheme.coeff_zᵃᵃᶠ), on_architecture(to, scheme.coeff_zᵃᵃᶜ),
on_architecture(to, scheme.bounds),
on_architecture(to, scheme.buffer_scheme),
on_architecture(to, scheme.advecting_velocity_scheme))

# Retrieve precomputed coefficients (+2 for julia's 1 based indices)
@inline retrieve_coeff(scheme::WENO, r, ::Val{1}, i, ::Type{Face}) = @inbounds scheme.coeff_xᶠᵃᵃ[r+2][i]
Expand Down