diff --git a/docs/src/fields.md b/docs/src/fields.md index e37215ee48..6d94b51c53 100644 --- a/docs/src/fields.md +++ b/docs/src/fields.md @@ -1,7 +1,7 @@ # Fields basics `Field`s and its relatives are core Oceananigans data structures. -`Field`s are more or less arrays of `data` located on a `grid`, whose entries +`Field`s are more or less arrays of _three dimensional_ `data` located on a `grid`, whose entries correspond to the average value of some quantity over some finite-sized volume. `Field`s also may contain `boundary_conditions`, may be computed from an `operand` or expression involving other fields, and may cover only a portion of the total @@ -326,7 +326,8 @@ heatmap(view(c, :, :, 1)) For `Field`s on three-dimensional grids, `set!` functions must have arguments `x, y, z` for `RectilinearGrid`, or `λ, φ, z` for `LatitudeLongitudeGrid` and `OrthogonalSphericalShellGrid`. But for `Field`s on one- and two-dimensional grids, only the arguments that correspond to the -non-`Flat` directions must be included. For example, to `set!` on a one-dimensional grid we write +non-`Flat` directions must be included. +For example, to `set!` on a one-dimensional grid we write ```jldoctest fields # Make a field on a one-dimensional grid @@ -346,6 +347,11 @@ set!(one_d_c, still_pretty_fun) └── max=19.5, min=1.5, mean=10.5 ``` +!!! note + Despite we `set` a `Field` with reduced arguments in the `Flat` directions, a `Field` remains + intrinsically a three-dimensional object as it maps to a three-dimensional data structure. + For this reason a `Field` must be always indexed by providing all three indices `i, j, k`. + ### A bit more about setting with functions Let's return to the three-dimensional `fun_stuff` case to investigate in more detail how `set!` works with functions. diff --git a/src/Fields/abstract_field.jl b/src/Fields/abstract_field.jl index bdc5add9e1..bf53f9a8d7 100644 --- a/src/Fields/abstract_field.jl +++ b/src/Fields/abstract_field.jl @@ -102,7 +102,7 @@ interior(f::AbstractField) = f ##### Coordinates of fields ##### -@propagate_inbounds node(i, j, k, ψ::AbstractField) = node(i, j, k, ψ.grid, instantiated_location(ψ)...) +@propagate_inbounds node(i, j, k, ψ::AbstractField) = node(i, j, k, ψ.grid, instantiated_location(ψ)...) @propagate_inbounds xnode(i, j, k, ψ::AbstractField) = xnode(i, j, k, ψ.grid, instantiated_location(ψ)...) @propagate_inbounds ynode(i, j, k, ψ::AbstractField) = ynode(i, j, k, ψ.grid, instantiated_location(ψ)...) @propagate_inbounds znode(i, j, k, ψ::AbstractField) = znode(i, j, k, ψ.grid, instantiated_location(ψ)...) diff --git a/test/test_field.jl b/test/test_field.jl index 3039d03baa..a8f9bfa3dd 100644 --- a/test/test_field.jl +++ b/test/test_field.jl @@ -5,7 +5,7 @@ using Statistics using Oceananigans.Fields: ReducedField, has_velocities using Oceananigans.Fields: VelocityFields, TracerFields, interpolate, interpolate! using Oceananigans.Fields: reduced_location -using Oceananigans.Fields: FractionalIndices, interpolator +using Oceananigans.Fields: fractional_indices, interpolator using Oceananigans.Fields: convert_to_0_360, convert_to_λ₀_λ₀_plus360 using Oceananigans.Grids: ξnode, ηnode, rnode using Oceananigans.Grids: total_length @@ -492,11 +492,11 @@ end for X in Xs (x, y, z) = X - fi = @allowscalar FractionalIndices(X, grid, loc, loc, loc) + fi, fj, fk = @allowscalar fractional_indices(X, grid, loc, loc, loc) - i⁻, i⁺, _ = interpolator(fi.i) - j⁻, j⁺, _ = interpolator(fi.j) - k⁻, k⁺, _ = interpolator(fi.k) + i⁻, i⁺, _ = interpolator(fi) + j⁻, j⁺, _ = interpolator(fj) + k⁻, k⁺, _ = interpolator(fk) x⁻ = @allowscalar ξnode(i⁻, j⁻, k⁻, grid, loc, loc, loc) y⁻ = @allowscalar ηnode(i⁻, j⁻, k⁻, grid, loc, loc, loc)