Oceananigans.jl: Why is `w*T` is a `MultiaryOperation`?

Created on 1 Sep 2020  ยท  5Comments  ยท  Source: CliMA/Oceananigans.jl

I'd expect it to be a BinaryOperation?

using Oceananigans, Oceananigans.Grids,Oceananigans.Diagnostics, Oceananigans.AbstractOperations
grid = RegularCartesianGrid(size=(16, 16, 16), extent=(1, 1, 1))
model = IncompressibleModel(grid=grid)
u, v, w = model.velocities
T, S = model.tracers
wT = w*T
````

MultiaryOperation at (Cell, Cell, Face)
โ”œโ”€โ”€ grid: RegularCartesianGrid{Float64,Periodic,Periodic,Bounded,OffsetArrays.OffsetArray{Float64,1,StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}}
โ”‚ โ”œโ”€โ”€ size: (16, 16, 16)
โ”‚ โ””โ”€โ”€ domain: x โˆˆ [0.0, 1.0], y โˆˆ [0.0, 1.0], z โˆˆ [-1.0, 0.0625]
โ””โ”€โ”€ tree:

  • at (Cell, Cell, Face)
    โ”œโ”€โ”€ OffsetArray{Float64, 3, Array{Float64,3}}
    โ””โ”€โ”€ OffsetArray{Float64, 3, Array{Float64,3}}
    ```
bug ๐Ÿž

All 5 comments

Seems that when the fields are at different locations you get a MultiaryOperation and when it's the same location you get a BinaryOperation:

julia> u*T
MultiaryOperation at (Face, Cell, Cell)
โ”œโ”€โ”€ grid: RegularCartesianGrid{Float64,Periodic,Periodic,Bounded,OffsetArrays.OffsetArray{Float64,1,StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}}
โ”‚   โ”œโ”€โ”€ size: (16, 16, 16)
โ”‚   โ””โ”€โ”€ domain: x โˆˆ [0.0, 1.0], y โˆˆ [0.0, 1.0], z โˆˆ [-1.0, 0.0625]
โ””โ”€โ”€ tree: 

* at (Face, Cell, Cell)
โ”œโ”€โ”€ OffsetArray{Float64, 3, Array{Float64,3}}
โ””โ”€โ”€ OffsetArray{Float64, 3, Array{Float64,3}}

julia> u*v
MultiaryOperation at (Face, Cell, Cell)
โ”œโ”€โ”€ grid: RegularCartesianGrid{Float64,Periodic,Periodic,Bounded,OffsetArrays.OffsetArray{Float64,1,StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}}
โ”‚   โ”œโ”€โ”€ size: (16, 16, 16)
โ”‚   โ””โ”€โ”€ domain: x โˆˆ [0.0, 1.0], y โˆˆ [0.0, 1.0], z โˆˆ [-1.0, 0.0625]
โ””โ”€โ”€ tree: 

* at (Face, Cell, Cell)
โ”œโ”€โ”€ OffsetArray{Float64, 3, Array{Float64,3}}
โ””โ”€โ”€ OffsetArray{Float64, 3, Array{Float64,3}}

julia> T*S
BinaryOperation at (Cell, Cell, Cell)
โ”œโ”€โ”€ grid: RegularCartesianGrid{Float64,Periodic,Periodic,Bounded,OffsetArrays.OffsetArray{Float64,1,StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}}
โ”‚   โ”œโ”€โ”€ size: (16, 16, 16)
โ”‚   โ””โ”€โ”€ domain: x โˆˆ [0.0, 1.0], y โˆˆ [0.0, 1.0], z โˆˆ [-1.0, 0.0625]
โ””โ”€โ”€ tree: 

* at (Cell, Cell, Cell) via identity
โ”œโ”€โ”€ OffsetArray{Float64, 3, Array{Float64,3}}
โ””โ”€โ”€ OffsetArray{Float64, 3, Array{Float64,3}}

julia> v*v
BinaryOperation at (Cell, Face, Cell)
โ”œโ”€โ”€ grid: RegularCartesianGrid{Float64,Periodic,Periodic,Bounded,OffsetArrays.OffsetArray{Float64,1,StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}}
โ”‚   โ”œโ”€โ”€ size: (16, 16, 16)
โ”‚   โ””โ”€โ”€ domain: x โˆˆ [0.0, 1.0], y โˆˆ [0.0, 1.0], z โˆˆ [-1.0, 0.0625]
โ””โ”€โ”€ tree: 

* at (Cell, Face, Cell) via identity
โ”œโ”€โ”€ OffsetArray{Float64, 3, Array{Float64,3}}
โ””โ”€โ”€ OffsetArray{Float64, 3, Array{Float64,3}}

Possibly we need to change the definition of MultiaryOperation to a, b, c, d.... I guess there can be Varargs of length zero?

Relevant lines are

https://github.com/CliMA/Oceananigans.jl/blob/f13a0a26df78cd1c1495d56ef5e7ea2fbbbfb23c/src/AbstractOperations/multiary_operations.jl#L25-L47

If two fields are at the same location, that scenario may possibly get shortcut by this method:

https://github.com/CliMA/Oceananigans.jl/blob/f13a0a26df78cd1c1495d56ef5e7ea2fbbbfb23c/src/AbstractOperations/binary_operations.jl#L68

I guess there can be Varargs of length zero?

Yup looks like it

julia> f(s, x...) = @show x
f (generic function with 1 method)

julia> f(ฯ€);
x = ()

julia> f(ฯ€, "โˆซ", "โˆ‚");
x = ("โˆซ", "โˆ‚")

That should be an easy fix. Not sure, but BinaryOperation might be preferred over mulitiary because it avoids the ntuple magic unrolling.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

glwagner picture glwagner  ยท  6Comments

glwagner picture glwagner  ยท  7Comments

glwagner picture glwagner  ยท  4Comments

glwagner picture glwagner  ยท  7Comments

truedichotomy picture truedichotomy  ยท  8Comments