From 78e980f755c63844bf8e08eb983feff0eb028b83 Mon Sep 17 00:00:00 2001 From: cristianchiriac <80774326+cristianchiriac@users.noreply.github.com> Date: Sat, 17 Oct 2026 20:58:54 +0300 Subject: [PATCH] fix(model_splitter): keep maxats when copying the ATS package _create_sln_tdis passed only the ATS perioddata to the new TDIS package, so the split simulation's ATS file was written with the default MAXATS 1 while PERIODDATA still held every record, and MODFLOW 6 failed to read it. Pass maxats together with perioddata. Closes #2868 --- autotest/test_model_splitter.py | 37 +++++++++++++++++++++++++++++++ flopy/mf6/utils/model_splitter.py | 9 ++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/autotest/test_model_splitter.py b/autotest/test_model_splitter.py index 041ecc430..9f5d196e8 100644 --- a/autotest/test_model_splitter.py +++ b/autotest/test_model_splitter.py @@ -1938,6 +1938,43 @@ def test_ats(function_tmpdir): assert success +def test_ats_multiple_periods(function_tmpdir): + nper = 4 + sim = flopy.mf6.MFSimulation(sim_ws=function_tmpdir) + tdis = flopy.mf6.ModflowTdis( + sim, + nper=nper, + perioddata=[(1.0, 1, 1.0)] + [(10.0, 10, 1.0)] * (nper - 1), + ) + ats_perioddata = [(kper, 1.0, 0.1, 5.0, 2.0, 5.0) for kper in range(1, nper)] + tdis.ats.initialize(maxats=len(ats_perioddata), perioddata=ats_perioddata) + + flopy.mf6.ModflowIms(sim) + gwf = flopy.mf6.ModflowGwf(sim, modelname="ats") + flopy.mf6.ModflowGwfdis(gwf, nlay=1, nrow=1, ncol=10, top=10.0, botm=0.0) + flopy.mf6.ModflowGwfic(gwf, strt=5.0) + flopy.mf6.ModflowGwfnpf(gwf, k=1.0) + flopy.mf6.ModflowGwfchd( + gwf, stress_period_data=[[(0, 0, 0), 6.0], [(0, 0, 9), 4.0]] + ) + + array = np.ones((1, 10), dtype=int) + array[0, 5:] = 2 + + mfs = flopy.mf6.utils.Mf6Splitter(sim) + new_sim = mfs.split_model(array) + + ats = new_sim.tdis.ats + assert ats.maxats.get_data() == len(ats_perioddata) + assert len(ats.perioddata.get_data()) == len(ats_perioddata) + + split_ws = function_tmpdir / "split" + new_sim.set_sim_path(split_ws) + new_sim.write_simulation(silent=True) + ats_text = (split_ws / ats.filename).read_text().upper().split() + assert ats_text[ats_text.index("MAXATS") + 1] == str(len(ats_perioddata)) + + @requires_exe("mf6") def test_reconstruct_recarray(function_tmpdir): sim_path = get_example_data_path() / "mf6-freyberg" diff --git a/flopy/mf6/utils/model_splitter.py b/flopy/mf6/utils/model_splitter.py index 19df3656e..5790a8d8b 100644 --- a/flopy/mf6/utils/model_splitter.py +++ b/flopy/mf6/utils/model_splitter.py @@ -1362,8 +1362,13 @@ def _create_sln_tdis(self): elif key == "ats_perioddata": data = getattr(pak, "ats") if len(data._packages) > 0: - data = data._packages[0].perioddata.array - d[key] = data + # pass maxats along with perioddata, otherwise the new + # ATS package keeps the default maxats of 1 + ats = data._packages[0] + d[key] = { + "maxats": ats.maxats.get_data(), + "perioddata": ats.perioddata.array, + } else: data = getattr(pak, key)