forked from JulianaBarrios/ExFlopy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ex1.py
131 lines (111 loc) · 3.47 KB
/
Ex1.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
"""
Spyder Editor
This is a temporary script file.
"""
import os
import numpy as np
import matplotlib.pyplot as plt
import flopy# -*- coding: utf-8 -*-
#Datos
name = "Mod18_01_1"
h1 = 95.25
h2 = 90
Nlay = 10
N = 101
L = 400.0
H = 50.0
k = 1.0
#Busca mf6 en la carpeta especificada y guarda los archivos
sim = flopy.mf6.MFSimulation(
sim_name=name,
exe_name="D:/Games/mf6.2.0/mf6.2.0/bin/mf6.exe",
version="mf6", sim_ws="Workspace")
#Crea objetos de Flopy TDIS
tdis = flopy.mf6.ModflowTdis(
sim, pname="tdis", time_units="DAYS", nper=1, perioddata=[(1.0, 1, 1.0)])
#Crea el paquete de objetos de Flopy IMS
ims = flopy.mf6.ModflowIms(sim, pname="ims", complexity="SIMPLE")
#Crea el modelo de flujo de agua
model_nam_file = "{}.nam".format(name)
gwf = flopy.mf6.ModflowGwf(sim, modelname=name, model_nam_file=model_nam_file)
#Se define espesores de filas y paquete de discretización
bot = np.linspace(-H / Nlay, -H, Nlay)
delrow = delcol = L / (N - 1) #Espesor de filas
dis = flopy.mf6.ModflowGwfdis( #Paquete de discretización
gwf,
nlay=Nlay,
nrow=N,
ncol=N,
delr=delrow,
delc=delcol,
top=0.0,
botm=bot,)
#Condiciones iniciales
start = h1 * np.ones((Nlay, N, N))
ic = flopy.mf6.ModflowGwfic(gwf, pname="ic", strt=start)
#Paquete que controla el flujo entre creldas = npf
k=np.ones([10,N,N])
k[1,:,:]=5e-1
npf = flopy.mf6.ModflowGwfnpf(gwf, icelltype=1, k=k, save_flows=True)
#
chd_rec = []
chd_rec.append(((0, int(N / 4), int(N / 4)), h2))
chd_rec.append(((1, int(3*N / 4), int(N / 4)), h2-5))
for layer in range(0, Nlay):
for row_col in range(0, N):
chd_rec.append(((layer, row_col, 0), h1))
chd_rec.append(((layer, row_col, N - 1), h1))
if row_col != 0 and row_col != N - 1:
chd_rec.append(((layer, 0, row_col), h1))
chd_rec.append(((layer, N - 1, row_col), h1))
chd = flopy.mf6.ModflowGwfchd(
gwf,
maxbound=len(chd_rec),
stress_period_data=chd_rec,
save_flows=True,)
#
iper = 0
ra = chd.stress_period_data.get_data(key=iper)
ra
# Create the output control (`OC`) Package
headfile = "{}.hds".format(name)
head_filerecord = [headfile]
budgetfile = "{}.cbb".format(name)
budget_filerecord = [budgetfile]
saverecord = [("HEAD", "ALL"), ("BUDGET", "ALL")]
printrecord = [("HEAD", "LAST")]
oc = flopy.mf6.ModflowGwfoc(
gwf,
saverecord=saverecord,
head_filerecord=head_filerecord,
budget_filerecord=budget_filerecord,
printrecord=printrecord,)
#Construya los .txt
sim.write_simulation()
#Condición de éxito
success, buff = sim.run_simulation()
if not success:
raise Exception("MODFLOW 6 did not terminate normally.")
#Imprimiendo resultados
headfile = "Workspace" + '/' + headfile
hds = flopy.utils.binaryfile.HeadFile(headfile)
h = hds.get_data(kstpkper=(0, 0))
x = y = np.linspace(0, L, N)
y = y[::-1]
fig = plt.figure(figsize=(6, 6))
ax = fig.add_subplot(1, 1, 1, aspect="equal")
c = ax.contour(x, y, h[0], np.arange(90, 100.1, 0.2), colors="black")
plt.clabel(c, fmt="%2.1f")
#Plotear otra capa
x = y = np.linspace(0, L, N)
y = y[::-1]
fig = plt.figure(figsize=(6, 6))
ax = fig.add_subplot(1, 1, 1, aspect="equal")
c = ax.contour(x, y, h[-5], np.arange(90, 100.1, 0.2), colors="black")
plt.clabel(c, fmt="%1.1f")
#Ploteando sección transversal
z = np.linspace(-H / Nlay / 2, -H + H / Nlay / 2, Nlay)
fig = plt.figure(figsize=(5, 2.5))
ax = fig.add_subplot(1, 1, 1, aspect="auto")
c = ax.contour(x, z, h[:, 50, :], np.arange(90, 100.1, 0.2), colors="black")
plt.clabel(c, fmt="%1.1f")