GridTools.jl
GridTools.Dimension
— Typeabstract type Dimension
Examples
julia> struct Cell_ <: Dimension end
julia> Cell = Cell_()
GridTools.Field
— TypeField(dims::Tuple, data::Array, broadcast_dims::Tuple)
Examples
julia> new_field = Field((Cell, K), fill(1.0, (3,2)))
3x2 Field with dims (Main.GridTools.Cell_(), Main.GridTools.K_()) and broadcasted_dims (Main.GridTools.Cell_(), Main.GridTools.K_()):
1.0 1.0
1.0 1.0
1.0 1.0
GridTools.Connectivity
— TypeConnectivity(data::Array, source::Tuple, target::Tuple, dims::Int)
Examples
julia> new_connectivity = Connectivity(fill(1, (3,2)), Cell, (Edge, E2C), 2)
3x2 Field with dims (Main.GridTools.Cell_(), Main.GridTools.K_()) and broadcasted_dims (Main.GridTools.Cell_(), Main.GridTools.K_()):
1 1
1 1
1 1
GridTools.where
— Functionwhere(mask::Field, true, false)
The 'where' loops over each entry of the mask and returns values corresponding to the same indexes of either the true or the false branch.
Arguments
mask::Field
: a field with eltype Booleantrue
: a tuple, a field, or a scalarfalse
: a tuple, a field, or a scalar
Examples
julia> mask = Field((Cell, K), rand(Bool, (3,3)))
3x3 Field with dims (Cell_(), K_()) and broadcasted_dims (Cell_(), K_()):
1 0 0
0 1 0
1 1 1
julia> a = Field((Cell, K), fill(1.0, (3,3)));
julia> b = Field((Cell, K), fill(2.0, (3,3)));
julia> where(mask, a, b)
3x3 Field with dims (Cell_(), K_()) and broadcasted_dims (Cell_(), K_()):
1.0 2.0 2.0
2.0 1.0 2.0
1.0 1.0 1.0
The where
function builtin also allows for nesting of tuples. In this scenario, it will first perform an unrolling: where(mask, ((a, b), (b, a)), ((c, d), (d, c)))
–> where(mask, (a, b), (c, d))
and where(mask, (b, a), (d, c))
and then combine results to match the return type:
GridTools.neighbor_sum
— Functionneighbor_sum(f::Field; axis::Dimension)
Sums along the axis dimension. Outputs a field with dimensions size(f.dims)-1.
GridTools.broadcast
— Functionbroadcast(f::Field, b_dims::Tuple)
Sets the broadcast dimension of Field f to b_dims