From 58381aa8ef0a6b8e48343ef21f5ae69f9e4447da Mon Sep 17 00:00:00 2001 From: jlarsen Date: Mon, 12 May 2025 12:25:55 -0700 Subject: [PATCH 1/2] fix(column lengths): autoscale array write to ncol for structured multi-model simulations --- autotest/test_model_splitter.py | 23 ++++++++++++++++++++++- flopy/mf6/mfmodel.py | 7 +++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/autotest/test_model_splitter.py b/autotest/test_model_splitter.py index 71a1cbd5da..2700cfd2ba 100644 --- a/autotest/test_model_splitter.py +++ b/autotest/test_model_splitter.py @@ -14,6 +14,12 @@ def test_structured_model_splitter(function_tmpdir): sim_path = get_example_data_path() / "mf6-freyberg" + from pathlib import Path + + function_tmpdir = Path("./temp") + + split_path = function_tmpdir / "split_model" + sim = MFSimulation.load(sim_ws=sim_path) sim.set_sim_path(function_tmpdir) sim.write_simulation() @@ -32,7 +38,7 @@ def test_structured_model_splitter(function_tmpdir): mfsplit = Mf6Splitter(sim) new_sim = mfsplit.split_model(array) - new_sim.set_sim_path(function_tmpdir / "split_model") + new_sim.set_sim_path(split_path) new_sim.write_simulation() new_sim.run_simulation() @@ -49,6 +55,21 @@ def test_structured_model_splitter(function_tmpdir): err_msg = "Heads from original and split models do not match" np.testing.assert_allclose(new_heads, original_heads, err_msg=err_msg) + # test that line length is ncol for each model.... + ll_dict = { + split_path / f"freyberg_001.npf": ml0.dis.ncol.get_data(), + split_path / f"freyberg_100.npf": ml1.dis.ncol.get_data(), + } + for f, ncol in ll_dict.items(): + with open(f) as foo: + while "internal" not in foo.readline().lower(): + continue + + line = foo.readline().strip() + tmp = line.split() + if len(tmp) != ncol: + raise AssertionError("Array column length is not equal to ncol") + @requires_exe("mf6") def test_vertex_model_splitter(function_tmpdir): diff --git a/flopy/mf6/mfmodel.py b/flopy/mf6/mfmodel.py index 54c6f49ba4..0abc25cbdf 100644 --- a/flopy/mf6/mfmodel.py +++ b/flopy/mf6/mfmodel.py @@ -1318,6 +1318,13 @@ def write(self, ext_file_action=ExtFileAction.copy_relative_paths): self.name_file.write(ext_file_action=ext_file_action) + if not self.simulation_data.max_columns_user_set: + grid_type = self.get_grid_type() + if grid_type == DiscretizationType.DIS: + self.simulation_data.max_columns_of_data = self.dis.ncol.get_data() + self.simulation_data.max_columns_user_set = False + self.simulation_data.max_columns_auto_set = True + # write packages for pp in self.packagelist: if ( From 87837f39cdd0c2eb33824b2707a12d75b2fb9f6d Mon Sep 17 00:00:00 2001 From: jlarsen Date: Mon, 12 May 2025 12:28:27 -0700 Subject: [PATCH 2/2] linting --- autotest/test_model_splitter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autotest/test_model_splitter.py b/autotest/test_model_splitter.py index 2700cfd2ba..712b2809ac 100644 --- a/autotest/test_model_splitter.py +++ b/autotest/test_model_splitter.py @@ -57,8 +57,8 @@ def test_structured_model_splitter(function_tmpdir): # test that line length is ncol for each model.... ll_dict = { - split_path / f"freyberg_001.npf": ml0.dis.ncol.get_data(), - split_path / f"freyberg_100.npf": ml1.dis.ncol.get_data(), + split_path / "freyberg_001.npf": ml0.dis.ncol.get_data(), + split_path / "freyberg_100.npf": ml1.dis.ncol.get_data(), } for f, ncol in ll_dict.items(): with open(f) as foo: