|
| 1 | +""" |
| 2 | +Test the dependent_variable_scale option for gwt for a one-dimensional model grid |
| 3 | +of square cells. |
| 4 | +""" |
| 5 | + |
| 6 | +import flopy |
| 7 | +import numpy as np |
| 8 | +import pytest |
| 9 | +from framework import TestFramework |
| 10 | + |
| 11 | +dewatered = [False, True, False, True] |
| 12 | +perched = [False, False, True, True] |
| 13 | +chd1_lst = (-0.5, 0.0) |
| 14 | +cases = [f"vcv{n:02d}_02" for n in range(len(dewatered))] |
| 15 | + |
| 16 | + |
| 17 | +def build_model(idx, ws, vhfb=False): |
| 18 | + nlay, nrow, ncol = 2, 1, 2 |
| 19 | + nper = 2 |
| 20 | + perlen = [1.0] * nper |
| 21 | + nstp = [1] * nper |
| 22 | + tsmult = [1.0] * nper |
| 23 | + delr = 1.0 |
| 24 | + delc = 1.0 |
| 25 | + top = 1.0 |
| 26 | + botm = [0.0, -1.0] |
| 27 | + |
| 28 | + chd0 = 0.5 |
| 29 | + |
| 30 | + strt = chd0 |
| 31 | + |
| 32 | + icelltype = 1 |
| 33 | + hk = 100.0 # 50000.0 # 100.0 |
| 34 | + area = delc * delr |
| 35 | + vk = 0.001 |
| 36 | + if vhfb: |
| 37 | + if dewatered[idx]: |
| 38 | + v0 = 1.0 / ((area * vk) / (0.5 * (chd0 - botm[0]))) |
| 39 | + # v1 should be 0.0 |
| 40 | + v1 = 0.0 |
| 41 | + else: |
| 42 | + v0 = 1.0 / ((area * vk) / (0.5 * (chd0 - botm[0]))) |
| 43 | + v1 = 1.0 / ((area * vk) / (0.5 * (botm[0] - botm[1]))) |
| 44 | + vcont = 1.0 / (v0 + v1) |
| 45 | + else: |
| 46 | + pass |
| 47 | + |
| 48 | + tdis_rc = [] |
| 49 | + for i in range(nper): |
| 50 | + tdis_rc.append((perlen[i], nstp[i], tsmult[i])) |
| 51 | + |
| 52 | + name = cases[idx] |
| 53 | + |
| 54 | + sim = flopy.mf6.MFSimulation( |
| 55 | + sim_name=name, version="mf6", exe_name="mf6", sim_ws=ws |
| 56 | + ) |
| 57 | + |
| 58 | + tdis = flopy.mf6.ModflowTdis(sim, time_units="DAYS", nper=nper, perioddata=tdis_rc) |
| 59 | + |
| 60 | + ims = flopy.mf6.ModflowIms( |
| 61 | + sim, |
| 62 | + print_option="SUMMARY", |
| 63 | + complexity="simple", |
| 64 | + outer_dvclose=1e-8, |
| 65 | + outer_maximum=200, |
| 66 | + inner_dvclose=1e-9, |
| 67 | + inner_maximum=100, |
| 68 | + ) |
| 69 | + |
| 70 | + gwf = flopy.mf6.ModflowGwf( |
| 71 | + sim, |
| 72 | + modelname=name, |
| 73 | + print_input=True, |
| 74 | + ) |
| 75 | + |
| 76 | + dis = flopy.mf6.ModflowGwfdis( |
| 77 | + gwf, |
| 78 | + length_units="feet", |
| 79 | + nlay=nlay, |
| 80 | + nrow=nrow, |
| 81 | + ncol=ncol, |
| 82 | + delr=delr, |
| 83 | + delc=delc, |
| 84 | + top=top, |
| 85 | + botm=botm, |
| 86 | + ) |
| 87 | + |
| 88 | + ic = flopy.mf6.ModflowGwfic(gwf, strt=strt) |
| 89 | + |
| 90 | + if dewatered[idx]: |
| 91 | + cvoptions = "variablecv dewatered" |
| 92 | + else: |
| 93 | + cvoptions = "variablecv" |
| 94 | + |
| 95 | + npf = flopy.mf6.ModflowGwfnpf( |
| 96 | + gwf, |
| 97 | + print_flows=True, |
| 98 | + save_flows=True, |
| 99 | + cvoptions=cvoptions, |
| 100 | + perched=perched[idx], |
| 101 | + icelltype=icelltype, |
| 102 | + k=hk, |
| 103 | + k33=vk, |
| 104 | + ) |
| 105 | + |
| 106 | + chd_spd = {} |
| 107 | + for n in range(nper): |
| 108 | + spd = [((0, 0, 0), chd0)] |
| 109 | + spd += [((1, 0, 0), chd1_lst[n])] |
| 110 | + chd_spd[n] = spd |
| 111 | + chd = flopy.mf6.ModflowGwfchd( |
| 112 | + gwf, |
| 113 | + maxbound=len(spd), |
| 114 | + stress_period_data=chd_spd, |
| 115 | + ) |
| 116 | + |
| 117 | + obs_data = { |
| 118 | + "flowja.obs.csv": [ |
| 119 | + ("h0", "head", (0, 0, 1)), |
| 120 | + ("h1", "head", (1, 0, 1)), |
| 121 | + ("vflow", "FLOW-JA-FACE", (0, 0, 1), (1, 0, 1)), |
| 122 | + ] |
| 123 | + } |
| 124 | + obs = flopy.mf6.ModflowUtlobs(gwf, continuous=obs_data) |
| 125 | + |
| 126 | + return sim |
| 127 | + |
| 128 | + |
| 129 | +def build_models(idx, test): |
| 130 | + ws = test.workspace |
| 131 | + sim = build_model(idx, ws, vhfb=True) |
| 132 | + |
| 133 | + return sim, None |
| 134 | + |
| 135 | + |
| 136 | +def check_results(idx, test): |
| 137 | + ws = test.workspace |
| 138 | + sim = flopy.mf6.MFSimulation.load(sim_ws=ws, verbosity_level=0) |
| 139 | + gwf = sim.get_model() |
| 140 | + |
| 141 | + nper = sim.tdis.nper.array |
| 142 | + delr = gwf.dis.delr.array[1] |
| 143 | + delc = gwf.dis.delc.array[0] |
| 144 | + area = delr * delc |
| 145 | + |
| 146 | + cellids = [(0, 0, 1), (1, 0, 1)] |
| 147 | + botm0 = gwf.dis.botm.array[cellids[0]] |
| 148 | + botm1 = gwf.dis.botm.array[cellids[1]] |
| 149 | + vk = gwf.npf.k33.array[cellids[0]] |
| 150 | + |
| 151 | + obs = gwf.obs.output.obs().get_data() |
| 152 | + h0 = obs["H0"] |
| 153 | + h1 = obs["H1"] |
| 154 | + |
| 155 | + answer = obs["VFLOW"] |
| 156 | + |
| 157 | + is_dewatered = dewatered[idx] |
| 158 | + is_perched = perched[idx] |
| 159 | + |
| 160 | + vflow = [] |
| 161 | + for n in range(nper): |
| 162 | + if is_dewatered and h1[n] < botm0: |
| 163 | + v0 = 1.0 / ((area * vk) / (0.5 * (h0[n] - botm0))) |
| 164 | + v1 = 0.0 |
| 165 | + else: |
| 166 | + v0 = 1.0 / ((area * vk) / (0.5 * (h0[n] - botm0))) |
| 167 | + v1 = 1.0 / ((area * vk) / (0.5 * (botm0 - botm1))) |
| 168 | + vcont = 1.0 / (v0 + v1) |
| 169 | + vflow.append(vcont * (h1[n] - h0[n])) |
| 170 | + |
| 171 | + if is_perched and h1[n] < botm0: |
| 172 | + qcorr = vcont * (h1[n] - botm0) |
| 173 | + vflow[n] -= qcorr |
| 174 | + |
| 175 | + vflow = np.array(vflow) |
| 176 | + |
| 177 | + print(f"H0: {h0}") |
| 178 | + print(f"H1: {h1}") |
| 179 | + print(f"Vertical flow: {answer}") |
| 180 | + print(f"Answer: {vflow}") |
| 181 | + |
| 182 | + assert np.allclose(vflow, answer), "simulated results not equal to the answer" |
| 183 | + |
| 184 | + |
| 185 | +@pytest.mark.parametrize("idx, name", enumerate(cases)) |
| 186 | +def test_mf6model(idx, name, function_tmpdir, targets): |
| 187 | + test = TestFramework( |
| 188 | + name=name, |
| 189 | + workspace=function_tmpdir, |
| 190 | + targets=targets, |
| 191 | + build=lambda t: build_models(idx, t), |
| 192 | + check=lambda t: check_results(idx, t), |
| 193 | + ) |
| 194 | + test.run() |
0 commit comments