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

Grid constructors do not check correct ordering of array-based coordinates #3307

Closed
glwagner opened this issue Oct 4, 2023 · 1 comment · Fixed by #3319
Closed

Grid constructors do not check correct ordering of array-based coordinates #3307

glwagner opened this issue Oct 4, 2023 · 1 comment · Fixed by #3319
Labels
good first issue 🐤 Let us know if you're interested in working on this! grids 🗺️ user interface/experience 💻

Comments

@glwagner
Copy link
Member

glwagner commented Oct 4, 2023

We do check that intervals are increasing:

julia> using Oceananigans

julia> grid = RectilinearGrid(size=2, z=(0, -1), topology=(Flat, Flat, Bounded))
ERROR: ArgumentError: z=(0, -1) should be an increasing interval.
Stacktrace:
 [1] validate_dimension_specification(T::Type, ξ::Tuple{Int64, Int64}, dir::Symbol, N::Int64, FT::Type)
   @ Oceananigans.Grids ~/.julia/packages/Oceananigans/0y15B/src/Grids/input_validation.jl:73
 [2] validate_rectilinear_domain(TX::Type, TY::Type, TZ::Type, FT::Type, size::Tuple{Int64, Int64, Int64}, extent::Nothing, x::Nothing, y::Nothing, z::Tuple{Int64, Int64})
   @ Oceananigans.Grids ~/.julia/packages/Oceananigans/0y15B/src/Grids/input_validation.jl:100
 [3] validate_rectilinear_grid_args(topology::Tuple{DataType, DataType, DataType}, size::Int64, halo::Nothing, FT::Type, extent::Nothing, x::Nothing, y::Nothing, z::Tuple{Int64, Int64})
   @ Oceananigans.Grids ~/.julia/packages/Oceananigans/0y15B/src/Grids/rectilinear_grid.jl:293
 [4] RectilinearGrid(architecture::CPU, FT::DataType; size::Int64, x::Nothing, y::Nothing, z::Tuple{Int64, Int64}, halo::Nothing, extent::Nothing, topology::Tuple{DataType, DataType, DataType})
   @ Oceananigans.Grids ~/.julia/packages/Oceananigans/0y15B/src/Grids/rectilinear_grid.jl:268
 [5] RectilinearGrid
   @ ~/.julia/packages/Oceananigans/0y15B/src/Grids/rectilinear_grid.jl:254 [inlined]
 [6] top-level scope
   @ REPL[4]:1

However, if we use explicit interfaces rather than an interval, the constructor seems to be happy:

julia> grid = RectilinearGrid(size=2, z=[0, -0.5, -1], topology=(Flat, Flat, Bounded))
1×1×2 RectilinearGrid{Float64, Flat, Flat, Bounded} on CPU with 0×0×3 halo
├── Flat x
├── Flat y
└── Bounded  z  [0.0, -1.0]      variably spaced with min(Δz)=-0.5, max(Δz)=-0.5

This grid is invalid but was able to be constructed. We should check that and throw an appropriate error so users don't get confused.

@navidcy
Copy link
Collaborator

navidcy commented Oct 5, 2023

Nice catch!

@navidcy navidcy added good first issue 🐤 Let us know if you're interested in working on this! grids 🗺️ labels Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue 🐤 Let us know if you're interested in working on this! grids 🗺️ user interface/experience 💻
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants