|
| 1 | +import flopy |
| 2 | +import pytest |
| 3 | +from framework import TestFramework |
| 4 | + |
| 5 | +# fmt: off |
| 6 | +obs_names = [ |
| 7 | + "delay-flowtop", "delay-flowtop", |
| 8 | + "delay-flowbot", "delay-flowbot", |
| 9 | + "delay-head", "delay-head", |
| 10 | + "delay-gstress", "delay-gstress", |
| 11 | + "delay-estress", "delay-estress", |
| 12 | + "delay-preconstress", "delay-preconstress", |
| 13 | + "delay-compaction", "delay-compaction", |
| 14 | + "delay-thickness", "delay-thickness", |
| 15 | + "delay-theta", "delay-theta", |
| 16 | + "csub", "csub", |
| 17 | + "inelastic-csub", "inelastic-csub", |
| 18 | + "elastic-csub", "elastic-csub", |
| 19 | + "interbed-compaction", "interbed-compaction", |
| 20 | + "inelastic-compaction", "inelastic-compaction", |
| 21 | + "elastic-compaction", "elastic-compaction", |
| 22 | + ] |
| 23 | +# fmt: off |
| 24 | +boundname = [ |
| 25 | + False, True, |
| 26 | + False, True, |
| 27 | + False, True, |
| 28 | + False, True, |
| 29 | + False, True, |
| 30 | + False, True, |
| 31 | + False, True, |
| 32 | + False, True, |
| 33 | + False, True, |
| 34 | + False, True, |
| 35 | + False, True, |
| 36 | + False, True, |
| 37 | + False, True, |
| 38 | + False, True, |
| 39 | + False, True, |
| 40 | + ] |
| 41 | +# fmt: off |
| 42 | +test_fail = [ |
| 43 | + False, False, |
| 44 | + False, False, |
| 45 | + False, True, |
| 46 | + False, True, |
| 47 | + False, True, |
| 48 | + False, True, |
| 49 | + False, True, |
| 50 | + False, True, |
| 51 | + False, True, |
| 52 | + False, False, |
| 53 | + False, False, |
| 54 | + False, False, |
| 55 | + False, True, |
| 56 | + False, True, |
| 57 | + False, True, |
| 58 | + ] |
| 59 | +cases = [f"csub_obs{idx + 1:02d}" for idx, _ in enumerate(obs_names)] |
| 60 | + |
| 61 | +paktest = "csub" |
| 62 | +budtol = 1e-2 |
| 63 | +ndcell = [19] * len(cases) |
| 64 | + |
| 65 | +# static model data |
| 66 | +# spatial discretization |
| 67 | +nlay, nrow, ncol = 1, 1, 3 |
| 68 | +shape3d = (nlay, nrow, ncol) |
| 69 | +size3d = nlay * nrow * ncol |
| 70 | +delr, delc = 1.0, 1.0 |
| 71 | +top = 0.0 |
| 72 | +botm = [-100.0] |
| 73 | + |
| 74 | +# temporal discretization |
| 75 | +nper = 1 |
| 76 | +perlen = [1000.0 for _ in range(nper)] |
| 77 | +nstp = [100 for _ in range(nper)] |
| 78 | +tsmult = [1.05 for _ in range(nper)] |
| 79 | +steady = [False for _ in range(nper)] |
| 80 | + |
| 81 | +strt = 0.0 |
| 82 | +strt6 = 1.0 |
| 83 | +hnoflo = 1e30 |
| 84 | +hdry = -1e30 |
| 85 | +hk = 1e6 |
| 86 | +laytyp = [0] |
| 87 | +S = 1e-4 |
| 88 | +sy = 0.0 |
| 89 | + |
| 90 | +nouter, ninner = 1000, 300 |
| 91 | +hclose, rclose, relax = 1e-6, 1e-6, 0.97 |
| 92 | + |
| 93 | +tdis_rc = [] |
| 94 | +for i in range(nper): |
| 95 | + tdis_rc.append((perlen[i], nstp[i], tsmult[i])) |
| 96 | + |
| 97 | +ib = 1 |
| 98 | + |
| 99 | +c = [] |
| 100 | +c6 = [] |
| 101 | +for j in range(0, ncol, 2): |
| 102 | + c.append([0, 0, j, strt, strt]) |
| 103 | + c6.append([(0, 0, j), strt]) |
| 104 | +cd = {0: c} |
| 105 | +cd6 = {0: c6} |
| 106 | + |
| 107 | +# sub data |
| 108 | +ndb = 1 |
| 109 | +nndb = 0 |
| 110 | +cc = 100.0 |
| 111 | +cr = 1.0 |
| 112 | +void = 0.82 |
| 113 | +theta = void / (1.0 + void) |
| 114 | +kv = 0.025 |
| 115 | +sgm = 0.0 |
| 116 | +sgs = 0.0 |
| 117 | +ini_stress = 1.0 |
| 118 | +thick = [1.0] |
| 119 | +sfe = cr * thick[0] |
| 120 | +sfv = cc * thick[0] |
| 121 | +lnd = [0] |
| 122 | +ldnd = [0] |
| 123 | +dp = [[kv, cr, cc]] |
| 124 | +ss = S / (100.0 - thick[0]) |
| 125 | + |
| 126 | +ds15 = [0, 0, 0, 2052, 0, 0, 0, 0, 0, 0, 0, 0] |
| 127 | +ds16 = [0, 0, 0, 100, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1] |
| 128 | + |
| 129 | + |
| 130 | +def get_model(idx, ws): |
| 131 | + name = cases[idx] |
| 132 | + |
| 133 | + sim = flopy.mf6.MFSimulation( |
| 134 | + sim_name=name, version="mf6", exe_name="mf6", sim_ws=ws |
| 135 | + ) |
| 136 | + # create tdis package |
| 137 | + tdis = flopy.mf6.ModflowTdis(sim, time_units="DAYS", nper=nper, perioddata=tdis_rc) |
| 138 | + |
| 139 | + # create iterative model solution |
| 140 | + ims = flopy.mf6.ModflowIms( |
| 141 | + sim, |
| 142 | + print_option="SUMMARY", |
| 143 | + outer_dvclose=hclose, |
| 144 | + outer_maximum=nouter, |
| 145 | + under_relaxation="NONE", |
| 146 | + inner_maximum=ninner, |
| 147 | + inner_dvclose=hclose, |
| 148 | + rcloserecord=rclose, |
| 149 | + linear_acceleration="CG", |
| 150 | + scaling_method="NONE", |
| 151 | + reordering_method="NONE", |
| 152 | + relaxation_factor=relax, |
| 153 | + ) |
| 154 | + |
| 155 | + # create gwf model |
| 156 | + gwf = flopy.mf6.ModflowGwf(sim, modelname=name) |
| 157 | + |
| 158 | + dis = flopy.mf6.ModflowGwfdis( |
| 159 | + gwf, |
| 160 | + nlay=nlay, |
| 161 | + nrow=nrow, |
| 162 | + ncol=ncol, |
| 163 | + delr=delr, |
| 164 | + delc=delc, |
| 165 | + top=top, |
| 166 | + botm=botm, |
| 167 | + filename=f"{name}.dis", |
| 168 | + ) |
| 169 | + |
| 170 | + # initial conditions |
| 171 | + ic = flopy.mf6.ModflowGwfic(gwf, strt=strt, filename=f"{name}.ic") |
| 172 | + |
| 173 | + # node property flow |
| 174 | + npf = flopy.mf6.ModflowGwfnpf(gwf, save_flows=False, icelltype=laytyp, k=hk, k33=hk) |
| 175 | + # storage |
| 176 | + sto = flopy.mf6.ModflowGwfsto( |
| 177 | + gwf, |
| 178 | + save_flows=False, |
| 179 | + iconvert=laytyp, |
| 180 | + ss=0.0, |
| 181 | + sy=sy, |
| 182 | + storagecoefficient=True, |
| 183 | + transient={0: True}, |
| 184 | + ) |
| 185 | + |
| 186 | + # chd files |
| 187 | + chd = flopy.mf6.modflow.mfgwfchd.ModflowGwfchd( |
| 188 | + gwf, maxbound=len(c6), stress_period_data=cd6, save_flows=False |
| 189 | + ) |
| 190 | + |
| 191 | + # csub files |
| 192 | + sub6 = [ |
| 193 | + [ |
| 194 | + 0, |
| 195 | + (0, 0, 1), |
| 196 | + "delay", |
| 197 | + ini_stress, |
| 198 | + thick[0], |
| 199 | + 1.0, |
| 200 | + 230.258658761733000, |
| 201 | + 2.302586587617330, |
| 202 | + theta, |
| 203 | + kv, |
| 204 | + ini_stress, |
| 205 | + ] |
| 206 | + ] |
| 207 | + bname = "interbed" |
| 208 | + if boundname[idx]: |
| 209 | + sub6[0].append(bname) |
| 210 | + obs_idx = ("obs_value", obs_names[idx], bname) |
| 211 | + else: |
| 212 | + obs_idx = ("obs_value", obs_names[idx], (0,), (0,)) |
| 213 | + |
| 214 | + opth = f"{name}.csub.obs" |
| 215 | + csub = flopy.mf6.ModflowGwfcsub( |
| 216 | + gwf, |
| 217 | + boundnames=boundname[idx], |
| 218 | + head_based=False, |
| 219 | + print_input=True, |
| 220 | + save_flows=True, |
| 221 | + ndelaycells=ndcell[idx], |
| 222 | + ninterbeds=1, |
| 223 | + beta=0.0, |
| 224 | + cg_ske_cr=ss, |
| 225 | + packagedata=sub6, |
| 226 | + ) |
| 227 | + orecarray = {} |
| 228 | + orecarray["csub_obs.csv"] = [obs_idx] |
| 229 | + csub_obs_package = csub.obs.initialize( |
| 230 | + filename=opth, digits=10, print_input=True, continuous=orecarray |
| 231 | + ) |
| 232 | + |
| 233 | + # output control |
| 234 | + oc = flopy.mf6.ModflowGwfoc( |
| 235 | + gwf, |
| 236 | + printrecord=[("BUDGET", "ALL")], |
| 237 | + ) |
| 238 | + |
| 239 | + return sim |
| 240 | + |
| 241 | + |
| 242 | +def build_models(idx, test): |
| 243 | + sim = get_model(idx, test.workspace) |
| 244 | + |
| 245 | + return sim, None |
| 246 | + |
| 247 | + |
| 248 | +@pytest.mark.parametrize("idx, name", enumerate(cases)) |
| 249 | +def test_mf6model(idx, name, function_tmpdir, targets): |
| 250 | + test = TestFramework( |
| 251 | + name=name, |
| 252 | + workspace=function_tmpdir, |
| 253 | + build=lambda t: build_models(idx, t), |
| 254 | + targets=targets, |
| 255 | + xfail=test_fail[idx], |
| 256 | + ) |
| 257 | + test.run() |
0 commit comments