Skip to content

Commit

Permalink
feat(str): add IRDFLG and IPTFLG control to STR (#905)
Browse files Browse the repository at this point in the history
Closes #788
  • Loading branch information
jdhughes-dev authored Jun 9, 2020
1 parent 04b74bd commit 3182f57
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 14 deletions.
11 changes: 8 additions & 3 deletions autotest/t015_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def test_str_free():

# get pointer to str package
str = m.str
str.istcb2 = -1

# add aux variables to str
aux_names = ['aux iface', 'aux xyz']
Expand All @@ -65,16 +66,20 @@ def test_str_free():
ntrib=str.ntrib, ndiv=str.ndiv,
icalc=str.icalc, const=str.const,
ipakcb=str.ipakcb, istcb2=str.istcb2,
iptflg=str.iptflg, irdflg=str.irdflg,
stress_period_data={0: current},
segment_data=str.segment_data,
options=aux_names)

# add head output to oc file
oclst = ['PRINT HEAD', 'PRINT BUDGET', 'SAVE HEAD']
spd = {(0,0): oclst, (0,1): oclst, (0,2): oclst}
oclst = ['PRINT HEAD', 'PRINT BUDGET', 'SAVE HEAD', 'SAVE BUDGET']
spd = {(0, 0): oclst, (0, 1): oclst, (0, 2): oclst}
oc = flopy.modflow.ModflowOc(m, stress_period_data=spd)
oc.reset_budgetunit()

# reset ipakcb for str package to get ascii output in lst file
str.ipakcb = -1

m.write_input()
if run:
try:
Expand Down Expand Up @@ -134,4 +139,4 @@ def test_str_plot():

if __name__ == '__main__':
test_str_free()
#test_str_plot()
# test_str_plot()
86 changes: 75 additions & 11 deletions flopy/modflow/mfstr.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ class ModflowStr(Package):
datasets 6 and 8 and the dtype for datasets 9 and 10 data in
stress_period_data and segment_data dictionaries.
(default is None)
irdflg : integer or dictionary
is a integer or dictionary containing a integer flag, when positive
suppresses printing of the stream input data for a stress period. If
an integer is passed, all stress periods will use the same value.
If a dictionary is passed, stress periods not in the dictionary will
assigned a value of 1. Default is None which will assign a value of 1
to all stress periods.
iptflg : integer or dictionary
is a integer or dictionary containing a integer flag, when positive
suppresses printing of stream results for a stress period. If an
integer is passed, all stress periods will use the same value.
If a dictionary is passed, stress periods not in the dictionary will
assigned a value of 1. Default is None which will assign a value of 1
to all stress periods.
stress_period_data : dictionary of reach data
Each dictionary contains a list of str reach data for a stress period.
Expand Down Expand Up @@ -202,17 +216,17 @@ class ModflowStr(Package):
>>> import flopy
>>> m = flopy.modflow.Modflow()
>>> strd = {}
>>> strd[0] = [[2, 3, 4, 15.6, 1050., -4]] #this river boundary will be
>>> strd[0] = [[2, 3, 4, 15.6, 1050., -4]] #this str boundary will be
>>> #applied to all stress periods
>>> str8 = flopy.modflow.ModflowStr(m, stress_period_data=strd)
>>> str = flopy.modflow.ModflowStr(m, stress_period_data=strd)
"""

def __init__(self, model, mxacts=0, nss=0, ntrib=0, ndiv=0, icalc=0,
const=86400., ipakcb=None, istcb2=None,
dtype=None, stress_period_data=None, segment_data=None,
extension='str', unitnumber=None, filenames=None,
options=None, **kwargs):
irdflg=None, iptflg=None, extension='str',
unitnumber=None, filenames=None, options=None, **kwargs):
"""
Package constructor.
Expand Down Expand Up @@ -290,6 +304,45 @@ def __init__(self, model, mxacts=0, nss=0, ntrib=0, ndiv=0, icalc=0,
# parameters are not supported
self.npstr = 0

# dataset 5
# check type of irdflg and iptflg
msg = ''
if irdflg is not None and not isinstance(irdflg, (int, dict)):
msg = 'irdflg'
if iptflg is not None and not isinstance(iptflg, (int, dict)):
if len(msg) > 0:
msg += ' and '
msg += 'iptflg'
if len(msg) > 0:
msg += ' must be an integer or a dictionary'
raise TypeError(msg)

# process irdflg
self.irdflg = {}
for n in range(self.parent.nper):
if irdflg is None:
self.irdflg[n] = 1
elif isinstance(irdflg, int):
self.irdflg[n] = irdflg
elif isinstance(irdflg, dict):
if n in irdflg:
self.irdflg[n] = irdflg[n]
else:
self.irdflg[n] = 1

# process iptflg
self.iptflg = {}
for n in range(self.parent.nper):
if iptflg is None:
self.iptflg[n] = 1
elif isinstance(iptflg, int):
self.iptflg[n] = iptflg
elif isinstance(iptflg, dict):
if n in iptflg:
self.iptflg[n] = iptflg[n]
else:
self.iptflg[n] = 1

# determine dtype for dataset 6
if dtype is not None:
self.dtype = dtype[0]
Expand Down Expand Up @@ -482,9 +535,10 @@ def write_file(self):
itmp = -1
else:
itmp = tdata.shape[0]
line = '{:10d}{:10d}{:10d} # stress period {}\n'.format(itmp, 0,
0,
iper + 1)
line = '{:10d}'.format(itmp) + \
'{:10d}'.format(self.irdflg[iper]) + \
'{:10d}'.format(self.iptflg[iper]) + \
' # stress period {}\n'.format(iper + 1)
f_str.write(line)
if itmp > 0:
tdata = np.recarray.copy(tdata)
Expand Down Expand Up @@ -647,8 +701,10 @@ def load(f, model, nper=None, ext_unit_dict=None):
model.verbose)

if nper is None:
nrow, ncol, nlay, nper = model.get_nrow_ncol_nlay_nper()
nper = model.nper

irdflg = {}
iptflg = {}
stress_period_data = {}
segment_data = {}
for iper in range(nper):
Expand All @@ -659,12 +715,19 @@ def load(f, model, nper=None, ext_unit_dict=None):
if line == '':
break
t = line.strip().split()

# set itmp
itmp = int(t[0])
irdflg, iptflg = 0, 0

# set irdflg and iptflg - initialize to 0 since this is how
# MODFLOW would interpret a missing value
iflg0, iflg1 = 0, 0
if len(t) > 1:
irdflg = int(t[1])
iflg0 = int(t[1])
if len(t) > 2:
iptflg = int(t[2])
iflg1 = int(t[2])
irdflg[iper] = iflg0
iptflg[iper] = iflg1

if itmp == 0:
bnd_output = None
Expand Down Expand Up @@ -810,6 +873,7 @@ def load(f, model, nper=None, ext_unit_dict=None):
strpak = ModflowStr(model, mxacts=mxacts, nss=nss,
ntrib=ntrib, ndiv=ndiv, icalc=icalc,
const=const, ipakcb=ipakcb, istcb2=istcb2,
iptflg=iptflg, irdflg=irdflg,
stress_period_data=stress_period_data,
segment_data=segment_data,
options=options, unitnumber=unitnumber,
Expand Down

0 comments on commit 3182f57

Please sign in to comment.