-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoulomb_stress_dynamic.py
313 lines (285 loc) · 9.58 KB
/
coulomb_stress_dynamic.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
import os
import pickle
import numpy as np
from mpi4py import MPI
from pygrnwang.read_qssp import read_stress_tensor
from pygrnwang.utils import group
from pygrnwang.focal_mechanism import plane2nd, plane2mt
from pygrnwang.signal_process import resample
from coulomb_failure_stress_change.coulomb_stress_static import (
cal_coulomb_stress,
cal_coulomb_stress_poroelasticity,
)
d2m = 111194.92664455874
def find_nearest_dep(dep, dep_list):
dep_list = np.array(dep_list)
return dep_list[np.argmin(np.abs(dep - dep_list))]
def cal_stress_vector_ned(stress_enz, n):
# 重构3x3应力张量
sigma11, sigma12, sigma13, sigma22, sigma23, sigma33 = stress_enz.T
stress_tensor_ned = np.array(
[
[sigma22, sigma12, -sigma23],
[sigma12, sigma11, -sigma13],
[-sigma23, -sigma13, sigma33],
]
).T # Shape will be (n, 3, 3)
# Perform the dot product of each tensor with the vector n
sigma_vector = np.einsum("ijk,k->ij", stress_tensor_ned, n.flatten())
# sigmas = np.dot(sigma_vectors, np.array([n]).T)
# taus = np.dot(sigma_vectors, np.array([d]).T)
return sigma_vector
def cal_coulomb_stress_grn_point2point(
path_green,
fm_source,
source_point,
fm_field,
field_point,
points_green_geo_flatten,
event_dep_list,
receiver_dep_list,
srate_cfs,
time_reduction,
N_T,
max_slowness=0.4,
mu_f=0.4,
mu_f_pore=0.6,
B_pore=0.75,
interp=False,
):
N_T = int(N_T)
stress_enz = np.zeros((N_T, 6))
receiver_depth = find_nearest_dep(field_point[2], receiver_dep_list)
event_depth = find_nearest_dep(source_point[2], event_dep_list)
points_green_geo = points_green_geo_flatten.reshape(2, len(points_green_geo_flatten)//2).T
stress_enz_1source = read_stress_tensor(
path_green=path_green,
event_depth=event_depth,
receiver_depth=receiver_depth,
points_green_geo=points_green_geo,
source=source_point,
station=field_point,
mt=plane2mt(1, *fm_source),
interp=interp,
) # enz
for i_enz in range(6):
stress_enz[: -round(time_reduction * srate_cfs), i_enz] = stress_enz_1source[
round(time_reduction * srate_cfs):, i_enz
]
point_sta = np.array(field_point[:2]) - np.array(source_point[:2])
dist = np.sqrt(point_sta[0] ** 2 + point_sta[1] ** 2) * d2m / 1e3
t_cut_slowness = dist * max_slowness # max slowness
ind_const = round((t_cut_slowness + 1) * srate_cfs)
if ind_const < N_T:
stress_enz[ind_const:, i_enz] = stress_enz[ind_const, i_enz]
n_obs, d_obs = plane2nd(*fm_field)
n = np.array([n_obs.flatten()]).T
d = np.array([d_obs.flatten()]).T
sigma_vector = cal_stress_vector_ned(stress_enz, n) # ned
sigma = np.dot(sigma_vector, np.array([n]).T).flatten()
tau = np.dot(sigma_vector, np.array([d]).T).flatten()
mean_stress = (stress_enz[:, 0] + stress_enz[:, 3] + stress_enz[:, 5]) / 3
coulomb_stress = cal_coulomb_stress(
norm_stress_drop=sigma, shear_stress_drop=tau, mu_f=mu_f
)
coulomb_stress_pore = cal_coulomb_stress_poroelasticity(
norm_stress_drop=sigma,
shear_stress_drop=tau,
mean_stress_drop=mean_stress,
mu_f_pore=mu_f_pore,
B=B_pore,
)
return (
stress_enz,
sigma_vector,
sigma,
tau,
mean_stress,
coulomb_stress,
coulomb_stress_pore,
)
def cal_coulomb_stress_plane2single_point(
path_green,
path_faults,
source_inds,
field_point,
points_green_geo,
event_dep_list,
receiver_dep_list,
srate_stf,
srate_cfs,
N_T,
time_reduction,
n_obs,
d_obs,
mu_f=0.4,
mu_f_pore=0.6,
B_pore=0.75,
interp=False,
):
N_T = int(N_T)
stress_enz = np.zeros((N_T, 6))
receiver_depth = find_nearest_dep(field_point[2], receiver_dep_list)
for ind in source_inds:
# print(ind)
sub_faults_source = np.load(
os.path.join(path_faults, "sub_faults_plane%d.npy" % ind)
)
sub_fms = np.load(os.path.join(
path_faults, "sub_fms_plane%d.npy" % ind))
sub_stfs = np.load(os.path.join(
path_faults, "sub_stfs_plane%d.npy" % ind))
sub_m0s = np.load(os.path.join(
path_faults, "sub_m0s_plane%d.npy" % ind))
# sub_slips = np.load(os.path.join(path_faults, "sub_slips_plane%d.npy" % ind))
for i in range(sub_faults_source.shape[0]):
event_depth = find_nearest_dep(
sub_faults_source[i][2], event_dep_list)
stress_enz_1source = read_stress_tensor(
path_green=path_green,
event_depth=event_depth,
receiver_depth=receiver_depth,
points_green_geo=points_green_geo,
source=sub_faults_source[i],
station=field_point,
mt=plane2mt(1, *sub_fms[i]),
interp=interp,
) # enz
for i_enz in range(6):
sub_stf = resample(
sub_stfs[i],
srate_old=srate_stf,
srate_new=srate_cfs,
zero_phase=True,
)
sub_stf = sub_stf / (np.sum(sub_stf) / srate_cfs) * sub_m0s[i]
sigma_temp = stress_enz_1source[
round(time_reduction * srate_cfs):, i_enz
]
sigma_temp = sigma_temp - sigma_temp[0]
# sigma_temp[0] = 0
#
# len(sub_stf) must larger than time_reduction !!!
#
stress_enz_1source[:, i_enz] = (
np.convolve(sub_stf, sigma_temp)[:N_T] / srate_cfs
)
point_sta = np.array(field_point[:2]) - np.array(
sub_faults_source[i][:2]
)
dist = np.sqrt(point_sta[0] ** 2 +
point_sta[1] ** 2) * d2m / 1e3
t_cut_slowness = dist * 0.4 # max slowness
ind_const = round((t_cut_slowness + 1) *
srate_cfs + len(sub_stf))
if ind_const < N_T:
stress_enz_1source[ind_const:, i_enz] = stress_enz_1source[
ind_const, i_enz
]
stress_enz = stress_enz + stress_enz_1source
n = np.array([n_obs.flatten()]).T
d = np.array([d_obs.flatten()]).T
sigma_vector = cal_stress_vector_ned(stress_enz, n) # ned
sigma = np.dot(sigma_vector, np.array([n]).T).flatten()
tau = np.dot(sigma_vector, np.array([d]).T).flatten()
mean_stress = (stress_enz[:, 0] + stress_enz[:, 3] + stress_enz[:, 5]) / 3
coulomb_stress = cal_coulomb_stress(
norm_stress_drop=sigma, shear_stress_drop=tau, mu_f=mu_f
)
coulomb_stress_pore = cal_coulomb_stress_poroelasticity(
norm_stress_drop=sigma,
shear_stress_drop=tau,
mean_stress_drop=mean_stress,
mu_f_pore=mu_f_pore,
B=B_pore,
)
return (
stress_enz,
sigma_vector,
sigma,
tau,
mean_stress,
coulomb_stress,
coulomb_stress_pore,
)
def prepare_multi_points(
processes_num,
path_output,
path_green,
path_faults_source,
source_inds,
field_points,
field_fms,
points_green_geo,
event_dep_list,
receiver_dep_list,
srate_stf,
srate_cfs,
N_T,
time_reduction,
mu_f=0.4,
mu_f_pore=0.6,
B_pore=0.75,
interp=False,
):
N_points = len(field_points)
paras_list = []
for i in range(N_points):
n_obs, d_obs = plane2nd(*field_fms[i])
paras_list.append(
[
path_green,
path_faults_source,
source_inds,
field_points[i],
points_green_geo,
event_dep_list,
receiver_dep_list,
srate_stf,
srate_cfs,
N_T,
time_reduction,
n_obs,
d_obs,
mu_f,
mu_f_pore,
B_pore,
interp,
]
)
group_list = group(paras_list, processes_num)
with open(os.path.join(path_output, "group_list.pkl"), "wb") as fw:
pickle.dump(group_list, fw)
def cal_coulomb_stress_multi_points_mpi(
path_output,
):
with open(os.path.join(path_output, "group_list.pkl"), "rb") as fr:
group_list = pickle.load(fr)
N_all = 0
for ind_group in range(len(group_list)):
N_all = N_all + len(group_list[ind_group])
for ind_group in range(len(group_list)):
comm = MPI.COMM_WORLD
processes_num = comm.Get_size()
rank = comm.Get_rank()
if processes_num < len(group_list[0]):
raise ValueError(
"processes_num is %d, item num in group is %d. \n"
"Pleasse check the process num!" % (
processes_num, len(group_list[0]))
)
print("ind_group:%d rank:%d" % (ind_group, rank))
if ind_group * len(group_list[0]) + rank < N_all:
paras = group_list[ind_group][rank]
cfs_data = cal_coulomb_stress_plane2single_point(*paras)
with open(
os.path.join(
path_output,
"%d_%d_%f_%f_%f.pkl"
% (ind_group, rank, paras[3][0], paras[3][1], paras[3][2]),
),
"wb",
) as fw:
pickle.dump(cfs_data, fw)
if __name__ == "__main__":
pass