From 3303781bd01327cc9cee10ba4befc7a7cdec3e4c Mon Sep 17 00:00:00 2001 From: Chris Nicol Date: Tue, 17 Aug 2021 14:48:24 +1000 Subject: [PATCH 1/3] fix(pakbase) unstructured storage check (#1187) in pakbase/_check_storage.py, np.asarray() still throws an error when using a jagged list for unstructured models https://github.com/modflowpy/flopy/issues/1187#issuecomment-899509532 * change to np.concatenate jagged list to a flat array close #1187 --- flopy/pakbase.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/flopy/pakbase.py b/flopy/pakbase.py index 20870b4301..d0bbb8725f 100644 --- a/flopy/pakbase.py +++ b/flopy/pakbase.py @@ -385,7 +385,7 @@ def _check_storage(self, chk, storage_coeff): for l in self.laytyp ] ) - if self.ss.shape[1] is None: + if self.sy.shape[1] is None: # unstructured; build flat nodal property array slicers (by layer) node_to = np.cumsum([s.array.size for s in self.ss]) node_from = np.array([0] + list(node_to[:-1])) @@ -395,11 +395,11 @@ def _check_storage(self, chk, storage_coeff): for n_from, n_to in zip(node_from, node_to) ] )[inds] - sarrays["sy"] = np.asarray( + sarrays["sy"] = np.concatenate( [sarrays["sy"][sl] for sl in node_k_slices] ).flatten() - active = np.asarray( - [active[sl] for sl in node_k_slices], dtype=bool + active = np.concatenate( + [active[sl] for sl in node_k_slices] ).flatten() else: sarrays["sy"] = sarrays["sy"][inds, :, :] From d8c8f03a3a5e51c552606efd03fc79ad22da6a41 Mon Sep 17 00:00:00 2001 From: Chris Nicol Date: Tue, 17 Aug 2021 15:01:01 +1000 Subject: [PATCH 2/3] skip storage check if no convertible layers --- flopy/pakbase.py | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/flopy/pakbase.py b/flopy/pakbase.py index d0bbb8725f..36851485a1 100644 --- a/flopy/pakbase.py +++ b/flopy/pakbase.py @@ -385,25 +385,26 @@ def _check_storage(self, chk, storage_coeff): for l in self.laytyp ] ) - if self.sy.shape[1] is None: - # unstructured; build flat nodal property array slicers (by layer) - node_to = np.cumsum([s.array.size for s in self.ss]) - node_from = np.array([0] + list(node_to[:-1])) - node_k_slices = np.array( - [ - np.s_[n_from:n_to] - for n_from, n_to in zip(node_from, node_to) - ] - )[inds] - sarrays["sy"] = np.concatenate( - [sarrays["sy"][sl] for sl in node_k_slices] - ).flatten() - active = np.concatenate( - [active[sl] for sl in node_k_slices] - ).flatten() - else: - sarrays["sy"] = sarrays["sy"][inds, :, :] - active = active[inds, :, :] + if inds.any(): + if self.sy.shape[1] is None: + # unstructured; build flat nodal property array slicers (by layer) + node_to = np.cumsum([s.array.size for s in self.ss]) + node_from = np.array([0] + list(node_to[:-1])) + node_k_slices = np.array( + [ + np.s_[n_from:n_to] + for n_from, n_to in zip(node_from, node_to) + ] + )[inds] + sarrays["sy"] = np.concatenate( + [sarrays["sy"][sl] for sl in node_k_slices] + ).flatten() + active = np.concatenate( + [active[sl] for sl in node_k_slices] + ).flatten() + else: + sarrays["sy"] = sarrays["sy"][inds, :, :] + active = active[inds, :, :] else: iconvert = self.iconvert.array for ishape in np.ndindex(active.shape): From d00fe3fcb0b8fe0c52ec115388faa53b8106e7ea Mon Sep 17 00:00:00 2001 From: Chris Nicol Date: Tue, 17 Aug 2021 15:18:01 +1000 Subject: [PATCH 3/3] skip storage check if no convertible layers... --- flopy/pakbase.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/flopy/pakbase.py b/flopy/pakbase.py index 36851485a1..39a42e3a43 100644 --- a/flopy/pakbase.py +++ b/flopy/pakbase.py @@ -376,6 +376,7 @@ def _check_storage(self, chk, storage_coeff): ) # only check specific yield for convertible layers + skip_sy_check = False if "laytyp" in self.__dict__: inds = np.array( [ @@ -405,6 +406,8 @@ def _check_storage(self, chk, storage_coeff): else: sarrays["sy"] = sarrays["sy"][inds, :, :] active = active[inds, :, :] + else: + skip_sy_check = True else: iconvert = self.iconvert.array for ishape in np.ndindex(active.shape): @@ -412,19 +415,20 @@ def _check_storage(self, chk, storage_coeff): active[ishape] = ( iconvert[ishape] > 0 or iconvert[ishape] < 0 ) - chk.values( - sarrays["sy"], - active & (sarrays["sy"] < 0), - "zero or negative specific yield values", - "Error", - ) - self._check_thresholds( - chk, - sarrays["sy"], - active, - chk.property_threshold_values["sy"], - "specific yield", - ) + if not skip_sy_check: + chk.values( + sarrays["sy"], + active & (sarrays["sy"] < 0), + "zero or negative specific yield values", + "Error", + ) + self._check_thresholds( + chk, + sarrays["sy"], + active, + chk.property_threshold_values["sy"], + "specific yield", + ) class Package(PackageInterface):