|
| 1 | +""" |
| 2 | +General test for the interface model approach. |
| 3 | +It compares the skewed decomposition of the domain |
| 4 | +to the trivial analytical result (constant gradient). |
| 5 | +In this case with the use of idomain to deactivate half |
| 6 | +of the sub-models. Note that the cells with idomain==0 |
| 7 | +overlap with the active cells of the other model. |
| 8 | +
|
| 9 | + 'leftmodel' 'rightmodel' |
| 10 | +
|
| 11 | + 1 1 1 0 0 0 0 1 1 1 1 1 1 1 |
| 12 | + 1 1 1 1 0 0 0 0 1 1 1 1 1 1 |
| 13 | + 1 1 1 1 1 0 0 + 0 0 1 1 1 1 1 |
| 14 | + 1 1 1 1 1 1 0 0 0 0 1 1 1 1 |
| 15 | + 1 1 1 1 1 1 1 0 0 0 0 1 1 1 |
| 16 | +
|
| 17 | +We assert equality on the head values and check budgets. |
| 18 | +""" |
| 19 | + |
| 20 | +import os |
| 21 | + |
| 22 | +import flopy |
| 23 | +import numpy as np |
| 24 | +import pytest |
| 25 | +from flopy.mf6.utils import Mf6Splitter |
| 26 | +from framework import TestFramework |
| 27 | + |
| 28 | +cases = ["ifmod_skewed"] |
| 29 | + |
| 30 | +# some global convenience...: |
| 31 | +# model name |
| 32 | +mname = "skewed" |
| 33 | + |
| 34 | +# solver criterion |
| 35 | +hclose_check = 1e-9 |
| 36 | +max_inner_it = 300 |
| 37 | +nper = 1 |
| 38 | + |
| 39 | +# model spatial discretization |
| 40 | +nlay = 1 |
| 41 | +ncol = 10 |
| 42 | +nrow = 5 |
| 43 | + |
| 44 | +# idomain |
| 45 | +idomain = np.ones((nlay, nrow, ncol)) |
| 46 | + |
| 47 | +delr = 1.0 |
| 48 | +delc = 1.0 |
| 49 | +area = delr * delc |
| 50 | + |
| 51 | +# top/bot of the aquifer |
| 52 | +tops = [1.0, 0.0] |
| 53 | + |
| 54 | +# hydraulic conductivity |
| 55 | +hk = 10.0 |
| 56 | + |
| 57 | +# boundary stress period data |
| 58 | +h_left = 10.0 |
| 59 | +h_right = 1.0 |
| 60 | + |
| 61 | +# initial head |
| 62 | +h_start = 0.0 |
| 63 | + |
| 64 | +# head boundaries |
| 65 | +lchd = [[(ilay, irow, 0), h_left] for irow in range(nrow) for ilay in range(nlay)] |
| 66 | +rchd = [ |
| 67 | + [(ilay, irow, ncol - 1), h_right] for irow in range(nrow) for ilay in range(nlay) |
| 68 | +] |
| 69 | +chd = lchd + rchd |
| 70 | + |
| 71 | +chd_spd = {0: chd} |
| 72 | + |
| 73 | + |
| 74 | +def get_model(idx, dir): |
| 75 | + name = cases[idx] |
| 76 | + |
| 77 | + # parameters and spd |
| 78 | + # tdis |
| 79 | + tdis_rc = [] |
| 80 | + for i in range(nper): |
| 81 | + tdis_rc.append((1.0, 1, 1)) |
| 82 | + |
| 83 | + # solver data |
| 84 | + nouter, ninner = 100, max_inner_it |
| 85 | + hclose, rclose, relax = hclose_check, 1e-3, 0.97 |
| 86 | + |
| 87 | + sim = flopy.mf6.MFSimulation( |
| 88 | + sim_name=name, version="mf6", exe_name="mf6", sim_ws=dir |
| 89 | + ) |
| 90 | + |
| 91 | + tdis = flopy.mf6.ModflowTdis(sim, time_units="DAYS", nper=nper, perioddata=tdis_rc) |
| 92 | + |
| 93 | + ims = flopy.mf6.ModflowIms( |
| 94 | + sim, |
| 95 | + print_option="SUMMARY", |
| 96 | + outer_dvclose=hclose, |
| 97 | + outer_maximum=nouter, |
| 98 | + under_relaxation="NONE", |
| 99 | + inner_maximum=ninner, |
| 100 | + inner_dvclose=hclose, |
| 101 | + rcloserecord=rclose, |
| 102 | + linear_acceleration="CG", |
| 103 | + scaling_method="NONE", |
| 104 | + reordering_method="NONE", |
| 105 | + relaxation_factor=relax, |
| 106 | + filename="gwf.ims", |
| 107 | + ) |
| 108 | + |
| 109 | + gwf = flopy.mf6.ModflowGwf(sim, modelname=mname, save_flows=True) |
| 110 | + |
| 111 | + dis = flopy.mf6.ModflowGwfdis( |
| 112 | + gwf, |
| 113 | + nlay=nlay, |
| 114 | + nrow=nrow, |
| 115 | + ncol=ncol, |
| 116 | + delr=delr, |
| 117 | + delc=delc, |
| 118 | + xorigin=0.0, |
| 119 | + yorigin=0.0, |
| 120 | + top=tops[0], |
| 121 | + botm=tops[1:], |
| 122 | + idomain=idomain, |
| 123 | + ) |
| 124 | + |
| 125 | + # initial conditions |
| 126 | + ic = flopy.mf6.ModflowGwfic(gwf, strt=h_start) |
| 127 | + |
| 128 | + # node property flow |
| 129 | + npf = flopy.mf6.ModflowGwfnpf( |
| 130 | + gwf, |
| 131 | + save_specific_discharge=True, |
| 132 | + icelltype=0, |
| 133 | + k=hk, |
| 134 | + ) |
| 135 | + |
| 136 | + # chd file |
| 137 | + chd = flopy.mf6.ModflowGwfchd(gwf, stress_period_data=chd_spd) |
| 138 | + |
| 139 | + # output control |
| 140 | + oc = flopy.mf6.ModflowGwfoc( |
| 141 | + gwf, |
| 142 | + head_filerecord=f"{mname}.hds", |
| 143 | + budget_filerecord=f"{mname}.cbc", |
| 144 | + headprintrecord=[("COLUMNS", 10, "WIDTH", 15, "DIGITS", 6, "GENERAL")], |
| 145 | + saverecord=[("HEAD", "LAST"), ("BUDGET", "LAST")], |
| 146 | + ) |
| 147 | + |
| 148 | + # split the model |
| 149 | + splitter = Mf6Splitter(sim) |
| 150 | + mask = np.zeros(shape=(nrow, ncol)) |
| 151 | + for irow in range(nrow): |
| 152 | + istart = irow + 3 |
| 153 | + mask[irow, istart:] = 1 |
| 154 | + split_sim = splitter.split_model(mask) |
| 155 | + split_sim.set_sim_path(dir) |
| 156 | + |
| 157 | + return split_sim |
| 158 | + |
| 159 | + |
| 160 | +def build_models(idx, test): |
| 161 | + sim = get_model(idx, test.workspace) |
| 162 | + return sim, None |
| 163 | + |
| 164 | + |
| 165 | +def check_output(idx, test): |
| 166 | + print("comparing heads to single model reference...") |
| 167 | + |
| 168 | + sim = flopy.mf6.MFSimulation.load(sim_ws=test.workspace) |
| 169 | + |
| 170 | + mname_left = sim.model_names[0] |
| 171 | + mname_right = sim.model_names[1] |
| 172 | + |
| 173 | + fpth = os.path.join(test.workspace, f"{mname_left}.hds") |
| 174 | + hds_left = flopy.utils.HeadFile(fpth).get_alldata() |
| 175 | + hds_left[hds_left == 1.0e30] = 0.0 |
| 176 | + |
| 177 | + fpth = os.path.join(test.workspace, f"{mname_right}.hds") |
| 178 | + hds_right = flopy.utils.HeadFile(fpth).get_alldata() |
| 179 | + hds_right[hds_right == 1.0e30] = 0.0 |
| 180 | + |
| 181 | + hds = np.zeros((nrow, ncol), dtype=float) |
| 182 | + hds[:, 0:7] = hds[:, 0:7] + hds_left[:, :] |
| 183 | + hds[:, 3:] = hds[:, 3:] + hds_right[:, :] |
| 184 | + |
| 185 | + cst_gradient = np.linspace(10.0, 1.0, ncol) |
| 186 | + for irow in range(nrow): |
| 187 | + assert hds[irow, :] == pytest.approx(cst_gradient, rel=10 * hclose_check), ( |
| 188 | + f"Head values for row {irow} do not match analytical result. " |
| 189 | + f"Expected {cst_gradient}, but got {hds[irow, :]}" |
| 190 | + ) |
| 191 | + |
| 192 | + # check budget error from .lst file |
| 193 | + for mname in [mname_left, mname_right]: |
| 194 | + fpth = os.path.join(test.workspace, f"{mname}.lst") |
| 195 | + for line in open(fpth): |
| 196 | + if line.lstrip().startswith("PERCENT"): |
| 197 | + cumul_balance_error = float(line.split()[3]) |
| 198 | + assert abs(cumul_balance_error) < 0.00001, ( |
| 199 | + f"Cumulative balance error = {cumul_balance_error} for {mname}, " |
| 200 | + "should equal 0.0" |
| 201 | + ) |
| 202 | + |
| 203 | + |
| 204 | +@pytest.mark.parametrize("idx, name", enumerate(cases)) |
| 205 | +@pytest.mark.developmode |
| 206 | +def test_mf6model(idx, name, function_tmpdir, targets): |
| 207 | + test = TestFramework( |
| 208 | + name=name, |
| 209 | + workspace=function_tmpdir, |
| 210 | + build=lambda t: build_models(idx, t), |
| 211 | + check=lambda t: check_output(idx, t), |
| 212 | + targets=targets, |
| 213 | + ) |
| 214 | + test.run() |
0 commit comments