Skip to content

Commit

Permalink
Merge 7aaa796 into 5098c56
Browse files Browse the repository at this point in the history
  • Loading branch information
jlarsen-usgs authored Aug 7, 2021
2 parents 5098c56 + 7aaa796 commit e94a4a3
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 5 deletions.
10 changes: 9 additions & 1 deletion autotest/t504_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,7 @@ def test_mf6_output():

bud = ml.oc.output.budget()
hds = ml.oc.output.head()
lst = ml.oc.output.list()

idomain = np.ones(ml.modelgrid.shape, dtype=int)
zonbud = ml.oc.output.zonebudget(idomain)
Expand All @@ -1184,9 +1185,13 @@ def test_mf6_output():
if not isinstance(zonbud, flopy.utils.ZoneBudget6):
raise AssertionError()

if not isinstance(lst, flopy.utils.MfListBudget):
raise AssertionError()

bud = ml.output.budget()
hds = ml.output.head()
zonbud = ml.output.zonebudget(idomain)
lst = ml.output.list()

if not isinstance(bud, flopy.utils.CellBudgetFile):
raise TypeError()
Expand All @@ -1197,6 +1202,9 @@ def test_mf6_output():
if not isinstance(zonbud, flopy.utils.ZoneBudget6):
raise TypeError()

if not isinstance(lst, flopy.utils.MfListBudget):
raise TypeError()

uzf = ml.uzf
uzf_bud = uzf.output.budget()
conv = uzf.output.package_convergence()
Expand All @@ -1220,7 +1228,7 @@ def test_mf6_output():
print(uzf.output.__dict__)
raise AssertionError(", ".join(uzf.output.methods()))

if len(ml.output.methods()) != 3:
if len(ml.output.methods()) != 4:
raise AssertionError()

if ml.dis.output.methods() is not None:
Expand Down
3 changes: 2 additions & 1 deletion flopy/mf6/mfmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from ..mbase import ModelInterface
from .utils.mfenums import DiscretizationType
from .data import mfstructure
from .utils.output_util import MF6Output
from ..utils.check import mf6check


Expand Down Expand Up @@ -606,7 +607,7 @@ def output(self):
try:
return self.oc.output
except AttributeError:
return None
return MF6Output(self)

def export(self, f, **kwargs):
"""Method to export a model to a shapefile or netcdf file
Expand Down
50 changes: 47 additions & 3 deletions flopy/mf6/utils/output_util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import os
from ...utils import HeadFile, CellBudgetFile, Mf6Obs, ZoneBudget6, ZoneFile6
from ...utils import (
HeadFile,
CellBudgetFile,
Mf6Obs,
ZoneBudget6,
ZoneFile6,
MfListBudget,
MtListBudget,
)
from ...utils.observationfile import CsvFile
from ...pakbase import PackageInterface
from ...mbase import ModelInterface


class MF6Output:
Expand All @@ -16,7 +25,7 @@ class MF6Output:
"""

def __init__(self, obj):
from ..modflow import ModflowUtlobs
from ..modflow import ModflowUtlobs, ModflowGwtoc, ModflowGwfoc

# set initial observation definitions
methods = {
Expand All @@ -31,9 +40,25 @@ def __init__(self, obj):
self._methods = []
self._sim_ws = obj.simulation_data.mfpath.get_sim_path()

if not isinstance(obj, PackageInterface):
if not isinstance(obj, (PackageInterface, ModelInterface)):
raise TypeError("Only mf6 PackageInterface types can be used")

# capture the list file for Models and for OC packages
if isinstance(obj, (ModelInterface, ModflowGwfoc, ModflowGwtoc)):
if isinstance(obj, ModelInterface):
ml = obj
else:
ml = obj.parent
self._mtype = ml.model_type
nam_file = ml.model_nam_file[:-4]
self._lst = ml.name_file.blocks["options"].datasets["list"].array
if self._lst is None:
self._lst = "{}.lst".format(nam_file)
setattr(self, "list", self.__list)
self._methods.append("list()")
if isinstance(obj, ModelInterface):
return

obspkg = False
if isinstance(obj, ModflowUtlobs):
# this is a package
Expand Down Expand Up @@ -267,6 +292,25 @@ def __csv(self, f=None):
except (IOError, FileNotFoundError):
return None

def __list(self):
"""
Method to read list files
Returns
-------
MfListBudget, MtListBudget object
"""
if self._lst is not None:
reader = MfListBudget
if self._mtype == "gwt":
reader = MtListBudget

try:
list_file = os.path.join(self._sim_ws, self._lst)
return reader(list_file)
except (AssertionError, IOError, FileNotFoundError):
return None

def __mulitfile_handler(self, f, flist):
"""
Expand Down

0 comments on commit e94a4a3

Please sign in to comment.