Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions autotest/t016_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
8 changes: 8 additions & 0 deletions examples/data/mfusg_test/rch_evt_tests/usg_rch_evt.str
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions examples/data/mfusg_test/rch_evt_tests/usg_rch_evt_str.nam
Original file line number Diff line number Diff line change
@@ -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
51 changes: 37 additions & 14 deletions flopy/modflow/mfstr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -587,22 +589,27 @@ 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))

# dataset 8
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))

Expand Down Expand Up @@ -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]

Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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:
Expand All @@ -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

Expand Down