|
| 1 | +""" |
| 2 | +Test to make sure that mf6 is failing with head-dependent boundary conditions with |
| 3 | +elevations below the bottom of the layer (only ghb and drain are tested). Also check |
| 4 | +that the no check option works with head-dependent boundary conditions with elevations |
| 5 | +less than the cell bottom. |
| 6 | +""" |
| 7 | + |
| 8 | +import flopy |
| 9 | +import numpy as np |
| 10 | +import pytest |
| 11 | +from framework import TestFramework |
| 12 | + |
| 13 | +xfail = [True, True, False, False] |
| 14 | +boundaries = ["ghb", "drn", "ghb", "drn"] |
| 15 | +check = [None, None, True, True] |
| 16 | +cases = [f"{bnd}{idx:02d}" for idx, bnd in enumerate(boundaries)] |
| 17 | + |
| 18 | + |
| 19 | +def build_models(idx, test): |
| 20 | + ws = test.workspace |
| 21 | + |
| 22 | + bnd = boundaries[idx] |
| 23 | + |
| 24 | + nlay, nrow, ncol = 2, 1, 1 |
| 25 | + nper = 1 |
| 26 | + perlen = [1.0] |
| 27 | + nstp = [1] |
| 28 | + tsmult = [1.0] |
| 29 | + delr = 1.0 |
| 30 | + delc = 1.0 |
| 31 | + top = 1.0 |
| 32 | + botm = [0.0, -1.0] |
| 33 | + strt = 1 |
| 34 | + hk = 1.0 |
| 35 | + |
| 36 | + tdis_rc = [] |
| 37 | + for i in range(nper): |
| 38 | + tdis_rc.append((perlen[i], nstp[i], tsmult[i])) |
| 39 | + |
| 40 | + name = cases[idx] |
| 41 | + |
| 42 | + sim = flopy.mf6.MFSimulation( |
| 43 | + sim_name=name, |
| 44 | + version="mf6", |
| 45 | + exe_name="mf6", |
| 46 | + sim_ws=ws, |
| 47 | + nocheck=check[idx], |
| 48 | + ) |
| 49 | + |
| 50 | + tdis = flopy.mf6.ModflowTdis( |
| 51 | + sim, |
| 52 | + time_units="DAYS", |
| 53 | + nper=nper, |
| 54 | + perioddata=tdis_rc, |
| 55 | + ) |
| 56 | + |
| 57 | + gwf = flopy.mf6.ModflowGwf( |
| 58 | + sim, |
| 59 | + modelname=name, |
| 60 | + print_input=True, |
| 61 | + ) |
| 62 | + |
| 63 | + ims = flopy.mf6.ModflowIms( |
| 64 | + sim, |
| 65 | + print_option="SUMMARY", |
| 66 | + complexity="simple", |
| 67 | + outer_dvclose=1e-8, |
| 68 | + outer_maximum=200, |
| 69 | + inner_dvclose=1e-9, |
| 70 | + inner_maximum=100, |
| 71 | + ) |
| 72 | + sim.register_ims_package(ims, [gwf.name]) |
| 73 | + |
| 74 | + dis = flopy.mf6.ModflowGwfdis( |
| 75 | + gwf, |
| 76 | + length_units="feet", |
| 77 | + nlay=nlay, |
| 78 | + nrow=nrow, |
| 79 | + ncol=ncol, |
| 80 | + delr=delr, |
| 81 | + delc=delc, |
| 82 | + top=top, |
| 83 | + botm=botm, |
| 84 | + ) |
| 85 | + |
| 86 | + ic = flopy.mf6.ModflowGwfic(gwf, strt=strt) |
| 87 | + |
| 88 | + npf = flopy.mf6.ModflowGwfnpf( |
| 89 | + gwf, |
| 90 | + icelltype=1, |
| 91 | + k=hk, |
| 92 | + ) |
| 93 | + |
| 94 | + spd = [((1, 0, 0), strt)] |
| 95 | + chd = flopy.mf6.ModflowGwfchd( |
| 96 | + gwf, |
| 97 | + maxbound=len(spd), |
| 98 | + stress_period_data=spd, |
| 99 | + ) |
| 100 | + |
| 101 | + spd = [((0, 0, 0), botm[0] - 0.1, 1.0, "bc")] |
| 102 | + if bnd == "ghb": |
| 103 | + p = flopy.mf6.ModflowGwfghb( |
| 104 | + gwf, |
| 105 | + boundnames=True, |
| 106 | + maxbound=len(spd), |
| 107 | + stress_period_data=spd, |
| 108 | + ) |
| 109 | + elif bnd == "drn": |
| 110 | + p = flopy.mf6.ModflowGwfdrn( |
| 111 | + gwf, |
| 112 | + boundnames=True, |
| 113 | + maxbound=len(spd), |
| 114 | + stress_period_data=spd, |
| 115 | + ) |
| 116 | + obs_data = [ |
| 117 | + ("obs1", f"{bnd}", "bc"), |
| 118 | + ] |
| 119 | + obs_name = "bnd.obs" |
| 120 | + p.obs.initialize( |
| 121 | + filename=obs_name, |
| 122 | + continuous={f"{obs_name}.csv": obs_data}, |
| 123 | + ) |
| 124 | + |
| 125 | + oc = flopy.mf6.ModflowGwfoc( |
| 126 | + gwf, |
| 127 | + printrecord=[("BUDGET", "ALL"), ("HEAD", "ALL")], |
| 128 | + ) |
| 129 | + |
| 130 | + return sim, None |
| 131 | + |
| 132 | + |
| 133 | +def check_results(idx, test): |
| 134 | + if not xfail[idx]: |
| 135 | + ws = test.workspace |
| 136 | + sim = flopy.mf6.MFSimulation.load(sim_ws=ws) |
| 137 | + gwf = sim.get_model() |
| 138 | + |
| 139 | + bnd = boundaries[idx] |
| 140 | + if bnd == "ghb": |
| 141 | + obs = gwf.ghb.output.obs().get_data() |
| 142 | + elif bnd == "drn": |
| 143 | + obs = gwf.drn.output.obs().get_data() |
| 144 | + v = obs[0][1] |
| 145 | + print(obs) |
| 146 | + answer = -0.55 |
| 147 | + assert np.allclose(v, answer), f"boundary flux ({v}) not close to {answer}" |
| 148 | + |
| 149 | + |
| 150 | +@pytest.mark.parametrize("idx, name", enumerate(cases)) |
| 151 | +def test_mf6model(idx, name, function_tmpdir, targets): |
| 152 | + test = TestFramework( |
| 153 | + name=name, |
| 154 | + workspace=function_tmpdir, |
| 155 | + targets=targets, |
| 156 | + build=lambda t: build_models(idx, t), |
| 157 | + check=lambda t: check_results(idx, t), |
| 158 | + xfail=xfail[idx], |
| 159 | + ) |
| 160 | + test.run() |
0 commit comments