From 3088e51bb546afc5a68103a81821c750480263b7 Mon Sep 17 00:00:00 2001 From: Chris Nicol <37314969+cnicol-gwlogic@users.noreply.github.com> Date: Tue, 2 Feb 2021 04:58:10 +1100 Subject: [PATCH] fix(modflow/mflpf) mfusg unstructured lpf ikcflag addition (#1044) * 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 --- autotest/t506_test.py | 18 ++++++++++++++++++ flopy/modflow/mflpf.py | 39 ++++++++++++++++++++++++++++----------- 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/autotest/t506_test.py b/autotest/t506_test.py index 9cbd6fb40..074cf4ed2 100644 --- a/autotest/t506_test.py +++ b/autotest/t506_test.py @@ -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 diff --git a/flopy/modflow/mflpf.py b/flopy/modflow/mflpf.py index 19e77794d..552128409 100644 --- a/flopy/modflow/mflpf.py +++ b/flopy/modflow/mflpf.py @@ -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") @@ -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, , 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 @@ -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 @@ -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 @@ -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, )