diff --git a/autotest/t016_test.py b/autotest/t016_test.py index 9c2ac4a103..bc4441e631 100644 --- a/autotest/t016_test.py +++ b/autotest/t016_test.py @@ -315,6 +315,28 @@ def test_usg_ss_to_tr(): return +def test_usg_str(): + # test mfusg model with str package + print("testing unstructured mfusg with STR: usg_rch_evt_str.nam") + + new_ws = f"{base_dir}_test_usg_str" + test_setup = FlopyTestSetup(verbose=True, test_dirs=new_ws) + + model_ws = os.path.join( + "..", "examples", "data", "mfusg_test", "rch_evt_tests" + ) + nam = "usg_rch_evt_str.nam" + m = flopy.mfusg.MfUsg.load(nam, model_ws=model_ws, exe_name=v) + + m.model_ws = new_ws + m.write_input() + if run: + success, buff = m.run_model() + assert success + + return + + if __name__ == "__main__": test_usg_disu_load() test_usg_sms_load() @@ -325,3 +347,4 @@ def test_usg_ss_to_tr(): test_usg_rch_evt_models02() test_usg_rch_evt_models02a() test_usg_ss_to_tr() + test_usg_str() diff --git a/examples/data/mfusg_test/rch_evt_tests/usg_rch_evt.str b/examples/data/mfusg_test/rch_evt_tests/usg_rch_evt.str new file mode 100644 index 0000000000..01df79612e --- /dev/null +++ b/examples/data/mfusg_test/rch_evt_tests/usg_rch_evt.str @@ -0,0 +1,8 @@ + 3 1 0 0 1 86400 50 50 + 3 0 0 + 8 1 1 1.0 0.0 0.1 2.0 2.5 + 5 1 2 0.0 0.0 0.1 1.9 2.4 + 2 1 3 0.0 0.0 0.1 1.8 2.3 + 1.0 0.001 0.1 + 1.0 0.001 0.1 + 1.0 0.001 0.1 diff --git a/examples/data/mfusg_test/rch_evt_tests/usg_rch_evt_str.nam b/examples/data/mfusg_test/rch_evt_tests/usg_rch_evt_str.nam new file mode 100644 index 0000000000..2f65a314e4 --- /dev/null +++ b/examples/data/mfusg_test/rch_evt_tests/usg_rch_evt_str.nam @@ -0,0 +1,13 @@ +LIST 7 usg_rch_evt_str.lst +BAS6 1 usg_rch_evt.bas +SMS 19 usg_rch_evt.sms +DISU 29 usg_rch_evt.disu +OC 22 usg_rch_evt.oc +RCH 18 usg_rch_evt.rch +evt 17 usg_rch_evt.evt +str 27 usg_rch_evt.str +CHD 199 usg_rch_evt.chd +LPF 11 usg_rch_evt.lpf +DATA(BINARY) 50 usg_rch_evt_str.cbb +DATA(BINARY) 30 usg_rch_evt_str.hds +DATA(BINARY) 31 usg_rch_evt_str.ddn diff --git a/flopy/modflow/mfstr.py b/flopy/modflow/mfstr.py index e92eb2472e..503cbe454d 100644 --- a/flopy/modflow/mfstr.py +++ b/flopy/modflow/mfstr.py @@ -561,6 +561,8 @@ def write_file(self): # set column lengths for fixed format input files for # datasets 6, 8, and 9 fmt6 = [5, 5, 5, 5, 5, 15, 10, 10, 10, 10] + if not self.parent.structured: + del fmt6[1:3] fmt8 = [10, 10, 10] fmt9 = 5 @@ -587,14 +589,19 @@ def write_file(self): tdata = np.recarray.copy(tdata) # dataset 6 for line in tdata: - line["k"] += 1 - line["i"] += 1 - line["j"] += 1 + if self.parent.structured: + line["k"] += 1 + line["i"] += 1 + line["j"] += 1 + ds8_idx_from, ds8_idx_to = 10, 12 + else: + line["node"] += 1 + ds8_idx_from, ds8_idx_to = 8, 10 ds6 = [] for idx, v in enumerate(line): - if idx < 10 or idx > 12: + if idx < ds8_idx_from or idx > ds8_idx_to: ds6.append(v) - if idx > 12: + if idx > ds8_idx_to: fmt6 += [10] f_str.write(write_fixed_var(ds6, ipos=fmt6, free=free)) @@ -602,7 +609,7 @@ def write_file(self): if self.icalc > 0: for line in tdata: ds8 = [] - for idx in range(10, 13): + for idx in range(ds8_idx_from, ds8_idx_to + 1): ds8.append(line[idx]) f_str.write(write_fixed_var(ds8, ipos=fmt8, free=free)) @@ -677,6 +684,10 @@ def load(cls, f, model, nper=None, ext_unit_dict=None): np.float32, np.float32, ] + if not model.structured: + del type6[1:3] + del fmt6[1:3] + fmt8 = [10, 10, 10] fmt9 = [5] @@ -751,7 +762,9 @@ def load(cls, f, model, nper=None, ext_unit_dict=None): # read parameter data if npstr > 0: - dt = ModflowStr.get_empty(1, aux_names=aux_names).dtype + dt = ModflowStr.get_empty( + 1, aux_names=aux_names, structured=model.structured + ).dtype pak_parms = mfparbc.load( f, npstr, dt, model, ext_unit_dict, model.verbose ) @@ -788,7 +801,7 @@ def load(cls, f, model, nper=None, ext_unit_dict=None): bnd_output = None seg_output = None current, current_seg = ModflowStr.get_empty( - itmp, nss, aux_names=aux_names + itmp, nss, aux_names=aux_names, structured=model.structured ) elif itmp > 0: if npstr > 0: @@ -818,7 +831,9 @@ def load(cls, f, model, nper=None, ext_unit_dict=None): data_dict = current_dict[iname] current = ModflowStr.get_empty( - par_dict["nlst"], aux_names=aux_names + par_dict["nlst"], + aux_names=aux_names, + structured=model.structured, ) # get appropriate parval @@ -842,7 +857,10 @@ def load(cls, f, model, nper=None, ext_unit_dict=None): if model.verbose: print(" reading str dataset 6") current, current_seg = ModflowStr.get_empty( - itmp, nss, aux_names=aux_names + itmp, + nss, + aux_names=aux_names, + structured=model.structured, ) for ibnd in range(itmp): line = f.readline() @@ -863,9 +881,14 @@ def load(cls, f, model, nper=None, ext_unit_dict=None): current[ibnd][name] = np.float32(tt[iaux]) # convert indices to zero-based - current["k"] -= 1 - current["i"] -= 1 - current["j"] -= 1 + if model.structured: + current["k"] -= 1 + current["i"] -= 1 + current["j"] -= 1 + ds8_idx_from, ds8_idx_to = 10, 13 + else: + current["node"] -= 1 + ds8_idx_from, ds8_idx_to = 8, 11 # read dataset 8 if icalc > 0: @@ -875,7 +898,7 @@ def load(cls, f, model, nper=None, ext_unit_dict=None): line = f.readline() t = read_fixed_var(line, ipos=fmt8, free=free) ipos = 0 - for idx in range(10, 13): + for idx in range(ds8_idx_from, ds8_idx_to): current[ibnd][idx] = np.float32(t[ipos]) ipos += 1