Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new MeshArray_wh type, returned by exchange #160

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MeshArrays"
uuid = "cb8c808f-1acf-59a3-9d2b-6e38d009f683"
authors = ["gaelforget <gforget@mit.edu>"]
version = "0.3.16"
version = "0.3.17"

[deps]
CatViews = "81a5f4ea-a946-549a-aa7e-2a7f63a27d31"
Expand Down
4 changes: 2 additions & 2 deletions ext/MeshArraysMakieExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ function interpolation_demo(Γ)

#

XCtiles=Tiles(τ,exchange(Γ.XC))
YCtiles=Tiles(τ,exchange(Γ.YC))
XCtiles=Tiles(τ,exchange(Γ.XC).MA)
YCtiles=Tiles(τ,exchange(Γ.YC).MA)

iiTile=tiles[f[1]][i[1],j[1]]; iiFace=τ[iiTile].face

Expand Down
8 changes: 4 additions & 4 deletions src/Exchanges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
exchange(u::MeshArray,v::MeshArray,N::Integer)
"""
function exchange(fld::MeshArray)
FLD=exch_T_N(fld,1);
MeshArray_wh(exch_T_N(fld,1),1)
end

function exchange(fld::MeshArray,N::Integer)
FLD=exch_T_N(fld,N);
MeshArray_wh(exch_T_N(fld,N),N)
end

function exchange(u::MeshArray,v::MeshArray)
(uex,vex)=exch_UV_N(u,v,1);
MeshArray_wh.(exch_UV_N(u,v,1),1)

Check warning on line 25 in src/Exchanges.jl

View check run for this annotation

Codecov / codecov/patch

src/Exchanges.jl#L25

Added line #L25 was not covered by tests
end

function exchange(u::MeshArray,v::MeshArray,N::Integer)
(uex,vex)=exch_UV_N(u,v,N);
MeshArray_wh.(exch_UV_N(u,v,N),N)
end

## dispatch over grid types
Expand Down
4 changes: 2 additions & 2 deletions src/Grids.jl
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ field locations) and add them to Γ.
"""
function GridAddWS!(Γ::Dict)

XC=exchange(Γ["XC"])
YC=exchange(Γ["YC"])
XC=exchange(Γ["XC"]).MA
YC=exchange(Γ["YC"]).MA
nFaces=XC.grid.nFaces
uX=XC.meta.unit
uY=YC.meta.unit
Expand Down
10 changes: 5 additions & 5 deletions src/Interpolation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,16 @@ function InterpolationFactors(Γ,lon::Array{T,1},lat::Array{T,1}) where {T}
#2. t_XC, t_XC, t_f, t_i, t_j
t=vec(write(tiles)[c])
t_list=unique(t)
t_XC=Tiles(τ,exchange(Γ.XC))
t_YC=Tiles(τ,exchange(Γ.YC))
t_XC=Tiles(τ,exchange(Γ.XC).MA)
t_YC=Tiles(τ,exchange(Γ.YC).MA)

t_f=MeshArray(γ,Int); [t_f[ii][:,:].=ii for ii=1:γ.nFaces]
t_i=MeshArray(γ,Int); [t_i[ii]=collect(1:γ.fSize[ii][1])*ones(Int,1,γ.fSize[ii][2]) for ii=1:γ.nFaces]
t_j=MeshArray(γ,Int); [t_j[ii]=ones(Int,γ.fSize[ii][1],1)*collect(1:γ.fSize[ii][2])' for ii=1:γ.nFaces]

t_f=Tiles(τ,exchange(t_f))
t_i=Tiles(τ,exchange(t_i))
t_j=Tiles(τ,exchange(t_j))
t_f=Tiles(τ,exchange(t_f).MA)
t_i=Tiles(τ,exchange(t_i).MA)
t_j=Tiles(τ,exchange(t_j).MA)

x_q=fill(0.0,1,4)
y_q=fill(0.0,1,4)
Expand Down
3 changes: 2 additions & 1 deletion src/MeshArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ include("Grids_simple.jl")
include("demo.jl")
include("Integration.jl")

export AbstractMeshArray, MeshArray, gcmgrid, varmeta, gridpath, gridmask
export AbstractMeshArray, MeshArray, MeshArray_wh
export gcmgrid, varmeta, gridpath, gridmask
export GridSpec, GridLoad, GridLoadVar, Grids_simple
export exchange, Tiles, Tiles!, Interpolate, InterpolationFactors, knn, interpolation_setup
#The following exch_UV differs from normal exchange; incl. exch_UV_N
Expand Down
18 changes: 9 additions & 9 deletions src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ end

function gradient(inFLD::MeshArray,Γ::NamedTuple,doDIV::Bool)

exFLD=exchange(inFLD,1)
exFLD=exchange(inFLD,1).MA
dFLDdx=similar(inFLD)
dFLDdy=similar(inFLD)

Expand All @@ -63,7 +63,7 @@ end

function gradient(inFLD::MeshArray,iDXC::MeshArray,iDYC::MeshArray)

exFLD=exchange(inFLD,1)
exFLD=exchange(inFLD,1).MA
dFLDdx=similar(inFLD)
dFLDdy=similar(inFLD)

Expand Down Expand Up @@ -92,15 +92,15 @@ function curl(u::MeshArray,v::MeshArray,Γ::NamedTuple)
fac=exchange(1.0 ./Γ.RAZ,1)
(U,V)=exchange(u,v,1)
(DXC,DYC)=exchange(Γ.DXC,Γ.DYC,1)
[DXC[i].=abs.(DXC[i]) for i in eachindex(U)]
[DYC[i].=abs.(DYC[i]) for i in eachindex(V)]
[DXC.MA[i].=abs.(DXC.MA[i]) for i in eachindex(U.MA)]
[DYC.MA[i].=abs.(DYC.MA[i]) for i in eachindex(V.MA)]

for i in eachindex(U)
ucur=U[i][2:end,:]
vcur=V[i][:,2:end]
for i in eachindex(U.MA)
ucur=U.MA[i][2:end,:]
vcur=V.MA[i][:,2:end]
tmpcurl=ucur[:,1:end-1]-ucur[:,2:end]
tmpcurl=tmpcurl-(vcur[1:end-1,:]-vcur[2:end,:])
tmpcurl=tmpcurl.*fac[i][1:end-1,1:end-1]
tmpcurl=tmpcurl.*fac.MA[i][1:end-1,1:end-1]

##still needed:
##- deal with corners
Expand Down Expand Up @@ -402,7 +402,7 @@ function edge_mask(mskCint::MeshArray)
mskW=similar(mskCint)
mskS=similar(mskCint)

mskCint=exchange(mskCint,1)
mskCint=exchange(mskCint,1).MA

for i in eachindex(mskCint)
tmp1=mskCint[i]
Expand Down
9 changes: 5 additions & 4 deletions src/Solvers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ function MaskWetPoints(TrspCon)
mskDry=1.0 * isnan.(mskWet)
mskDry=mask(mskDry,NaN,0.0)
#
tmp1=fill(1.0,mskWet); tmp2=exchange(tmp1);
tmp1=fill(1.0,mskWet)
tmp2=exchange(tmp1).MA
for I=1:size(tmp1.f,1)
tmp3=mskWet[I]; tmp4=tmp2[I];
tmp4=tmp4[2:end-1,1:end-2]+tmp4[2:end-1,3:end]+tmp4[1:end-2,2:end-1]+tmp4[3:end,2:end-1];
Expand Down Expand Up @@ -69,7 +70,7 @@ function SeedWetPoints(tmp::MeshArray,Kmap::MeshArray,Lmap::MeshArray,I...)
FLDkkFROMtmp[aa][ii:3:end,jj:3:end]=Kmap[aa][ii:3:end,jj:3:end]
FLDkkFROMtmp[aa][findall(isnan.(tmp[aa]))].=0.0

FLDkkFROM=exchange(FLDkkFROMtmp)
FLDkkFROM=exchange(FLDkkFROMtmp).MA
FLDkkFROM=mask(FLDkkFROM,0.0)

for bb in 1:tmp.grid.nFaces
Expand Down Expand Up @@ -224,10 +225,10 @@ function VectorPotential(TrspX::MeshArray,TrspY::MeshArray,Γ::NamedTuple,method
if fldU.grid.nFaces>1
TMP1=similar(psi)
for I in eachindex(TMP1); TMP1[I] = fill(I,size(psi[I])); end
TMP2=exchange(TMP1) #this is a trick
TMP2=exchange(TMP1).MA #this is a trick

for I in 1:TrspX.grid.nFaces-1
tmp2=exchange(psi) #this is a trick
tmp2=exchange(psi).MA #this is a trick
tmp3=tmp2[I+1]; tmp3[3:end-2,3:end-2].=NaN #mask out interior points
TMP3=TMP2[I+1]; tmp3[findall(TMP3.>I+1)].=NaN #mask out edges points coming from unadjusted faces
tmp3[findall(TMP3.==0)].=NaN
Expand Down
6 changes: 5 additions & 1 deletion src/Types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ end

## derivative types


"""
gridpath

Expand Down Expand Up @@ -286,3 +285,8 @@ function Base.show(io::IO, z::gridmask)
return
end

Base.@kwdef struct MeshArray_wh
MA::MeshArray
HS::Int #halo size
end

2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ include(joinpath(p,"../examples/Demos.jl"))
exchange(Rend,2)
exchange(dRdx,dRdy,1)
(dRdx_e,dRdy_e)=exchange(dRdx,dRdy,1)
@test isa(dRdx_e,MeshArray)
@test isa(dRdx_e,MeshArray_wh)
end
end

Expand Down
Loading