-
Notifications
You must be signed in to change notification settings - Fork 188
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
Bug in determination of indices of parent array by parent_index_range
#3572
Comments
Can you find another way to say this? I can't make sense of it --- how can an array "consider" something? |
What do you mean exactly with "the parent array should consider halos"? |
oh I just saw @glwagner was asking the same.. |
Btw I have no idea what's happening in the code you posted above @siddharthabishnu. Why When I run this on main I get: julia> using Oceananigans
julia> grid = RectilinearGrid(size=(3, 3, 1), x=(0, 1), y=(0, 1), z=(0, 1));
julia> model = HydrostaticFreeSurfaceModel(; grid,
momentum_advection = nothing,
free_surface = ExplicitFreeSurface(; gravitational_acceleration = 10),
closure = nothing,
tracers = nothing,
buoyancy = nothing)
HydrostaticFreeSurfaceModel{CPU, RectilinearGrid}(time = 0 seconds, iteration = 0)
├── grid: 3×3×1 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 3×3×1 halo
├── timestepper: QuasiAdamsBashforth2TimeStepper
├── tracers: ()
├── closure: Nothing
├── buoyancy: Nothing
├── free surface: ExplicitFreeSurface with gravitational acceleration 10.0 m s⁻²
├── advection scheme:
│ └── momentum: Nothing
└── coriolis: Nothing
julia> Hc, Nc, Nz = grid.Hx, grid.Nx, grid.Nz
(3, 3, 1) So given this ambiguity, I then don't even know what |
parent_index_range
I think this is a better MWE: julia> using Oceananigans
julia> grid = RectilinearGrid(size=(3, 3, 1), x=(0, 1), y=(0, 1), z=(0, 1));
julia> model = HydrostaticFreeSurfaceModel(; grid);
julia> view(model.free_surface.η, :, :, 2:2)
ERROR: BoundsError: attempt to access 9×9×1 Array{Float64, 3} at index [1:9, 1:9, 3:3]
Stacktrace:
[1] throw_boundserror(A::Array{Float64, 3}, I::Tuple{Base.Slice{Base.OneTo{Int64}}, Base.Slice{Base.OneTo{Int64}}, UnitRange{Int64}})
@ Base ./abstractarray.jl:734
[2] checkbounds
@ ./abstractarray.jl:699 [inlined]
[3] view
@ ./subarray.jl:179 [inlined]
[4] offset_windowed_data(data::OffsetArray{Float64, 3, Array{…}}, Loc::Tuple{DataType, DataType, DataType}, grid::RectilinearGrid{Float64, Periodic, Periodic, Bounded, Float64, Float64, Float64, OffsetVector{…}, OffsetVector{…}, OffsetVector{…}, CPU}, indices::Tuple{Colon, Colon, UnitRange{…}})
@ Oceananigans.Fields ~/Projects/Oceananigans.jl/src/Fields/field.jl:248
[5] view(f::Field{Center, Center, Face, Nothing, RectilinearGrid{…}, Tuple{…}, OffsetArray{…}, Float64, FieldBoundaryConditions{…}, Nothing, Oceananigans.Fields.FieldBoundaryBuffers{…}}, i::Function, j::Function, k::UnitRange{Int64})
@ Oceananigans.Fields ~/Projects/Oceananigans.jl/src/Fields/field.jl:316
[6] top-level scope
@ REPL[6]:1
Some type information was truncated. Use `show(err)` to see complete types. We should be able to call |
We don't even need to make a model (that makes the MWE take longer than it should): julia> grid = RectilinearGrid(size=(1, 2, 3), x=(0, 1), y=(0, 1), z=(0, 1))
1×2×3 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 1×2×3 halo
├── Periodic x ∈ [0.0, 1.0) regularly spaced with Δx=1.0
├── Periodic y ∈ [0.0, 1.0) regularly spaced with Δy=0.5
└── Bounded z ∈ [0.0, 1.0] regularly spaced with Δz=0.333333
julia> windowed = CenterField(grid, indices=(:, :, 2:2))
1×2×1 Field{Center, Center, Center} on RectilinearGrid on CPU
├── grid: 1×2×3 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 1×2×3 halo
├── boundary conditions: FieldBoundaryConditions
│ └── west: Periodic, east: Periodic, south: Periodic, north: Periodic, bottom: Nothing, top: Nothing, immersed: ZeroFlux
├── indices: (:, :, 2:2)
└── data: 3×6×1 OffsetArray(::Array{Float64, 3}, 0:2, -1:4, 2:2) with eltype Float64 with indices 0:2×-1:4×2:2
└── max=0.0, min=0.0, mean=0.0
julia> view(windowed, :, :, 2:2)
ERROR: BoundsError: attempt to access 3×6×1 Array{Float64, 3} at index [1:3, 1:6, 5:5]
Stacktrace:
[1] throw_boundserror(A::Array{Float64, 3}, I::Tuple{Base.Slice{Base.OneTo{Int64}}, Base.Slice{Base.OneTo{Int64}}, UnitRange{Int64}})
@ Base ./abstractarray.jl:734
[2] checkbounds
@ ./abstractarray.jl:699 [inlined]
[3] view
@ ./subarray.jl:179 [inlined]
[4] offset_windowed_data(data::OffsetArray{Float64, 3, Array{…}}, Loc::Tuple{DataType, DataType, DataType}, grid::RectilinearGrid{Float64, Periodic, Periodic, Bounded, Float64, Float64, Float64, OffsetVector{…}, OffsetVector{…}, OffsetVector{…}, CPU}, indices::Tuple{Colon, Colon, UnitRange{…}})
@ Oceananigans.Fields ~/Projects/Oceananigans.jl/src/Fields/field.jl:248
[5] view(f::Field{Center, Center, Center, Nothing, RectilinearGrid{…}, Tuple{…}, OffsetArray{…}, Float64, FieldBoundaryConditions{…}, Nothing, Oceananigans.Fields.FieldBoundaryBuffers{…}}, i::Function, j::Function, k::UnitRange{Int64})
@ Oceananigans.Fields ~/Projects/Oceananigans.jl/src/Fields/field.jl:316
[6] top-level scope
@ REPL[11]:1
Some type information was truncated. Use `show(err)` to see complete types. |
The bug is here: Oceananigans.jl/src/Grids/grid_utils.jl Line 226 in ed77780
I think it should just be parent_index_range(index::UnitRange, loc, topo, halo) = UnitRange(1, length(index)) 🤦 |
@navidcy, the title's been fixed and the issue identified with @glwagner. It's been resolved in commit bbfc656. Regarding your earlier query, the output of |
@siddharthabishnu, just copy-paste the input and output from the REPL directly. Don't edit the code snippet otherwise there is the danger of making a typo/mistake. |
btw, this -> #3260 seems related or duplicate of this issue? |
Agreed. I learnt that the hard way. I won't do it in the future. |
@navidcy, I concur that the issue remains unresolved. Initially, I thought it was addressed during the manual bounds-checking that @glwagner and I conducted together. However, since other tests are failing, we cannot proceed with merging this PR at this time. |
Well sure, we'll merge when it's sorted out. |
Consider the following MWE:
The error occurs because the parent array of
model.free_surface.η
takes the z-halo into consideration, which does not exist for the ssh field. Generally, when dealing with 1D or 2D fields, the parent array should consider halos only in the dimensions along which the field is defined, rather than in all dimensions as currently implemented. PR #3573 aims to close this issue.The text was updated successfully, but these errors were encountered: