-
Notifications
You must be signed in to change notification settings - Fork 1
/
fractend.py
424 lines (295 loc) · 15.7 KB
/
fractend.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
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
from sga import stcoordline, pole, principalstress, shearonplane
'''
fractendpy is the python version of FracTend by David Healy & Tara Stephens (July 2018), it runs on a base of code from
Allmendinger et al., 2012 "Structural geology algorithms". Additional equations and code from Morris et al., 1996 Geology;
Streit & Hillis, 2004 Energy; Jolly & Sanderson, 1997 Journal of Structural Geology.
Requires numpy and matplotlib
Oct 2022
Ben Melosh
'''
class stress_state():
def __init__(self, fracture_poles, sigma1, sigma2, sigma3, trend_s1, plunge_s1, trend_s3, Pf, mu_static, cohesion, sigmaN_mohr, increment, ncontours):
# User inputs
self.fracture_poles = fracture_poles
self.sigma1 = sigma1
self.sigma2 = sigma2
self.sigma3 = sigma3
self.trend_s1 = trend_s1
self.plunge_s1 = plunge_s1
self.trend_s3 = trend_s3
self.Pf = Pf
self.mu_static = mu_static
self.cohesion = cohesion
self.sigmaN_mohr = sigmaN_mohr
self.increment = increment
self.ncontours = ncontours
# Run
self.stresstensor()
self.normal_and_shear_stress()
self.tendencies()
self.stress_ratios()
self.azimuthal_variation()
self.equal_area_projection()
self.pole_to_cart()
self.stress_to_cart()
self.write_stress_to_file()
def stresstensor(self):
'''
Returns
stress_tensor: 3x3 stress tensor with principal stresses
sorted_sigma: 1X3 array with principal stresses
sigmad: differential stress
'''
self.sorted_sigma = [self.sigma1, self.sigma2, self.sigma3]
self.sigmad = self.sigma1 - self.sigma3
self.stress_tensor = np.diag(self.sorted_sigma)
return self.stress_tensor
def normal_and_shear_stress(self):
'''
Calculate normal and shear stresses for all directions on all surfaces.
Returns
'''
# convert stress orientations into radians
self.trend_s1_rad = np.radians(self.trend_s1)# * np.pi / 180
self.plunge_s1_rad = np.radians(self.plunge_s1)# * np.pi / 180
self.trend_s3_rad = np.radians(self.trend_s3)# * np.pi / 180
# define a 3d space
# for all directions in 3-space, calculate normal and shear stresses
# on all 3d surfaces
phi_index = 0
theta_index = 0
#increment = 10
phi_min = 90
phi_max = 180
theta_min = 0
theta_max = 360
phi_n = (phi_max - phi_min)//self.increment + 1 #divide to make int
theta_n = (theta_max - theta_min)//self.increment + 1
self.sigmaN = np.zeros((theta_n, phi_n))
self.tau = np.zeros((theta_n, phi_n))
for idp, phi in enumerate(range(90,181,self.increment)):
phi_rad = (phi - 90) * np.pi/180
for idt, theta in enumerate(range(0,361,self.increment)):
theta_rad = theta * np.pi / 180
# convert pole to strike and dip
[strike, dip] = pole(theta_rad, phi_rad, 0)
# calculate normal and shear stress on the plane
[stress_fracture, dc_stress_fracture, R] = shearonplane(self.stress_tensor, self.trend_s1_rad, self.plunge_s1_rad, self.trend_s3_rad, strike, dip)
np.nan_to_num(stress_fracture, copy=False, nan=0.0) # This line converts nan values into zero, nan values are generated when
#the dip of the surface is parallel to sigma 1 and sigma 3
# save normal and shear stresses for later calculation
self.sigmaN[idt][idp] = stress_fracture[0][0]#(1,1)
self.tau[idt][idp] = stress_fracture[2][0]#(3,1)
# import pdb
# pdb.set_trace()
#return sigmaN, tau
def tendencies(self):#sigmaN, tau, sorted_sigma, mu_static, Pf):
# calculate tendencies - slip, dilatation and frac. suscep
# calculate normalised slip tendency (Morris et al., 1996)
self.TsMax = (self.tau / self.sigmaN ).max()
self.Ts = ( self.tau / self.sigmaN ) / self.TsMax
# calculate dilatation tendency (Ferril et al., 1999)
self.Td = ( self.sorted_sigma[0] - self.sigmaN ) / ( self.sorted_sigma[0] - self.sorted_sigma[2] )
# calculate shear stress/ dilation displacement ratio
# from Delaney et al.(1988)
self.TD = self.tau / (self.sorted_sigma[2] + self.Pf)
# calculate fracture susceptibility
self.Sf = self.sigmaN - ( self.tau / self.mu_static )
# calculate muOA (opening angle), Jolly & Sanderson, 1997
OA = self.tau / (self.Pf - self.sigmaN)
self.muOAfracture = np.arctan(OA) * (180/np.pi)
#return TsMax, Ts, Td, TD, Sf, OA, muOAfracture
def stress_ratios(self):
# Calculate and display various stress ratios:
Phi = ( self.sigma2 - self.sigma3 ) / ( self.sigma1 - self.sigma3 )
R = (self.sigma1 - self.sigma2) / (self.sigma1 - self.sigma3)
Rprime = ( self.Pf - self.sigma3 ) / ( self.sigma1 - self.sigma3 )
print('Printing some stress ratios')
print('---------------------------')
print('Phi: {:1.2f}'.format(Phi))
print('R: {:1.2f}'.format(R))
print('Rprime: {:1.2f}'.format(Rprime))
print('---------------------------')
#return Phi, R, Rprime
def azimuthal_variation(self):
# plot azimuthal variation of tendencies, with poles to fractures
# overlain
deltaP = self.increment * np.pi / 180
phiP = np.arange(np.pi/2, np.pi+deltaP, deltaP)
phiP = phiP - np.pi/2
thetaP = np.arange(0, 2*np.pi+deltaP, deltaP)
[self.phiP, self.thetaP] = np.meshgrid(phiP, thetaP)
#return phiP, thetaP
def equal_area_projection(self):
# equal area projection
dp = np.sqrt(1 - np.sin(self.phiP))
self.xeqarea = dp * np.sin(self.thetaP)
self.yeqarea = dp * np.cos(self.thetaP)
self.rPrim = 1
self.xPrim = np.arange(self.rPrim*-1, self.rPrim, 0.0001)
self.yPrim = np.sqrt(np.square(self.rPrim) - np.square(self.xPrim))
#return dp, xeqarea, yeqarea, rPrim, xPrim, yPrim
def pole_to_cart(self):
fracture_poles_rad = np.radians(self.fracture_poles)# * np.pi / 180
# convert Fracture pole plunges and plunge directions to cartesian coords
dp = np.sqrt(1 - np.sin(fracture_poles_rad[:,0]))
newTrend = np.remainder(fracture_poles_rad[:,1], 2*np.pi)
self.xFractures = dp * np.sin(newTrend)
self.yFractures = dp * np.cos(newTrend)
#return xFractures, yFractures
def stress_to_cart(self):
'''
'''
# convert stress orientations into radians
trend_s1_rad = np.radians(self.trend_s1)
plunge_s1_rad = np.radians(self.plunge_s1)
trend_s3_rad = np.radians(self.trend_s3)
# convert principal stress orientations into cartesian coords for equal
# area
[pstress, dCp] = principalstress(self.stress_tensor, trend_s1_rad, plunge_s1_rad, trend_s3_rad)
trendS2rad = pstress[1,1]
plungeS2rad = pstress[1,2]
plungeS3rad = pstress[2,2]
[self.xS1, self.yS1] = stcoordline(trend_s1_rad, plunge_s1_rad, 1)
[self.xS2, self.yS2] = stcoordline(trendS2rad, plungeS2rad, 1)
[self.xS3, self.yS3] = stcoordline(trend_s3_rad, plungeS3rad, 1)
# import pdb
# pdb.set_trace()
#return xS1, yS1, xS2, yS2, xS3, yS3
def write_stress_to_file(self):
'''
Calculates stress and shear values for each supplied pole, returns .csv file
'''
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#% for each plane in the input file
#% new loop to calculate specifc values for the supplied poles
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fracture_poles_rad = np.radians(self.fracture_poles) #* np.pi / 180
n_fractures = len(self.fracture_poles)
# convert stress orientations into radians
trend_s1_rad = np.radians(self.trend_s1) # * np.pi / 180
plunge_s1_rad = np.radians(self.plunge_s1) #* np.pi / 180
trend_s3_rad = np.radians(self.trend_s3) #* np.pi / 180
self.sigmaNFracture = np.zeros((n_fractures,1))
self.tauFracture = np.zeros((n_fractures,1))
for i in range(0, n_fractures):
# convert fracture pole to strike and dip
[strike, dip] = pole(fracture_poles_rad[i,1], fracture_poles_rad[i,0], 0)
# calculate normal and shear stress on the plane
[stressFracture, dcStressFracture, R] = shearonplane(self.stress_tensor, trend_s1_rad, plunge_s1_rad, trend_s3_rad, strike, dip)
# save normal and shear stresses for later calculation
self.sigmaNFracture[i] = stressFracture[0,0]
self.tauFracture[i] = stressFracture[2,0]
# end for each plane
# calculate normalised slip tendency
TsFractureFile = (self.tauFracture / self.sigmaNFracture) / self.TsMax
# calculate dilatation tendency
TdFractureFile = ( self.sorted_sigma[0] - self.sigmaNFracture ) / ( self.sorted_sigma[0] - self.sorted_sigma[2] )
# calculate fracture susceptibility
SfFractureFile = self.sigmaNFracture - ( self.tauFracture / self.mu_static )
# calculate opening angle
OAFile = self.tauFracture / (self.Pf - self.sigmaNFracture)
muOAfractureFile = np.arctan(OAFile) * (180/np.pi)
# write out text file of data values for the specific fracture poles
self.all_data_for_export = np.hstack((self.fracture_poles, TsFractureFile, TdFractureFile, SfFractureFile, self.tauFracture, self.sigmaNFracture, muOAfractureFile))
np.savetxt("ftp_results.csv",
self.all_data_for_export,
delimiter=',',
fmt='%2.2f'+','+'%3.2f'+','+'%1.3f'+','+'%1.3f'+','+'%5.2f'+','+'%5.2f'+','+'%5.2f'+','+'%5.3f',
header='plunge'+','+'trend'+','+'Ts'+','+'Td'+','+'Sf'+','+'tau'+','+'sigmaN'+','+'muOA',
comments='')
return self.all_data_for_export
def stereonet_plot(self, dataset, dataset_name='dataset_name'):#stress_tensor, stress_orientations, increment, fracture_poles, ncontours, '):
'''
Function to plot stereonet of different tendency data.
dataset is the input data you want to plot.
slip tendency, Ts
Dilatation Tendency, Td
fracture susceptibility, Sf
opening angle, OA
stress_tensor: 3x3 array of principle stress magnitudes
stress_orientations: list of trends and plunge of stress orientations
increment: value defining the resolution to calculate and plot at.
fracture_poles: plunge, trend values of poles to fracture planes from initial input.
ncontours: the number of contours in the plot.
dataset_name: a string name for plot label.
Ben Melosh Oct 2022
'''
n_fractures = len(self.fracture_poles) # Calculate number of fractures
# calculate plotting area and tendency variations
fig, ax = plt.subplots(1, figsize=(6,6))
sn = plt.contourf(self.xeqarea, self.yeqarea, dataset, self.ncontours)#, 'EdgeColor', 'none')
ax.plot(self.xPrim, self.yPrim, '-k', linewidth=1)
ax.plot(self.xPrim, self.yPrim*-1, '-k', linewidth=1)
ax.plot(self.xFractures, self.yFractures, '.r',markeredgecolor='k', markersize=15)
ax.plot(self.xS1, self.yS1, 's', markersize=10, markeredgecolor='k', markerfacecolor='w')
ax.annotate(text='\u03C3'+'1', xy=(self.xS1+0.05, self.yS1+0.05))
ax.plot(self.xS2, self.yS2, 'd', markersize=10, markeredgecolor='k', markerfacecolor='w')
ax.annotate(text='\u03C3'+'2', xy=(self.xS2+0.05, self.yS2+0.05))
ax.plot(self.xS3, self.yS3, '^', markersize=10, markeredgecolor='k', markerfacecolor='w')
ax.annotate(text='\u03C3'+'3', xy=(self.xS3+0.05, self.yS3+0.05))
ax.set_xticks([])
ax.set_yticks([])
plt.gca().set_aspect('equal', adjustable='box')
plt.xlim([-1.05, 1.05])
plt.ylim([-1.05, 1.05])
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.05)
# creating colorbar
fig.colorbar(sn, cax = cax, orientation = "vertical")
fig.axes[0].set_title('{}'.format(dataset_name) + ' n={}'.format(n_fractures))
fig.savefig("./{}_stereo.pdf".format(dataset_name), dpi=300, transparent=True)
plt.show()
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#% plot Mohr diagrams, with fractures & contoured stability measures
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
def mohr_plot(self, dataset, dataset_name='dataset_name'):
'''
Function to plot Mohr circles, uses plotmohr_OA.py
dataset: the tendency data you want to plot,
slip tendency, Ts
Dilatation Tendency, Td
fracture susceptibility, Sf
opening angle, OA
stress_tensor: 3x3 tensor of the principal stresses
sigmaN: numpy array with normal stresses
tau: numpy array with shear stresses
ncountours: number of contours
fracture_poles: number of fractures from your dataset
dataset_name: string of the name of your dataset for plotting
'''
n_fractures = len(self.fracture_poles)
#sigmaN_mohr = 100
tau_mohr = self.cohesion + self.mu_static * self.sigmaN_mohr
## Calculating the mohr circle
theta_mohr = np.arange(0, 2*np.pi, 2*np.pi/360)
sin2theta_mohr = np.sin(2 * theta_mohr)
cos2theta_mohr = np.cos(2 * theta_mohr)
tau13_mohr = ((self.sigma1 - self.sigma3)/2)*sin2theta_mohr
sigma13_mohr = (self.sigma1 + self.sigma3)/2 + ((self.sigma1-self.sigma3)/2)*cos2theta_mohr
tau12_mohr=((self.sigma1 - self.sigma2)/2)*sin2theta_mohr
sigma12_mohr=(self.sigma1 + self.sigma2)/2 + ((self.sigma1 - self.sigma2)/2)*cos2theta_mohr
tau23_mohr = ((self.sigma2 - self.sigma3)/2)*sin2theta_mohr
sigma23_mohr = (self.sigma2 + self.sigma3)/2 + ((self.sigma2 - self.sigma3)/2)*cos2theta_mohr
xm = sigma13_mohr.max()
ym = tau13_mohr.max()
## Plot the mohr circle
fig, ax = plt.subplots(1, figsize=(6,6))
plt.plot([0, self.sigmaN_mohr], [self.cohesion, tau_mohr], '-r', linewidth=1)
ax.contourf(self.sigmaN, self.tau, dataset, self.ncontours)
ax.plot(sigma13_mohr, tau13_mohr, linewidth=1, color='k')
ax.plot(sigma12_mohr, tau12_mohr, linewidth=1, color='k')
ax.plot(sigma23_mohr, tau23_mohr, linewidth=1, color='k')
for f in range(0,n_fractures): #1:n_fractures
ax.plot(self.sigmaNFracture[f], self.tauFracture[f], '.r', markersize=10)
plt.gca().set_aspect('equal', adjustable='box')
plt.xlim([0, self.sigma1*1.05])
plt.ylim([0, self.sigmad*0.75])
ax.set_xlabel('Effective normal stress, MPa')
ax.set_ylabel('Shear stress, MPa')
plt.title('{}'.format(dataset_name)+' n='+'{}'.format(n_fractures))
fig.savefig("./{}_mohr.pdf".format(dataset_name), dpi=300, transparent=True)
plt.show()