-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add masked operators
- Loading branch information
Showing
16 changed files
with
355 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "Chmy" | ||
uuid = "33a72cf0-4690-46d7-b987-06506c2248b9" | ||
authors = ["Ivan Utkin <[email protected]>, Ludovic Raess <[email protected]>, and contributors"] | ||
version = "0.1.10" | ||
version = "0.1.12" | ||
|
||
[deps] | ||
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
for (dim, coord) in enumerate((:x, :y, :z)) | ||
_l = Symbol(:left, coord) | ||
_r = Symbol(:right, coord) | ||
_δ = Symbol(:δ, coord) | ||
_∂ = Symbol(:∂, coord) | ||
|
||
@eval begin | ||
export $_δ, $_∂, $_l, $_r | ||
|
||
""" | ||
$($_l)(f, I) | ||
"left side" of a field (`[1:end-1]`) in $($(string(coord))) direction. | ||
""" | ||
@add_cartesian function $_l(f::AbstractField, I::Vararg{Integer,N}) where {N} | ||
left(f, Dim($dim), I...) | ||
end | ||
|
||
""" | ||
$($_r)(f, I) | ||
"right side" of a field (`[2:end]`) in $($(string(coord))) direction. | ||
""" | ||
@add_cartesian function $_r(f::AbstractField, I::Vararg{Integer,N}) where {N} | ||
right(f, Dim($dim), I...) | ||
end | ||
|
||
""" | ||
$($_δ)(f, I) | ||
Finite difference in $($(string(coord))) direction. | ||
""" | ||
@add_cartesian function $_δ(f::AbstractField, I::Vararg{Integer,N}) where {N} | ||
δ(f, Dim($dim), I...) | ||
end | ||
|
||
""" | ||
$($_∂)(f, grid, I) | ||
Directional partial derivative in $($(string(coord))) direction. | ||
""" | ||
@add_cartesian function $_∂(f::AbstractField, grid, I::Vararg{Integer,N}) where {N} | ||
∂(f, grid, Dim($dim), I...) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
struct FieldMask1D{T,CF,VF} <: AbstractMask{T,1} | ||
c::CF | ||
v::VF | ||
function FieldMask1D{T}(c::AbstractField{T,1}, v::AbstractField{T,1}) where {T} | ||
return new{T,typeof(c),typeof(v)}(c, v) | ||
end | ||
end | ||
|
||
function FieldMask1D(arch::Architecture, grid::StructuredGrid{1}, type=eltype(grid); kwargs...) | ||
c = Field(arch, grid, Center(), type; kwargs...) | ||
v = Field(arch, grid, Vertex(), type; kwargs...) | ||
return FieldMask1D{type}(c, v) | ||
end | ||
|
||
@propagate_inbounds at(ω::FieldMask1D, ::Tuple{Center}, ix) = ω.c[ix] | ||
@propagate_inbounds at(ω::FieldMask1D, ::Tuple{Vertex}, ix) = ω.v[ix] | ||
|
||
struct FieldMask2D{T,CCF,VVF,VCF,CVF} <: AbstractMask{T,2} | ||
cc::CCF | ||
vv::VVF | ||
vc::VCF | ||
cv::CVF | ||
function FieldMask2D{T}(cc::AbstractField{T,2}, vv::AbstractField{T,2}, vc::AbstractField{T,2}, cv::AbstractField{T,2}) where {T} | ||
return new{T,typeof(cc),typeof(vv),typeof(vc),typeof(cv)}(cc, vv, vc, cv) | ||
end | ||
end | ||
|
||
function FieldMask2D(arch::Architecture, grid::StructuredGrid{2}, type=eltype(grid); kwargs...) | ||
cc = Field(arch, grid, Center(), type; kwargs...) | ||
vv = Field(arch, grid, Vertex(), type; kwargs...) | ||
vc = Field(arch, grid, (Vertex(), Center()), type; kwargs...) | ||
cv = Field(arch, grid, (Center(), Vertex()), type; kwargs...) | ||
return FieldMask2D{type}(cc, vv, vc, cv) | ||
end | ||
|
||
@propagate_inbounds at(ω::FieldMask2D, ::Tuple{Center,Center}, ix, iy) = ω.cc[ix, iy] | ||
@propagate_inbounds at(ω::FieldMask2D, ::Tuple{Vertex,Vertex}, ix, iy) = ω.vv[ix, iy] | ||
@propagate_inbounds at(ω::FieldMask2D, ::Tuple{Vertex,Center}, ix, iy) = ω.vc[ix, iy] | ||
@propagate_inbounds at(ω::FieldMask2D, ::Tuple{Center,Vertex}, ix, iy) = ω.cv[ix, iy] | ||
|
||
struct FieldMask3D{T,CCCF,VVVF,VCCF,CVCF,CCVF,VVCF,VCVF,CVVF} <: AbstractMask{T,3} | ||
ccc::CCCF | ||
vvv::VVVF | ||
vcc::VCCF | ||
cvc::CVCF | ||
ccv::CCVF | ||
vvc::VVCF | ||
vcv::VCVF | ||
cvv::CVVF | ||
function FieldMask3D{T}(ccc::AbstractField{T,3}, | ||
vvv::AbstractField{T,3}, | ||
vcc::AbstractField{T,3}, | ||
cvc::AbstractField{T,3}, | ||
ccv::AbstractField{T,3}, | ||
vvc::AbstractField{T,3}, | ||
vcv::AbstractField{T,3}, | ||
cvv::AbstractField{T,3}) where {T} | ||
return new{T, | ||
typeof(ccc), | ||
typeof(vvv), | ||
typeof(vcc), | ||
typeof(cvc), | ||
typeof(ccv), | ||
typeof(vvc), | ||
typeof(vcv), | ||
typeof(cvv)}(ccc, vvv, vcc, cvc, ccv, vvc, vcv, cvv) | ||
end | ||
end | ||
|
||
function FieldMask3D(arch::Architecture, grid::StructuredGrid{3}, type=eltype(grid); kwargs...) | ||
ccc = Field(arch, grid, Center(), type; kwargs...) | ||
vvv = Field(arch, grid, Vertex(), type; kwargs...) | ||
vcc = Field(arch, grid, (Vertex(), Center(), Center()), type; kwargs...) | ||
cvc = Field(arch, grid, (Center(), Vertex(), Center()), type; kwargs...) | ||
ccv = Field(arch, grid, (Center(), Center(), Vertex()), type; kwargs...) | ||
vvc = Field(arch, grid, (Vertex(), Vertex(), Center()), type; kwargs...) | ||
vcv = Field(arch, grid, (Vertex(), Center(), Vertex()), type; kwargs...) | ||
cvv = Field(arch, grid, (Center(), Vertex(), Vertex()), type; kwargs...) | ||
return FieldMask3D{type}(ccc, vvv, vcc, cvc, ccv, vvc, vcv, cvv) | ||
end | ||
|
||
@propagate_inbounds at(ω::FieldMask3D, ::Tuple{Center,Center,Center}, ix, iy, iz) = ω.ccc[ix, iy, iz] | ||
@propagate_inbounds at(ω::FieldMask3D, ::Tuple{Vertex,Vertex,Vertex}, ix, iy, iz) = ω.vvv[ix, iy, iz] | ||
@propagate_inbounds at(ω::FieldMask3D, ::Tuple{Vertex,Center,Center}, ix, iy, iz) = ω.vcc[ix, iy, iz] | ||
@propagate_inbounds at(ω::FieldMask3D, ::Tuple{Center,Vertex,Center}, ix, iy, iz) = ω.cvc[ix, iy, iz] | ||
@propagate_inbounds at(ω::FieldMask3D, ::Tuple{Center,Center,Vertex}, ix, iy, iz) = ω.ccv[ix, iy, iz] | ||
@propagate_inbounds at(ω::FieldMask3D, ::Tuple{Vertex,Vertex,Center}, ix, iy, iz) = ω.vvc[ix, iy, iz] | ||
@propagate_inbounds at(ω::FieldMask3D, ::Tuple{Vertex,Center,Vertex}, ix, iy, iz) = ω.vcv[ix, iy, iz] | ||
@propagate_inbounds at(ω::FieldMask3D, ::Tuple{Center,Vertex,Vertex}, ix, iy, iz) = ω.cvv[ix, iy, iz] | ||
|
||
FieldMask(arch::Architecture, grid::StructuredGrid{1}, args...; kwargs...) = FieldMask1D(arch, grid, args...; kwargs...) | ||
FieldMask(arch::Architecture, grid::StructuredGrid{2}, args...; kwargs...) = FieldMask2D(arch, grid, args...; kwargs...) | ||
FieldMask(arch::Architecture, grid::StructuredGrid{3}, args...; kwargs...) = FieldMask3D(arch, grid, args...; kwargs...) | ||
|
||
# Adapt rules | ||
|
||
Adapt.adapt_structure(to, f::FieldMask1D{T}) where {T} = FieldMask1D{T}(Adapt.adapt(to, f.c), Adapt.adapt(to, f.v)) | ||
|
||
function Adapt.adapt_structure(to, f::FieldMask2D{T}) where {T} | ||
FieldMask2D{T}(Adapt.adapt(to, f.cc), Adapt.adapt(to, f.vv), | ||
Adapt.adapt(to, f.vc), Adapt.adapt(to, f.cv)) | ||
end | ||
|
||
function Adapt.adapt_structure(to, f::FieldMask3D{T}) where {T} | ||
FieldMask3D{T}(Adapt.adapt(to, f.ccc), | ||
Adapt.adapt(to, f.vvv), | ||
Adapt.adapt(to, f.vcc), | ||
Adapt.adapt(to, f.cvc), | ||
Adapt.adapt(to, f.ccv), | ||
Adapt.adapt(to, f.vvc), | ||
Adapt.adapt(to, f.vcv), | ||
Adapt.adapt(to, f.cvv)) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
for (dim, coord) in enumerate((:x, :y, :z)) | ||
_l = Symbol(:left, coord) | ||
_r = Symbol(:right, coord) | ||
_δ = Symbol(:δ, coord) | ||
_∂ = Symbol(:∂, coord) | ||
|
||
@eval begin | ||
export $_δ, $_∂, $_l, $_r | ||
|
||
""" | ||
$($_l)(f, ω, I) | ||
"left side" of a field (`[1:end-1]`) in $($(string(coord))) direction, masked with `ω`. | ||
""" | ||
@add_cartesian function $_l(f::AbstractField, ω::AbstractMask, I::Vararg{Integer,N}) where {N} | ||
left(f, ω, Dim($dim), I...) | ||
end | ||
|
||
""" | ||
$($_r)(f, ω, I) | ||
"right side" of a field (`[2:end]`) in $($(string(coord))) direction, masked with `ω`. | ||
""" | ||
@add_cartesian function $_r(f::AbstractField, ω::AbstractMask, I::Vararg{Integer,N}) where {N} | ||
right(f, ω, Dim($dim), I...) | ||
end | ||
|
||
""" | ||
$($_δ)(f, ω, I) | ||
Finite difference in $($(string(coord))) direction, masked with `ω`. | ||
""" | ||
@add_cartesian function $_δ(f::AbstractField, ω::AbstractMask, I::Vararg{Integer,N}) where {N} | ||
δ(f, ω, Dim($dim), I...) | ||
end | ||
|
||
""" | ||
$($_∂)(f, ω, grid, I) | ||
Directional partial derivative in $($(string(coord))) direction, masked with `ω`. | ||
""" | ||
@add_cartesian function $_∂(f::AbstractField, ω::AbstractMask, grid, I::Vararg{Integer,N}) where {N} | ||
∂(f, ω, grid, Dim($dim), I...) | ||
end | ||
end | ||
end |
Oops, something went wrong.