Skip to content

Commit b744b94

Browse files
authored
Merge pull request #160 from gaelforget/v0p3p17b
new MeshArray_wh type, returned by exchange
2 parents 89bd745 + a574809 commit b744b94

10 files changed

+36
-30
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "MeshArrays"
22
uuid = "cb8c808f-1acf-59a3-9d2b-6e38d009f683"
33
authors = ["gaelforget <[email protected]>"]
4-
version = "0.3.16"
4+
version = "0.3.17"
55

66
[deps]
77
CatViews = "81a5f4ea-a946-549a-aa7e-2a7f63a27d31"

ext/MeshArraysMakieExt.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,8 @@ function interpolation_demo(Γ)
341341

342342
#
343343

344-
XCtiles=Tiles(τ,exchange.XC))
345-
YCtiles=Tiles(τ,exchange.YC))
344+
XCtiles=Tiles(τ,exchange.XC).MA)
345+
YCtiles=Tiles(τ,exchange.YC).MA)
346346

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

src/Exchanges.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ Exchange / transfer data between neighboring arrays. Other methods are
1414
exchange(u::MeshArray,v::MeshArray,N::Integer)
1515
"""
1616
function exchange(fld::MeshArray)
17-
FLD=exch_T_N(fld,1);
17+
MeshArray_wh(exch_T_N(fld,1),1)
1818
end
1919

2020
function exchange(fld::MeshArray,N::Integer)
21-
FLD=exch_T_N(fld,N);
21+
MeshArray_wh(exch_T_N(fld,N),N)
2222
end
2323

2424
function exchange(u::MeshArray,v::MeshArray)
25-
(uex,vex)=exch_UV_N(u,v,1);
25+
MeshArray_wh.(exch_UV_N(u,v,1),1)
2626
end
2727

2828
function exchange(u::MeshArray,v::MeshArray,N::Integer)
29-
(uex,vex)=exch_UV_N(u,v,N);
29+
MeshArray_wh.(exch_UV_N(u,v,N),N)
3030
end
3131

3232
## dispatch over grid types

src/Grids.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,8 @@ field locations) and add them to Γ.
353353
"""
354354
function GridAddWS!::Dict)
355355

356-
XC=exchange(Γ["XC"])
357-
YC=exchange(Γ["YC"])
356+
XC=exchange(Γ["XC"]).MA
357+
YC=exchange(Γ["YC"]).MA
358358
nFaces=XC.grid.nFaces
359359
uX=XC.meta.unit
360360
uY=YC.meta.unit

src/Interpolation.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,16 @@ function InterpolationFactors(Γ,lon::Array{T,1},lat::Array{T,1}) where {T}
157157
#2. t_XC, t_XC, t_f, t_i, t_j
158158
t=vec(write(tiles)[c])
159159
t_list=unique(t)
160-
t_XC=Tiles(τ,exchange.XC))
161-
t_YC=Tiles(τ,exchange.YC))
160+
t_XC=Tiles(τ,exchange.XC).MA)
161+
t_YC=Tiles(τ,exchange.YC).MA)
162162

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

167-
t_f=Tiles(τ,exchange(t_f))
168-
t_i=Tiles(τ,exchange(t_i))
169-
t_j=Tiles(τ,exchange(t_j))
167+
t_f=Tiles(τ,exchange(t_f).MA)
168+
t_i=Tiles(τ,exchange(t_i).MA)
169+
t_j=Tiles(τ,exchange(t_j).MA)
170170

171171
x_q=fill(0.0,1,4)
172172
y_q=fill(0.0,1,4)

src/MeshArrays.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ include("Grids_simple.jl")
2828
include("demo.jl")
2929
include("Integration.jl")
3030

31-
export AbstractMeshArray, MeshArray, gcmgrid, varmeta, gridpath, gridmask
31+
export AbstractMeshArray, MeshArray, MeshArray_wh
32+
export gcmgrid, varmeta, gridpath, gridmask
3233
export GridSpec, GridLoad, GridLoadVar, Grids_simple
3334
export exchange, Tiles, Tiles!, Interpolate, InterpolationFactors, knn, interpolation_setup
3435
#The following exch_UV differs from normal exchange; incl. exch_UV_N

src/Operations.jl

+9-9
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ end
4040

4141
function gradient(inFLD::MeshArray::NamedTuple,doDIV::Bool)
4242

43-
exFLD=exchange(inFLD,1)
43+
exFLD=exchange(inFLD,1).MA
4444
dFLDdx=similar(inFLD)
4545
dFLDdy=similar(inFLD)
4646

@@ -63,7 +63,7 @@ end
6363

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

66-
exFLD=exchange(inFLD,1)
66+
exFLD=exchange(inFLD,1).MA
6767
dFLDdx=similar(inFLD)
6868
dFLDdy=similar(inFLD)
6969

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

98-
for i in eachindex(U)
99-
ucur=U[i][2:end,:]
100-
vcur=V[i][:,2:end]
98+
for i in eachindex(U.MA)
99+
ucur=U.MA[i][2:end,:]
100+
vcur=V.MA[i][:,2:end]
101101
tmpcurl=ucur[:,1:end-1]-ucur[:,2:end]
102102
tmpcurl=tmpcurl-(vcur[1:end-1,:]-vcur[2:end,:])
103-
tmpcurl=tmpcurl.*fac[i][1:end-1,1:end-1]
103+
tmpcurl=tmpcurl.*fac.MA[i][1:end-1,1:end-1]
104104

105105
##still needed:
106106
##- deal with corners
@@ -402,7 +402,7 @@ function edge_mask(mskCint::MeshArray)
402402
mskW=similar(mskCint)
403403
mskS=similar(mskCint)
404404

405-
mskCint=exchange(mskCint,1)
405+
mskCint=exchange(mskCint,1).MA
406406

407407
for i in eachindex(mskCint)
408408
tmp1=mskCint[i]

src/Solvers.jl

+5-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ function MaskWetPoints(TrspCon)
1717
mskDry=1.0 * isnan.(mskWet)
1818
mskDry=mask(mskDry,NaN,0.0)
1919
#
20-
tmp1=fill(1.0,mskWet); tmp2=exchange(tmp1);
20+
tmp1=fill(1.0,mskWet)
21+
tmp2=exchange(tmp1).MA
2122
for I=1:size(tmp1.f,1)
2223
tmp3=mskWet[I]; tmp4=tmp2[I];
2324
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];
@@ -69,7 +70,7 @@ function SeedWetPoints(tmp::MeshArray,Kmap::MeshArray,Lmap::MeshArray,I...)
6970
FLDkkFROMtmp[aa][ii:3:end,jj:3:end]=Kmap[aa][ii:3:end,jj:3:end]
7071
FLDkkFROMtmp[aa][findall(isnan.(tmp[aa]))].=0.0
7172

72-
FLDkkFROM=exchange(FLDkkFROMtmp)
73+
FLDkkFROM=exchange(FLDkkFROMtmp).MA
7374
FLDkkFROM=mask(FLDkkFROM,0.0)
7475

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

229230
for I in 1:TrspX.grid.nFaces-1
230-
tmp2=exchange(psi) #this is a trick
231+
tmp2=exchange(psi).MA #this is a trick
231232
tmp3=tmp2[I+1]; tmp3[3:end-2,3:end-2].=NaN #mask out interior points
232233
TMP3=TMP2[I+1]; tmp3[findall(TMP3.>I+1)].=NaN #mask out edges points coming from unadjusted faces
233234
tmp3[findall(TMP3.==0)].=NaN

src/Types.jl

+5-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ end
229229

230230
## derivative types
231231

232-
233232
"""
234233
gridpath
235234
@@ -286,3 +285,8 @@ function Base.show(io::IO, z::gridmask)
286285
return
287286
end
288287

288+
Base.@kwdef struct MeshArray_wh
289+
MA::MeshArray
290+
HS::Int #halo size
291+
end
292+

test/runtests.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ include(joinpath(p,"../examples/Demos.jl"))
3131
exchange(Rend,2)
3232
exchange(dRdx,dRdy,1)
3333
(dRdx_e,dRdy_e)=exchange(dRdx,dRdy,1)
34-
@test isa(dRdx_e,MeshArray)
34+
@test isa(dRdx_e,MeshArray_wh)
3535
end
3636
end
3737

0 commit comments

Comments
 (0)