-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExample_Infrastructure.py
427 lines (368 loc) · 20.7 KB
/
Example_Infrastructure.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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
import numpy as np
import time
from matplotlib import pyplot as plt
from calcTrilinearInterpWeights import calcTrilinearInterpWeights
from formCell2EdgeMatrix import formCell2EdgeMatrix
from formEdge2EdgeMatrix import formEdge2EdgeMatrix
from formFace2EdgeMatrix import formFace2EdgeMatrix
from formRectMeshConnectivity import formRectMeshConnectivity
from makeRectMeshModelBlocks import makeRectMeshModelBlocks
from solveRESnet import solveRESnet
if __name__ == '__main__':
"""
Demonstration of complex infrastructure modeling
In the following, a dipole-dipole survey is simulated for
Model #1: A uniform half-space
Model #2: Model #1 with two anomalous blocks buried
Model #3: Model #2 with infrastructure (a steel cased well and a steel-sheet warehouse)
Model #4: Model #3 with an above-ground pipe connecting the well and the warehouse
"""
'''Setup the 3D mesh'''
# Create a 3D rectilinear mesh
h = 1 # smallest horizontal grid size
ratio = 1.4 # expansion rate
nctbc = 15 # number of cells to boundary condition
nodeX = np.round(np.concatenate(
(-np.cumsum(h * np.power(ratio, (np.arange(nctbc, -1, -1)))[::-1])[::-1] - 45,
np.arange(-45, 45 + h, h),
45 + np.cumsum(h * np.power(ratio, np.arange(nctbc + 1)))),
axis=None)) # node locations in X
nodeY = np.round(np.concatenate(
(-np.cumsum(h * np.power(ratio, (np.arange(nctbc, -1, -1)))[::-1])[::-1] - 12,
np.arange(-12, 12 + h, h),
12 + np.cumsum(h * np.power(ratio, np.arange(nctbc + 1)))),
axis=None)) # node locations in Y
h = 1 # smallest vertical grid size
ratio = 1.4 # expansion rate
nctbc = 15 # number of cells to boundary condition
nodeZ = np.concatenate((np.arange(4, -11, -h), -10 - np.round(np.cumsum(h * ratio ** (np.arange(nctbc + 1))))),
axis=0) # node locations in Z (top of mesh at 4 m above the surface)
'''Setup the electric surveys (dipole-dipole)'''
spacing = 4 # meters between two electrodes
Aloc = np.arange(-40, 29, spacing)
Ntx = len(Aloc) # number of source combos
tx = [None] * Ntx
rx = [None] * Ntx
for i in range(Ntx):
tx[i] = np.array([[Aloc[i], 0, 0, 1], # A electrode
[Aloc[i] + spacing, 0, 0, -1]]) # B electrode
Mloc = np.arange(Aloc[i] + spacing * 2, 37, spacing) # M electrodes
Nloc = np.arange(Aloc[i] + spacing * 3, 41, spacing) # N electrodes
rx[i] = np.column_stack((Mloc, np.zeros_like(Mloc), np.zeros_like(Mloc),
Nloc, np.zeros_like(Nloc), np.zeros_like(Nloc))) # Mx My(=0) Mz(=0) Nx Ny(=0) Nz(=0)
Ndata = sum(range(1, Ntx + 1)) # total number of data
'''Define Model #1: Uniform half-space'''
blkLoc = [[-np.inf, np.inf, -np.inf, np.inf, np.inf, 0], # a uniform layer for the air (above surface)
[-np.inf, np.inf, -np.inf, np.inf, 0, -np.inf]] # a uniform half-space below surface
blkCon = [[1e-5], # air conductivity
[0.01]] # earth half-space conductivity
'''Form a resistor network'''
# Get connectivity properties of nodes, edges, faces, cells
nodes, edges, lengths, faces, areas, cells, volumes = formRectMeshConnectivity(nodeX, nodeY, nodeZ)
# Get conductive property model vectors (convert the block-model description to values on edges, faces and cells)
cellCon, faceCon, edgeCon = makeRectMeshModelBlocks(nodeX, nodeY, nodeZ, blkLoc, blkCon, [], [], [])
# Convert conductive objects to conductance on edges
Edge2Edge = formEdge2EdgeMatrix(edges, lengths)
Face2Edge = formFace2EdgeMatrix(edges, lengths, faces, areas)
Cell2Edge = formCell2EdgeMatrix(edges, lengths, faces, cells, volumes)
Ce = Edge2Edge.dot(edgeCon) # conductance from edges
Cf = Face2Edge.dot(faceCon) # conductance from faces
Cc = Cell2Edge.dot(cellCon) # conductance from cells
C = Ce + Cf + Cc # total conductance
'''Solve the resistor network problem'''
# Calculate current sources on the nodes using info in tx
Ntx = len(tx) # number of tx-rx sets
sources = np.zeros((nodes.shape[0], Ntx)) # current source intensity at all nodes (for all source configurations)
for i in range(Ntx):
# weights for the distribution of point current source to the neighboring nodes
weights = calcTrilinearInterpWeights(nodeX, nodeY, nodeZ, tx[i][:, :3])
# total current intensities at all the nodes
sources[:, i] = weights.dot(tx[i][:, 3])
# Obtain potentials at the nodes, potential differences and current along the edges
start_time = time.time()
potentials, potentialDiffs, currents = solveRESnet(edges, C, sources)
end_time = time.time()
print(f"Time: {(end_time - start_time):.6f} seconds")
# Get simulated data
data = []
for i in range(Ntx):
# weights for the interpolation of potential data at the M-electrode location
Mw = calcTrilinearInterpWeights(nodeX, nodeY, nodeZ, rx[i][:, :3])
# weights for the interpolation of potential data at the N-electrode location
Nw = calcTrilinearInterpWeights(nodeX, nodeY, nodeZ, rx[i][:, 3:6])
# calculate the potential difference data as "M - N"
data.append((Mw.T - Nw.T) @ potentials[:, i])
data1 = data # save to data1
'''Plot Model #1's apparent resistivity'''
ABMNKVR1 = np.zeros((Ndata, 7))
count = 0
for i in range(Ntx):
A = tx[i][0, 0]
B = tx[i][1, 0]
for j in range(rx[i].shape[0]):
M = rx[i][j, 0]
N = rx[i][j, 3]
K = 2 * np.pi / (1 / (M - A) - 1 / (M - B) - 1 / (N - A) + 1 / (N - B)) # geometric factor
count += 1
# [A B M N geometric_factor potential_difference apparent_resistivity]
ABMNKVR1[count - 1, :] = [A, B, M, N, K, data1[i][j], K * data1[i][j]]
x = np.sum(ABMNKVR1[:, :4], axis=1) / 4 # mid-point of four electrodes
n = (ABMNKVR1[:, 2] - ABMNKVR1[:, 1]) / spacing # n-spacing as pseudo-depth
plt.figure()
plt.scatter(x, n, 500, np.log10(ABMNKVR1[:, 6]), marker='s', cmap='jet')
plt.gca().invert_yaxis()
plt.grid(True)
plt.colorbar(label='Apparent resistivity log(Ohm*m)')
plt.xlabel('X (m)')
plt.ylabel('n-spacing')
plt.title('(1) Model #1: Half-space')
'''Define Model #2: Two blocks in half-space'''
blkLoc = np.array([[-np.inf, np.inf, -np.inf, np.inf, np.inf, 0], # a uniform layer for the air (above surface)
[-np.inf, np.inf, -np.inf, np.inf, 0, -np.inf], # a uniform half-space below surface
[-30, -20, -4, 4, -6, -10], # an anomalous conductive block
[0, 8, -8, 2, -2, -6]]) # an anomalous resistive block
blkCon = np.array([1e-5, # air conductivity
0.01, # earth conductivity
0.1, # block conductivity
0.001]) # block conductivity
'''Form a resistor network'''
# Get connectivity properties of nodes, edges, faces, cells
nodes, edges, lengths, faces, areas, cells, volumes = formRectMeshConnectivity(nodeX, nodeY, nodeZ)
# Get conductive property model vectors (convert the block-model description to values on edges, faces, and cells)
cellCon, faceCon, edgeCon = makeRectMeshModelBlocks(nodeX, nodeY, nodeZ, blkLoc, blkCon, None, None, None)
# Convert all conductive objects to conductance on edges
Edge2Edge = formEdge2EdgeMatrix(edges, lengths)
Face2Edge = formFace2EdgeMatrix(edges, lengths, faces, areas)
Cell2Edge = formCell2EdgeMatrix(edges, lengths, faces, cells, volumes)
Ce = Edge2Edge.dot(edgeCon) # conductance from edges
Cf = Face2Edge.dot(faceCon) # conductance from faces
Cc = Cell2Edge.dot(cellCon) # conductance from cells
C = Ce + Cf + Cc # total conductance
'''Solve the resistor network problem'''
# Calculate current sources on the nodes using info in tx
Ntx = len(tx) # number of tx-rx sets
sources = np.zeros((nodes.shape[0], Ntx)) # current source intensity at all nodes (for all source configurations)
for i in range(Ntx):
# weights for the distribution of point current source to the neighboring nodes
weights = calcTrilinearInterpWeights(nodeX, nodeY, nodeZ, tx[i][:, :3])
# total current intensities at all the nodes
sources[:, i] = weights.dot(tx[i][:, 3])
# Obtain potentials at the nodes, potential differences and current along the edges
start_time = time.time()
potentials, potentialDiffs, currents = solveRESnet(edges, C, sources)
end_time = time.time()
print(f"Time: {(end_time - start_time):.6f} seconds")
# Get simulated data
data = []
for i in range(Ntx):
# weights for the interpolation of potential data at the M-electrode location
Mw = calcTrilinearInterpWeights(nodeX, nodeY, nodeZ, rx[i][:, :3])
# weights for the interpolation of potential data at the N-electrode location
Nw = calcTrilinearInterpWeights(nodeX, nodeY, nodeZ, rx[i][:, 3:6])
# calculate the potential difference data as "M - N"
data.append((Mw.T - Nw.T) @ potentials[:, i])
data2 = data # save to data2
'''Plot Model #2's apparent resistivity'''
ABMNKVR2 = np.zeros((Ndata, 7))
count = 0
for i in range(Ntx):
A = tx[i][0, 0]
B = tx[i][1, 0]
for j in range(rx[i].shape[0]):
M = rx[i][j, 0]
N = rx[i][j, 3]
K = 2 * np.pi / (1 / (M - A) - 1 / (M - B) - 1 / (N - A) + 1 / (N - B)) # geometric factor
count += 1
# [A B M N geometric_factor potential_difference apparent_resistivity]
ABMNKVR2[count - 1, :] = [A, B, M, N, K, data2[i][j], K * data2[i][j]]
x = np.sum(ABMNKVR2[:, :4], axis=1) / 4 # mid-point of four electrodes
n = (ABMNKVR2[:, 2] - ABMNKVR2[:, 1]) / spacing # n-spacing as pseudo-depth
plt.figure()
plt.scatter(x, n, s=500, c=np.log10(ABMNKVR2[:, 6]), marker='s', cmap='viridis', alpha=1.0)
plt.gca().invert_yaxis()
plt.colorbar(label='Apparent resistivity log(Ohm*m)')
plt.xlabel('X (m)')
plt.ylabel('n-spacing')
plt.title('(2) Model #2: Two blocks')
plt.grid(True)
'''Define Model #3: Infrastructure'''
blkLoc = np.array([[-np.inf, np.inf, -np.inf, np.inf, np.inf, 0], # a uniform layer for the air (above surface)
[-np.inf, np.inf, -np.inf, np.inf, 0, -np.inf], # a uniform half-space below surface
[-30, -20, -4, 4, -6, -10], # an anomalous conductive block
[0, 8, -8, 2, -2, -6], # an anomalous resistive block
[-18, -18, -6, -6, 0, -100], # a steel cased well
[6, 16, 4, 4, 6, -2], # southern wall of steel-sheet warehouse
[6, 16, 10, 10, 6, -2], # northern wall of steel-sheet warehouse
[6, 6, 4, 10, 6, -2], # western wall of steel-sheet warehouse
[16, 16, 4, 10, 6, -2], # eastern wall of steel-sheet warehouse
[6, 16, 4, 10, 6, 6]]) # roof
blkCon = np.array([1e-5, # air conductivity
0.01, # earth conductivity
0.1, # block conductivity
0.001, # block conductivity
np.pi * (0.05 ** 2 - 0.04 ** 2) * 5e6,
# steel casing's edgeCon (cross-sectional area times intrinsic conductivity)
0.005 * 5e6, # steel sheet's faceCon (thickness times intrinsic conductivity)
0.005 * 5e6, # steel sheet's faceCon (thickness times intrinsic conductivity)
0.005 * 5e6, # steel sheet's faceCon (thickness times intrinsic conductivity)
0.005 * 5e6, # steel sheet's faceCon (thickness times intrinsic conductivity)
0.005 * 5e6]) # steel sheet's faceCon (thickness times intrinsic conductivity)
'''Form a resistor network'''
# Get connectivity properties of nodes, edges, faces, cells
nodes, edges, lengths, faces, areas, cells, volumes = formRectMeshConnectivity(nodeX, nodeY, nodeZ)
# Get conductive property model vectors (convert the block-model description to values on edges, faces and cells)
cellCon, faceCon, edgeCon = makeRectMeshModelBlocks(nodeX, nodeY, nodeZ, blkLoc, blkCon, [], [], [])
# Convert all conductive objects to conductance on edges
Edge2Edge = formEdge2EdgeMatrix(edges, lengths)
Face2Edge = formFace2EdgeMatrix(edges, lengths, faces, areas)
Cell2Edge = formCell2EdgeMatrix(edges, lengths, faces, cells, volumes)
Ce = Edge2Edge.dot(edgeCon) # conductance from edges
Cf = Face2Edge.dot(faceCon) # conductance from faces
Cc = Cell2Edge.dot(cellCon) # conductance from cells
C = Ce + Cf + Cc # total conductance
'''Solve the resistor network problem'''
# Calculate current sources on the nodes using info in tx
Ntx = len(tx) # number of tx-rx sets
sources = np.zeros((nodes.shape[0], Ntx)) # current source intensity at all nodes (for all source configurations)
for i in range(Ntx):
# weights for the distribution of point current source to the neighboring nodes
weights = calcTrilinearInterpWeights(nodeX, nodeY, nodeZ, tx[i][:, :3])
# total current intensities at all the nodes
sources[:, i] = weights.dot(tx[i][:, 3])
# Obtain potentials at the nodes, potential differences, and current along the edges
start_time = time.time()
potentials, potentialDiffs, currents = solveRESnet(edges, C, sources)
end_time = time.time()
print(f"Time: {(end_time - start_time):.6f} seconds")
# Get simulated data
data = []
for i in range(Ntx):
# weights for the interpolation of potential data at the M-electrode location
Mw = calcTrilinearInterpWeights(nodeX, nodeY, nodeZ, rx[i][:, :3])
# weights for the interpolation of potential data at the N-electrode location
Nw = calcTrilinearInterpWeights(nodeX, nodeY, nodeZ, rx[i][:, 3:6])
# calculate the potential difference data as "M - N"
data.append((Mw.T - Nw.T) @ potentials[:, i])
data3 = data # save to data3
'''Plot Model #3's apparent resistivity'''
ABMNKVR3 = np.zeros((Ndata, 7))
count = 0
for i in range(Ntx):
A = tx[i][0, 0]
B = tx[i][1, 0]
for j in range(rx[i].shape[0]):
M = rx[i][j, 0]
N = rx[i][j, 3]
K = 2 * np.pi / (1 / (M - A) - 1 / (M - B) - 1 / (N - A) + 1 / (N - B)) # geometric factor
count += 1
# [A B M N geometric_factor potential_difference apparent_resistivity]
ABMNKVR3[count - 1, :] = [A, B, M, N, K, data3[i][j], K * data3[i][j]]
x = np.sum(ABMNKVR3[:, :4], axis=1) / 4 # mid-point of four electrodes
n = (ABMNKVR3[:, 2] - ABMNKVR3[:, 1]) / spacing # n-spacing as pseudo-depth
plt.figure()
plt.scatter(x, n, s=500, c=np.log10(ABMNKVR3[:, 6]), marker='s', cmap='viridis')
plt.gca().invert_yaxis()
plt.colorbar(label='Apparent resistivity log(Ohm*m)')
plt.grid(True)
plt.xlabel('X (m)')
plt.ylabel('n-spacing')
plt.title('(3) Model #3: Infrastructure')
'''Define Model #4: Above-ground pipe'''
blkLoc = np.array([
[-np.inf, np.inf, -np.inf, np.inf, np.inf, 0], # a uniform layer for the air (above surface)
[-np.inf, np.inf, -np.inf, np.inf, 0, -np.inf], # a uniform half-space below surface
[-30, -20, -4, 4, -6, -10], # an anomalous conductive block
[0, 8, -8, 2, -2, -6], # an anomalous resistive block
[-18, -18, -6, -6, 4, -100], # a steel cased well
[6, 16, 4, 4, 6, -2], # southern wall of steel-sheet warehouse
[6, 16, 10, 10, 6, -2], # northern wall of steel-sheet warehouse
[6, 6, 4, 10, 6, -2], # western wall of steel-sheet warehouse
[16, 16, 4, 10, 6, -2], # eastern wall of steel-sheet warehouse
[6, 16, 4, 10, 6, 6] # roof
])
blkCon = np.array([
1e-5, # air conductivity
0.01, # earth conductivity
0.1, # block conductivity
0.001, # block conductivity
np.pi * (0.05 ** 2 - 0.04 ** 2) * 5e6,
# steel casing's edgeCon (cross-sectional area times intrinsic conductivity)
0.005 * 5e6, # steel sheet's faceCon (thickness times intrinsic conductivity)
0.005 * 5e6, # steel sheet's faceCon (thickness times intrinsic conductivity)
0.005 * 5e6, # steel sheet's faceCon (thickness times intrinsic conductivity)
0.005 * 5e6, # steel sheet's faceCon (thickness times intrinsic conductivity)
0.005 * 5e6 # steel sheet's faceCon (thickness times intrinsic conductivity)
])
'''Form a resistor network'''
# Get connectivity properties of nodes, edges, faces, cells
nodes, edges, lengths, faces, areas, cells, volumes = formRectMeshConnectivity(nodeX, nodeY, nodeZ)
# Get conductive property model vectors (convert the block-model description to values on edges, faces, and cells)
cellCon, faceCon, edgeCon = makeRectMeshModelBlocks(nodeX, nodeY, nodeZ, blkLoc, blkCon, [], [], [])
# Convert all conductive objects to conductance on edges
Edge2Edge = formEdge2EdgeMatrix(edges, lengths)
Face2Edge = formFace2EdgeMatrix(edges, lengths, faces, areas)
Cell2Edge = formCell2EdgeMatrix(edges, lengths, faces, cells, volumes)
Ce = Edge2Edge.dot(edgeCon) # conductance from edges
Cf = Face2Edge.dot(faceCon) # conductance from faces
Cc = Cell2Edge.dot(cellCon) # conductance from cells
C = Ce + Cf + Cc # total conductance
# Add above-ground pipe
pipeStart = np.array([-18, -6, 4]) # where the pipe starts
pipeEnd = np.array([6, 4, 4]) # where the pipe ends
pipeLength = np.linalg.norm(pipeStart - pipeEnd) # length of the pipe
pipeStartNode = np.where((nodes[:, 0] == pipeStart[0]) & (nodes[:, 1] == pipeStart[1]) &
(nodes[:, 2] == pipeStart[2]))[0] # search for the starting node
pipeEndNode = np.where((nodes[:, 0] == pipeEnd[0]) & (nodes[:, 1] == pipeEnd[1]) &
(nodes[:, 2] == pipeEnd[2]))[0] # search for the ending node
tmp = [pipeStartNode[0] + 1, pipeEndNode[0] + 1]
edges = np.vstack((edges, tmp)) # append an additional edge representing the pipe
# append an additional conductance representing the pipe
C = np.append(C, np.pi * (0.05 ** 2 - 0.04 ** 2) * 5e6 / pipeLength)
'''Solve the resistor network problem'''
# Calculate current sources on the nodes using info in tx
Ntx = len(tx) # number of tx-rx sets
sources = np.zeros((nodes.shape[0], Ntx)) # current source intensity at all nodes (for all source configurations)
for i in range(Ntx):
# weights for the distribution of point current source to the neighboring nodes
weights = calcTrilinearInterpWeights(nodeX, nodeY, nodeZ, tx[i][:, :3])
# total current intensities at all the nodes
sources[:, i] = weights.dot(tx[i][:, 3])
# Obtain potentials at the nodes, potential differences, and current along the edges
start_time = time.time()
potentials, potentialDiffs, currents = solveRESnet(edges, C, sources)
end_time = time.time()
print(f"Time: {(end_time - start_time):.6f} seconds")
# Get simulated data
data = []
for i in range(Ntx):
# weights for the interpolation of potential data at the M-electrode location
Mw = calcTrilinearInterpWeights(nodeX, nodeY, nodeZ, rx[i][:, :3])
# weights for the interpolation of potential data at the N-electrode location
Nw = calcTrilinearInterpWeights(nodeX, nodeY, nodeZ, rx[i][:, 3:6])
# calculate the potential difference data as "M - N"
data.append((Mw.T - Nw.T) @ potentials[:, i])
data4 = data # save to data4
'''Plot Model #4's apparent resistivity'''
ABMNKVR4 = np.zeros((Ndata, 7))
count = 0
for i in range(Ntx):
A = tx[i][0, 0]
B = tx[i][1, 0]
for j in range(rx[i].shape[0]):
M = rx[i][j, 0]
N = rx[i][j, 3]
K = 2 * np.pi / (1 / (M - A) - 1 / (M - B) - 1 / (N - A) + 1 / (N - B)) # geometric factor
count += 1
# [A, B, M, N, geometric_factor, potential_difference, apparent_resistivity]
ABMNKVR4[count - 1, :] = [A, B, M, N, K, data4[i][j], K * data4[i][j]]
x = np.sum(ABMNKVR4[:, 0:4], axis=1) / 4 # mid-point of four electrodes
n = (ABMNKVR4[:, 2] - ABMNKVR4[:, 1]) / spacing # n-spacing as pseudo-depth
plt.figure()
plt.scatter(x, n, s=500, c=np.log10(ABMNKVR4[:, 6]), marker='s', cmap='viridis')
plt.gca().invert_yaxis()
plt.colorbar(label='Apparent resistivity log(Ohm*m)')
plt.xlabel('X (m)')
plt.ylabel('n-spacing')
plt.title('(4) Model #4: Above-ground pipe')
plt.grid(True)
plt.show()