|
| 1 | +""" |
| 2 | +Test that stress packages issue a warning (not an error) when a boundary |
| 3 | +condition entry references a cell that is not in the active grid domain. |
| 4 | +The model should run to completion and the listing file should contain a |
| 5 | +warning about the inactive cell. |
| 6 | +
|
| 7 | +Packages tested: RCH, WEL, GHB, DRN, RIV, CHD |
| 8 | +""" |
| 9 | + |
| 10 | +import os |
| 11 | + |
| 12 | +import flopy |
| 13 | +import numpy as np |
| 14 | +import pytest |
| 15 | +from framework import TestFramework |
| 16 | + |
| 17 | +cases = [ |
| 18 | + "inact_rch", |
| 19 | + "inact_wel", |
| 20 | + "inact_ghb", |
| 21 | + "inact_drn", |
| 22 | + "inact_riv", |
| 23 | + "inact_chd", |
| 24 | +] |
| 25 | + |
| 26 | +nlay, nrow, ncol = 1, 3, 3 |
| 27 | +inactive_cell = (0, 0, 0) |
| 28 | +chd_cell = (0, 2, 2) |
| 29 | +top = 10.0 |
| 30 | +botm = 0.0 |
| 31 | +strt = 5.0 |
| 32 | +idomain = np.ones((nlay, nrow, ncol), dtype=int) |
| 33 | +idomain[inactive_cell] = 0 |
| 34 | + |
| 35 | + |
| 36 | +def _base_sim(test, name): |
| 37 | + ws = test.workspace |
| 38 | + sim = flopy.mf6.MFSimulation( |
| 39 | + sim_name=name, version="mf6", exe_name="mf6", sim_ws=ws |
| 40 | + ) |
| 41 | + flopy.mf6.ModflowTdis(sim, nper=1, perioddata=[(1.0, 1, 1.0)]) |
| 42 | + flopy.mf6.ModflowIms( |
| 43 | + sim, |
| 44 | + outer_dvclose=1e-6, |
| 45 | + inner_dvclose=1e-6, |
| 46 | + ) |
| 47 | + gwf = flopy.mf6.ModflowGwf(sim, modelname=name) |
| 48 | + flopy.mf6.ModflowGwfdis( |
| 49 | + gwf, |
| 50 | + nlay=nlay, |
| 51 | + nrow=nrow, |
| 52 | + ncol=ncol, |
| 53 | + top=top, |
| 54 | + botm=botm, |
| 55 | + idomain=idomain, |
| 56 | + ) |
| 57 | + flopy.mf6.ModflowGwfnpf(gwf, k=1.0) |
| 58 | + flopy.mf6.ModflowGwfic(gwf, strt=strt) |
| 59 | + flopy.mf6.ModflowGwfchd( |
| 60 | + gwf, |
| 61 | + stress_period_data={0: [[chd_cell, strt]]}, |
| 62 | + ) |
| 63 | + |
| 64 | + return sim, gwf |
| 65 | + |
| 66 | + |
| 67 | +def build_models(idx, test): |
| 68 | + name = cases[idx] |
| 69 | + sim, gwf = _base_sim(test, name) |
| 70 | + |
| 71 | + if idx == 0: |
| 72 | + # RCH: one entry on the inactive cell, one on an active cell |
| 73 | + flopy.mf6.ModflowGwfrch( |
| 74 | + gwf, |
| 75 | + stress_period_data={ |
| 76 | + 0: [ |
| 77 | + [inactive_cell, 1e-3], |
| 78 | + [(0, 1, 1), 1e-3], |
| 79 | + ] |
| 80 | + }, |
| 81 | + ) |
| 82 | + |
| 83 | + elif idx == 1: |
| 84 | + # WEL: one entry on the inactive cell |
| 85 | + flopy.mf6.ModflowGwfwel( |
| 86 | + gwf, |
| 87 | + stress_period_data={ |
| 88 | + 0: [ |
| 89 | + [inactive_cell, -1.0], |
| 90 | + [(0, 1, 1), -1.0], |
| 91 | + ] |
| 92 | + }, |
| 93 | + ) |
| 94 | + |
| 95 | + elif idx == 2: |
| 96 | + # GHB: one entry on the inactive cell |
| 97 | + flopy.mf6.ModflowGwfghb( |
| 98 | + gwf, |
| 99 | + stress_period_data={ |
| 100 | + 0: [ |
| 101 | + [inactive_cell, strt, 1.0], |
| 102 | + [(0, 1, 1), strt, 1.0], |
| 103 | + ] |
| 104 | + }, |
| 105 | + ) |
| 106 | + |
| 107 | + elif idx == 3: |
| 108 | + # DRN: one entry on the inactive cell |
| 109 | + flopy.mf6.ModflowGwfdrn( |
| 110 | + gwf, |
| 111 | + stress_period_data={ |
| 112 | + 0: [ |
| 113 | + [inactive_cell, 3.0, 1.0], |
| 114 | + [(0, 1, 1), 3.0, 1.0], |
| 115 | + ] |
| 116 | + }, |
| 117 | + ) |
| 118 | + |
| 119 | + elif idx == 4: |
| 120 | + # RIV: one entry on the inactive cell |
| 121 | + flopy.mf6.ModflowGwfriv( |
| 122 | + gwf, |
| 123 | + stress_period_data={ |
| 124 | + 0: [ |
| 125 | + [inactive_cell, strt, 1.0, botm], |
| 126 | + [(0, 1, 1), strt, 1.0, botm], |
| 127 | + ] |
| 128 | + }, |
| 129 | + ) |
| 130 | + |
| 131 | + elif idx == 5: |
| 132 | + # CHD: one entry on the inactive cell (the base sim already has a |
| 133 | + # CHD on an active cell; add a separate package with the bad entry) |
| 134 | + flopy.mf6.ModflowGwfchd( |
| 135 | + gwf, |
| 136 | + stress_period_data={ |
| 137 | + 0: [ |
| 138 | + [inactive_cell, strt], |
| 139 | + [(0, 0, 1), strt], |
| 140 | + ] |
| 141 | + }, |
| 142 | + pname="chd_bad", |
| 143 | + filename=f"{name}_bad.chd", |
| 144 | + ) |
| 145 | + |
| 146 | + return sim, None |
| 147 | + |
| 148 | + |
| 149 | +def check_output(idx, test): |
| 150 | + mfsim_lst = os.path.join(test.workspace, "mfsim.lst") |
| 151 | + assert os.path.isfile(mfsim_lst) |
| 152 | + lst_text = open(mfsim_lst).read() |
| 153 | + assert "Normal termination" in lst_text |
| 154 | + warning_phrase = "outside active grid domain" |
| 155 | + assert warning_phrase.lower() in lst_text.lower() |
| 156 | + |
| 157 | + |
| 158 | +@pytest.mark.parametrize("idx, name", enumerate(cases)) |
| 159 | +def test_mf6model(idx, name, function_tmpdir, targets): |
| 160 | + test = TestFramework( |
| 161 | + name=name, |
| 162 | + workspace=function_tmpdir, |
| 163 | + build=lambda t: build_models(idx, t), |
| 164 | + check=lambda t: check_output(idx, t), |
| 165 | + targets=targets, |
| 166 | + ) |
| 167 | + test.run() |
0 commit comments