Skip to content

Commit b4a28c5

Browse files
authored
fix(mf6): accept stress period data cellid as nested list (#2584)
fix #2583
1 parent 2c41a10 commit b4a28c5

File tree

2 files changed

+81
-2
lines changed

2 files changed

+81
-2
lines changed

autotest/test_mf6.py

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2334,7 +2334,7 @@ def test_remove_model(function_tmpdir, example_data_path):
23342334

23352335
@requires_pkg("shapely")
23362336
@requires_exe("triangle")
2337-
def test_flopy_2283(function_tmpdir):
2337+
def test_issue_2283(function_tmpdir):
23382338
# create triangular grid
23392339
triangle_ws = function_tmpdir / "triangle"
23402340
triangle_ws.mkdir()
@@ -2384,3 +2384,82 @@ def test_flopy_2283(function_tmpdir):
23842384
assert gwf.modelgrid.xoffset == disv.xorigin.get_data()
23852385
assert gwf.modelgrid.yoffset == disv.yorigin.get_data()
23862386
assert gwf.modelgrid.angrot == disv.angrot.get_data()
2387+
2388+
2389+
@pytest.mark.parametrize("form", ["flat", "list", "tuple"])
2390+
@pytest.mark.parametrize("mode", ["internal", "external"])
2391+
@pytest.mark.parametrize("list_", ["legacy", "pandas"])
2392+
def test_issue_2583(function_tmpdir, form, mode, list_):
2393+
name = "2583"
2394+
sim = flopy.mf6.MFSimulation(
2395+
sim_name=name,
2396+
sim_ws=function_tmpdir,
2397+
exe_name="mf6",
2398+
use_pandas=list_ == "pandas",
2399+
)
2400+
tdis = flopy.mf6.ModflowTdis(sim)
2401+
ims = flopy.mf6.ModflowIms(sim)
2402+
gwf = flopy.mf6.ModflowGwf(sim, modelname=name, save_flows=True)
2403+
dis = flopy.mf6.ModflowGwfdis(gwf, nrow=10, ncol=10)
2404+
ic = flopy.mf6.ModflowGwfic(gwf)
2405+
npf = flopy.mf6.ModflowGwfnpf(
2406+
gwf, save_specific_discharge=True, save_saturation=True
2407+
)
2408+
if form == "flat":
2409+
chd_spd = {
2410+
0: [[0, 0, 0, 1.0, 1.0], [0, 9, 9, 0.0, 0.0]],
2411+
1: [[0, 0, 0, 0.0, 0.0], [0, 9, 9, 1.0, 2.0]],
2412+
}
2413+
elif form == "list":
2414+
chd_spd = {
2415+
0: [[[0, 0, 0], 1.0, 1.0], [[0, 9, 9], 0.0, 0.0]],
2416+
1: [[[0, 0, 0], 0.0, 0.0], [[0, 9, 9], 1.0, 2.0]],
2417+
}
2418+
elif form == "tuple":
2419+
chd_spd = {
2420+
0: [[(0, 0, 0), 1.0, 1.0], [(0, 9, 9), 0.0, 0.0]],
2421+
1: [[(0, 0, 0), 0.0, 0.0], [(0, 9, 9), 1.0, 2.0]],
2422+
}
2423+
chd = flopy.mf6.ModflowGwfchd(
2424+
gwf, pname="CHD-1", stress_period_data=chd_spd, auxiliary=["concentration"]
2425+
)
2426+
if mode == "external":
2427+
chd.set_all_data_external()
2428+
2429+
sim.write_simulation()
2430+
2431+
chd_file_path = function_tmpdir / f"{name}.chd"
2432+
data_lines = []
2433+
2434+
if mode == "internal":
2435+
chd_lines = chd_file_path.open().readlines()
2436+
read = False
2437+
for line in chd_lines:
2438+
if line.startswith("#"):
2439+
continue
2440+
if line.startswith("BEGIN period 1"):
2441+
read = True
2442+
continue
2443+
if line.startswith("END"):
2444+
read = False
2445+
if read:
2446+
data_lines.append(line.strip().split())
2447+
else:
2448+
data_file_path = function_tmpdir / "2583.chd_stress_period_data_1.txt"
2449+
data_lines = [l.strip().split() for l in data_file_path.open().readlines()]
2450+
2451+
assert len(data_lines) == 2
2452+
2453+
first = data_lines[0]
2454+
assert first[0] == "1"
2455+
assert first[1] == "1"
2456+
assert first[2] == "1"
2457+
assert float(first[3]) == 1.0
2458+
assert float(first[4]) == 1.0
2459+
2460+
second = data_lines[1]
2461+
assert second[0] == "1"
2462+
assert second[1] == "10"
2463+
assert second[2] == "10"
2464+
assert float(second[3]) == 0.0
2465+
assert float(second[4]) == 0.0

flopy/mf6/data/mfdataplist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ def _untuple_cellids(self, pdata):
494494
data_item.type == DatumType.integer
495495
and data_item.name.lower() == "cellid"
496496
):
497-
if isinstance(pdata.iloc[0, data_idx], tuple):
497+
if isinstance(pdata.iloc[0, data_idx], (list, tuple)):
498498
fields_to_correct.append((data_idx, columns[data_idx]))
499499
data_idx += 1
500500
else:

0 commit comments

Comments
 (0)