Skip to content

Commit

Permalink
Remove redundant advection aliases (#3912)
Browse files Browse the repository at this point in the history
* Update centered_reconstruction.jl

* Update Advection.jl

* Update upwind_biased_reconstruction.jl

* Update weno_reconstruction.jl

* some changes

* Update test_nonhydrostatic_models.jl
  • Loading branch information
simone-silvestri authored Nov 11, 2024
1 parent 4619055 commit 37d0e29
Show file tree
Hide file tree
Showing 40 changed files with 81 additions and 94 deletions.
2 changes: 1 addition & 1 deletion benchmark/benchmark_advection_schemes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ if GPU in Architectures
end

for Arch in Architectures
suite_arch = speedups_suite(suite[@tagged Arch], base_case=(Arch, CenteredSecondOrder))
suite_arch = speedups_suite(suite[@tagged Arch], base_case=(Arch, Centered))
df_arch = speedups_dataframe(suite_arch, slowdown=true)
sort!(df_arch, :Schemes, by=string)
benchmarks_pretty_table(df_arch, title="Advection schemes relative performance ($Arch)")
Expand Down
4 changes: 1 addition & 3 deletions src/Advection/Advection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ export
advective_tracer_flux_z,

AdvectionScheme,
Centered, CenteredSecondOrder, CenteredFourthOrder,
UpwindBiased, UpwindBiasedFirstOrder, UpwindBiasedThirdOrder, UpwindBiasedFifthOrder,
WENO, WENOThirdOrder, WENOFifthOrder,
Centered, UpwindBiased, WENO,
VectorInvariant, WENOVectorInvariant,
FluxFormAdvection,
EnergyConserving,
Expand Down
3 changes: 0 additions & 3 deletions src/Advection/centered_reconstruction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ on_architecture(to, scheme::Centered{N, FT}) where {N, FT} =
# Useful aliases
Centered(grid, FT::DataType=Float64; kwargs...) = Centered(FT; grid, kwargs...)

CenteredSecondOrder(grid=nothing, FT::DataType=Float64) = Centered(grid, FT; order=2)
CenteredFourthOrder(grid=nothing, FT::DataType=Float64) = Centered(grid, FT; order=4)

const ACAS = AbstractCenteredAdvectionScheme

# left and right biased for Centered reconstruction are just symmetric!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const ω̂₁ = 5/18
const ω̂ₙ = 5/18
const ε₂ = 1e-20

# Here in the future we can easily add UpwindBiasedFifthOrder
# Here in the future we can easily add UpwindBiased
const BoundPreservingScheme = PositiveWENO

# Is this immersed-boundary safe without having to extend it in ImmersedBoundaries.jl? I think so... (velocity on immmersed boundaries is masked to 0)
Expand Down
8 changes: 2 additions & 6 deletions src/Advection/upwind_biased_reconstruction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#####

"""
struct UpwindBiasedFifthOrder <: AbstractUpwindBiasedAdvectionScheme{3}
struct UpwindBiased <: AbstractUpwindBiasedAdvectionScheme{3}
Upwind-biased fifth-order advection scheme.
Upwind-biased reconstruction scheme.
"""
struct UpwindBiased{N, FT, XT, YT, ZT, CA, SI} <: AbstractUpwindBiasedAdvectionScheme{N, FT}
"Coefficient for Upwind reconstruction on stretched ``x``-faces"
Expand Down Expand Up @@ -95,10 +95,6 @@ on_architecture(to, scheme::UpwindBiased{N, FT}) where {N, FT} =
# Useful aliases
UpwindBiased(grid, FT::DataType=Float64; kwargs...) = UpwindBiased(FT; grid, kwargs...)

UpwindBiasedFirstOrder(grid=nothing, FT::DataType=Float64) = UpwindBiased(grid, FT; order = 1)
UpwindBiasedThirdOrder(grid=nothing, FT::DataType=Float64) = UpwindBiased(grid, FT; order = 3)
UpwindBiasedFifthOrder(grid=nothing, FT::DataType=Float64) = UpwindBiased(grid, FT; order = 5)

const AUAS = AbstractUpwindBiasedAdvectionScheme

# symmetric interpolation for UpwindBiased and WENO
Expand Down
12 changes: 6 additions & 6 deletions src/Advection/vector_invariant_upwinding.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ end
@inline extract_centered_scheme(scheme::AUAS) = scheme.advecting_velocity_scheme

"""
OnlySelfUpwinding(; cross_scheme = CenteredSecondOrder(),
OnlySelfUpwinding(; cross_scheme = Centered(),
δU_stencil = FunctionStencil(divergence_smoothness),
δV_stencil = FunctionStencil(divergence_smoothness),
δu²_stencil = FunctionStencil(u_smoothness),
Expand All @@ -43,7 +43,7 @@ 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()`.
in the kinetic energy gradient and the divergence flux. Defaults to `Centered()`.
- `δU_stencil`: Stencil used for smoothness indicators of `δx_U` in case of a `WENO` upwind reconstruction.
Defaults to `FunctionStencil(divergence_smoothness)`
- `δV_stencil`: Same as `δU_stencil` but for the smoothness of `δy_V`
Expand All @@ -52,15 +52,15 @@ Keyword arguments
- `δv²_stencil`: Same as `δu²_stencil` but for the smoothness of `δy_v²`
Defaults to `FunctionStencil(v_smoothness)`
"""
OnlySelfUpwinding(; cross_scheme = CenteredSecondOrder(),
OnlySelfUpwinding(; cross_scheme = Centered(),
δU_stencil = FunctionStencil(divergence_smoothness),
δV_stencil = FunctionStencil(divergence_smoothness),
δu²_stencil = FunctionStencil(u_smoothness),
δv²_stencil = FunctionStencil(v_smoothness),
) = OnlySelfUpwinding(extract_centered_scheme(cross_scheme), δU_stencil, δV_stencil, δu²_stencil, δv²_stencil)

"""
CrossAndSelfUpwinding(; cross_scheme = CenteredSecondOrder(),
CrossAndSelfUpwinding(; cross_scheme = Centered(),
divergence_stencil = DefaultStencil(),
δu²_stencil = FunctionStencil(u_smoothness),
δv²_stencil = FunctionStencil(v_smoothness))
Expand All @@ -74,15 +74,15 @@ Keyword arguments
=================
- `cross_scheme`: Advection scheme used for cross-reconstructed terms (tangential velocities)
in the kinetic energy gradient. Defaults to `CenteredSecondOrder()`.
in the kinetic energy gradient. Defaults to `Centered()`.
- `divergence_stencil`: Stencil used for smoothness indicators of `δx_U + δy_V` in case of a
`WENO` upwind reconstruction. Defaults to `DefaultStencil()`.
- `δu²_stencil`: Stencil used for smoothness indicators of `δx_u²` in case of a `WENO` upwind reconstruction.
Defaults to `FunctionStencil(u_smoothness)`
- `δv²_stencil`: Same as `δu²_stencil` but for the smoothness of `δy_v²`
Defaults to `FunctionStencil(v_smoothness)`
"""
CrossAndSelfUpwinding(; cross_scheme = CenteredSecondOrder(),
CrossAndSelfUpwinding(; cross_scheme = Centered(),
divergence_stencil = DefaultStencil(),
δu²_stencil = FunctionStencil(u_smoothness),
δv²_stencil = FunctionStencil(v_smoothness),
Expand Down
4 changes: 0 additions & 4 deletions src/Advection/weno_reconstruction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,6 @@ end

WENO(grid, FT::DataType=Float64; kwargs...) = WENO(FT; grid, kwargs...)

# Some usefull aliases
WENOThirdOrder(grid=nothing, FT::DataType=Float64; kwargs...) = WENO(grid, FT; order=3, kwargs...)
WENOFifthOrder(grid=nothing, FT::DataType=Float64; kwargs...) = WENO(grid, FT; order=5, kwargs...)

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

Expand Down
2 changes: 1 addition & 1 deletion src/Biogeochemistry.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Biogeochemistry

using Oceananigans.Grids: Center, xnode, ynode, znode
using Oceananigans.Advection: div_Uc, CenteredSecondOrder
using Oceananigans.Advection: div_Uc, Centered
using Oceananigans.Architectures: device, architecture
using Oceananigans.Fields: ZeroField

Expand Down
2 changes: 1 addition & 1 deletion src/Forcings/advective_forcing.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Oceananigans.Advection: UpwindBiasedFifthOrder, div_Uc, div_𝐯u, div_𝐯v, div_𝐯w
using Oceananigans.Advection: div_Uc, div_𝐯u, div_𝐯v, div_𝐯w
using Oceananigans.Fields: ZeroField, ConstantField
using Oceananigans.Utils: SumOfArrays
using Adapt
Expand Down
12 changes: 6 additions & 6 deletions src/Grids/automatic_halo_sizing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ Example
=======
```jldoctest
using Oceananigans.Advection: CenteredFourthOrder
using Oceananigans.Advection: Centered(order=4)
using Oceananigans.Grids: required_halo_size_x
required_halo_size_x(CenteredFourthOrder())
required_halo_size_x(Centered(order=4))
# output
2
Expand All @@ -28,10 +28,10 @@ Example
=======
```jldoctest
using Oceananigans.Advection: CenteredFourthOrder
using Oceananigans.Advection: Centered(order=4)
using Oceananigans.Grids: required_halo_size_y
required_halo_size_y(CenteredFourthOrder())
required_halo_size_y(Centered(order=4))
# output
2
Expand All @@ -48,10 +48,10 @@ Example
=======
```jldoctest
using Oceananigans.Advection: CenteredFourthOrder
using Oceananigans.Advection: Centered(order=4)
using Oceananigans.Grids: required_halo_size_z
required_halo_size_z(CenteredFourthOrder())
required_halo_size_z(Centered(order=4))
# output
2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using OrderedCollections: OrderedDict

using Oceananigans.DistributedComputations
using Oceananigans.Architectures: AbstractArchitecture
using Oceananigans.Advection: AbstractAdvectionScheme, CenteredSecondOrder, VectorInvariant, adapt_advection_order
using Oceananigans.Advection: AbstractAdvectionScheme, Centered, VectorInvariant, adapt_advection_order
using Oceananigans.BuoyancyModels: validate_buoyancy, regularize_buoyancy, SeawaterBuoyancy, g_Earth
using Oceananigans.BoundaryConditions: regularize_field_boundary_conditions
using Oceananigans.Biogeochemistry: validate_biogeochemistry, AbstractBiogeochemistry, biogeochemical_auxiliary_fields
Expand Down Expand Up @@ -57,7 +57,7 @@ default_free_surface(grid; gravitational_acceleration=g_Earth) =
HydrostaticFreeSurfaceModel(; grid,
clock = Clock{eltype(grid)}(time = 0),
momentum_advection = VectorInvariant(),
tracer_advection = CenteredSecondOrder(),
tracer_advection = Centered(),
buoyancy = SeawaterBuoyancy(eltype(grid)),
coriolis = nothing,
free_surface = default_free_surface(grid, gravitational_acceleration=g_Earth),
Expand Down Expand Up @@ -104,7 +104,7 @@ Keyword arguments
function HydrostaticFreeSurfaceModel(; grid,
clock = Clock{eltype(grid)}(time = 0),
momentum_advection = VectorInvariant(),
tracer_advection = CenteredSecondOrder(),
tracer_advection = Centered(),
buoyancy = nothing,
coriolis = nothing,
free_surface = default_free_surface(grid, gravitational_acceleration=g_Earth),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ end
validate_velocity_boundary_conditions(::SingleColumnGrid, velocities) = nothing
validate_velocity_boundary_conditions(::SingleColumnGrid, ::PrescribedVelocityFields) = nothing
validate_momentum_advection(momentum_advection, ::SingleColumnGrid) = nothing
validate_tracer_advection(tracer_advection_tuple::NamedTuple, ::SingleColumnGrid) = CenteredSecondOrder(), tracer_advection_tuple
validate_tracer_advection(tracer_advection_tuple::NamedTuple, ::SingleColumnGrid) = Centered(), tracer_advection_tuple
validate_tracer_advection(tracer_advection::AbstractAdvectionScheme, ::SingleColumnGrid) = tracer_advection, NamedTuple()

compute_w_from_continuity!(velocities, arch, ::SingleColumnGrid; kwargs...) = nothing
Expand Down
4 changes: 2 additions & 2 deletions src/Models/Models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export

using Oceananigans: AbstractModel, fields, prognostic_fields
using Oceananigans.AbstractOperations: AbstractOperation
using Oceananigans.Advection: AbstractAdvectionScheme, CenteredSecondOrder, VectorInvariant
using Oceananigans.Advection: AbstractAdvectionScheme, Centered, VectorInvariant
using Oceananigans.Fields: AbstractField, Field, flattened_unique_values, boundary_conditions
using Oceananigans.Grids: AbstractGrid, halo_size, inflate_halo_size
using Oceananigans.OutputReaders: update_field_time_series!, extract_field_time_series
Expand Down Expand Up @@ -80,7 +80,7 @@ extract_boundary_conditions(field::Field) = field.boundary_conditions

""" Returns a default_tracer_advection, tracer_advection `tuple`. """
validate_tracer_advection(invalid_tracer_advection, grid) = error("$invalid_tracer_advection is invalid tracer_advection!")
validate_tracer_advection(tracer_advection_tuple::NamedTuple, grid) = CenteredSecondOrder(), tracer_advection_tuple
validate_tracer_advection(tracer_advection_tuple::NamedTuple, grid) = Centered(), tracer_advection_tuple
validate_tracer_advection(tracer_advection::AbstractAdvectionScheme, grid) = tracer_advection, NamedTuple()
validate_tracer_advection(tracer_advection::Nothing, grid) = nothing, NamedTuple()

Expand Down
6 changes: 3 additions & 3 deletions src/Models/NonhydrostaticModels/nonhydrostatic_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using OrderedCollections: OrderedDict

using Oceananigans.Architectures: AbstractArchitecture
using Oceananigans.DistributedComputations: Distributed
using Oceananigans.Advection: CenteredSecondOrder, adapt_advection_order
using Oceananigans.Advection: Centered, adapt_advection_order
using Oceananigans.BuoyancyModels: validate_buoyancy, regularize_buoyancy, SeawaterBuoyancy
using Oceananigans.Biogeochemistry: validate_biogeochemistry, AbstractBiogeochemistry, biogeochemical_auxiliary_fields
using Oceananigans.BoundaryConditions: regularize_field_boundary_conditions
Expand Down Expand Up @@ -56,7 +56,7 @@ end
"""
NonhydrostaticModel(; grid,
clock = Clock{eltype(grid)}(time = 0),
advection = CenteredSecondOrder(),
advection = Centered(),
buoyancy = nothing,
coriolis = nothing,
stokes_drift = nothing,
Expand Down Expand Up @@ -113,7 +113,7 @@ Keyword arguments
"""
function NonhydrostaticModel(; grid,
clock = Clock{eltype(grid)}(time = 0),
advection = CenteredSecondOrder(),
advection = Centered(),
buoyancy = nothing,
coriolis = nothing,
stokes_drift = nothing,
Expand Down
8 changes: 4 additions & 4 deletions src/Models/ShallowWaterModels/shallow_water_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using Oceananigans: AbstractModel, AbstractOutputWriter, AbstractDiagnostic
using Oceananigans.Architectures: AbstractArchitecture, CPU
using Oceananigans.AbstractOperations: @at, KernelFunctionOperation
using Oceananigans.DistributedComputations
using Oceananigans.Advection: CenteredSecondOrder, VectorInvariant
using Oceananigans.Advection: Centered, VectorInvariant
using Oceananigans.BoundaryConditions: regularize_field_boundary_conditions
using Oceananigans.Fields: Field, tracernames, TracerFields, XFaceField, YFaceField, CenterField, compute!
using Oceananigans.Forcings: model_forcing
Expand Down Expand Up @@ -62,7 +62,7 @@ struct VectorInvariantFormulation end
ShallowWaterModel(; grid,
gravitational_acceleration,
clock = Clock{eltype(grid)}(time = 0),
momentum_advection = UpwindBiasedFifthOrder(),
momentum_advection = UpwindBiased(order=5),
tracer_advection = WENO(),
mass_advection = WENO(),
coriolis = nothing,
Expand All @@ -86,7 +86,7 @@ Keyword arguments
- `gravitational_acceleration`: (required) The gravitational acceleration constant.
- `clock`: The `clock` for the model.
- `momentum_advection`: The scheme that advects velocities. See `Oceananigans.Advection`.
Default: `UpwindBiasedFifthOrder()`.
Default: `UpwindBiased(order=5)`.
- `tracer_advection`: The scheme that advects tracers. See `Oceananigans.Advection`. Default: `WENO()`.
- `mass_advection`: The scheme that advects the mass equation. See `Oceananigans.Advection`. Default:
`WENO()`.
Expand All @@ -113,7 +113,7 @@ function ShallowWaterModel(;
grid,
gravitational_acceleration,
clock = Clock{eltype(grid)}(time=0),
momentum_advection = UpwindBiasedFifthOrder(),
momentum_advection = UpwindBiased(order=5),
tracer_advection = WENO(),
mass_advection = WENO(),
coriolis = nothing,
Expand Down
14 changes: 7 additions & 7 deletions test/test_hydrostatic_free_surface_models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ topos_3d = ((Periodic, Periodic, Bounded),
grid = RectilinearGrid(topology=topo, size=(1, 1, 1), extent=(1, 2, 3), halo=(1, 1, 1))
hcabd_closure = ScalarBiharmonicDiffusivity()

@test_throws ArgumentError HydrostaticFreeSurfaceModel(grid=grid, tracer_advection=CenteredFourthOrder())
@test_throws ArgumentError HydrostaticFreeSurfaceModel(grid=grid, tracer_advection=UpwindBiasedThirdOrder())
@test_throws ArgumentError HydrostaticFreeSurfaceModel(grid=grid, tracer_advection=UpwindBiasedFifthOrder())
@test_throws ArgumentError HydrostaticFreeSurfaceModel(grid=grid, momentum_advection=UpwindBiasedFifthOrder())
@test_throws ArgumentError HydrostaticFreeSurfaceModel(grid=grid, tracer_advection=Centered(order=4))
@test_throws ArgumentError HydrostaticFreeSurfaceModel(grid=grid, tracer_advection=UpwindBiased(order=3))
@test_throws ArgumentError HydrostaticFreeSurfaceModel(grid=grid, tracer_advection=UpwindBiased(order=5))
@test_throws ArgumentError HydrostaticFreeSurfaceModel(grid=grid, momentum_advection=UpwindBiased(order=5))
@test_throws ArgumentError HydrostaticFreeSurfaceModel(grid=grid, closure=hcabd_closure)

# Big enough
Expand All @@ -146,13 +146,13 @@ topos_3d = ((Periodic, Periodic, Bounded),
model = HydrostaticFreeSurfaceModel(grid=bigger_grid, closure=hcabd_closure)
@test model isa HydrostaticFreeSurfaceModel

model = HydrostaticFreeSurfaceModel(grid=bigger_grid, momentum_advection=UpwindBiasedFifthOrder())
model = HydrostaticFreeSurfaceModel(grid=bigger_grid, momentum_advection=UpwindBiased(order=5))
@test model isa HydrostaticFreeSurfaceModel

model = HydrostaticFreeSurfaceModel(grid=bigger_grid, closure=hcabd_closure)
@test model isa HydrostaticFreeSurfaceModel

model = HydrostaticFreeSurfaceModel(grid=bigger_grid, tracer_advection=UpwindBiasedFifthOrder())
model = HydrostaticFreeSurfaceModel(grid=bigger_grid, tracer_advection=UpwindBiased(order=5))
@test model isa HydrostaticFreeSurfaceModel
end
end
Expand Down Expand Up @@ -246,7 +246,7 @@ topos_3d = ((Periodic, Periodic, Bounded),
end
end

for momentum_advection in (VectorInvariant(), WENOVectorInvariant(), CenteredSecondOrder(), WENO())
for momentum_advection in (VectorInvariant(), WENOVectorInvariant(), Centered(), WENO())
@testset "Time-stepping HydrostaticFreeSurfaceModels [$arch, $(typeof(momentum_advection))]" begin
@info " Testing time-stepping HydrostaticFreeSurfaceModels [$arch, $(typeof(momentum_advection))]..."
@test time_step_hydrostatic_model_works(rectilinear_grid; momentum_advection)
Expand Down
4 changes: 2 additions & 2 deletions test/test_nonhydrostatic_models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ using Oceananigans.Grids: required_halo_size_x, required_halo_size_y, required_h
@test model.grid.Hx == 1 && model.grid.Hy == 3 && model.grid.Hz == 4

# Model ensures that halos are at least of size 2
for scheme in (CenteredFourthOrder(), UpwindBiasedThirdOrder())
for scheme in (Centered(order=4), UpwindBiased(order=3))
model = NonhydrostaticModel(advection=scheme, grid=minimal_grid)
@test model.grid.Hx == 2 && model.grid.Hy == 2 && model.grid.Hz == 2

Expand All @@ -54,7 +54,7 @@ using Oceananigans.Grids: required_halo_size_x, required_halo_size_y, required_h
end

# Model ensures that halos are at least of size 3
for scheme in (WENO(), UpwindBiasedFifthOrder())
for scheme in (WENO(), UpwindBiased(order=5))
model = NonhydrostaticModel(advection=scheme, grid=minimal_grid)
@test model.grid.Hx == 3 && model.grid.Hy == 3 && model.grid.Hz == 3

Expand Down
2 changes: 1 addition & 1 deletion test/test_shallow_water_models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ end
end

# Advection = nothing is broken as halo does not have a maximum
for advection in (nothing, CenteredSecondOrder(), WENO())
for advection in (nothing, Centered(), WENO())
@testset "Time-stepping ShallowWaterModels [$arch, $(typeof(advection))]" begin
@info " Testing time-stepping ShallowWaterModels [$arch, $(typeof(advection))]..."
@test time_stepping_shallow_water_model_works(arch, topos[1], nothing, advection)
Expand Down
Loading

0 comments on commit 37d0e29

Please sign in to comment.