Skip to content

Commit

Permalink
(0.90.12) Bugfix for SpitExplicitFreeSurface on MultiRegionGrids …
Browse files Browse the repository at this point in the history
…and make `SpitExplicitFreeSurface` the default + don't allow more halos than interior points (#3514)

* code cleanup

* cleanup

* MultiRegionGrids default to SplitExplicitFreeSurface

* fix typo

* cleaner Nsubsteps

* code cleaning

* provide g

* fix to not reduce the number of halos

* small bugfix

* ensure that the test does not create a halo region bigger than the grid's interior

* ensure halo ≤ size for each non-Flat dim

* default halo size is not less than corresponding dim size

* more informative argument error

* use coordinate_name

* remove debug

* use map instead of broadcast

Co-authored-by: Gregory L. Wagner <[email protected]>

* Update src/MultiRegion/multi_region_grid.jl

Co-authored-by: Simone Silvestri <[email protected]>

* set! calls initialize!(model)

* minor fix in docstring

* fix tests

* fix tests

* only enforce halo <= size for horizontal coords

* better and cleaner

* fix error msg

* fix tests

* fix test and add back some skipped tests

* fix tests

* fix tests

* fix tests

* fix tests

* fix tests

* fix tests

* fix tests

* fix tests

* fix doctests

* fix doctests

* fix doctests

* κ -> ν

* fix tests

* bump patch release

* fix tests

* fix doctests

* clean up conformal_cubed_sphere_panel from file

* clean up conformal_cubed_sphere_panel from file

* clean up conformal_cubed_sphere_panel from file

* fix tests

* fix tests

---------

Co-authored-by: Simone Silvestri <[email protected]>
Co-authored-by: Gregory L. Wagner <[email protected]>
Co-authored-by: Simone Silvestri <[email protected]>
  • Loading branch information
4 people committed Apr 8, 2024
1 parent 4666469 commit ce4faba
Show file tree
Hide file tree
Showing 42 changed files with 276 additions and 230 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Oceananigans"
uuid = "9e8cae18-63c1-5223-a75c-80ca9d6e9a09"
authors = ["Climate Modeling Alliance and contributors"]
version = "0.90.11"
version = "0.90.12"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
4 changes: 2 additions & 2 deletions docs/src/model_setup/background_fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ model.background_fields.velocities.u
# output
FunctionField located at (Face, Center, Center)
├── func: U (generic function with 1 method)
├── grid: 1×1×1 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 3×3×3 halo
├── grid: 1×1×1 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 1×1×1 halo
├── clock: Clock(time=0 seconds, iteration=0, last_Δt=Inf days)
└── parameters: nothing
```
Expand Down Expand Up @@ -101,7 +101,7 @@ model.background_fields.tracers.b
# output
FunctionField located at (Center, Center, Center)
├── func: B (generic function with 1 method)
├── grid: 1×1×1 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 3×3×3 halo
├── grid: 1×1×1 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 1×1×1 halo
├── clock: Clock(time=0 seconds, iteration=0, last_Δt=Inf days)
└── parameters: (α = 3.14, N = 1.0, f = 0.1)
```
10 changes: 5 additions & 5 deletions docs/src/model_setup/boundary_conditions.md
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,11 @@ julia> velocity_bcs = FieldBoundaryConditions(immersed=ValueBoundaryCondition(0.
julia> model = NonhydrostaticModel(; grid, boundary_conditions=(u=velocity_bcs, v=velocity_bcs, w=velocity_bcs));
┌ Warning: `ImmersedBoundaryCondition` is experimental.
└ @ Oceananigans.ImmersedBoundaries ~/repos/Oceananigans.jl3/src/ImmersedBoundaries/immersed_boundary_condition.jl:54
└ @ Oceananigans.ImmersedBoundaries ~/Oceananigans.jl/src/ImmersedBoundaries/immersed_boundary_condition.jl:54
┌ Warning: `ImmersedBoundaryCondition` is experimental.
└ @ Oceananigans.ImmersedBoundaries ~/repos/Oceananigans.jl3/src/ImmersedBoundaries/immersed_boundary_condition.jl:54
└ @ Oceananigans.ImmersedBoundaries ~/Oceananigans.jl/src/ImmersedBoundaries/immersed_boundary_condition.jl:54
┌ Warning: `ImmersedBoundaryCondition` is experimental.
└ @ Oceananigans.ImmersedBoundaries ~/repos/Oceananigans.jl3/src/ImmersedBoundaries/immersed_boundary_condition.jl:54
└ @ Oceananigans.ImmersedBoundaries ~/Oceananigans.jl/src/ImmersedBoundaries/immersed_boundary_condition.jl:54
julia> model.velocities.w.boundary_conditions.immersed
ImmersedBoundaryCondition:
Expand All @@ -477,7 +477,7 @@ cells may also be specified by manually building an `ImmersedBoundaryCondition`:
```jldoctest; filter = r".*@ Oceananigans.ImmersedBoundaries.*"
julia> bottom_drag_bc = ImmersedBoundaryCondition(bottom=ValueBoundaryCondition(0.0))
┌ Warning: `ImmersedBoundaryCondition` is experimental.
└ @ Oceananigans.ImmersedBoundaries ~/repos/Oceananigans.jl3/src/ImmersedBoundaries/immersed_boundary_condition.jl:54
└ @ Oceananigans.ImmersedBoundaries ~/Oceananigans.jl/src/ImmersedBoundaries/immersed_boundary_condition.jl:54
ImmersedBoundaryCondition:
├── west: Nothing
├── east: Nothing
Expand Down Expand Up @@ -532,7 +532,7 @@ FluxBoundaryCondition: ContinuousBoundaryFunction immersed_linear_drag at (Nothi
julia> u_immersed_bc = ImmersedBoundaryCondition(bottom = immersed_drag_u)
┌ Warning: `ImmersedBoundaryCondition` is experimental.
└ @ Oceananigans.ImmersedBoundaries ~/repos/Oceananigans.jl3/src/ImmersedBoundaries/immersed_boundary_condition.jl:54
└ @ Oceananigans.ImmersedBoundaries ~/Oceananigans.jl/src/ImmersedBoundaries/immersed_boundary_condition.jl:54
ImmersedBoundaryCondition:
├── west: Nothing
├── east: Nothing
Expand Down
6 changes: 3 additions & 3 deletions docs/src/model_setup/output_writers.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ JLD2OutputWriter scheduled on TimeInterval(20 minutes):
├── array type: Array{Float64}
├── including: [:grid, :coriolis, :buoyancy, :closure]
├── file_splitting: NoFileSplitting
└── file size: 27.4 KiB
└── file size: 27.2 KiB
```

and a time- and horizontal-average of tracer `c` every 20 minutes of simulation time
Expand All @@ -223,7 +223,7 @@ JLD2OutputWriter scheduled on TimeInterval(20 minutes):
├── array type: Array{Float64}
├── including: [:grid, :coriolis, :buoyancy, :closure]
├── file_splitting: NoFileSplitting
└── file size: 17.5 KiB
└── file size: 17.3 KiB
```


Expand Down Expand Up @@ -280,5 +280,5 @@ JLD2OutputWriter scheduled on TimeInterval(4 days):
├── array type: Array{Float64}
├── including: [:grid, :coriolis, :buoyancy, :closure]
├── file_splitting: NoFileSplitting
└── file size: 26.7 KiB
└── file size: 26.5 KiB
```
2 changes: 1 addition & 1 deletion src/AbstractOperations/binary_operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ julia> c, d = (CenterField(RectilinearGrid(size=(1, 1, 1), extent=(1, 1, 1))) fo
julia> plus_or_times(c, d)
BinaryOperation at (Center, Center, Center)
├── grid: 1×1×1 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 3×3×3 halo
├── grid: 1×1×1 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 1×1×1 halo
└── tree:
plus_or_times at (Center, Center, Center)
   ├── 1×1×1 Field{Center, Center, Center} on RectilinearGrid on CPU
Expand Down
2 changes: 1 addition & 1 deletion src/AbstractOperations/conditional_operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ julia> c = CenterField(RectilinearGrid(size=(2, 1, 1), extent=(1, 1, 1)));
julia> f(i, j, k, grid, c) = i < 2; d = condition_operand(cos, c, f, 10)
ConditionalOperation at (Center, Center, Center)
├── operand: 2×1×1 Field{Center, Center, Center} on RectilinearGrid on CPU
├── grid: 2×1×1 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 3×3×3 halo
├── grid: 2×1×1 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 2×1×1 halo
├── func: cos (generic function with 40 methods)
├── condition: f (generic function with 1 method)
└── mask: 10
Expand Down
4 changes: 2 additions & 2 deletions src/AbstractOperations/grid_metrics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ julia> c = CenterField(RectilinearGrid(size=(1, 1, 1), extent=(1, 2, 3)));
julia> c_dz = c * Δz # returns BinaryOperation between Field and GridMetricOperation
BinaryOperation at (Center, Center, Center)
├── grid: 1×1×1 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 3×3×3 halo
├── grid: 1×1×1 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 1×1×1 halo
└── tree:
* at (Center, Center, Center)
   ├── 1×1×1 Field{Center, Center, Center} on RectilinearGrid on CPU
Expand Down Expand Up @@ -89,7 +89,7 @@ julia> c .= 1;
julia> c_dV = c * volume
BinaryOperation at (Center, Center, Center)
├── grid: 2×2×2 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 3×3×3 halo
├── grid: 2×2×2 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 2×2×2 halo
└── tree:
* at (Center, Center, Center)
   ├── 2×2×2 Field{Center, Center, Center} on RectilinearGrid on CPU
Expand Down
10 changes: 5 additions & 5 deletions src/AbstractOperations/kernel_function_operation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ struct KernelFunctionOperation{LX, LY, LZ, G, T, K, D} <: AbstractOperation{LX,
grid = RectilinearGrid(size=(1, 8, 8), extent=(1, 1, 1));
random_kernel_function(i, j, k, grid) = rand(); # use CUDA.rand on the GPU
kernel_op = KernelFunctionOperation{Center, Center, Center}(random_kernel_function, grid)
# output
KernelFunctionOperation at (Center, Center, Center)
├── grid: 1×8×8 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 3×3×3 halo
├── grid: 1×8×8 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 1×3×3 halo
├── kernel_function: random_kernel_function (generic function with 1 method)
└── arguments: ()
```
Expand All @@ -47,15 +47,15 @@ struct KernelFunctionOperation{LX, LY, LZ, G, T, K, D} <: AbstractOperation{LX,
using Oceananigans.Operators: ζ₃ᶠᶠᶜ # called with signature ζ₃ᶠᶠᶜ(i, j, k, grid, u, v)
model = HydrostaticFreeSurfaceModel(; grid);
u, v, w = model.velocities;
ζ_op = KernelFunctionOperation{Face, Face, Center}(ζ₃ᶠᶠᶜ, grid, u, v)
# output
KernelFunctionOperation at (Face, Face, Center)
├── grid: 1×8×8 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 3×3×3 halo
├── grid: 1×8×8 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 1×3×3 halo
├── kernel_function: ζ₃ᶠᶠᶜ (generic function with 1 method)
└── arguments: ("1×8×8 Field{Face, Center, Center} on RectilinearGrid on CPU", "1×8×8 Field{Center, Face, Center} on RectilinearGrid on CPU")
```
Expand Down
4 changes: 2 additions & 2 deletions src/AbstractOperations/multiary_operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ julia> c, d, e = Tuple(CenterField(RectilinearGrid(size=(1, 1, 1), extent=(1, 1,
julia> harmonic_plus(c, d, e) # before magic @multiary transformation
BinaryOperation at (Center, Center, Center)
├── grid: 1×1×1 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 3×3×3 halo
├── grid: 1×1×1 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 1×1×1 halo
└── tree:
* at (Center, Center, Center)
   ├── 0.3333333333333333
Expand All @@ -103,7 +103,7 @@ Set{Any} with 3 elements:
julia> harmonic_plus(c, d, e)
MultiaryOperation at (Center, Center, Center)
├── grid: 1×1×1 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 3×3×3 halo
├── grid: 1×1×1 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 1×1×1 halo
└── tree:
harmonic_plus at (Center, Center, Center)
   ├── 1×1×1 Field{Center, Center, Center} on RectilinearGrid on CPU
Expand Down
2 changes: 1 addition & 1 deletion src/AbstractOperations/unary_operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ julia> c = CenterField(RectilinearGrid(size=(1, 1, 1), extent=(1, 1, 1)));
julia> square_it(c)
UnaryOperation at (Center, Center, Center)
├── grid: 1×1×1 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 3×3×3 halo
├── grid: 1×1×1 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 1×1×1 halo
└── tree:
square_it at (Center, Center, Center) via identity
   └── 1×1×1 Field{Center, Center, Center} on RectilinearGrid on CPU
Expand Down
2 changes: 1 addition & 1 deletion src/BuoyancyModels/buoyancy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ model = NonhydrostaticModel(; grid, buoyancy, tracers=:b)
# output
NonhydrostaticModel{CPU, RectilinearGrid}(time = 0 seconds, iteration = 0)
├── grid: 1×8×8 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 3×3×3 halo
├── grid: 1×8×8 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 1×3×3 halo
├── timestepper: QuasiAdamsBashforth2TimeStepper
├── advection scheme: Centered reconstruction order 2
├── tracers: b
Expand Down
20 changes: 10 additions & 10 deletions src/Fields/field.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ julia> grid = RectilinearGrid(size=(2, 3, 4), extent=(1, 1, 1));
julia> ω = Field{Face, Face, Center}(grid)
2×3×4 Field{Face, Face, Center} on RectilinearGrid on CPU
├── grid: 2×3×4 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 3×3×3 halo
├── grid: 2×3×4 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 2×3×3 halo
├── boundary conditions: FieldBoundaryConditions
│ └── west: Periodic, east: Periodic, south: Periodic, north: Periodic, bottom: ZeroFlux, top: ZeroFlux, immersed: ZeroFlux
└── data: 8×9×10 OffsetArray(::Array{Float64, 3}, -2:5, -2:6, -2:7) with eltype Float64 with indices -2:5×-2:6×-2:7
└── data: 6×9×10 OffsetArray(::Array{Float64, 3}, -1:4, -2:6, -2:7) with eltype Float64 with indices -1:4×-2:6×-2:7
└── max=0.0, min=0.0, mean=0.0
```
Expand All @@ -138,24 +138,24 @@ julia> u = XFaceField(grid); v = YFaceField(grid);
julia> ωₛ = Field(∂x(v) - ∂y(u), indices=(:, :, grid.Nz))
2×3×1 Field{Face, Face, Center} on RectilinearGrid on CPU
├── grid: 2×3×4 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 3×3×3 halo
├── grid: 2×3×4 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 2×3×3 halo
├── boundary conditions: FieldBoundaryConditions
│ └── west: Periodic, east: Periodic, south: Periodic, north: Periodic, bottom: Nothing, top: Nothing, immersed: ZeroFlux
├── indices: (:, :, 4:4)
├── operand: BinaryOperation at (Face, Face, Center)
├── status: time=0.0
└── data: 8×9×1 OffsetArray(::Array{Float64, 3}, -2:5, -2:6, 4:4) with eltype Float64 with indices -2:5×-2:6×4:4
└── data: 6×9×1 OffsetArray(::Array{Float64, 3}, -1:4, -2:6, 4:4) with eltype Float64 with indices -1:4×-2:6×4:4
└── max=0.0, min=0.0, mean=0.0
julia> compute!(ωₛ)
2×3×1 Field{Face, Face, Center} on RectilinearGrid on CPU
├── grid: 2×3×4 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 3×3×3 halo
├── grid: 2×3×4 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 2×3×3 halo
├── boundary conditions: FieldBoundaryConditions
│ └── west: Periodic, east: Periodic, south: Periodic, north: Periodic, bottom: Nothing, top: Nothing, immersed: ZeroFlux
├── indices: (:, :, 4:4)
├── operand: BinaryOperation at (Face, Face, Center)
├── status: time=0.0
└── data: 8×9×1 OffsetArray(::Array{Float64, 3}, -2:5, -2:6, 4:4) with eltype Float64 with indices -2:5×-2:6×4:4
└── data: 6×9×1 OffsetArray(::Array{Float64, 3}, -1:4, -2:6, 4:4) with eltype Float64 with indices -1:4×-2:6×4:4
└── max=0.0, min=0.0, mean=0.0
```
"""
Expand Down Expand Up @@ -276,21 +276,21 @@ julia> grid = RectilinearGrid(size=(2, 3, 4), x=(0, 1), y=(0, 1), z=(0, 1));
julia> c = CenterField(grid)
2×3×4 Field{Center, Center, Center} on RectilinearGrid on CPU
├── grid: 2×3×4 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 3×3×3 halo
├── grid: 2×3×4 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 2×3×3 halo
├── boundary conditions: FieldBoundaryConditions
│ └── west: Periodic, east: Periodic, south: Periodic, north: Periodic, bottom: ZeroFlux, top: ZeroFlux, immersed: ZeroFlux
└── data: 8×9×10 OffsetArray(::Array{Float64, 3}, -2:5, -2:6, -2:7) with eltype Float64 with indices -2:5×-2:6×-2:7
└── data: 6×9×10 OffsetArray(::Array{Float64, 3}, -1:4, -2:6, -2:7) with eltype Float64 with indices -1:4×-2:6×-2:7
└── max=0.0, min=0.0, mean=0.0
julia> c .= rand(size(c)...);
julia> v = view(c, :, 2:3, 1:2)
2×2×2 Field{Center, Center, Center} on RectilinearGrid on CPU
├── grid: 2×3×4 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 3×3×3 halo
├── grid: 2×3×4 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 2×3×3 halo
├── boundary conditions: FieldBoundaryConditions
│ └── west: Periodic, east: Periodic, south: Nothing, north: Nothing, bottom: Nothing, top: Nothing, immersed: ZeroFlux
├── indices: (:, 2:3, 1:2)
└── data: 8×2×2 OffsetArray(view(::Array{Float64, 3}, :, 5:6, 4:5), -2:5, 2:3, 1:2) with eltype Float64 with indices -2:5×2:3×1:2
└── data: 6×2×2 OffsetArray(view(::Array{Float64, 3}, :, 5:6, 4:5), -1:4, 2:3, 1:2) with eltype Float64 with indices -1:4×2:3×1:2
└── max=0.972136, min=0.0149088, mean=0.59198
julia> size(v)
Expand Down
2 changes: 1 addition & 1 deletion src/Grids/automatic_halo_sizing.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
required_halo_size(tendency_term)
Returns the required size of halos for a term appearing
Return the required size of halos for a term appearing
in the tendency for a velocity field or tracer field.
Example
Expand Down
51 changes: 38 additions & 13 deletions src/Grids/input_validation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ using Oceananigans: tupleit
##### Some validation tools
#####

# Tuple inflation for topologies with Flat dimensions
# Tuple inflation/deflation for topologies with Flat dimensions

"adds tup element with `default` value for flat dimensions"
inflate_tuple(TX, TY, TZ, tup; default) = tup

inflate_tuple(::Type{Flat}, TY, TZ, tup; default) = tuple(default, tup[1], tup[2])
Expand All @@ -17,13 +19,26 @@ inflate_tuple(::Type{Flat}, ::Type{Flat}, TZ, tup; default) = (default, default,

inflate_tuple(::Type{Flat}, ::Type{Flat}, ::Type{Flat}, tup; default) = (default, default, default)

"removes tup elements that correspond to flat dimensions"
deflate_tuple(TX, TY, TZ, tup) = tup

deflate_tuple(::Type{Flat}, TY, TZ, tup) = tuple(tup[2], tup[3])
deflate_tuple(TY, ::Type{Flat}, TZ, tup) = tuple(tup[1], tup[3])
deflate_tuple(TY, TZ, ::Type{Flat}, tup) = tuple(tup[1], tup[2])

deflate_tuple(TX, ::Type{Flat}, ::Type{Flat}, tup) = (tup[1],)
deflate_tuple(::Type{Flat}, TY, ::Type{Flat}, tup) = (tup[2],)
deflate_tuple(::Type{Flat}, ::Type{Flat}, TZ, tup) = (tup[3],)

deflate_tuple(::Type{Flat}, ::Type{Flat}, ::Type{Flat}, tup) = ()

topological_tuple_length(TX, TY, TZ) = sum(T === Flat ? 0 : 1 for T in (TX, TY, TZ))

"""Validate that an argument tuple is the right length and has elements of type `argtype`."""
function validate_tupled_argument(arg, argtype, argname, len=3; greater_than=0)
length(arg) == len || throw(ArgumentError("length($argname) must be $len."))
all(isa.(arg, argtype)) || throw(ArgumentError("$argname=$arg must contain $(argtype)s."))
all(arg .> greater_than) || throw(ArgumentError("Elements of $argname=$arg must be > $(greater_than)!"))
length(arg) == len || throw(ArgumentError("length($argname) must be $len."))
all(isa.(arg, argtype)) || throw(ArgumentError("$argname=$arg must contain $(argtype)s."))
all(arg .> greater_than) || throw(ArgumentError("Elements of $argname=$arg must be > $(greater_than)!"))
return nothing
end

Expand All @@ -49,21 +64,31 @@ function validate_size(TX, TY, TZ, sz)
return inflate_tuple(TX, TY, TZ, sz, default=1)
end

# Note that the default halo size is specified to be 1 in the following function.
# This is easily changed but many of the tests will fail so this situation needs to be
# Note that if provided with halo=nothing, the default halo size for coord i
# is the min(default_halo_size, size[i]).
# While this is easy to change, many of tests might fail so this situation needs to be
# cleaned up.
function validate_halo(TX, TY, TZ, ::Nothing)
halo = Tuple(3 for i = 1:topological_tuple_length(TX, TY, TZ))
return validate_halo(TX, TY, TZ, halo)
function validate_halo(TX, TY, TZ, size, ::Nothing)
maximum_halo = size
default_halo = (3, 3, 3)
halo = map(min, default_halo, maximum_halo)
halo = deflate_tuple(TX, TY, TZ, halo)
return validate_halo(TX, TY, TZ, size, halo)
end

function validate_halo(TX, TY, TZ, halo)
coordinate_name(i) = i == 1 ? "x" : i == 2 ? "y" : "z"

function validate_halo(TX, TY, TZ, size, halo)
halo = tupleit(halo)
validate_tupled_argument(halo, Integer, "halo", topological_tuple_length(TX, TY, TZ))
return inflate_tuple(TX, TY, TZ, halo, default=0)
end
halo = inflate_tuple(TX, TY, TZ, halo, default=0)

coordinate_name(i) = i == 1 ? "x" : i == 2 ? "y" : "z"
for i in 1:2
!(halo[i] size[i]) && throw(ArgumentError("halo must be ≤ size for coordinate $(coordinate_name(i))"))
end

return halo
end

function validate_dimension_specification(T, ξ, dir, N, FT)

Expand Down
2 changes: 1 addition & 1 deletion src/Grids/latitude_longitude_grid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ function validate_lat_lon_grid_args(topology, size, halo, FT, latitude, longitud
latitude = validate_dimension_specification(TY, latitude, :latitude, Nφ, FT)
z = validate_dimension_specification(TZ, z, :z, Nz, FT)

halo = validate_halo(TX, TY, TZ, halo)
halo = validate_halo(TX, TY, TZ, size, halo)
topology = (TX, TY, TZ)

return topology, size, halo, latitude, longitude, z, precompute_metrics
Expand Down
Loading

2 comments on commit ce4faba

@navidcy
Copy link
Collaborator Author

@navidcy navidcy commented on ce4faba Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/104446

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.90.12 -m "<description of version>" ce4fabaa0c6ddfd20ae43c671bbaec7bb5dae847
git push origin v0.90.12

Please sign in to comment.