Skip to content

Commit 87f8535

Browse files
mjrenomjreno
authored andcommitted
add tests
1 parent 2b1ac9b commit 87f8535

16 files changed

Lines changed: 1152 additions & 146 deletions

autotest/test_gwf_disv_uzf.py

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import numpy as np
1515
import pytest
1616
from flopy.utils.gridutil import get_disv_kwargs
17-
from framework import TestFramework
17+
from framework import DNODATA, TestFramework
1818

1919
cases = ["disv_with_uzf"]
2020
nlay = 5
@@ -109,20 +109,21 @@
109109
uzf_spd.update({t: spd})
110110

111111

112-
# Work up the GHB boundary
112+
# Work up the GHB / GHBA boundary
113113
ghb_ids = [(ncol - 1) + i * ncol for i in range(nrow)]
114114
ghb_spd = []
115+
abhead = np.full((nlay, ncpl), DNODATA, dtype=np.float64)
116+
acond = np.full((nlay, ncpl), DNODATA, dtype=np.float64)
115117
cond = 1e4
116118
for k in np.arange(3, 5, 1):
117119
for i in ghb_ids:
118120
ghb_spd.append([(k, i), 14.0, cond])
121+
abhead[k, i] = 14.0
122+
acond[k, i] = cond
119123

120124

121-
def build_models(idx, test):
122-
name = cases[idx]
123-
125+
def get_model(ws, name, array_input=False):
124126
# build MODFLOW 6 files
125-
ws = test.workspace
126127
sim = flopy.mf6.MFSimulation(
127128
sim_name=name, version="mf6", exe_name="mf6", sim_ws=ws
128129
)
@@ -171,7 +172,10 @@ def build_models(idx, test):
171172
sto = flopy.mf6.ModflowGwfsto(gwf, iconvert=1, ss=1e-5, sy=0.2, transient=True)
172173

173174
# general-head boundary
174-
ghb = flopy.mf6.ModflowGwfghb(gwf, print_flows=True, stress_period_data=ghb_spd)
175+
if array_input:
176+
ghb = flopy.mf6.ModflowGwfghba(gwf, print_flows=True, bhead=abhead, cond=acond)
177+
else:
178+
ghb = flopy.mf6.ModflowGwfghb(gwf, print_flows=True, stress_period_data=ghb_spd)
175179

176180
# unsaturated-zone flow
177181
etobs = []
@@ -220,18 +224,18 @@ def build_models(idx, test):
220224
obs_dict = {f"{name}.obs.csv": obs_lst}
221225
obs = flopy.mf6.ModflowUtlobs(gwf, pname="head_obs", digits=20, continuous=obs_dict)
222226

223-
return sim, None
227+
return sim
224228

225229

226-
def check_output(idx, test):
230+
def check_output(ws, name):
227231
# Next, get the binary printed heads
228-
fpth = os.path.join(test.workspace, test.name + ".hds")
232+
fpth = os.path.join(ws, name + ".hds")
229233
hobj = flopy.utils.HeadFile(fpth, precision="double")
230234
hds = hobj.get_alldata()
231235
hds = hds.reshape((np.sum(nstp), 5, 10, 10))
232236

233237
# Get the MF6 cell-by-cell fluxes
234-
bpth = os.path.join(test.workspace, test.name + ".cbc")
238+
bpth = os.path.join(ws, name + ".cbc")
235239
bobj = flopy.utils.CellBudgetFile(bpth, precision="double")
236240
bobj.get_unique_record_names()
237241
# ' STO-SS'
@@ -249,7 +253,7 @@ def check_output(idx, test):
249253
gwet = gwetv.reshape((np.sum(nstp), 5, 10, 10))
250254

251255
# Also retrieve the binary UZET output
252-
uzpth = os.path.join(test.workspace, test.name + ".uzf.bud")
256+
uzpth = os.path.join(ws, name + ".uzf.bud")
253257
uzobj = flopy.utils.CellBudgetFile(uzpth, precision="double")
254258
uzobj.get_unique_record_names()
255259
# b' FLOW-JA-FACE',
@@ -353,6 +357,31 @@ def check_output(idx, test):
353357
print("Finished running checks")
354358

355359

360+
def build_models(idx, test):
361+
# build MODFLOW 6 files
362+
ws = test.workspace
363+
name = cases[idx]
364+
sim = get_model(ws, name)
365+
366+
# build comparison array_input model
367+
ws = os.path.join(test.workspace, "mf6")
368+
mc = get_model(ws, name, array_input=True)
369+
370+
return sim, mc
371+
372+
373+
def check_outputs(idx, test):
374+
name = cases[idx]
375+
376+
# check output MODFLOW 6 files
377+
ws = test.workspace
378+
check_output(ws, name)
379+
380+
# check output comparison array_input model
381+
ws = os.path.join(test.workspace, "mf6")
382+
check_output(ws, name)
383+
384+
356385
@pytest.mark.slow
357386
@pytest.mark.parametrize("idx, name", enumerate(cases))
358387
def test_mf6model(idx, name, function_tmpdir, targets):
@@ -361,6 +390,7 @@ def test_mf6model(idx, name, function_tmpdir, targets):
361390
workspace=function_tmpdir,
362391
targets=targets,
363392
build=lambda t: build_models(idx, t),
364-
check=lambda t: check_output(idx, t),
393+
check=lambda t: check_outputs(idx, t),
394+
compare="mf6",
365395
)
366396
test.run()

autotest/test_gwf_sfr_inactive02.py

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
# Test evap in SFR reaches (no interaction with gwf)
22

3+
import os
34

45
import flopy
56
import numpy as np
67
import pytest
7-
from framework import TestFramework
8+
from framework import DNODATA, TestFramework
89

910
HDRY, HNOFLO = -1e30, 1e30
1011

1112
cases = ["sfr-inactive02"]
1213

1314

14-
def build_models(idx, test):
15+
def get_model(ws, name, array_input=False):
1516
# Base simulation and model name and workspace
16-
ws = test.workspace
17-
name = cases[idx]
1817

1918
length_units = "m"
2019
time_units = "sec"
@@ -66,7 +65,15 @@ def build_models(idx, test):
6665
icelltype=1, # >0 means saturated thickness varies with computed head
6766
)
6867
flopy.mf6.ModflowGwfic(gwf, strt=1.0)
69-
flopy.mf6.ModflowGwfghb(gwf, stress_period_data=[((0, 0, 0), 1.0, 1e6)])
68+
if array_input:
69+
# if False:
70+
bhead = np.full(nlay * nrow * ncol, DNODATA, dtype=np.float64)
71+
cond = np.full(nlay * nrow * ncol, DNODATA, dtype=np.float64)
72+
bhead[0] = 1.0
73+
cond[0] = 1e6
74+
flopy.mf6.ModflowGwfghba(gwf, bhead=bhead, cond=cond)
75+
else:
76+
flopy.mf6.ModflowGwfghb(gwf, stress_period_data=[((0, 0, 0), 1.0, 1e6)])
7077

7178
# sfr data
7279
nreaches = 4
@@ -116,7 +123,7 @@ def build_models(idx, test):
116123
print_stage=True,
117124
print_flows=True,
118125
print_input=True,
119-
stage_filerecord=f"{name}.sfr.hds",
126+
stage_filerecord=f"{name}.sfr.stg",
120127
budget_filerecord=f"{name}.sfr.cbc",
121128
length_conversion=1.0,
122129
time_conversion=1.0,
@@ -150,11 +157,11 @@ def build_models(idx, test):
150157
saverecord=[("head", "all"), ("budget", "all")],
151158
)
152159

153-
return sim, None
160+
return sim
154161

155162

156-
def check_output(idx, test):
157-
sim = flopy.mf6.MFSimulation.load(sim_ws=test.workspace)
163+
def check_output(ws, name):
164+
sim = flopy.mf6.MFSimulation.load(sim_ws=ws)
158165
gwf = sim.get_model()
159166
sfr = gwf.get_package("SFR-1")
160167
stage = sfr.output.stage().get_alldata().squeeze()
@@ -214,13 +221,39 @@ def check_output(idx, test):
214221
)
215222

216223

224+
def build_models(idx, test):
225+
# build MODFLOW 6 files
226+
ws = test.workspace
227+
name = cases[idx]
228+
sim = get_model(ws, name)
229+
230+
# build comparison array_input model
231+
ws = os.path.join(test.workspace, "mf6")
232+
mc = get_model(ws, name, array_input=True)
233+
234+
return sim, mc
235+
236+
237+
def check_outputs(idx, test):
238+
name = cases[idx]
239+
240+
# check output MODFLOW 6 files
241+
ws = test.workspace
242+
check_output(ws, name)
243+
244+
# check output comparison array_input model
245+
ws = os.path.join(test.workspace, "mf6")
246+
check_output(ws, name)
247+
248+
217249
@pytest.mark.parametrize("idx, name", enumerate(cases))
218250
def test_mf6model(idx, name, function_tmpdir, targets):
219251
test = TestFramework(
220252
name=name,
221253
workspace=function_tmpdir,
222254
targets=targets,
223255
build=lambda t: build_models(idx, t),
224-
check=lambda t: check_output(idx, t),
256+
check=lambda t: check_outputs(idx, t),
257+
compare="mf6",
225258
)
226259
test.run()

autotest/test_gwf_uzf01.py

Lines changed: 63 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@
88
import flopy
99
import numpy as np
1010
import pytest
11-
from framework import TestFramework
11+
from framework import DNODATA, TestFramework
1212

1313
cases = ["gwf_uzf01a"]
1414
nlay, nrow, ncol = 100, 1, 1
1515

1616

17-
def build_models(idx, test):
18-
name = cases[idx]
19-
17+
def get_model(ws, name, array_input=False):
2018
perlen = [500.0]
2119
nper = len(perlen)
2220
nstp = [10]
@@ -37,7 +35,6 @@ def build_models(idx, test):
3735
tdis_rc.append((perlen[i], nstp[i], tsmult[i]))
3836

3937
# build MODFLOW 6 files
40-
ws = test.workspace
4138
sim = flopy.mf6.MFSimulation(
4239
sim_name=name, version="mf6", exe_name="mf6", sim_ws=ws
4340
)
@@ -101,16 +98,39 @@ def build_models(idx, test):
10198
transient={0: True},
10299
)
103100

104-
# ghb
105-
ghbspdict = {
106-
0: [[(nlay - 1, 0, 0), 1.5, 1.0]],
107-
}
108-
ghb = flopy.mf6.ModflowGwfghb(
109-
gwf,
101+
# ghb / ghba
102+
if array_input:
103+
ghb_obs = {f"{name}.ghb.obs.csv": [("100_1_1", "GHBA", (99, 0, 0))]}
104+
bhead = np.full(nlay * nrow * ncol, DNODATA, dtype=np.float64)
105+
cond = np.full(nlay * nrow * ncol, DNODATA, dtype=np.float64)
106+
bhead[nlay - 1] = 1.5
107+
cond[nlay - 1] = 1.0
108+
ghb = flopy.mf6.ModflowGwfghba(
109+
gwf,
110+
print_input=True,
111+
print_flows=True,
112+
bhead=bhead,
113+
cond=cond,
114+
save_flows=False,
115+
)
116+
else:
117+
ghb_obs = {f"{name}.ghb.obs.csv": [("100_1_1", "GHB", (99, 0, 0))]}
118+
ghbspdict = {
119+
0: [[(nlay - 1, 0, 0), 1.5, 1.0]],
120+
}
121+
ghb = flopy.mf6.ModflowGwfghb(
122+
gwf,
123+
print_input=True,
124+
print_flows=True,
125+
stress_period_data=ghbspdict,
126+
save_flows=False,
127+
)
128+
129+
ghb.obs.initialize(
130+
filename=f"{name}.ghb.obs",
131+
digits=20,
110132
print_input=True,
111-
print_flows=True,
112-
stress_period_data=ghbspdict,
113-
save_flows=False,
133+
continuous=ghb_obs,
114134
)
115135

116136
# note: for specifying lake number, use fortran indexing!
@@ -171,13 +191,10 @@ def build_models(idx, test):
171191
obs_dict = {f"{name}.obs.csv": obs_lst}
172192
obs = flopy.mf6.ModflowUtlobs(gwf, pname="head_obs", digits=20, continuous=obs_dict)
173193

174-
return sim, None
194+
return sim
175195

176196

177-
def check_output(idx, test):
178-
name = test.name
179-
ws = test.workspace
180-
197+
def check_output(ws, name):
181198
# check binary grid file
182199
fname = os.path.join(ws, name + ".dis.grb")
183200
grbobj = flopy.mf6.utils.MfGrdFile(fname)
@@ -221,13 +238,39 @@ def check_output(idx, test):
221238
)
222239

223240

241+
def build_models(idx, test):
242+
# build MODFLOW 6 files
243+
ws = test.workspace
244+
name = cases[idx]
245+
sim = get_model(ws, name)
246+
247+
# build comparison array_input model
248+
ws = os.path.join(test.workspace, "mf6")
249+
mc = get_model(ws, name, array_input=True)
250+
251+
return sim, mc
252+
253+
254+
def check_outputs(idx, test):
255+
name = cases[idx]
256+
257+
# check output MODFLOW 6 files
258+
ws = test.workspace
259+
check_output(ws, name)
260+
261+
# check output comparison array_input model
262+
ws = os.path.join(test.workspace, "mf6")
263+
check_output(ws, name)
264+
265+
224266
@pytest.mark.parametrize("idx, name", enumerate(cases))
225267
def test_mf6model(idx, name, function_tmpdir, targets):
226268
test = TestFramework(
227269
name=name,
228270
workspace=function_tmpdir,
229271
build=lambda t: build_models(idx, t),
230-
check=lambda t: check_output(idx, t),
272+
check=lambda t: check_outputs(idx, t),
231273
targets=targets,
274+
compare="mf6",
232275
)
233276
test.run()

0 commit comments

Comments
 (0)