Skip to content

Commit

Permalink
use get_package instead of package_type_dict
Browse files Browse the repository at this point in the history
  • Loading branch information
deltamarnix committed Oct 10, 2024
1 parent 2ba46dc commit 3f67021
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
45 changes: 22 additions & 23 deletions autotest/regression/test_mf6.py
Original file line number Diff line number Diff line change
Expand Up @@ -4497,22 +4497,21 @@ def test006_2models_mvr(function_tmpdir, example_data_path):
exg_pkg.exchangedata.set_data(exg_data)

# test getting packages
pkg_dict = parent_model.package_dict
assert len(pkg_dict) == 6
pkg_names = parent_model.package_names
assert len(pkg_names) == 6
pkg_list = parent_model.get_package()
assert len(pkg_list) == 6
# confirm that this is a copy of the original dictionary with references
# to the packages
del pkg_dict[pkg_names[0]]
assert len(pkg_dict) == 5
pkg_dict = parent_model.package_dict
assert len(pkg_dict) == 6

old_val = pkg_dict["dis"].nlay.get_data()
pkg_dict["dis"].nlay = 22
pkg_dict = parent_model.package_dict
assert pkg_dict["dis"].nlay.get_data() == 22
pkg_dict["dis"].nlay = old_val
del pkg_list[0]
assert len(pkg_list) == 5
pkg_list = parent_model.get_package()
assert len(pkg_list) == 6

dis_pkg = parent_model.get_package("dis")
old_val = dis_pkg.nlay.get_data()
dis_pkg.nlay = 22
pkg_list = parent_model.get_package()
assert dis_pkg.nlay.get_data() == 22
dis_pkg.nlay = old_val

# write simulation again
save_folder = function_tmpdir / "save"
Expand Down Expand Up @@ -4560,8 +4559,8 @@ def test006_2models_mvr(function_tmpdir, example_data_path):
model = sim.get_model(model_name)
for package in model_package_check:
assert (
package in model.package_type_dict
or package in sim.package_type_dict
model.get_package(package, type_only=True) is not None
or sim.get_package(package, type_only=True) is not None
) == (package in load_only or f"{package}6" in load_only)
assert (len(sim._exchange_files) > 0) == (
"gwf6-gwf6" in load_only or "gwf-gwf" in load_only
Expand All @@ -4577,10 +4576,10 @@ def test006_2models_mvr(function_tmpdir, example_data_path):
)
model_parent = sim.get_model("parent")
model_child = sim.get_model("child")
assert "oc" not in model_parent.package_type_dict
assert "oc" in model_child.package_type_dict
assert "npf" in model_parent.package_type_dict
assert "npf" not in model_child.package_type_dict
assert model_parent.get_package("oc") is None
assert model_child.get_package("oc") is not None
assert model_parent.get_package("npf") is not None
assert model_child.get_package("npf") is None

# test running a runnable load_only case
sim = MFSimulation.load(
Expand Down Expand Up @@ -4652,9 +4651,9 @@ def test001e_uzf_3lay(function_tmpdir, example_data_path):
sim.set_sim_path(function_tmpdir)
model = sim.get_model()
for package in model_package_check:
assert (package in model.package_type_dict) == (
package in load_only or f"{package}6" in load_only
)
assert (
model.get_package(package, type_only=True) is not None
) == (package in load_only or f"{package}6" in load_only)
# test running a runnable load_only case
sim = MFSimulation.load(
model_name, "mf6", "mf6", pth, load_only=load_only_lists[0]
Expand Down
18 changes: 9 additions & 9 deletions autotest/test_model_splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,19 +467,19 @@ def test_empty_packages(function_tmpdir):
m0 = new_sim.get_model(f"{base_name}_0")
m1 = new_sim.get_model(f"{base_name}_1")

if "chd_0" in m0.package_dict:
raise AssertionError(f"Empty CHD file written to {base_name}_0 model")

if "wel_0" in m1.package_dict:
raise AssertionError(f"Empty WEL file written to {base_name}_1 model")
assert not m0.get_package(
name="chd_0"
), f"Empty CHD file written to {base_name}_0 model"
assert not m1.get_package(
name="wel_0"
), f"Empty WEL file written to {base_name}_1 model"

mvr_status0 = m0.sfr.mover.array
mvr_status1 = m0.sfr.mover.array

if not mvr_status0 or not mvr_status1:
raise AssertionError(
"Mover status being overwritten in options splitting"
)
assert (
mvr_status0 and mvr_status1
), "Mover status being overwritten in options splitting"


@requires_exe("mf6")
Expand Down
3 changes: 2 additions & 1 deletion flopy/mf6/mfsimbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
PackageContainerType,
VerbosityLevel,
)
from flopy.mf6.mfmodel import MFModel
from flopy.mf6.mfpackage import MFChildPackages, MFPackage
from flopy.mf6.modflow import mfnam, mftdis
from flopy.mf6.utils import binaryfile_utils, mfobservation
Expand Down Expand Up @@ -1871,7 +1872,7 @@ def model_dict(self):
"""
return self._models.copy()

def get_model(self, model_name=None):
def get_model(self, model_name=None) -> Optional[MFModel]:
"""
Returns the models in the simulation with a given model name, name
file name, or model type.
Expand Down
2 changes: 1 addition & 1 deletion flopy/mf6/utils/model_splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def optimize_splitting_mask(self, nparts):
lak_array = np.zeros((ncpl,), dtype=int)
laks = []
hfbs = []
for _, package in self._model.package_dict.items():
for package in self._model.get_package():
if isinstance(
package,
(
Expand Down

0 comments on commit 3f67021

Please sign in to comment.