forked from GeoDesignTool/GeoDT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeoDT.py
4537 lines (4117 loc) · 182 KB
/
GeoDT.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
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
import iapws.iapws97
print('GeoDT_3.8.3')
# ****************************************************************************
# Calculate economic potential of EGS & optimize borehole layout with caging
# Author: Luke P. Frash
#
# Notation:
# !!! for code needing to be updated (e.g, limitations or work in progress)
# *** for breaks between key sections
# ****************************************************************************
# ****************************************************************************
#### libraries
# ****************************************************************************
import numpy as np
from scipy.linalg import solve
# from scipy.stats import lognorm
import pylab
import math
from iapws import IAPWS97 as therm
import SimpleGeometry as sg
from scipy import stats
# import sys
# import matplotlib.pyplot as plt
# import copy
# ****************************************************************************
#### unit conversions
# ****************************************************************************
# Unit conversions for convenience
lpm = (0.1 * 0.1 * 0.1) / (60.0)
ft = 12 * 25.4e-3 # m
m = (1.0 / ft) # ft
deg = 1.0 * math.pi / 180.0
# rad=1.0/deg
gal = 3.785 * 0.1 * 0.1 * 0.1 # m^3=3.785 l
gpm = gal / 60.0
liter = 0.1 * 0.1 * 0.1
lps = liter / 1.0 # = liters per second
cP = 10.0 ** -3 # Pa-s
g = 9.81 # m/s2
MPa = 10.0 ** 6.0 # Pa
GPa = 10.0 ** 9.0 # Pa
darcy = 9.869233 * 10 ** -13 # m2
mD = darcy * 10.0 ** 3.0 # m2
yr = 365.2425 * 24.0 * 60.0 * 60.0 # s
mLmin = 1.66667e-8 # m3/s
um2cm = 1.0e-12 # m2
pi = math.pi
# ****************************************************************************
#### classes, functions, and modules
# ****************************************************************************
def HF(r, x0, strikeRad, dipRad, h=0.5):
"""
Place a radial hydraulic fracture of radius r at x0
"""
# start with a disk
disk = sg.diskObj(r, h)
disk = sg.rotateObj(disk, [0.0, 1.0, 0.0], dipRad)
disk = sg.rotateObj(disk, [0.0, 0.0, 1.0], -strikeRad)
disk = sg.transObj(disk, x0)
return disk
def typ(key):
"""
definitions and cross-referencing for pipe types
"""
ret = []
choices = np.asarray([
['boundary', '-3'],
['producer', '-2'],
['injector', '-1'],
['pipe', '0'],
['fracture', '1'],
['propped', '2'],
['darcy', '3'],
['choke', '4']
])
key = str(key)
ret = np.where(choices == key)
if ret[1] == 0:
ret = int(choices[ret[0], 1][0])
elif ret[1] == 1:
ret = str(choices[ret[0], 0][0])
else:
print('**invalid pipe type defined**')
ret = []
return ret
def azn_dip(x0, x1):
"""
Returns
-------
azn and dip from endpoints
"""
dx = x1[0] - x0[0]
dy = x1[1] - x0[1]
dz = x1[2] - x0[2]
dr = (dx ** 2.0 + dy ** 2.0) ** 0.5
azn = []
dip = []
if dx == 0 and dy >= 0:
azn = 0.0
elif dx == 0:
azn = pi
else:
azn = np.sign(dx) * np.arccos(dy / dr) + (1 - np.sign(dx)) * pi
if dr == 0.0:
dip = -np.sign(dz) * pi / 2.0
else:
dip = -np.arctan(dz / dr)
return azn, dip
def exponential_trunc(nsam,
bval=1.0,
Mmax=5.0,
Mwin=1.0,
prob=0.1):
"""
random samples from a truncated exponential distribution
"""
# zero-centered Mcap
lamba = np.log(10) * bval
Mcap = (-1.0 / lamba) * np.log(prob / (np.exp(lamba * Mwin) - 1.0 + prob))
# calculated Mmin
Mmin = Mmax - Mcap
# sample sets with resamples out-of-range values
s0 = np.random.exponential(1.0 / (np.log(10) * bval), nsam) + Mmin
iters = 0
while 1:
iters += 1
r_pl = s0 > Mmax
if np.sum(r_pl) > 0:
r_dr = np.random.exponential(1.0 / (np.log(10) * bval), nsam) + Mmin
s0 = s0 * (1 - r_pl) + r_dr * (r_pl)
else:
break
if iters > 100:
break
return s0
def contact_trunc(nsam,
weight=0.15,
bd_nom=0.002,
stddev=0.5 * 0.002,
exp_B=0.5,
exp_C=0.5 / np.pi,
bd_min=0.0001,
bd_max=3.0 * 0.002):
"""
get random samples from a 'contact' distribution
"""
# binomial samples
n1 = np.random.binomial(nsam, weight, (1))
n2 = nsam - n1
# exponential samples
s1 = np.random.exponential(exp_B, n1) * exp_C * bd_nom + bd_min
iters = 0
while 1:
iters += 1
r_pl = s1 > bd_max
if np.sum(r_pl) > 0:
r_dr = np.random.exponential(exp_B, n1) * exp_C * bd_nom + bd_min
s1 = s1 * (1 - r_pl) + r_dr * (r_pl)
else:
break
if iters > 100:
break
# normal samples
s2 = np.random.normal(bd_nom, stddev, n2)
iters = 0
while 1:
iters += 1
r_pl = (s2 > bd_max) + (s2 < bd_min)
if np.sum(r_pl) > 0:
r_dr = np.random.normal(bd_nom, stddev, n2)
s2 = s2 * (1 - r_pl) + r_dr * (r_pl)
else:
break
if iters > 100:
break
s0 = np.concatenate((s1, s2), axis=0)
return s0
def lognorm_trunc(nsam, logmu=0.0, logdev=1.0,
loglo=-2.0, loghi=2.0):
"""
get random samples from a log normal distribution
"""
# normal samples
s0 = np.random.normal(logmu, logdev, nsam)
iters = 0
while 1:
iters += 1
r_pl = (s0 > loghi) + (s0 < loglo)
if np.sum(r_pl) > 0:
r_dr = np.random.normal(logmu, logdev, nsam)
s0 = s0 * (1 - r_pl) + r_dr * (r_pl)
else:
break
if iters > 100:
break
return 10.0 ** s0
def norm_trunc(nsam,
mu=0.0,
dev=1.0,
lo=-2.0,
hi=2.0):
"""
get random samples from a log normal distribution
"""
# normal samples
s0 = np.random.normal(mu, dev, nsam)
iters = 0
while 1:
iters += 1
r_pl = (s0 > hi) + (s0 < lo)
if np.sum(r_pl) > 0:
r_dr = np.random.normal(mu, dev, nsam)
s0 = s0 * (1 - r_pl) + r_dr * (r_pl)
else:
break
if iters > 100:
break
return s0
class Cauchy:
"""
functions modified from JPM
"""
def __init__(self):
self.sigP = np.zeros((3, 3), dtype=float)
self.sigG = np.zeros((3, 3), dtype=float)
self.Sh = 0.0 # Pa
self.SH = 0.0 # Pa
self.SV = 0.0 # Pa
self.Sh_azn = 0.0 * deg # rad
self.Sh_dip = 0.0 * deg # rad
def rotationMatrix(self, axis, theta):
"""
http://stackoverflow.com/questions/6802577/python-rotation-of-3d-vector
"""
# return the rotation matrix associated with counterclockwise rotation about the given axis by theta radians.
axis = np.asarray(axis)
axis = axis / math.sqrt(np.dot(axis, axis))
a = math.cos(theta / 2.0)
b, c, d = -axis * math.sin(theta / 2.0)
aa, bb, cc, dd = a * a, b * b, c * c, d * d
bc, ad, ac, ab, bd, cd = b * c, a * d, a * c, a * b, b * d, c * d
return np.array([[aa + bb - cc - dd, 2 * (bc + ad), 2 * (bd - ac)],
[2 * (bc - ad), aa + cc - bb - dd, 2 * (cd + ab)],
[2 * (bd + ac), 2 * (cd - ab), aa + dd - bb - cc]])
def rotateTensor(self, tensor, axis, theta):
"""
http://www.continuummechanics.org/stressxforms.html
"""
rot = self.rotationMatrix(axis, theta)
return np.dot(rot, np.dot(tensor, np.transpose(rot)))
def normal_from_dip(self, dip_direction, dip_angle):
"""
Projection of normal plane from dip directions
"""
# dip_direction=0 is north -> nrmxH=0, nrmyH=1
# dip_direction=90 is east -> nrmxH=1, nrmyH=0
nrmxH = np.sin(dip_direction)
nrmyH = np.cos(dip_direction)
# The lateral components of the normals are corrected for the dip angle
nrmx = nrmxH * np.sin(dip_angle)
nrmy = nrmyH * np.sin(dip_angle)
# The vertical
nrmz = np.cos(dip_angle)
return np.asarray([nrmx, nrmy, nrmz])
def Pc(self, nrmP, phi, mcc):
"""
normal stress and critical slip or opening pressure
"""
# Shear traction on the fault segment
t = np.zeros([3])
for i in range(3):
for j in range(3):
t[i] += self.sigG[j][i] * nrmP[j]
# Normal component of the traction
Sn = 0.0
for i in range(3):
Sn += t[i] * nrmP[i]
# Shear component of the traction
tauV = np.zeros([3])
for i in range(3):
tauV[i] = t[i] - Sn * nrmP[i]
tau = np.sqrt(tauV[0] * tauV[0] + tauV[1] * tauV[1] + tauV[2] * tauV[2])
# Critical pressure for slip from mohr-coulomb
Pc1 = Sn - (tau - mcc) / np.tan(phi)
# Critical pressure for tensile opening
Pc2 = Sn + mcc
# Critical pressure for fracture activation
Pc = np.min([Pc1, Pc2])
return Pc, Sn, tau
def Pc_frac(self, strike, dip, phi, mcc):
"""
critical slip given fracture strike and dip
"""
# get fracture normal vector
nrmG = self.normal_from_dip(strike + np.pi / 2, dip)
return self.Pc(nrmG, phi, mcc)
def set_sigG_from_Principal(self, Sh, SH, SV, ShAzn, ShDip):
"""
Set cauchy stress tensor from rotated principal stresses
"""
# Stresses in the principal stress directions
# We have been given the azimuth of the minimum stress, ShAzimuthDeg, to compare with 90 (x-dir)
# That is Sh==Sxx, SH=Syy, SV=Szz in the principal stress coord system
sigP = np.asarray([
[Sh, 0.0, 0.0],
[0.0, SH, 0.0],
[0.0, 0.0, SV]
])
# Rotate about z-axis
deltaShAz = ShAzn - np.pi / 2.0 # (ShAznDeg-90.0)*np.pi/180.0
# Rotate about y-axis
ShDip = -ShDip # -ShDipDeg*np.pi/180.0
sigG = self.rotateTensor(sigP, [0.0, 1.0, 0.0], -ShDip)
sigG = self.rotateTensor(sigG, [0.0, 0.0, 1.0], -deltaShAz)
self.sigP = sigP
self.sigG = sigG
self.Sh = Sh # Pa
self.SH = SH # Pa
self.SV = SV # Pa
self.Sh_azn = ShAzn # Deg*deg #rad
self.Sh_dip = ShDip # Deg*deg #rad
return sigG
def plot_Pc(self, phi, mcc, filename='Pc_stereoplot.png'):
"""
Plot critical pressure
"""
# Working variables
nRad = 100
dip_angle_deg = np.asarray(range(nRad + 1)) * (90.0 / nRad)
nTheta = 200
dip_dir_radians = np.asarray(range(nTheta + 1)) * (2.0 * np.pi / nTheta)
png_dpi = 128
# Calculate critical dP
criticalDelPpG = np.zeros([nRad, nTheta])
for i in range(nRad):
for j in range(nTheta):
# Convert the x and y into a normal to the fracture using dip angle and dip direction
nrmG = self.normal_from_dip(dip_dir_radians[j], dip_angle_deg[i] * deg)
nrmx, nrmy, nrmz = nrmG[0], nrmG[1], nrmG[2]
criticalDelPpG[i, j], h1, h2 = self.Pc(np.asarray([nrmx, nrmy, nrmz]), phi, mcc)
# Plot critical slip pressure (lower hemisphere projection)
fig = pylab.figure(figsize=(6, 4.75), dpi=png_dpi, tight_layout=True, facecolor='w', edgecolor='k')
ax = fig.add_subplot(111, projection='polar')
ax.set_theta_zero_location("N")
ax.set_theta_direction(-1)
pylab.pcolormesh(dip_dir_radians + np.pi, dip_angle_deg,
np.ma.masked_where(np.isnan(criticalDelPpG), criticalDelPpG), vmin=110.0 * MPa,
vmax=150.0 * MPa, cmap='rainbow_r') # vmin=0.0*MPa, vmax=self.SH,cmap='rainbow_r')
ax.grid(True)
ax.set_rgrids([0, 30, 60, 90], labels=[])
ax.set_thetagrids([0, 90, 180, 270])
pylab.colorbar()
ax.set_title("Critical pressure for Mohr-Coulomb failure", va='bottom')
pylab.savefig(filename, format='png', dpi=png_dpi)
pylab.close()
class Reservoir:
"""
reservoir object
"""
def __init__(self):
# rock properties
self.size = 800.0 # m
self.ResDepth = 6000.0 # m
self.ResGradient = 50.0 # 56.70 # C/km; average = 25 C/km
self.ResRho = 2700.0 # kg/m3
self.ResKt = 2.5 # W/m-K
self.ResSv = 2063.0 # kJ/m3-K
self.AmbTempC = 25.0 # C
self.AmbPres = 0.101 * MPa # Example: 0.01 MPa #Atmospheric: 0.101 # MPa
self.ResE = 50.0 * GPa
self.Resv = 0.3
self.ResG = self.ResE / (2.0 * (1.0 + self.Resv))
self.Ks3 = 0.5
self.Ks2 = 0.75 # 0.75
self.s3Azn = 0.0 * deg
self.s3AznVar = 0.0 * deg
self.s3Dip = 0.0 * deg
self.s3DipVar = 0.0 * deg
# fracture orientation parameters #[i,:] set, [0,0:2] min, max --or-- nom, std
self.fNum = np.asarray([10,
10,
10], dtype=int) # count
"""
number of fractures in each set
"""
self.fDia = np.asarray([[300.0, 900.0],
[300.0, 900.0],
[300.0, 900.0]], dtype=float) # m
self.fStr = np.asarray([[79.0 * deg, 8.0 * deg],
[0.0 * deg, 8.0 * deg],
[180.0 * deg, 8.0 * deg]], dtype=float) # m
self.fDip = np.asarray([[60.0 * deg, 8.0 * deg],
[90.0 * deg, 8.0 * deg],
[0.0 * deg, 8.0 * deg]], dtype=float) # m
# fracture hydraulic parameters
self.gamma = np.asarray([10.0 ** -3.0, 10.0 ** -2.0, 10.0 ** -1.2])
self.n1 = np.asarray([1.0, 1.0, 1.0])
self.a = np.asarray([0.000, 0.200, 0.800])
self.b = np.asarray([0.999, 1.0, 1.001])
self.N = np.asarray([0.0, 0.6, 2.0])
self.alpha = np.asarray([2.0e-9, 2.9e-8, 10.0e-8])
self.prop_alpha = np.asarray([2.0e-9, 2.9e-8, 10.0e-8])
self.bh = np.asarray([0.00005, 0.0001, 0.0002]) # np.asarray([0.00005,0.00010,0.00020])
self.bh_min = 0.00005 # m
self.bh_max = 0.02 # 0.02000 #m
self.bh_bound = 0.003
self.f_roughness = np.asarray([0.80, 0.90, 1.00])
# well parameters
self.w_count = 3 # wells
self.w_spacing = 200.0 # m
self.w_length = 800.0 # m
self.w_azimuth = self.s3Azn + 0.0 * deg # rad
self.w_dip = self.s3Dip + 0.0 * deg # rad
self.w_proportion = 0.8 # m/m
self.w_phase = -45.0 * deg # rad
self.w_toe = 0.0 * deg # rad
self.w_skew = 15.0 * deg # rad
self.w_intervals = 5 # breaks in well length
self.ra = 0.0254 * 3.0 # 0.0254*3.0 #m
self.rb = self.ra + 0.0254 * 0.5 # m
self.rc = self.ra + 0.0254 * 1.0 # m
self.rgh = 80.0
# cement properties
self.CemKt = 2.0 # W/m-K
self.CemSv = 2000.0 # kJ/m3-K
# thermal-electric power parameters
self.GenEfficiency = 0.85 # kWe/kWt
# self.InjPres = 1.0 #Example: 0.135 #Model: 2.0 # MPa
# self.TargetPower = 1000 #Example: 2964 # kWe
self.LifeSpan = 20.5 * yr # years
self.TimeSteps = 41 # steps
self.p_whp = 1.0 * MPa # Pa
self.Tinj = 95.0 # C
self.H_ConvCoef = 3.0 # kW/m2-K
self.dT0 = 10.0 # K
self.dE0 = 500.0 # kJ/m2
# water base parameters
self.PoreRho = 980.0 # kg/m3 starting guess
self.Poremu = 0.9 * cP # Pa-s
self.Porek = 0.1 * mD # m2
self.kf = 300.0 * um2cm # m2
# calculated parameters
self.BH_T = self.ResDepth * 10 ** -3.0 * self.ResGradient + self.AmbTempC + 273.15 # K
self.BH_P = self.PoreRho * g * self.ResDepth + self.AmbPres # Pa
self.s1 = self.ResRho * g * self.ResDepth # Pa
self.s2 = self.Ks2 * (self.s1 - self.BH_P) + self.BH_P # Pa
self.s3 = self.Ks3 * (self.s1 - self.BH_P) + self.BH_P # Pa
# cauchy stress
self.stress = Cauchy()
self.stress.set_sigG_from_Principal(self.s3, self.s2, self.s1, self.s3Azn, self.s3Dip)
# self.stress.plot_Pc(30.0*deg,5.0*MPa)
# stimulation parameters
self.perf = 1
self.r_perf = 50.0 # m
self.sand = 0.3
"""sand ratio in frac fluid by volume"""
self.leakoff = 0.0
"""Carter leakoff"""
self.dPp = -2.0 * MPa
"""production well pressure drawdown"""
self.dPi = 0.5 * MPa
self.stim_limit = 5
self.Qinj = 0.01 # m3/s
self.Vinj = self.Qinj * self.LifeSpan
self.Qstim = 0.04 # m3/s
self.Vstim = 50000.0 # m3
self.pfinal_max = 999.9 * MPa # Pa, maximum long term injection pressure
self.bval = 1.0
"""Gutenberg-Richter magnitude scaling"""
self.phi = np.asarray([20.0 * deg, 35.0 * deg, 50.0 * deg]) # rad
self.mcc = np.asarray([5.0 * MPa, 10.0 * MPa, 15.0 * MPa]) # Pa
self.hfmcc = 0.1 * MPa
self.hfphi = 30.0 * deg
self.Kic = 1.5 * MPa # Pa-m**0.5
def re_init(self):
# calculated parameters
self.ResG = self.ResE / (2.0 * (1.0 + self.Resv))
self.BH_T = self.ResDepth * 10 ** -3.0 * self.ResGradient + self.AmbTempC + 273.15 # K
self.BH_P = self.PoreRho * g * self.ResDepth + self.AmbPres # Pa
self.s1 = self.ResRho * g * self.ResDepth # Pa
self.s2 = self.Ks2 * (self.s1 - self.BH_P) + self.BH_P # Pa
self.s3 = self.Ks3 * (self.s1 - self.BH_P) + self.BH_P # Pa
self.stress.set_sigG_from_Principal(self.s3, self.s2, self.s1, self.s3Azn, self.s3Dip)
self.Vinj = self.Qinj * self.LifeSpan
# self.rb = self.ra + 0.0254*0.5 # m
# self.rc = self.ra + 0.0254*1.0 # m
class Surface:
"""
surface object
"""
def __init__(self, x0=0.0, y0=0.0, z0=0.0, dia=1.0, stk=0.0 * deg, dip=90.0 * deg,
ty='fracture', rock=Reservoir(),
mcc=-1, phi=-1):
# *** base parameters ***
# node number of center point
self.ci = -1
# geometry
self.c0 = np.asarray([x0, y0, z0])
self.dia = dia
self.str = stk
self.dip = dip
self.typ = typ(ty)
# shear strength
self.phi = -1.0 # rad
self.mcc = -1.0 # Pa
# stress state
self.sn = 5.0 * MPa
self.En = 50.0 * GPa
self.vn = 0.30
self.Pc = 0.0 * MPa
self.tau = 0.0 * MPa
# stimulation information
self.stim = 0
self.Pmax = 0.0 * MPa
self.Pcen = 0.0 * MPa
self.Mws = [-99.9] # maximum magnitude seismic event tracker
self.arup = 1.0 # rupture area available for seismicity
self.hydroprop = False
self.prop_load = 0.0 # m3 #absolute proppant volume
self.prop_alpha = norm_trunc(1, rock.prop_alpha[1], rock.prop_alpha[1], rock.prop_alpha[0], rock.prop_alpha[2])[
0] # proppant compressibility modulus
self.roughness = rock.f_roughness if type(rock.f_roughness) is float else \
np.random.uniform(rock.f_roughness[0], rock.f_roughness[2], (1))[0] # open flow roughness
self.kf = rock.kf # proppant pack permeability
# scaling
self.u_N = -1.0
self.u_alpha = -1.0
self.u_a = -1.0
self.u_b = -1.0
self.u_gamma = -1.0
self.u_n1 = -1.0
# hydraulic geometry
self.bh = -1.0
# *** stochastic sampled parameters *** #!!!
self.u_gamma = \
lognorm_trunc(1, np.log10(rock.gamma[1]), 0.45, np.log10(rock.gamma[0]), np.log10(rock.gamma[2]))[0]
self.u_n1 = np.random.uniform(rock.n1[0], rock.n1[2], (1))[0]
self.u_a = norm_trunc(1, rock.a[1], 0.150, rock.a[0], rock.a[2])[0]
self.u_b = np.random.uniform(rock.b[0], rock.b[2], (1))[0]
self.u_N = \
contact_trunc(1, 0.15, rock.N[1], 0.5 * rock.N[1], 0.5, 0.5 * rock.N[1] / np.pi, rock.N[0], rock.N[2])[0]
self.u_alpha = norm_trunc(1, rock.alpha[1], rock.alpha[1], rock.alpha[0], rock.alpha[2])[0]
self.bh = norm_trunc(1, rock.bh[1], rock.bh[1], rock.bh[0], rock.bh[2])[
0] # !!! would be nice to replace this with a physics based estimate
if phi < 0:
self.phi = np.random.uniform(rock.phi[0], rock.phi[2], (1))[0]
else:
self.phi = phi
if mcc < 0:
self.mcc = np.random.uniform(rock.mcc[0], rock.mcc[2], (1))[0]
else:
self.mcc = mcc
# stress state
self.Pc, self.sn, self.tau = rock.stress.Pc_frac(self.str, self.dip, self.phi, self.mcc)
# apertures
self.bd = self.bh / self.u_N
self.bd0 = self.bd
self.bd0p = 0.0
self.vol = (4.0 / 3.0) * pi * 0.25 * self.dia ** 2.0 * 0.5 * self.bd
self.arup = 0.25 * np.pi * self.dia ** 2.0
def check_integrity(self, rock=Reservoir(), pres=0.0):
"""
adjust fracture cohesion to prevent runaway stimulation at specified conditions
"""
# originally assigned values
Pc0 = self.Pc
mcc0 = self.mcc
phi0 = self.phi
# shear stability limit
mcc_c = self.tau - (self.sn - pres) * np.tan(self.phi)
# tensile stability limit
mcc_t = pres - self.sn
# update fracture cohesion to ensure stability at the input conditions
self.mcc = np.max([self.mcc, mcc_c, mcc_t])
# recompute critical conditions
self.Pc, self.sn, self.tau = rock.stress.Pc_frac(self.str, self.dip, self.phi, self.mcc)
# output message
if self.Pc > Pc0:
print(
'alert: critical fracture at Tau = %.2e, sn = %.2e, and Pp %.2e having phi = %.2e rad, mcc = %.2e Pa, Pc = %.2e Pa adjusted to phi = %.2e rad, mcc = %.2e Pa, Pc = %.2e Pa'
% (self.tau, self.sn, pres, phi0, mcc0, Pc0, self.phi, self.mcc, self.Pc))
def make_critical(self, rock=Reservoir(), pres=0.0):
"""
set fracture cohesion to critical value at specified conditions
"""
# shear stability limit
mcc_c = self.tau - (self.sn - pres) * np.tan(self.phi)
# tensile stability limit
mcc_t = pres - self.sn
# update fracture cohesion to enforce critical stability at the input conditions
self.mcc = np.max([mcc_c, mcc_t])
# recompute critical conditions
self.Pc, self.sn, self.tau = rock.stress.Pc_frac(self.str, self.dip, self.phi, self.mcc)
# output message
print(' hydrofrac critical cohesion calculated as %.2e Pa to obtain Pc = %.2e Pa' % (self.mcc, self.Pc))
# error case
if self.Pc <= self.sn:
print(' *** error: solution gives closed supercritical shear instead of hydrofracture')
def check_integrity_old(self, rock=Reservoir(), pres=0.0):
"""
adjust frictional properties to prevent runaway stimulation at specified conditions
(attempts to get more reasonable friction angle or more reasonable cohesion... but doesn't work well)
"""
# tensile stability
mcc_t = pres - self.sn
# low shear stress stability
mcc_s = self.tau - (self.sn - pres) * np.tan(self.phi)
# high shear stress stability
phi_s = np.arctan((self.tau - self.mcc) / (self.sn - pres))
# shear failure critical angle
if (pres < self.sn) and (self.mcc < self.tau):
mcc_crit = 0.0
phi_crit = phi_s
# tensile failure critical cohesion
else:
mcc_crit = np.max([mcc_t, mcc_s])
phi_crit = 0.0
# update fracture properties to attain stability at the input conditions
Pc0 = self.Pc
mcc0 = self.mcc
phi0 = self.phi
self.phi = np.max([self.phi, phi_crit])
self.mcc = np.max([self.mcc, mcc_crit])
# recompute critical conditions
self.Pc, self.sn, self.tau = rock.stress.Pc_frac(self.str, self.dip, self.phi, self.mcc)
# output message
if self.Pc > Pc0:
print(
'alert: critical fracture at Tau = %.2e, sn = %.2e, and Pp %.2e having mcc = %.2e Pa, phi = %.2e rad, Pc = %.2e Pa adjusted to phi = %.2e rad, mcc = %.2e Pa, Pc = %.2e Pa'
% (self.tau, self.sn, pres, mcc0, phi0, Pc0, self.phi, self.mcc, self.Pc))
# if (pres >= self.sn):
# phi_crit = 0.0 #use originally-specified phi
# mcc_crit = pres - self.sn + 1000.0 #1 kPa added to prevent numerical instabilities
# #low stress fractures cause calculated critical friction angles to be excessive so mcc must be modified instead
# elif (self.tau <= self.mcc):
# phi_crit = 0.0 #use originally-specified phi
# mcc_crit = self.tau - (self.sn - pres)*np.tan(self.phi)
# #high shear & high stress fractures are stable as a function of phi, but low phi can cause runaway stimulation
# else:
# pass
# phi_crit = np.arctan((self.tau-self.mcc+0.5*rock.dPi)/(self.sn-pres))
# if self.phi < phi_crit:
# self.phi = phi_crit
# self.mcc = mcc_crit
# self.Pc, self.sn, self.tau = rock.stress.Pc_frac(self.str, self.dip, self.phi, self.mcc)
# print('alert: a fracture was critically weak and adjusted to phi = %.2f' %(phi_crit))
# print('-- new Pc = %.3e Pa' %(self.Pc))
class Line:
"""
line objects
"""
def __init__(self,
x0=0.0,
y0=0.0,
z0=0.0,
length=1.0,
azn=0.0 * deg,
dip=0.0 * deg,
w_type='pipe',
ra=0.0254 * 3.0,
rb=0.0254 * 3.5,
rc=0.0254 * 3.5,
rough=80.0):
# position geometry
self.c0 = np.asarray([x0, y0, z0]) # origin
self.leg = length # length
self.azn = azn # axis azimuth north
self.dip = dip # axis dip from horizontal
self.typ = typ(w_type) # type of well
# flow geometry
self.ra = ra # m
self.rb = rb # m
self.rc = rc # m
self.rgh = rough
# stimulation traits
self.hydrofrac = False # was well already hydrofraced?
self.completed = False # was well stimulation process completed?
self.stabilize = False # was well flow stabilized?
class Nodes:
"""
node list object
"""
def __init__(self):
"""
initialization
"""
self.r0 = np.asarray([np.inf, np.inf, np.inf])
self.all = np.asarray([self.r0])
self.tol = 0.0005
self.num = len(self.all)
self.p = np.zeros(self.num, dtype=float)
self.T = np.zeros(self.num, dtype=float)
self.h = np.zeros(self.num, dtype=float)
# self.f_id = [[-1]]
def add(self, c=np.asarray([0.0, 0.0, 0.0])): # ,f_id=-1):
"""
add a node
"""
# round to within tolerance
if not (np.isinf(c[0])):
c = np.rint(c / self.tol) * self.tol
# check for duplicate existing node
ck_1 = np.asarray([np.isin(self.all[:, 0], c[0]), np.isin(self.all[:, 1], c[1]), np.isin(self.all[:, 2], c[2])])
ck_2 = ck_1[0, :] * ck_1[1, :] * ck_1[2, :]
ck_i = np.where(ck_2 == 1)
# yes duplicate -> return index of existing node
if len(ck_i[0]) > 0:
# if f_id != -1:
# self.f_id[ck_i[0][0]] += [f_id]
return False, ck_i[0][0]
# no duplicate -> add node -> return index of new node
else:
self.all = np.concatenate((self.all, np.asarray([c])), axis=0)
self.num = len(self.all)
self.p = np.concatenate((self.p, np.asarray([0.0])), axis=0)
self.T = np.concatenate((self.T, np.asarray([0.0])), axis=0)
self.h = np.concatenate((self.h, np.asarray([0.0])), axis=0)
# self.f_id += [[f_id]]
return True, len(self.all) - 1
class Pipes:
"""
pipe list object
"""
def __init__(self):
# initialization
self.num = 0
self.n0 = [] # source node
self.n1 = [] # target node
self.L = [] # length
self.W = [] # width
self.typ = [] # property source type
self.fID = [] # property source index
self.K = [] # flow solver coefficient
self.n = [] # flow solver exponent
self.Dh = [] # hydraulic aperture/diameter
self.Dh_max = [] # hydraulic aperture/diameter limit
self.frict = [] # hydraulic roughness
self.hydrofraced = False # tracker for fracture initiation
# add a pipe
def add(self, n0, n1, length, width, featTyp, featID, Dh=1.0, Dh_max=1.0, frict=1.0):
self.n0 += [n0]
self.n1 += [n1]
self.L += [length]
self.W += [width]
self.typ += [featTyp]
self.fID += [featID]
self.K += [1.0]
self.n += [1.0]
self.num = len(self.n0)
self.Dh += [Dh]
self.Dh_max += [Dh_max]
self.frict += [frict]
self.hydrofraced = False
def Dh_limit(self, Q, dP, rho=980.0, g=9.81, mu=0.9 * cP, k=0.1 * mD):
"""
set hydraulic aperture limits based on minimum pressure drop at target flow rate
"""
for i in range(0, self.num):
if (int(self.typ[i]) in [typ('injector'), typ('producer'), typ('pipe')]):
# a_max = (10.7e-5*self.L[i]*rho*g*Q/(dP*self.frict[i]**1.852))**(1.0/4.87) #oldest
# a_max = (10.7e-4*self.L[i]*rho*g*Q/(dP*self.frict[i]**1.852))**(1.0/4.87) #old 2/11/23
Lscaled = self.L[i] * mu / (0.9 * cP)
a_max = (10.7e-4 * Lscaled * rho * g * Q / (dP * self.frict[i] ** 1.852)) ** (1.0 / 4.87)
self.Dh_max[i] = a_max
elif (int(self.typ[i]) in [typ('boundary'), typ('fracture'), typ('propped'), typ('choke')]):
# bh_max = (12.0e-5*mu*Q*self.L[i]/(dP*self.W[i]))**(1.0/3.0)
bh_max = (12.0e-4 * mu * Q * self.L[i] / (dP * self.W[i])) ** (1.0 / 3.0)
self.Dh_max[i] = bh_max
elif (int(self.typ[i]) in [typ('darcy')]):
# t_max = 1.0e-5*Q*mu*self.L[i]/(k*self.W[i]*dP)
t_max = 1.0e-4 * Q * mu * self.L[i] / (k * self.W[i] * dP)
self.Dh_max[i] = t_max
else:
print('error: undefined type of conduit')
exit()
class Mesh:
"""
model object, functions, and data as object
"""
def __init__(self): # ,node=[],pipe=[],fracs=[],wells=[],hydfs=[],bound=[],geo3D=[]): #@@@ are these still used?
# domain information
self.rock = Reservoir()
self.nodes = Nodes()
self.pipes = Pipes()
self.fracs = []
self.wells = []
self.hydfs = []
self.bound = []
self.faces = []
# intersections tracker
self.trakr = [] # index of fractures in chain
# flow solver
self.H = [] # boundary pressure head array, m
self.Q = [] # boundary flow rate array, m3/s
self.q = [] # calculated pipe flow rates
self.v5 = [] # calculated inlet specific volume, m3/kg
self.i_p = [] # constant flow well pressures, Pa
self.i_q = [] # constant flow well rates, m3/s
self.p_p = [] # constant pressure well pressures, Pa
self.p_q = [] # constant pressure well rates, m3/s
self.b_p = [] # boundary pressure, Pa
self.b_q = [] # boundary rates, m3/s
# heat solver
self.Tb = [] # boundary temperatures
self.R0 = [] # thermal radius
self.Rt = [] # thermal radius over time
self.ms = [] # pipe mass flow rates
self.Et = [] # energy in rock over time
self.Qt = [] # heat flow from rock over time
self.Tt = [] # heat flow from rock over time
self.ht = [] # enthalpy over time
self.ts = [] # time stamps
self.w_h = [] # wellhead enthalpy
self.w_m = [] # wellhead mass flow
self.p_E = [] # production energy
self.b_h = [] # boundary enthalpy
self.b_m = [] # boundary mass flow
self.b_E = [] # boundary energy
self.i_E = [] # injection energy
self.i_mm = [] # mixed injection mass flow rate
self.p_mm = [] # mixed produced mass flow rate
self.p_hm = [] # mixed produced enthalpy
# power solver
self.Fout = [] # flash rankine power out
self.Bout = [] # binary isobutane power out
self.Qout = [] # pumping power out
self.Pout = [] # net power out
self.dhout = [] # heat extraction
# validation stuff
self.v_Rs = []
self.v_ts = []
self.v_Ps = []
self.v_ws = []
self.v_Vs = []
self.v_Pn = []
# economics
self.NPV = 0.0
# # Static per-fracture hydraulic resistance terms using method of Luke P. Frash; [lower,nominal,upper]
# # .... also calculates the stress states on the fractutres
# def static_KQn(self,
# rnd_N = [0.01,0.2,0.2],
# rnd_alpha = [-0.002/MPa,-0.028/MPa,-0.080/MPa],
# rnd_a = [0.01,0.05,0.20],
# rnd_b = [0.7,0.8,0.9],
# rnd_gamma = [0.001,0.01,0.03]):
# #size
# num = len(self.faces)
# #exponential for N, alpha, gamma, and a
# r = np.random.exponential(scale=0.25,size=num)
# r[r>1.0] = 1.0
# r[r<0] = 0.0
# N = r*(rnd_N[2]-rnd_N[0])+rnd_N[0]
# r = np.random.exponential(scale=0.25,size=num)
# r[r>1.0] = 1.0
# r[r<0] = 0.0
# alpha = r*(rnd_alpha[2]-rnd_alpha[0])+rnd_alpha[0]
# r = np.random.exponential(scale=0.25,size=num)
# r[r>1.0] = 1.0
# r[r<0] = 0.0
# a = r*(rnd_a[2]-rnd_a[0])+rnd_a[0]
# r = np.random.exponential(scale=0.25,size=num)
# r[r>1.0] = 1.0
# r[r<0] = 0.0
# gamma = r*(rnd_gamma[2]-rnd_gamma[0])+rnd_gamma[0]
# #uniform for b
# b = np.random.uniform(rnd_b[0],rnd_b[2],size=num)
# #store properties
# for n in range(0,num):
# #aperture scaling parameters
# self.faces[n].u_N = N[n]
# self.faces[n].u_alpha = alpha[n]
# self.faces[n].u_a = a[n]
# self.faces[n].u_b = b[n]
# self.faces[n].u_gamma = gamma[n]
# #stress states
# self.faces[n].Pc, self.faces[n].sn, self.faces[n].tau = self.rock.stress.Pc_frac(self.faces[n].str, self.faces[n].dip, self.faces[n].phi, self.faces[n].mcc)
def hydromech(self, f_id, fix=False): # , pp=-666.0):
"""
Propped fracture property estimation with geomechanics
"""
# initialize stim
stim = False