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

fix(Grid.saturated_thick): update saturated_thick to filter confining bed layers #1197

Merged
merged 1 commit into from
Aug 18, 2021
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
46 changes: 46 additions & 0 deletions autotest/t076_modelgrid_thick.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,53 @@ def test_unstructured_thick():
return


def test_ncb_thick():
nlay = 3
nrow = ncol = 15
laycbd = np.array([1, 2, 0], dtype=int)
ncb = np.count_nonzero(laycbd)
dx = dy = 150
delc = np.array([dy,] * nrow)
delr = np.array([dx, ] * ncol)
top = np.ones((15, 15))
botm = np.ones((nlay + ncb, nrow, ncol))
elevations = np.array([-10, -20, -40, -50, -70])[:, np.newaxis]
botm *= elevations[:, None]

modelgrid = StructuredGrid(
delc=delc,
delr=delr,
top=top,
botm=botm,
nlay=nlay,
nrow=nrow,
ncol=ncol,
laycbd=laycbd
)

thick = modelgrid.thick

if not thick.shape[0] == nlay + ncb:
raise AssertionError("grid thick attribute returns incorrect shape")

thick = modelgrid.remove_confining_beds(modelgrid.thick)
if not thick.shape == modelgrid.shape:
raise AssertionError("quasi3d confining beds not properly removed")

sat_thick = modelgrid.saturated_thick(modelgrid.thick)
if not sat_thick.shape == modelgrid.shape:
raise AssertionError(
"saturated_thickness confining beds not removed"
)

if sat_thick[1, 0, 0] != 20:
raise AssertionError(
"saturated_thickness is not properly indexing confining beds"
)


if __name__ == "__main__":
test_unstructured_thick()
test_vertices_thick()
test_structured_thick()
test_ncb_thick()
31 changes: 31 additions & 0 deletions flopy/discretization/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@ def saturated_thick(self, array, mask=None):
thick = self.thick
top = self.top_botm[:-1].reshape(thick.shape)
bot = self.top_botm[1:].reshape(thick.shape)
thick = self.remove_confining_beds(thick)
top = self.remove_confining_beds(top)
bot = self.remove_confining_beds(bot)
array = self.remove_confining_beds(array)

idx = np.where((array < top) & (array > bot))
thick[idx] = array[idx] - bot[idx]
idx = np.where(array <= bot)
Expand Down Expand Up @@ -451,6 +456,32 @@ def xyzvertices(self):
def cross_section_vertices(self):
return self.xyzvertices[0], self.xyzvertices[1]

def remove_confining_beds(self, array):
"""
Method to remove confining bed layers from an array

Parameters
----------
array : np.ndarray
array to remove quasi3d confining bed data from. Shape of axis 0
should be (self.lay + ncb) to remove beds
Returns
-------
np.ndarray
"""
if self.laycbd is not None:
ncb = np.count_nonzero(self.laycbd)
if ncb > 0:
if array.shape[0] == self.shape[0] + ncb:
cb = 0
idx = []
for ix, i in enumerate(self.laycbd):
idx.append(ix + cb)
if i > 0:
cb += 1
array = array[idx]
return array

def cross_section_lay_ncpl_ncb(self, ncb):
"""
Get PlotCrossSection compatible layers, ncpl, and ncb
Expand Down
2 changes: 1 addition & 1 deletion flopy/discretization/structuredgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def __init__(
self.__nlay = nlay
else:
if laycbd is not None:
self.__nlay = len(botm) - np.sum(laycbd > 0)
self.__nlay = len(botm) - np.count_nonzero(laycbd)
else:
self.__nlay = len(botm)
else:
Expand Down
2 changes: 1 addition & 1 deletion flopy/modflow/mf.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def modelgrid(self):
yoff=self._modelgrid.yoffset,
angrot=self._modelgrid.angrot,
nlay=self.dis.nlay,
laycbd=self.dis.laycbd,
laycbd=self.dis.laycbd.array,
)

# resolve offsets
Expand Down
5 changes: 3 additions & 2 deletions flopy/utils/postprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,12 +707,13 @@ def get_specific_discharge(
if classical_budget:
# get saturated thickness (head - bottom elev for unconfined layer)
if head is None:
sat_thk = modelgrid.thick
sat_thk = modelgrid.remove_confining_beds(modelgrid.thick)
else:
sat_thk = modelgrid.saturated_thick(
head, mask=[model.hdry, model.hnoflo]
)
sat_thk.shape = model.modelgrid.shape

sat_thk.shape = modelgrid.shape

# inform modelgrid of no-flow and dry cells
modelgrid = model.modelgrid
Expand Down