-
Notifications
You must be signed in to change notification settings - Fork 37
/
input_output.py
205 lines (161 loc) · 7.15 KB
/
input_output.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
"""
Codes for input-output of PyReSim
@author: Yohanes Nuwara
@email: [email protected]
"""
def read_input(filepath):
"""
Read input data (TXT file)
Input:
filepath = path to the input file (TXT format)
Output:
reservoir_input = reservoir data input (as Python dictionary format)
contains:
xi, yi, dx, dy, dz, kx, ky, kz, poro, rho, cpore, mu, B
west_boundary, east_boundary, south_boundary, north_boundary =
reservoir boundary information (as Python dictionary format)
contains:
* type (boundary type: 'constant_pressure', 'constant_pressuregrad', 'constant_rate', 'no_flow')
* loc (location of grid blocks: either 'all' means all gridblocks have the same boundary, OR the specified coordinates)
* value (boundary value: 'constant_pressure' in psi, 'constant_pressuregrad' in psi/ft, 'constant_rate' in STB/D)
well = well information (as Python dictionary format)
contains:
* name (well name)
* rw (well radius in inch)
* loc = (well coordinate)
* skin (well skin)
* well_config (well configuration for wells in the RESERVOIR BOUNDARY: 0, 1, 2, and 3. See DOCS for details)
* condition (well operating conditions: 'constant_fbhp', 'constant_pressuregrad', 'constant_rate', 'shutin')
* value (value of the operating conditions: 'constant_fbhp' in psi, 'constant_pressuregrad' in psi/ft, 'constant_rate' in STB/D)
"""
import numpy as np
# reservoir input
prop = np.loadtxt(filepath, max_rows=1, skiprows=12)
xi, yi, zi = (prop[0]).astype(int), (prop[1]).astype(int), (prop[2]).astype(int)
dx, dy, dz = prop[3], prop[4], prop[5]
kx, ky, kz, poro, rho = prop[6], prop[7], prop[8], prop[9], prop[10]
cpore, mu, B, cfluid = prop[11], prop[12], prop[13], prop[14]
if yi==0 and zi==0:
# reservoir is 1D
## create reservoir input dictionary
reservoir_input = {'xi': xi, 'dx': dx, 'dy': dy, 'dz': dz, 'kx': kx,
'poro': poro, 'rho': rho, 'cpore': cpore,
'mu': mu, 'B': B, 'cfluid': cfluid}
# well input
skiprow_wells = np.array([22,25,28,31,37,40])
wells = []
for i in range(len(skiprow_wells)):
well = np.loadtxt(filepath, max_rows=1, skiprows=skiprow_wells[i], delimiter=',')
wells.append(well)
well_xsc, well_rw, well_skin, well_value, well_config = wells[0], wells[2], wells[3], wells[4], wells[5]
well_name = np.loadtxt(filepath, max_rows=1, skiprows=19, delimiter=',', dtype=np.str)
well_condition = np.loadtxt(filepath, max_rows=1, skiprows=34, delimiter=',', dtype=np.str)
well_loc = well_xsc.tolist()
## create well information dictionary
well = {'well_name': well_name,
'well_loc': well_loc,
'well_rw': well_rw,
'well_skin': well_skin,
'well_condition': well_condition,
'well_value': well_value,
'well_config': well_config}
# reservoir boundary
skiprow_type = np.array([54, 67])
skiprow_value = np.array([57, 70])
btype = []; bvalue = []
for i in range(len(skiprow_type)):
type = np.loadtxt(filepath, max_rows=1, skiprows=skiprow_type[i], dtype=np.str)
value = np.loadtxt(filepath, max_rows=1, skiprows=skiprow_value[i])
# loc = np.loadtxt(filepath, max_rows=1, skiprows=skiprow_loc[i], dtype=np.str)
btype.append(type); bvalue.append(value)
west_type, east_type = btype[0], btype[1]
west_value, east_value = bvalue[0], bvalue[1]
## create reservoir boundary information
east_boundary = {"type": east_type,
"value": east_value}
west_boundary = {"type": west_type,
"value": west_value}
return reservoir_input, well, west_boundary, east_boundary
if yi!=0 and zi==0:
# reservoir is 2D
## create reservoir input dictionary
reservoir_input = {'xi': xi, 'yi': yi, 'dx': dx, 'dy': dy, 'dz': dz, 'kx': kx,
'ky': ky, 'poro': poro, 'rho': rho, 'cpore': cpore,
'mu': mu, 'B': B, 'cfluid': cfluid}
# well input
skiprow_wells = np.array([22,25,28,31,37,40])
wells = []
for i in range(len(skiprow_wells)):
well = np.loadtxt(filepath, max_rows=1, skiprows=skiprow_wells[i], delimiter=',')
wells.append(well)
well_xsc, well_ysc, well_rw, well_skin, well_value, well_config = wells[0], wells[1], wells[2], wells[3], wells[4], wells[5]
well_name = np.loadtxt(filepath, max_rows=1, skiprows=19, delimiter=',', dtype=np.str)
well_condition = np.loadtxt(filepath, max_rows=1, skiprows=34, delimiter=',', dtype=np.str)
## merge the xsc and ysc well coordinates into one coordinate
well_loc = np.zeros((len(well_xsc),2))
for i in range(len(well_xsc)):
well_loc[i] = [well_xsc[i], well_ysc[i]]
well_loc = well_loc.astype(int)
well_loc = well_loc.tolist()
## create well information dictionary
well = {'well_name': well_name,
'well_loc': well_loc,
'well_rw': well_rw,
'well_skin': well_skin,
'well_condition': well_condition,
'well_value': well_value,
'well_config': well_config}
# reservoir boundary
skiprow_type = np.array([54, 67, 80, 93])
skiprow_value = np.array([57, 70, 83, 96])
skiprow_loc = np.array([51, 64, 77, 90])
btype = []; bvalue = []; bloc = []
for i in range(len(skiprow_type)):
type = np.loadtxt(filepath, max_rows=1, skiprows=skiprow_type[i], dtype=np.str)
value = np.loadtxt(filepath, max_rows=1, skiprows=skiprow_value[i])
loc = np.loadtxt(filepath, max_rows=1, skiprows=skiprow_loc[i], dtype=np.str)
btype.append(type); bvalue.append(value); bloc.append(loc)
west_type, east_type, south_type, north_type = btype[0], btype[1], btype[2], btype[3]
west_value, east_value, south_value, north_value = bvalue[0], bvalue[1], bvalue[2], bvalue[3]
west_loc, east_loc, south_loc, north_loc = bloc[0], bloc[1], bloc[2], bloc[3]
## create reservoir boundary information
east_boundary = {"type": east_type,
"value": east_value,
"loc": east_loc}
west_boundary = {"type": west_type,
"value": west_value,
"loc": west_loc}
north_boundary = {"type": north_type,
"value": north_value,
"loc": north_loc}
south_boundary = {"type": south_type,
"value": south_value,
"loc": south_loc}
return reservoir_input, well, west_boundary, east_boundary, south_boundary, north_boundary
# def read_depth(filepath):
# """
# Read from depth data
# """
# import numpy as np
# data = np.loadtxt(filepath, skiprows=1)
# x, y, depth = data[:,0], data[:,1], data[:,2]
# if np.all(y==0):
# # reservoir grid is 1D
# return x, depth
# else:
# # reservoir grid is 2D
# return x, y, depth
def read_depth(filepath):
"""
Read from depth data
"""
import numpy as np
data = np.loadtxt(filepath, skiprows=1)
x, y, z = data[:,0], data[:,1], data[:,2]
if np.all(y==0):
# reservoir grid is 1D
z_array = np.array([x, z])
else:
# reservoir grid is 2D
z_array = np.array([x, y, z])
return z_array