From 703b00240f0108b9ff3fba9c02711890a3709427 Mon Sep 17 00:00:00 2001 From: scottrp <45947939+scottrp@users.noreply.github.com> Date: Fri, 1 Dec 2023 09:47:30 -0800 Subject: [PATCH 1/4] fix(subpackages): fixed detection issue of subpackages in some filein records --- autotest/test_mf6.py | 32 ++++++++++++++++++++++++++++++++ flopy/mf6/mfpackage.py | 1 - 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/autotest/test_mf6.py b/autotest/test_mf6.py index 487a98a526..5e848a2f68 100644 --- a/autotest/test_mf6.py +++ b/autotest/test_mf6.py @@ -49,6 +49,7 @@ ModflowNam, ModflowTdis, ModflowUtllaktab, + ModflowUtlspca, ) from flopy.mf6.coordinates.modeldimensions import ( DataDimensions, @@ -2230,6 +2231,37 @@ def test_multi_model(function_tmpdir): assert fi_out[1][2] is None assert fi_out[2][2] == "MIXED" + spca1 = ModflowUtlspca( + gwt2, + filename="gwt_model_1.rch1.spc", + print_input=True + ) + spca2 = ModflowUtlspca( + gwt2, + filename="gwt_model_1.rch2.spc", + print_input=False + ) + spca3 = ModflowUtlspca( + gwt2, + filename="gwt_model_1.rch3.spc", + print_input=True + ) + spca4 = ModflowUtlspca( + gwt2, + filename="gwt_model_1.rch4.spc", + print_input=True + ) + + # test writing and loading spca packages + sim2.write_simulation() + sim3 = MFSimulation.load(sim_ws=sim2.sim_path) + gwt3 = sim3.get_model("gwt_model_1") + spc1 = gwt3.get_package("gwt_model_1.rch1.spc") + assert isinstance(spc1, ModflowUtlspca) + assert spc1.print_input.get_data() is True + spc2 = gwt3.get_package("gwt_model_1.rch2.spc") + assert spc2.print_input.get_data() is not True + # create a new gwt model sourcerecarray = [("WEL-1", "AUX", "CONCENTRATION")] gwt_2 = get_gwt_model( diff --git a/flopy/mf6/mfpackage.py b/flopy/mf6/mfpackage.py index 747f1f6919..d7dcaabcea 100644 --- a/flopy/mf6/mfpackage.py +++ b/flopy/mf6/mfpackage.py @@ -1225,7 +1225,6 @@ def _get_package_info(self, dataset): ) return package_info_list - return None return None def _add_to_info_list( From 74f24f91bc73c3bf3db0f25e212c3215036b4311 Mon Sep 17 00:00:00 2001 From: scottrp <45947939+scottrp@users.noreply.github.com> Date: Mon, 4 Dec 2023 13:14:55 -0800 Subject: [PATCH 2/4] fix(recarray cellid): fixed problem when setting data with a recarray with layer/row/column fields (instead of cellid tuple) --- autotest/test_mf6.py | 53 +++++++++++++++++------- flopy/mf6/coordinates/modeldimensions.py | 8 ++-- flopy/mf6/data/mfdatastorage.py | 10 ++++- 3 files changed, 50 insertions(+), 21 deletions(-) diff --git a/autotest/test_mf6.py b/autotest/test_mf6.py index 5e848a2f68..080c939301 100644 --- a/autotest/test_mf6.py +++ b/autotest/test_mf6.py @@ -1685,12 +1685,41 @@ def test_sfr_connections(function_tmpdir, example_data_path): # reload simulation sim2 = MFSimulation.load(sim_ws=sim_ws) - sim.set_all_data_external() - sim.write_simulation() - success, buff = sim.run_simulation() + sim2.set_all_data_external() + sim2.write_simulation() + success, buff = sim2.run_simulation() assert ( success - ), f"simulation {sim.name} did not run after being reloaded" + ), f"simulation {sim2.name} did not run after being reloaded" + + # test sfr recarray data + model2 = sim2.get_model() + sfr2 = model2.get_package("sfr") + sfr_pd = sfr2.packagedata + rec_data = [ + (0, 0, 0, 0, 1.0, 1.0, 0.01, 10.0, 1.0, 1.0, 1.0, 1, 1.0, 0), + (1, 0, 1, 0, 1.0, 1.0, 0.01, 10.0, 1.0, 1.0, 1.0, 2, 1.0, 0), + ] + rec_type = [ + ("ifno", int), + ("layer", int), + ("row", int), + ("column", int), + ("rlen", float), + ("rwid", float), + ("rgrd", float), + ("rtp", float), + ("rbth", float), + ("rhk", float), + ("man", float), + ("nconn", int), + ("ustrf", float), + ("nvd", int), + ] + pkg_data = np.rec.array(rec_data, rec_type) + sfr_pd.set_record({"data": pkg_data}) + data = sfr_pd.get_data() + assert data[0][1] == (0, 0, 0) @requires_exe("mf6") @@ -2232,24 +2261,16 @@ def test_multi_model(function_tmpdir): assert fi_out[2][2] == "MIXED" spca1 = ModflowUtlspca( - gwt2, - filename="gwt_model_1.rch1.spc", - print_input=True + gwt2, filename="gwt_model_1.rch1.spc", print_input=True ) spca2 = ModflowUtlspca( - gwt2, - filename="gwt_model_1.rch2.spc", - print_input=False + gwt2, filename="gwt_model_1.rch2.spc", print_input=False ) spca3 = ModflowUtlspca( - gwt2, - filename="gwt_model_1.rch3.spc", - print_input=True + gwt2, filename="gwt_model_1.rch3.spc", print_input=True ) spca4 = ModflowUtlspca( - gwt2, - filename="gwt_model_1.rch4.spc", - print_input=True + gwt2, filename="gwt_model_1.rch4.spc", print_input=True ) # test writing and loading spca packages diff --git a/flopy/mf6/coordinates/modeldimensions.py b/flopy/mf6/coordinates/modeldimensions.py index c41003592b..5b9460ecf8 100644 --- a/flopy/mf6/coordinates/modeldimensions.py +++ b/flopy/mf6/coordinates/modeldimensions.py @@ -615,10 +615,10 @@ def _resolve_data_item_shape( if data is None: if ( self.simulation_data.verbosity_level.value - >= VerbosityLevel.normal.value + >= VerbosityLevel.verbose.value ): print( - "WARNING: Unable to resolve " + "INFORMATION: Unable to resolve " "dimension of {} based on shape " '"{}".'.format( data_item_struct.path, item[0] @@ -651,10 +651,10 @@ def _resolve_data_item_shape( else: if ( self.simulation_data.verbosity_level.value - >= VerbosityLevel.normal.value + >= VerbosityLevel.verbose.value ): print( - "WARNING: Unable to resolve " + "INFORMATION: Unable to resolve " "dimension of {} based on shape " '"{}".'.format( data_item_struct.path, item[0] diff --git a/flopy/mf6/data/mfdatastorage.py b/flopy/mf6/data/mfdatastorage.py index fa0836076e..ba241b9dc8 100644 --- a/flopy/mf6/data/mfdatastorage.py +++ b/flopy/mf6/data/mfdatastorage.py @@ -1276,6 +1276,10 @@ def store_internal( self.layer_storage.first_item().data_storage_type = ( DataStorageType.internal_array ) + if data is None or isinstance(data, np.recarray): + if not self.tuple_cellids(data): + # fix data so cellid is a single tuple + data = self.make_tuple_cellids(data.tolist()) if data is None or isinstance(data, np.recarray): if self._simulation_data.verify_data and check_data: self._verify_list(data) @@ -1604,7 +1608,11 @@ def make_tuple_cellids(self, data): def tuple_cellids(self, data): for data_entry, cellid in zip(data[0], self.recarray_cellid_list): if cellid: - if isinstance(data_entry, int): + if ( + isinstance(data_entry, int) + or isinstance(data_entry, np.int32) + or isinstance(data_entry, np.int64) + ): # cellid is stored in separate columns in the recarray # (eg: one column for layer one column for row and # one columne for column) From a5476878977d7f1d43151870fb46f538ab1af4b6 Mon Sep 17 00:00:00 2001 From: scottrp <45947939+scottrp@users.noreply.github.com> Date: Mon, 4 Dec 2023 13:23:47 -0800 Subject: [PATCH 3/4] fix --- flopy/mf6/data/mfdatastorage.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flopy/mf6/data/mfdatastorage.py b/flopy/mf6/data/mfdatastorage.py index ba241b9dc8..098152f01d 100644 --- a/flopy/mf6/data/mfdatastorage.py +++ b/flopy/mf6/data/mfdatastorage.py @@ -1606,6 +1606,8 @@ def make_tuple_cellids(self, data): return new_data def tuple_cellids(self, data): + if data is None: + return True for data_entry, cellid in zip(data[0], self.recarray_cellid_list): if cellid: if ( From 54154cbcbb90c4ba16de4ab3b952781818a458ed Mon Sep 17 00:00:00 2001 From: scottrp <45947939+scottrp@users.noreply.github.com> Date: Mon, 4 Dec 2023 13:44:14 -0800 Subject: [PATCH 4/4] fix --- flopy/mf6/data/mfdatastorage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flopy/mf6/data/mfdatastorage.py b/flopy/mf6/data/mfdatastorage.py index 098152f01d..8fef1c2b7e 100644 --- a/flopy/mf6/data/mfdatastorage.py +++ b/flopy/mf6/data/mfdatastorage.py @@ -1606,7 +1606,7 @@ def make_tuple_cellids(self, data): return new_data def tuple_cellids(self, data): - if data is None: + if data is None or len(data) == 0: return True for data_entry, cellid in zip(data[0], self.recarray_cellid_list): if cellid: