Skip to content

Commit 1a5bea7

Browse files
committed
document smart lump and spray function
1 parent 8cc95ba commit 1a5bea7

3 files changed

Lines changed: 9 additions & 21 deletions

File tree

src/extratools.jl

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
"""
2-
LUMP, SPRAY, v_c = lump_and_spray(wet3D, volume; f=Returns(true),di=2, dj=2, dk=1)
2+
LUMP, SPRAY, v_c = lump_and_spray(wet3D, vol, T, mask=trues(size(wet3D)); di=2, dj=2, dk=1)
33
44
returns the LUMP and SPRAY matrices, and the coarsened volume vector.
55
6+
The `vol` vector of volumes is used to make the LUMP operator volume-conserving.
7+
The `T` matrix is used to determine connectivity of the grid cells, so as to avoid lumping disconnected cells.
8+
The `mask` boolean array (same size as `wet3D`) can be used to restrict the lumping to a certain region.
9+
610
To get the coarsened vector from fine vector x, use
711
812
LUMP * x
@@ -108,20 +112,6 @@ function lump_and_spray(wet3D, vol, T, mask=trues(size(wet3D)); di=2, dj=2, dk=1
108112
end
109113

110114

111-
"""
112-
diconnected_cells(wet3D, T; di=2, dj=2, dk=1)
113-
114-
"""
115-
function connected_cells(wet3D, T; di=2, dj=2, dk=1)
116-
i, j = findnz(SPRAY * LUMP)
117-
connected_by_grid = sparse(i, j, true, size(T)...)
118-
i, j = findnz(T)
119-
connected_by_T = sparse(i, j, true, size(T)...)
120-
connected = connected_by_grid .& connected_by_T
121-
connected = ((connected^di)^dj)^dk
122-
end
123-
124-
125115

126116
"""
127117
as2D(x, wet3D)

test/interactive.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,16 @@ end
122122
# @profview_allocs transportmatrix(; ϕ, mlotst, gridmetrics, indices, ρ, κH, κVML, κVdeep) sample_rate=0.9
123123

124124

125+
# Test extreme coarsening and plot it
125126
# unpack model grid
126127
(; v3D, lat, lon, zt) = gridmetrics
127128
# unpack indices
128129
(; wet3D, N) = indices
129-
130130
v = v3D[wet3D]
131-
132131
@info "coarsening grid"
133132
SOmask = lat .< -35
134133
NAmask = @. (lat > 50) & ((lon < 100) | (250 < lon))
135134
mymask = repeat(.!SOmask .& .!NAmask, 1, 1, size(wet3D, 3))
136-
137-
# Test extreme coarsening and plot it
138135
LUMP, SPRAY, v_c = OceanTransportMatrixBuilder.lump_and_spray(wet3D, v, T, mymask; di=10, dj=10, dk=1)
139136
# Plot the lumping
140137
using CairoMakie

test/local_full.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,12 @@ end
137137

138138
# Test extreme coarsening to show behavior across land and plot it
139139
LUMP, SPRAY, v_c = OceanTransportMatrixBuilder.lump_and_spray(wet3D, v, T, mymask; di=10, dj=10, dk=1)
140-
sprayedrand = SPRAY * rand(size(LUMP, 1))
140+
colormap = cgrad(:okabe_ito, categorical=true)
141+
sprayedrand = SPRAY * rand(1:length(colormap), size(LUMP, 1))
141142
sprayedrand3D = OceanTransportMatrixBuilder.as3D(sprayedrand, wet3D)
142143
fig, ax, hm = surface(mod.(lon .- 80, 360) .+ 80, lat, zeros(size(lat));
143144
color=sprayedrand3D[:,:,1],
144-
colormap = :turbo,
145+
colormap,
145146
shading = false
146147
)
147148
outputfile = joinpath(outputdir, "LUMP_and_SPRAY_coarsening.png")

0 commit comments

Comments
 (0)