Skip to content

Commit

Permalink
feat(ModflowSms): add support for simple, moderate, complex (#906)
Browse files Browse the repository at this point in the history
* Close #774
  • Loading branch information
langevin-usgs committed Jun 9, 2020
1 parent 3182f57 commit f539d07
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 10 deletions.
52 changes: 50 additions & 2 deletions autotest/t016_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@
import flopy
import numpy as np


tpth = os.path.abspath(os.path.join('temp', 't016'))
if not os.path.isdir(tpth):
os.makedirs(tpth)


exe_name = 'mfusg'
v = flopy.which(exe_name)

run = True
if v is None:
run = False


def test_usg_disu_load():

pthusgtest = os.path.join('..', 'examples', 'data', 'mfusg_test',
Expand All @@ -17,7 +31,7 @@ def test_usg_disu_load():
assert isinstance(disu, flopy.modflow.ModflowDisU)

# Change where model files are written
model_ws = os.path.join('temp', 't016')
model_ws = tpth
m.model_ws = model_ws

# Write the disu file
Expand All @@ -37,6 +51,7 @@ def test_usg_disu_load():

return


def test_usg_sms_load():

pthusgtest = os.path.join('..', 'examples', 'data', 'mfusg_test',
Expand All @@ -52,7 +67,7 @@ def test_usg_sms_load():
assert isinstance(sms, flopy.modflow.ModflowSms)

# Change where model files are written
model_ws = os.path.join('temp', 't016')
model_ws = tpth
m.model_ws = model_ws

# Write the sms file
Expand All @@ -69,6 +84,39 @@ def test_usg_sms_load():

return


def test_usg_model():
mf = flopy.modflow.Modflow(version='mfusg', structured=True,
model_ws=tpth, modelname='simple',
exe_name=v)
dis = flopy.modflow.ModflowDis(mf, nlay=1, nrow=11, ncol=11)
bas = flopy.modflow.ModflowBas(mf)
lpf = flopy.modflow.ModflowLpf(mf)
wel = flopy.modflow.ModflowWel(mf, stress_period_data={0: [[0, 5, 5, -1.]]})
ghb = flopy.modflow.ModflowGhb(mf,
stress_period_data={
0: [[0, 0, 0, 1.0, 1000.],
[0, 9, 9, 0.0, 1000.], ]})
oc = flopy.modflow.ModflowOc(mf)
sms = flopy.modflow.ModflowSms(mf, options='complex')

# run with defaults
mf.write_input()
if run:
success, buff = mf.run_model()
assert success

# try different complexity options; all should run successfully
for complexity in ['simple', 'moderate', 'complex']:
print('testing MFUSG with sms complexity: ' + complexity)
sms = flopy.modflow.ModflowSms(mf, options=complexity)
sms.write_file()
if run:
success, buff = mf.run_model()
assert success


if __name__ == '__main__':
test_usg_disu_load()
test_usg_sms_load()
test_usg_model()
21 changes: 13 additions & 8 deletions flopy/modflow/mfsms.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ def __init__(self, model, hclose=1E-4, hiclose=1E-4, mxiter=100,
if options is None:
self.options = []
else:
if not isinstance(options, list):
options = [options]
self.options = options
self.parent.add_package(self)
return
Expand All @@ -319,21 +321,25 @@ def write_file(self):
"""
f = open(self.fn_path, 'w')
f.write('{}\n'.format(self.heading))
nopt = len(self.options)
if nopt > 0:
f.write(' '.join(self.options) + '\n')
f.write('{0} {1} {2} {3} {4} {5} {6}\n'.format(
self.hclose, self.hiclose, self.mxiter, self.iter1,
self.iprsms, self.nonlinmeth, self.linmeth))
if self.nonlinmeth != 0:
if self.nonlinmeth != 0 and nopt == 0:
f.write('{0} {1} {2} {3} {4} {5} {6} {7}\n'.format(
self.theta, self.akappa, self.gamma, self.amomentum,
self.numtrack, self.btol, self.breduc, self.reslim))
if self.linmeth == 1:
if self.linmeth == 1 and nopt == 0:
f.write('{0} {1} {2} {3} {4} {5} {6} {7}\n'.format(
self.iacl, self.norder, self.level, self.north,
self.iredsys, self.rrctol, self.idroptol, self.epsrn))
if self.linmeth == 2:
if self.linmeth == 2 and nopt == 0:
f.write('{0} {1} {2} {3} {4} {5}\n'.format(
self.clin, self.ipc, self.iscl, self.iord,
self.rclosepcgu, self.relaxpcgu))
f.write('\n')
f.close()

@staticmethod
Expand Down Expand Up @@ -390,13 +396,12 @@ def load(f, model, ext_unit_dict=None):
break

# Record 1a
nopt = 0
opts = ['simple', 'moderate', 'complex']
options = []
for o in opts:
if o in line.lower():
options.append(o)
nopt += 1
firstentry = line.strip().split()[0]
if firstentry.lower() in opts:
options.append(firstentry)
nopt = len(options)

if nopt > 0:
line = f.readline()
Expand Down

0 comments on commit f539d07

Please sign in to comment.