Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8d5c410

Browse files
authored
fix(model_splitter): copy on boundname remap (#2769)
Fix #2735
1 parent 6a5d271 commit 8d5c410

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

autotest/test_model_splitter.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,39 @@ def test_save_load_node_mapping_unstructured(function_tmpdir):
352352
np.testing.assert_allclose(new_heads, original_heads, err_msg=err_msg)
353353

354354

355+
@requires_pkg("h5py")
356+
def test_save_node_mapping_with_boundnames(function_tmpdir):
357+
# regression test for https://github.com/modflowpy/flopy/issues/2735
358+
# boundnames in stress packages were being inserted into _node_map,
359+
# causing save_node_mapping to fail with ValueError on int() conversion
360+
sim = flopy.mf6.MFSimulation(sim_name="test", sim_ws=str(function_tmpdir))
361+
flopy.mf6.ModflowTdis(sim)
362+
flopy.mf6.ModflowIms(sim)
363+
gwf = flopy.mf6.ModflowGwf(sim, modelname="test")
364+
flopy.mf6.ModflowGwfdis(gwf, nlay=1, nrow=10, ncol=10, top=10, botm=0)
365+
flopy.mf6.ModflowGwfic(gwf, strt=10)
366+
flopy.mf6.ModflowGwfnpf(gwf)
367+
flopy.mf6.ModflowGwfwel(
368+
gwf,
369+
stress_period_data={0: [((0, 2, 2), -1.0, "my_well")]},
370+
boundnames=True,
371+
)
372+
373+
array = np.zeros((10, 10), dtype=int)
374+
array[:, 5:] = 1
375+
mfsplit = Mf6Splitter(sim)
376+
mfsplit.split_model(array)
377+
378+
non_int_keys = [
379+
k for k in mfsplit._node_map if not isinstance(k, (int, np.integer))
380+
]
381+
assert not non_int_keys, f"boundnames leaked into _node_map: {non_int_keys}"
382+
383+
hdf_file = function_tmpdir / "node_map.hdf5"
384+
mfsplit.save_node_mapping(hdf_file)
385+
assert hdf_file.exists()
386+
387+
355388
def test_control_records(function_tmpdir):
356389
nrow = 10
357390
ncol = 10

flopy/mf6/utils/model_splitter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3484,7 +3484,7 @@ def _remap_package(self, package, ismvr=False):
34843484
pass
34853485

34863486
if hasattr(package, "obs"):
3487-
obs_map = {"cellid": self._node_map}
3487+
obs_map = {"cellid": dict(self._node_map)}
34883488
for mkey, mdict in mapped_data.items():
34893489
if "stress_period_data" in mdict:
34903490
for _, ra in mdict["stress_period_data"].items():

0 commit comments

Comments
 (0)