@@ -31,29 +31,28 @@ where the lumping should occur.
3131Outside of this region, no lumping.
3232Default is `f=Returns(true)`, i.e. lump everywhere.
3333"""
34- function lump_and_spray (wet3D, vol; f = Returns ( true ), di= 2 , dj= 2 , dk= 1 )
34+ function lump_and_spray (wet3D, vol, mask = trues ( size (wet3D)); di= 2 , dj= 2 , dk= 1 )
3535
3636 # extend the grid to avoid lumping cells outside of bounds
3737 nxyz = size (wet3D)
38+ C = CartesianIndices (nxyz)
3839 LUMPidx = zeros (Int, nxyz .+ (di - 1 , dj - 1 , dk - 1 ))
3940
4041 # loop once over all grid cells and assign lumped indices
4142 c = 1 # index / counter
4243 neighbours = CartesianIndices ((0 : di- 1 , 0 : dj- 1 , 0 : dk- 1 ))
43- C = CartesianIndices (nxyz)
4444 for 𝑖 in eachindex (C)
4545 C𝑖 = C[𝑖]
46- i, j, k = C𝑖. I
47- # assign index if not indexed yet
48- if LUMPidx[C𝑖] == 0
49- if f (i,j,k) # to all lumped cells if in region
50- LUMPidx[C𝑖 .+ neighbours] .= c
51- else # to only this cell if outside region
52- LUMPidx[C𝑖] = c
53- end
54- c += 1
46+ LUMPidx[C𝑖] ≠ 0 && mask[C𝑖] && continue # skip if index already assigned
47+ if mask[C𝑖] # if in region, assign all neighbours also in region
48+ LUMPidx[C𝑖 .+ neighbours] .= c
49+ else # to only this cell if outside region
50+ LUMPidx[C𝑖] = c
5551 end
52+ c += 1
5653 end
54+
55+ # Remove ghost cells outside of original grid
5756 LUMP = sparse (LUMPidx[C][:], 1 : length (C), 1 )
5857
5958 # Find wet points in coarsened grid
@@ -74,6 +73,13 @@ function lump_and_spray(wet3D, vol; f=Returns(true), di=2, dj=2, dk=1)
7473 SPRAY = copy (LUMP' )
7574 SPRAY. nzval .= 1
7675
76+ # Print some info
77+ nwet = size (LUMP, 2 )
78+ nwet_c = size (LUMP, 1 )
79+ @info """ LUMP and SPRAY:
80+ Matrix size reduction: $(round (100 (1 - nwet_c/ nwet))) % ($nwet -> $nwet_c )
81+ """
82+
7783 return LUMP, SPRAY, vol_c
7884end
7985
0 commit comments