-
Notifications
You must be signed in to change notification settings - Fork 323
/
Copy pathtest_mp7_cases.py
311 lines (283 loc) · 8.54 KB
/
test_mp7_cases.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
import numpy as np
from flopy.mf6 import (
MFSimulation,
ModflowGwf,
ModflowGwfdis,
ModflowGwfic,
ModflowGwfnpf,
ModflowGwfoc,
ModflowGwfrcha,
ModflowGwfriv,
ModflowGwfwel,
ModflowIms,
ModflowTdis,
)
from flopy.modflow import (
Modflow,
ModflowBas,
ModflowDis,
ModflowLpf,
ModflowOc,
ModflowPcg,
ModflowRch,
ModflowRiv,
ModflowWel,
)
from flopy.modpath import (
Modpath7,
Modpath7Bas,
Modpath7Sim,
ParticleData,
ParticleGroup,
)
class Mp7Cases:
nper, nstp, perlen, tsmult = 1, 1, 1.0, 1.0
nlay, nrow, ncol = 3, 21, 20
delr = delc = 500.0
top = 400.0
botm = [220.0, 200.0, 0.0]
laytyp = [1, 0, 0]
kh = [50.0, 0.01, 200.0]
kv = [10.0, 0.01, 20.0]
wel_loc = (2, 10, 9)
wel_q = -150000.0
rch = 0.005
riv_h = 320.0
riv_z = 317.0
riv_c = 1.0e5
zone3 = np.ones((nrow, ncol), dtype=np.int32)
zone3[wel_loc[1:]] = 2
zones = [1, 1, zone3]
# create particles
partlocs = []
partids = []
for i in range(nrow):
partlocs.append((0, i, 2))
partids.append(i)
part0 = ParticleData(partlocs, structured=True, particleids=partids)
pg0 = ParticleGroup(
particlegroupname="PG1", particledata=part0, filename="ex01a.sloc"
)
v = [(0,), (400,)]
pids = [1, 2]
part1 = ParticleData(v, structured=False, drape=1, particleids=pids)
pg1 = ParticleGroup(
particlegroupname="PG2", particledata=part1, filename="ex01a.pg2.sloc"
)
particlegroups = [pg0, pg1]
@staticmethod
def mf6(function_tmpdir):
"""
MODPATH 7 example 1 for MODFLOW 6
"""
ws = function_tmpdir / "mf6"
nm = "ex01_mf6"
# Create the Flopy simulation object
sim = MFSimulation(sim_name=nm, exe_name="mf6", version="mf6", sim_ws=ws)
# Create the Flopy temporal discretization object
pd = (Mp7Cases.perlen, Mp7Cases.nstp, Mp7Cases.tsmult)
tdis = ModflowTdis(
sim,
pname="tdis",
time_units="DAYS",
nper=Mp7Cases.nper,
perioddata=[pd],
)
# Create the Flopy groundwater flow (gwf) model object
model_nam_file = f"{nm}.nam"
gwf = ModflowGwf(
sim, modelname=nm, model_nam_file=model_nam_file, save_flows=True
)
# Create the Flopy iterative model solver (ims) Package object
ims = ModflowIms(
sim,
pname="ims",
complexity="SIMPLE",
rcloserecord=1e-3,
inner_dvclose=1e-6,
outer_dvclose=1e-6,
outer_maximum=50,
inner_maximum=100,
)
# create gwf file
dis = ModflowGwfdis(
gwf,
pname="dis",
nlay=Mp7Cases.nlay,
nrow=Mp7Cases.nrow,
ncol=Mp7Cases.ncol,
length_units="FEET",
delr=Mp7Cases.delr,
delc=Mp7Cases.delc,
top=Mp7Cases.top,
botm=Mp7Cases.botm,
)
# Create the initial conditions package
ic = ModflowGwfic(gwf, pname="ic", strt=Mp7Cases.top)
# Create the node property flow package
npf = ModflowGwfnpf(
gwf,
pname="npf",
icelltype=Mp7Cases.laytyp,
k=Mp7Cases.kh,
k33=Mp7Cases.kv,
)
# recharge
ModflowGwfrcha(gwf, recharge=Mp7Cases.rch)
# wel
wd = [(Mp7Cases.wel_loc, Mp7Cases.wel_q)]
ModflowGwfwel(gwf, maxbound=1, stress_period_data={0: wd})
# river
rd = []
for i in range(Mp7Cases.nrow):
rd.append(
[
(0, i, Mp7Cases.ncol - 1),
Mp7Cases.riv_h,
Mp7Cases.riv_c,
Mp7Cases.riv_z,
]
)
ModflowGwfriv(gwf, stress_period_data={0: rd})
# Create the output control package
headfile = f"{nm}.hds"
head_record = [headfile]
budgetfile = f"{nm}.cbb"
budget_record = [budgetfile]
saverecord = [("HEAD", "ALL"), ("BUDGET", "ALL")]
oc = ModflowGwfoc(
gwf,
pname="oc",
saverecord=saverecord,
head_filerecord=head_record,
budget_filerecord=budget_record,
)
return sim
@staticmethod
def mp7_mf6(function_tmpdir):
sim = Mp7Cases.mf6(function_tmpdir)
sim.write_simulation()
success, buff = sim.run_simulation()
assert success, "mf6 model did not run"
# create modpath files
mp = Modpath7(
modelname=f"{sim.name}_mp",
flowmodel=sim.get_model(sim.name),
exe_name="mp7",
model_ws=sim.sim_path,
)
defaultiface6 = {"RCH": 6, "EVT": 6}
mpbas = Modpath7Bas(mp, porosity=0.1, defaultiface=defaultiface6)
mpsim = Modpath7Sim(
mp,
simulationtype="combined",
trackingdirection="forward",
weaksinkoption="pass_through",
weaksourceoption="pass_through",
budgetoutputoption="summary",
budgetcellnumbers=[1049, 1259],
traceparticledata=[1, 1000],
referencetime=[0, 0, 0.0],
stoptimeoption="extend",
timepointdata=[500, 1000.0],
zonedataoption="on",
zones=Mp7Cases.zones,
particlegroups=Mp7Cases.particlegroups,
)
return mp
@staticmethod
def mf2005(function_tmpdir):
"""
MODPATH 7 example 1 for MODFLOW-2005
"""
ws = function_tmpdir / "mf2005"
nm = "ex01_mf2005"
iu_cbc = 130
m = Modflow(nm, model_ws=ws, exe_name="mf2005")
ModflowDis(
m,
nlay=Mp7Cases.nlay,
nrow=Mp7Cases.nrow,
ncol=Mp7Cases.ncol,
nper=Mp7Cases.nper,
itmuni=4,
lenuni=1,
perlen=Mp7Cases.perlen,
nstp=Mp7Cases.nstp,
tsmult=Mp7Cases.tsmult,
steady=True,
delr=Mp7Cases.delr,
delc=Mp7Cases.delc,
top=Mp7Cases.top,
botm=Mp7Cases.botm,
)
ModflowLpf(
m,
ipakcb=iu_cbc,
laytyp=Mp7Cases.laytyp,
hk=Mp7Cases.kh,
vka=Mp7Cases.kv,
)
ModflowBas(m, ibound=1, strt=Mp7Cases.top)
# recharge
ModflowRch(m, ipakcb=iu_cbc, rech=Mp7Cases.rch, nrchop=1)
# wel
wd = list(Mp7Cases.wel_loc) + [Mp7Cases.wel_q]
ModflowWel(m, ipakcb=iu_cbc, stress_period_data={0: wd})
# river
rd = []
for i in range(Mp7Cases.nrow):
rd.append(
[
0,
i,
Mp7Cases.ncol - 1,
Mp7Cases.riv_h,
Mp7Cases.riv_c,
Mp7Cases.riv_z,
]
)
ModflowRiv(m, ipakcb=iu_cbc, stress_period_data={0: rd})
# output control
ModflowOc(
m,
stress_period_data={(0, 0): ["save head", "save budget", "print head"]},
)
ModflowPcg(m, hclose=1e-6, rclose=1e-3, iter1=100, mxiter=50)
return m
@staticmethod
def mp7_mf2005(function_tmpdir):
m = Mp7Cases.mf2005(function_tmpdir)
m.write_input()
success, buff = m.run_model()
assert success, "mf2005 model did not run"
# create modpath files
mp = Modpath7(
modelname=f"{m.name}_mp",
flowmodel=m,
exe_name="mp7",
model_ws=m.model_ws,
)
defaultiface = {"RECHARGE": 6, "ET": 6}
mpbas = Modpath7Bas(mp, porosity=0.1, defaultiface=defaultiface)
mpsim = Modpath7Sim(
mp,
simulationtype="combined",
trackingdirection="forward",
weaksinkoption="pass_through",
weaksourceoption="pass_through",
budgetoutputoption="summary",
budgetcellnumbers=[1049, 1259],
traceparticledata=[1, 1000],
referencetime=[0, 0, 0.0],
stoptimeoption="extend",
timepointdata=[500, 1000.0],
zonedataoption="on",
zones=Mp7Cases.zones,
particlegroups=Mp7Cases.particlegroups,
)
return mp
def case_mp7_mf6(self, function_tmpdir):
return Mp7Cases.mp7_mf6(function_tmpdir)
def case_mp7_mf2005(self, function_tmpdir):
return Mp7Cases.mp7_mf2005(function_tmpdir)