Skip to content

Commit f9f6427

Browse files
mjrenomjreno
authored andcommitted
test_grid_array mf6 test
1 parent 3cbff2c commit f9f6427

File tree

3 files changed

+70
-90
lines changed

3 files changed

+70
-90
lines changed

autotest/test_mf6.py

Lines changed: 66 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,12 +1977,6 @@ def test_grid_array(function_tmpdir):
19771977
msg = "test_mf6 test_grid_array did not run"
19781978
warnings.warn(msg, UserWarning)
19791979
return
1980-
# get_data
1981-
# empty data in period block vs data repeating
1982-
# array
1983-
# aux values, test that they work the same as other arrays (is a value
1984-
# of zero always used even if aux is defined in a previous stress
1985-
# period?)
19861980

19871981
sim_name = "test_grid_array"
19881982
model_name = "test_grid_array"
@@ -2089,24 +2083,27 @@ def test_grid_array(function_tmpdir):
20892083
ncol = dis.ncol.get_data()
20902084

20912085
DNODATA = 3.0e30 # MF6 DNODATA constant
2086+
nper = 4
20922087
welqspd = {}
20932088
welconcspd = {}
20942089
for n in range(4):
20952090
q = np.full((nlay, nrow, ncol), DNODATA, dtype=float)
20962091
welconc = np.full((nlay, nrow, ncol), DNODATA, dtype=float)
20972092
welaux2 = np.full((nlay, nrow, ncol), DNODATA, dtype=float)
2098-
# TODO constant by layer
2099-
# welaux2 = [DNODATA]
2093+
# welcaux2 = np.full((nlay), DNODATA, dtype=float)
21002094
if n == 1:
21012095
q[0, 0, 0] = 0.25
21022096
welconc[0, 0, 0] = 0.0
21032097
welaux2[0, 0, 0] = 9.0
2098+
# welcaux2[0] = 9.0
21042099
elif n == 2:
21052100
q[0, 0, 0] = 0.1
21062101
welconc[0, 0, 0] = 9.0
21072102
welaux2[0, 0, 0] = 0.0
2103+
# welcaux2[0] = 0.0
21082104
welqspd[n] = q
21092105
welconcspd[n] = [welconc, welaux2]
2106+
# welconcspd[n] = [welconc, welcaux2]
21102107

21112108
# first create test package with multiple auxvars
21122109
wel = ModflowGwfwelg(
@@ -2121,32 +2118,16 @@ def test_grid_array(function_tmpdir):
21212118
aux=welconcspd,
21222119
)
21232120

2124-
print(wel.aux.array)
2125-
print(wel.aux.get_data())
2126-
21272121
# sim.write_simulation()
2128-
# assert False
21292122

21302123
assert len(wel.q.array) == 4
21312124
assert len(wel.q.get_data()) == 4
21322125
assert len(wel.aux.array) == 4
21332126
assert len(wel.aux.get_data()) == 4
2134-
assert np.allclose(wel.aux.array[0][0], wel.aux.get_data(0)[0])
2135-
assert np.allclose(wel.aux.array[0][1], wel.aux.get_data(0)[1])
2136-
assert np.allclose(wel.aux.array[1][0], wel.aux.get_data(1)[0])
2137-
assert np.allclose(wel.aux.array[1][1], wel.aux.get_data(1)[1])
2138-
assert np.allclose(wel.aux.array[2][0], wel.aux.get_data(2)[0])
2139-
assert np.allclose(wel.aux.array[2][1], wel.aux.get_data(2)[1])
2140-
assert np.allclose(wel.aux.array[3][0], wel.aux.get_data(3)[0])
2141-
assert np.allclose(wel.aux.array[3][1], wel.aux.get_data(3)[1])
2142-
assert np.allclose(wel.aux.array[0][0], wel.aux.get_data()[0][0])
2143-
assert np.allclose(wel.aux.array[0][1], wel.aux.get_data()[0][1])
2144-
assert np.allclose(wel.aux.array[1][0], wel.aux.get_data()[1][0])
2145-
assert np.allclose(wel.aux.array[1][1], wel.aux.get_data()[1][1])
2146-
assert np.allclose(wel.aux.array[2][0], wel.aux.get_data()[2][0])
2147-
assert np.allclose(wel.aux.array[2][1], wel.aux.get_data()[2][1])
2148-
assert np.allclose(wel.aux.array[3][0], wel.aux.get_data()[3][0])
2149-
assert np.allclose(wel.aux.array[3][1], wel.aux.get_data()[3][1])
2127+
for p in range(nper):
2128+
for iaux in range(2): # naux
2129+
assert np.allclose(wel.aux.array[p][iaux], wel.aux.get_data(p)[iaux])
2130+
assert np.allclose(wel.aux.array[p][iaux], wel.aux.get_data()[p][iaux])
21502131

21512132
assert not wel.has_stress_period_data
21522133
q_nan = np.where(wel.q.array == DNODATA, np.nan, wel.q.array)
@@ -2173,7 +2154,6 @@ def test_grid_array(function_tmpdir):
21732154

21742155
# remove test wel package
21752156
sim.write_simulation()
2176-
# assert False
21772157
wel.remove()
21782158

21792159
welqspd = {}
@@ -2240,20 +2220,6 @@ def test_grid_array(function_tmpdir):
22402220
aux_data_3 = wel.aux.get_data(3)
22412221
assert aux_data_3 is None
22422222

2243-
# drnspdict = {
2244-
# 0: [[(0, 0, 0), 60.0, 10.0]],
2245-
# 2: [],
2246-
# 3: [[(0, 0, 0), 55.0, 5.0]],
2247-
# }
2248-
# drn = ModflowGwfdrn(
2249-
# model,
2250-
# print_input=True,
2251-
# print_flows=True,
2252-
# stress_period_data=drnspdict,
2253-
# save_flows=False,
2254-
# pname="DRN-1",
2255-
# )
2256-
22572223
drnelevspd = {}
22582224
drncondspd = {}
22592225
for n in range(4):
@@ -2290,32 +2256,47 @@ def test_grid_array(function_tmpdir):
22902256
assert len(drn_cond_data) == 4
22912257
assert np.allclose(drn_elev_array[0], drn_elev_data[0])
22922258
assert np.allclose(drn_elev_array[0], drn.elev.get_data(0))
2293-
2294-
# drn_array = drn.stress_period_data.array
2295-
# assert drn_array[0][0][1] == 60.0
2296-
# assert drn_array[1][0][1] == 60.0
2297-
# assert drn_array[2] is None
2298-
# assert drn_array[3][0][1] == 55.0
2299-
# drn_gd_0 = drn.stress_period_data.get_data(0)
2300-
# assert drn_gd_0[0][1] == 60.0
2301-
# drn_gd_1 = drn.stress_period_data.get_data(1)
2302-
# assert drn_gd_1 is None
2303-
# drn_gd_2 = drn.stress_period_data.get_data(2)
2304-
# assert len(drn_gd_2) == 0
2305-
# drn_gd_3 = drn.stress_period_data.get_data(3)
2306-
# assert drn_gd_3[0][1] == 55.0
2307-
2308-
ghbspdict = {
2309-
0: [[(0, 1, 1), 60.0, 10.0]],
2310-
}
2311-
ghb = ModflowGwfghb(
2259+
for p in range(nper):
2260+
if p == 1:
2261+
assert drn_elev_data[p] is None
2262+
assert drn.elev.get_data(p) is None
2263+
else:
2264+
assert np.allclose(drn_elev_array[p], drn_elev_data[p])
2265+
assert np.allclose(drn_elev_array[p], drn.elev.get_data()[p])
2266+
assert np.allclose(drn_elev_array[p], drn.elev.get_data(p))
2267+
2268+
ghbbheadspd = {}
2269+
ghbcondspd = {}
2270+
bhead = np.full((nlay, nrow, ncol), DNODATA, dtype=float)
2271+
cond = np.full((nlay, nrow, ncol), DNODATA, dtype=float)
2272+
bhead[0, 1, 1] = 60.0
2273+
cond[0, 1, 1] = 10.0
2274+
ghbbheadspd[0] = bhead
2275+
ghbcondspd[0] = cond
2276+
2277+
ghb = ModflowGwfghbg(
23122278
model,
23132279
print_input=True,
23142280
print_flows=True,
2315-
stress_period_data=ghbspdict,
23162281
save_flows=False,
23172282
pname="GHB-1",
2318-
)
2283+
bhead=ghbbheadspd,
2284+
cond=ghbcondspd,
2285+
)
2286+
2287+
ghb_bhead_array = ghb.bhead.array
2288+
assert np.allclose(ghb.bhead.array[0], ghb.bhead.get_data()[0])
2289+
assert np.allclose(ghb.bhead.array[0], ghb.bhead.get_data(0))
2290+
assert np.allclose(ghb.cond.array[0], ghb.cond.get_data()[0])
2291+
assert np.allclose(ghb.cond.array[0], ghb.cond.get_data(0))
2292+
for p in range(1, nper):
2293+
assert ghb.bhead.get_data()[p] is None
2294+
assert ghb.bhead.get_data(p) is None
2295+
assert ghb.cond.get_data()[p] is None
2296+
assert ghb.cond.get_data(p) is None
2297+
assert len(ghb_bhead_array[p]) == len(ghb_bhead_array[0])
2298+
assert ghb_bhead_array[p].shape == ghb_bhead_array[0].shape
2299+
assert np.allclose(ghb_bhead_array[p], ghb_bhead_array[0])
23192300

23202301
lakpd = [(0, 70.0, 1), (1, 65.0, 1)]
23212302
lakecn = [
@@ -2384,11 +2365,8 @@ def test_grid_array(function_tmpdir):
23842365
)
23852366

23862367
# test writing and loading model
2387-
# print(wel.aux.array)
23882368
sim.write_simulation()
2389-
# print(wel.aux.array)
23902369
sim.run_simulation()
2391-
# print(wel.aux.array)
23922370

23932371
test_sim = MFSimulation.load(
23942372
sim_name,
@@ -2402,6 +2380,7 @@ def test_grid_array(function_tmpdir):
24022380
rcha = model.get_package("rcha")
24032381
wel = model.get_package("wel")
24042382
drn = model.get_package("drn")
2383+
ghb = model.get_package("ghb")
24052384
lak = model.get_package("lak")
24062385
lak_tab = model.get_package("laktab")
24072386
assert os.path.split(dis.filename)[1] == f"{model_name}.dis"
@@ -2435,7 +2414,6 @@ def test_grid_array(function_tmpdir):
24352414
aux_data_3 = rcha.aux.get_data(3)
24362415
assert aux_data_3[0][0][0] == 200.0
24372416

2438-
# TODO
24392417
wel_q_array = wel.q.array
24402418
assert np.all(wel_q_array[0][0] == 0.0)
24412419
assert wel_q_array[1][0][0, 0, 0] == 0.25
@@ -2447,8 +2425,6 @@ def test_grid_array(function_tmpdir):
24472425
assert welg_q_per[2][0, 0, 0] == 0.1
24482426
assert welg_q_per[3] is None
24492427
wel_aux_array = wel.aux.array
2450-
print(wel_aux_array)
2451-
# assert False
24522428
assert np.all(wel_aux_array[0][0] == 0.0)
24532429
assert wel_aux_array[1][0][0, 0, 0] == 0.0
24542430
assert wel_aux_array[2][0][0, 0, 0] == 0.0
@@ -2459,25 +2435,26 @@ def test_grid_array(function_tmpdir):
24592435
assert welg_aux_per[2][0][0, 0, 0] == 0.0
24602436
assert welg_aux_per[3] is None
24612437

2462-
welg_q_per1 = wel.q.get_data(1)
2463-
# print(wel.q.array)
2464-
assert welg_q_per1[0, 0, 0] == 0.25
2465-
welg_aux_per1 = wel.aux.get_data(1)
2466-
assert welg_aux_per1[0][0, 0, 0] == 0.0
2467-
2468-
# drn_array = drn.stress_period_data.array
2469-
# assert drn_array[0][0][1] == 60.0
2470-
# assert drn_array[1][0][1] == 60.0
2471-
# assert drn_array[2] is None
2472-
# assert drn_array[3][0][1] == 55.0
2473-
# drn_gd_0 = drn.stress_period_data.get_data(0)
2474-
# assert drn_gd_0[0][1] == 60.0
2475-
# drn_gd_1 = drn.stress_period_data.get_data(1)
2476-
# assert drn_gd_1 is None
2477-
# drn_gd_2 = drn.stress_period_data.get_data(2)
2478-
# assert len(drn_gd_2) == 0
2479-
# drn_gd_3 = drn.stress_period_data.get_data(3)
2480-
# assert drn_gd_3[0][1] == 55.0
2438+
# first axis is nper, second is naux, then grid
2439+
drn_elev_array = drn.elev.array
2440+
assert drn_elev_array[0][0][0, 0, 0] == 60.0
2441+
assert drn_elev_array[1][0][0, 0, 0] == 60.0
2442+
assert drn_elev_array[2][0][0, 0, 0] == DNODATA
2443+
assert drn_elev_array[3][0][0, 0, 0] == 55.0
2444+
assert np.allclose(drn_elev_array[0], drn.elev.get_data(0))
2445+
assert drn.elev.get_data(1) is None
2446+
assert np.allclose(drn_elev_array[2], drn.elev.get_data(2))
2447+
assert np.allclose(drn_elev_array[3], drn.elev.get_data(3))
2448+
2449+
ghb_bhead_array = ghb.bhead.array
2450+
assert ghb_bhead_array[0][0][0, 1, 1] == 60.0
2451+
assert ghb_bhead_array[1][0][0, 1, 1] == 60.0
2452+
assert ghb_bhead_array[2][0][0, 1, 1] == 60.0
2453+
assert ghb_bhead_array[3][0][0, 1, 1] == 60.0
2454+
assert np.allclose(ghb_bhead_array[0], ghb.bhead.get_data(0))
2455+
assert ghb.bhead.get_data(1) is None
2456+
assert ghb.bhead.get_data(2) is None
2457+
assert ghb.bhead.get_data(3) is None
24812458

24822459
lak_tab_array = lak.tables.get_data()
24832460
assert lak_tab_array[0][1] == "lak01.tab"

flopy/mf6/data/mfdatastorage.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2462,6 +2462,10 @@ def _build_full_data(self, apply_multiplier=False):
24622462
or not self._has_layer_dim()
24632463
):
24642464
full_data = self._fill_const_layer(layer) * mult
2465+
elif grid_aux:
2466+
ilayer = (layer[0]) % nlay
2467+
iaux = int((layer[0]) / nlay)
2468+
full_data[iaux][ilayer] = self._fill_const_layer(layer)[0] * mult
24652469
else:
24662470
full_data[layer] = self._fill_const_layer(layer) * mult
24672471
else:

flopy/mf6/data/mffileaccess.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,6 @@ def load_from_package(
778778
storage.init_layers(layers)
779779

780780
elif grid_aux:
781-
#if layer_shape[0] > 1:
782781
storage.layered = True
783782
auxidx = self._get_aux_var_index(arr_line[0])
784783
if auxidx == 0:

0 commit comments

Comments
 (0)