Skip to content

Transposed RingGrids.jl #802

@milankl

Description

@milankl

For parameterizations and also other vertically dominant components like a land model it would be good to have RingGrids that are transposed that means the vertical dimension comes first. Some ideas of how to do this:

  1. Where is the horizontal dimension? This could come 2nd or last. I believe in terms of memory access patterns 2nd is better and probably also easier to implement than last.
  2. It should be possible to transpose(field) that does not move or allocate any data, like transpose(::Array) works too
  3. It should be possible to transpose!(field) that transposes the data underlying field in-place and somehow declares the transposition in the field (or the grid). I'm leaning towards thinking about field.grid as the same whether it's a transposed field or not.

My first idea for an implementation would be to define

struct ColumnField{T, N, ArrayType <: AbstractArray, Grid <: AbstractGrid} <: AbstractField{T, N, ArrayType, Grid}
    data::ArrayType
    grid::Grid
end

# a view on data shared by Field and ColumnField
transpose(field::Field3D) = ColumnField(transpose(field.data), field.grid)

# corrupting field.data but returnin a ColumnField such that if treated as read-only
# would allow one to reuse the original field after another tranpose!
tranpose!(field::Field3D) = ColumnField(tranpose!(field.data), field.grid)

On 1. note that here I defined methods for ::Field3D one would need to implement ::Field4D and make a decision on where to tranpose the horizontal dimension to.

On 2. I don't see many problems here.

On 3. tranpose! currently does seem to exist and implementing this for non-square matrices isn't straight forward it seems but I'm sure people have solved this. Leaving the horizontal dimension 2nd would also make it easier to just loop tranpose! over all 3rd, 4th etc dimensions.

Most functionality in RingGrids.jl and SpeedyWeather is currently defined for AbstractField but would break with a ColumnField so a bunch of additional methods would be required for ::ColumnField but it's like object inheritance where we'd need to define all exceptions.

@bgroenks96 @maximilian-gelbrecht what do you think?

Metadata

Metadata

Labels

array types 🔢LowerTriangularMatrices and RingGridsgrid 🌐Points on a sphere

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions