Skip to content

Commit

Permalink
fix(modflow/mflpf) mfusg unstructured lpf ikcflag addition (#1044)
Browse files Browse the repository at this point in the history
* fix(modflow/mflpf) mfusg unstructured lpf ikcflag addition

Add writing of IKCFLAG to mfusg unstructured models' LPF package.
This was not previously written, which resulted in all flavours of mfusg
throwing an error on LPF load for unstructured models, if any keywords were
specified. No other model types are affected by this change.
Add test to existing t506_test.test_mfusg.

* fix(modflow/mflpf) mfusg unstructured lpf ikcflag addition

Add writing of IKCFLAG to mfusg unstructured models' LPF package.
This was not previously written, which resulted in all flavours of mfusg
throwing an error on LPF load for unstructured models, if any keywords were
specified. No other model types are affected by this change.
Add test to existing t506_test.test_mfusg.

* fix(modflow/mflpf) mfusg unstructured lpf ikcflag addition

Hard coded IKCFLAG == 0 in mfusg unstructured models' LPF package.
Allowing values of 1 and -1 opened a can of worms.
Add ikcflag to load method for mfusg unstructured models.
Add missing nocvcorrection option to lpf constructor call in load method.
Add load test for mfusg unstructured lpf with keyword options to existing t506_test.test_mfusg.

* fix(modflow/mflpf) mfusg unstructured lpf ikcflag addition

Remove test t506 black formatting from last commit

* retrigger checks
  • Loading branch information
cnicol-gwlogic committed Feb 1, 2021
1 parent b8322dd commit 3088e51
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
18 changes: 18 additions & 0 deletions autotest/t506_test.py
Expand Up @@ -340,6 +340,24 @@ def test_mfusg():
plt.savefig(fname)
plt.close('all')

# re-run with an LPF keyword specified. This would have thrown an error
# before the addition of ikcflag to mflpf.py (flopy 3.3.3 and earlier).
lpf = flopy.modflow.ModflowLpf(m, novfc=True, nocvcorrection=True)
m.write_input()
m.run_model()

# also test load of unstructured LPF with keywords
lpf2 = flopy.modflow.ModflowLpf.load(
os.path.join(ws, name + ".lpf"), m, check=False
)
msg = "NOCVCORRECTION and NOVFC should be in lpf options but at least one is not."
assert (
"NOVFC" in lpf2.options.upper()
and "NOCVCORRECTION" in lpf2.options.upper()
), msg

return


def test_disv_dot_plot():
# load up the vertex example problem
Expand Down
39 changes: 28 additions & 11 deletions flopy/modflow/mflpf.py
Expand Up @@ -269,6 +269,7 @@ def __init__(
hdry # Head in cells that are converted to dry during a simulation
)
self.nplpf = 0 # number of LPF parameters
self.ikcflag = 0 # 1 and -1 are not supported.
self.laytyp = Util2d(model, (nlay,), np.int32, laytyp, name="laytyp")
self.layavg = Util2d(model, (nlay,), np.int32, layavg, name="layavg")
self.chani = Util2d(model, (nlay,), np.float32, chani, name="chani")
Expand Down Expand Up @@ -396,12 +397,23 @@ def write_file(self, check=True, f=None):
# Item 0: text
f.write("{}\n".format(self.heading))

# Item 1: IBCFCB, HDRY, NPLPF
f.write(
"{0:10d}{1:10.6G}{2:10d} {3:s}\n".format(
self.ipakcb, self.hdry, self.nplpf, self.options
# Item 1: IBCFCB, HDRY, NPLPF, <IKCFLAG>, OPTIONS
if self.parent.version == "mfusg" and self.parent.structured == False:
f.write(
"{0:10d}{1:10.6G}{2:10d}{3:10d} {4:s}\n".format(
self.ipakcb,
self.hdry,
self.nplpf,
self.ikcflag,
self.options,
)
)
else:
f.write(
"{0:10d}{1:10.6G}{2:10d} {3:s}\n".format(
self.ipakcb, self.hdry, self.nplpf, self.options
)
)
)
# LAYTYP array
f.write(self.laytyp.string)
# LAYAVG array
Expand Down Expand Up @@ -497,6 +509,10 @@ def load(cls, f, model, ext_unit_dict=None, check=True):
print(" loading IBCFCB, HDRY, NPLPF...")
t = line_parse(line)
ipakcb, hdry, nplpf = int(t[0]), float(t[1]), int(t[2])
item1_len = 3
if model.version == "mfusg" and model.structured == False:
ikcflag = int(t[3])
item1_len = 4
# if ipakcb != 0:
# model.add_pop_key_list(ipakcb)
# ipakcb = 53
Expand All @@ -506,17 +522,17 @@ def load(cls, f, model, ext_unit_dict=None, check=True):
thickstrt = False
nocvcorrection = False
novfc = False
if len(t) > 3:
for k in range(3, len(t)):
if len(t) > item1_len:
for k in range(item1_len, len(t)):
if "STORAGECOEFFICIENT" in t[k].upper():
storagecoefficient = True
elif "CONSTANTCV" in t[k].upper():
if "CONSTANTCV" in t[k].upper():
constantcv = True
elif "THICKSTRT" in t[k].upper():
if "THICKSTRT" in t[k].upper():
thickstrt = True
elif "NOCVCORRECTION" in t[k].upper():
if "NOCVCORRECTION" in t[k].upper():
nocvcorrection = True
elif "NOVFC" in t[k].upper():
if "NOVFC" in t[k].upper():
novfc = True

# LAYTYP array
Expand Down Expand Up @@ -747,6 +763,7 @@ def load(cls, f, model, ext_unit_dict=None, check=True):
constantcv=constantcv,
thickstrt=thickstrt,
novfc=novfc,
nocvcorrection=nocvcorrection,
unitnumber=unitnumber,
filenames=filenames,
)
Expand Down

0 comments on commit 3088e51

Please sign in to comment.