Skip to content

Commit

Permalink
update(ModflowFlwob and ModflowHob): added "no_print", "options", and… (
Browse files Browse the repository at this point in the history
#414)

* update(ModflowFlwob and ModflowHob): added "no_print", "options", and "filenames" kwargs.

*  refactor(modpath): refactor MODPATH 7 particle classes

Refactor MODPATH 7 particle classes to make a clear distinction between
particle groups and particle data (locations, etc.).

* Changes to LKT for dealing with multi-species simulations that include lakes (#412)

* Explicit cast to np.array isn't preserved

* Fixes issue in LAK package _init_ routines when only a single lake is active

* Previous alteration worked for one lake, but didn't handle one stage for multiple lakes.  This should account for that condition

* Fix mis-statement

* LMT: Lacking support for keyword 'ALL' following Package_Flows keyword

* Add precision for variable thkmin

* PERLEN variable getting trucated by use of "G" (general form) when number of significant digits was > 4.

* Switching printing of PERLEN in BTN from 10.6G to 10G

* Fix for issue #402 including a new test for checking mtlkt.py

* Remove apostrophe from comment (interferes with Travis build)

* Rename test, another recent commit had the same name

* Remove argument from call to test

* refactor(modpath): refactor particledata (#416)

Refactor ParticleData (input style 1) so that it is the same as the 
node template (input style 3). Refactor NodeParticleTemplates 
particles into a single class. Add starting particle location data 
input style 2.

* New jupyter notebook for MT3D-USGS (#415)

* Explicit cast to np.array isn't preserved

* Fixes issue in LAK package _init_ routines when only a single lake is active

* Previous alteration worked for one lake, but didn't handle one stage for multiple lakes.  This should account for that condition

* Fix mis-statement

* LMT: Lacking support for keyword 'ALL' following Package_Flows keyword

* Add precision for variable thkmin

* PERLEN variable getting trucated by use of "G" (general form) when number of significant digits was > 4.

* Switching printing of PERLEN in BTN from 10.6G to 10G

* Fix for issue #402 including a new test for checking mtlkt.py

* Remove apostrophe from comment (interferes with Travis build)

* Rename test, another recent commit had the same name

* Remove argument from call to test

* Adding new example notebook for MT3D-USGS that uses SFT, LKT, and UZT, including connections between them

* Fixed a typo, added link for docs/notebook_examples.md in a reasonable section of the document

* An errant capital letter in the new notebook, switched to lowercase

* docs: update documentation (#417)

Update docstrings for MFGridFile class. Update README.md and
CONTRIBUTING.md. Update pre-commit.py to use develop branch for
branches with "-" or ":" in the branch name (it is assumed these
are bug fix or feature branches for the develop branch.

* refactor(lgrutil.py) : redesign of the hidden lgrutil gem

Unfortunately, this breaks backward compatibility (if anyone was using this).  But the new implementation should be a little easier to use.  Still  need to implement ghost nodes.

* Removed old newline character before "NOPRINT".

* docs: update docstrings (#418)

Update docstrings for HeadObservation, ModflowHobs, and ModflowFlwob
classes.

Closed #406

* docs: update docstrings (#419)

Update docstrings for sphinx.

* refactor(Modflow): Forgive loading models with an incomplete BAS6 package (#420)

* raise IOError if external file does not exist

* remove requirement that BAS6 needs to be loaded in full

* update(ModflowFlwob and ModflowHob): add condition test to check for user-specified output file names.

* update(ModflowFlwob and ModflowHob): reworked additional code again after refactorization of upstream branch.

* update(ModflowFlwob and ModflowHob): reordered kwargs in __init__ to reflect order in docstring.

* update(ModflowFlwob and ModflowHob): reworked additional code again after refactorization of upstream branch.

* update(ModflowFlwob and ModflowHob): pass list of filenames to Package.__init__() to achieve desired output file names.

* update(ModflowFlwob and ModflowHob): updated HOB test and added new code to test FLWOBS.

* update(ModflowFlwob and ModflowHob): pass mf executable name to new model upon load.
  • Loading branch information
jbellino-usgs authored and jdhughes-usgs committed Oct 18, 2018
1 parent 0f2e539 commit 5b1eed6
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 9 deletions.
82 changes: 81 additions & 1 deletion autotest/t041_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_hob_simple():
ib = np.ones(shape3d, dtype=np.int)
ib[0, 0, 0] = -1
m = flopy.modflow.Modflow(modelname=modelname, model_ws=pth,
verbose=True, exe_name=exe_name, )
verbose=False, exe_name=exe_name, )
dis = flopy.modflow.ModflowDis(m, nlay=1, nrow=11, ncol=11, nper=2,
perlen=[1, 1])

Expand Down Expand Up @@ -204,7 +204,87 @@ def test_obs_create_and_write():
raise ValueError('could not load new HOB output file')


def test_hob_options():
"""
test041 load and run a simple MODFLOW-2005 OBS example with specified filenames
"""
print('test041 load and run a simple MODFLOW-2005 OBS example with specified filenames')
pth = os.path.join(cpth, 'simple')
modelname = 'hob_simple'
pkglst = ['dis', 'bas6', 'pcg', 'lpf']
m = flopy.modflow.Modflow.load(modelname + '.nam', model_ws=pth, check=False,
load_only=pkglst, verbose=False, exe_name=exe_name)

obs = flopy.modflow.HeadObservation(m, layer=0, row=5, column=5,
time_series_data=[[1., 54.4],
[2., 55.2]])
f_in = modelname + '_custom_fname.hob'
f_out = modelname + '_custom_fname.hob.out'
filenames = [f_in, f_out]
hob = flopy.modflow.ModflowHob(m, iuhobsv=51, hobdry=-9999.,
obs_data=[obs], options=['NOPRINT'],
filenames=filenames)


# add DRN package
spd = {0: [[0, 5, 5, .5, 8e6],
[0, 8, 8, .7, 8e6]]}
drn = flopy.modflow.ModflowDrn(m, 53, stress_period_data=spd)

# flow observation

# Lists of length nqfb
nqobfb = [1, 1]
nqclfb = [1, 1]

# Lists of length nqtfb
obsnam = ['drob_1', 'drob_2']
irefsp = [1, 1]
toffset = [0, 0]
flwobs = [0., 0.]

# Lists of length (nqfb, nqclfb)
layer = [[1], [1]]
row = [[6], [9]]
column = [[6], [9]]
factor = [[1.], [1.]]

drob = flopy.modflow.ModflowFlwob(m,
nqfb=len(nqclfb),
nqcfb=np.sum(nqclfb),
nqtfb=np.sum(nqobfb),
nqobfb=nqobfb,
nqclfb=nqclfb,
obsnam=obsnam,
irefsp=irefsp,
toffset=toffset,
flwobs=flwobs,
layer=layer,
row=row,
column=column,
factor=factor,
flowtype='drn',
options=['NOPRINT'],
filenames=['flwobs_simple.drob',
'flwobs_simple.obd'])
# Write the model input files
m.write_input()

assert m.get_output(unit=51) == f_out, 'output filename ({}) does \
not match specified name'.format(m.get_output(unit=51))

assert os.path.isfile(os.path.join(pth, f_in)), 'specified HOB input file not found'

# run the modflow-2005 model
if run:
success, buff = m.run_model(silent=False)
assert success, 'could not run simple MODFLOW-2005 model'

return


if __name__ == '__main__':
test_hob_simple()
test_obs_create_and_write()
test_obs_load_and_write()
test_hob_options()
3 changes: 2 additions & 1 deletion flopy/mbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ def add_output_file(self, unit, fname=None, extension='cbc',
# determine if the file is in external_units
if abs(unit) in self.external_units:
idx = self.external_units.index(abs(unit))
fname = os.path.basename(self.external_fnames[idx])
if fname is None:
fname = os.path.basename(self.external_fnames[idx])
binflag = self.external_binflag[idx]
self.remove_external(unit=abs(unit))
# determine if the unit exists in the output data
Expand Down
46 changes: 42 additions & 4 deletions flopy/modflow/mfflwob.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,25 @@ class ModflowFlwob(Package):
Filename extension. If extension is None, extension is set to
['chob','obc','gbob','obg','drob','obd', 'rvob','obr']
(default is None).
no_print : boolean
When True or 1, a list of flow observations will not be
written to the Listing File (default is False)
options : list of strings
Package options (default is None).
unitnumber : list of int
File unit number. If unitnumber is None, unitnumber is set to
[40, 140, 41, 141, 42, 142, 43, 143] (default is None).
filenames : str or list of str
Filenames to use for the package and the output files. If
filenames=None the package name will be created using the model name
and package extension and the flwob output name will be created using
the model name and .out extension (for example,
modflowtest.out), if iufbobsv is a number greater than zero.
If a single string is passed the package will be set to the string
and flwob output name will be created using the model name and .out
extension, if iufbobsv is a number greater than zero. To define the
names for all package files (input and output) the length of the list
of strings should be 2. Default is None.
Attributes
Expand All @@ -88,7 +104,8 @@ def __init__(self, model, nqfb=0, nqcfb=0, nqtfb=0, iufbobsv=0,
tomultfb=1.0, nqobfb=None, nqclfb=None, obsnam=None,
irefsp=None, toffset=None, flwobs=None, layer=None,
row=None, column=None, factor=None, flowtype=None,
extension=None, unitnumber=None):
extension=None, no_print=False, options=None,
filenames=None, unitnumber=None):

"""
Package constructor
Expand Down Expand Up @@ -151,9 +168,19 @@ def __init__(self, model, nqfb=0, nqcfb=0, nqtfb=0, iufbobsv=0,
msg = 'ModflowFlwob: flowtype must be CHD, GHB, DRN, or RIV'
raise KeyError(msg)

# set filenames
if filenames is None:
filenames = [None, None]
elif isinstance(filenames, str):
filenames = [filenames, None]
elif isinstance(filenames, list):
if len(filenames) < 2:
filenames.append(None)

# call base package constructor
Package.__init__(self, model, extension, name, unitnumber,
allowDuplicates=True)
Package.__init__(self, model, extension=extension, name=name,
unit_number=unitnumber,
allowDuplicates=True, filenames=filenames)

self.nqfb = nqfb
self.nqcfb = nqcfb
Expand Down Expand Up @@ -198,6 +225,14 @@ def __init__(self, model, nqfb=0, nqcfb=0, nqtfb=0, iufbobsv=0,

# add more checks here

self.no_print = no_print
self.np = 0
if options is None:
options = []
if self.no_print:
options.append('NOPRINT')
self.options = options

# add checks for input compliance (obsnam length, etc.)
self.parent.add_package(self)

Expand All @@ -220,7 +255,10 @@ def write_file(self):
line = '{:10d}'.format(self.nqfb)
line += '{:10d}'.format(self.nqcfb)
line += '{:10d}'.format(self.nqtfb)
line += '{:10d}\n'.format(self.iufbobsv)
line += '{:10d}'.format(self.iufbobsv)
if self.no_print or 'NOPRINT' in self.options:
line += '{: >10}'.format('NOPRINT')
line += '\n'
f_fbob.write(line)
f_fbob.write('{:10e}\n'.format(self.tomultfb))

Expand Down
23 changes: 20 additions & 3 deletions flopy/modflow/mfhob.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class ModflowHob(Package):
will be used (default is None).
extension : string
Filename extension (default is hob)
no_print : boolean
When True or 1, a list of head observations will not be
written to the Listing File (default is False)
options : list of strings
Package options (default is None).
unitnumber : int
File unit number (default is None)
filenames : str or list of str
Expand Down Expand Up @@ -77,8 +82,9 @@ class ModflowHob(Package):
"""

def __init__(self, model, iuhobsv=None, hobdry=0, tomulth=1.0,
obs_data=None, hobname=None,
extension='hob', unitnumber=None, filenames=None):
obs_data=None, hobname=None, extension='hob',
no_print=False, options=None,
unitnumber=None, filenames=None):
"""
Package constructor
"""
Expand Down Expand Up @@ -140,6 +146,14 @@ def __init__(self, model, iuhobsv=None, hobdry=0, tomulth=1.0,
# set self.obs_data
self.obs_data = obs_data

self.no_print = no_print
self.np = 0
if options is None:
options = []
if self.no_print:
options.append('NOPRINT')
self.options = options

# add checks for input compliance (obsnam length, etc.)
self.parent.add_package(self)

Expand Down Expand Up @@ -194,7 +208,10 @@ def write_file(self):
f.write('{:10d}'.format(self.mobs))
f.write('{:10d}'.format(self.maxm))
f.write('{:10d}'.format(self.iuhobsv))
f.write('{:10.4g}\n'.format(self.hobdry))
f.write('{:10.4g}'.format(self.hobdry))
if self.no_print or 'NOPRINT' in self.options:
f.write('{: >10}'.format('NOPRINT'))
f.write('\n')

# write dataset 2
f.write('{:10.4g}\n'.format(self.tomulth))
Expand Down

0 comments on commit 5b1eed6

Please sign in to comment.