-
Notifications
You must be signed in to change notification settings - Fork 16
/
chapter1_Rayleigh.m
177 lines (156 loc) · 5.88 KB
/
chapter1_Rayleigh.m
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
clc; clear all
tic
%%% 参数设置 %%%
N = 400;
fm = 30;
space_x = 0.5; space_z = 0.5; % 网格步长
sample_t = 0.05/1000; % 时间步长0.05ms
T = 250/1000; % 总时间为250ms
K = T/sample_t; % 外层时间循环总次数:250/0.05 = 5000次
layer = 20*space_x; % 吸收层的厚度
coefficientR = 0.0001; % 理想的反射系数:基本不反射
C1 = 1.125;
C2 = -0.04166667;
%%% 均匀半空间模型的初始化 %%%
for i = 1:N
for j = 1:N
VP(i,j) = 1000;
VS(i,j) = 570;
Density(i,j) = 2*1000;
lame1(i,j) = Density(i,j) * (VP(i,j)^2 - 2*VS(i,j)^2);
lame2(i,j) = Density(i,j) * VS(i,j)^2;
end
end
%%% U、V、P、Q、R:速度、应力全空间初始化 %%%
for i = 1:N
for j = 1:N
% 全x向的参数:
U_x(i,j) = 0;
V_x(i,j) = 0;
P_x(i,j) = 0;
Q_x(i,j) = 0;
R_x(i,j) = 0;
% 全y向的参数:
U_y(i,j) = 0;
V_y(i,j) = 0;
P_y(i,j) = 0;
Q_y(i,j) = 0;
R_y(i,j) = 0;
% 时间:
U(i,j) = 0;
V(i,j) = 0;
P(i,j) = 0;
Q(i,j) = 0;
R(i,j) = 0;
%
dx(i) = 0;
dy(j) = 0;
end
end
%%% AEA 自由表面边界条件 %%%
% 其实就是把原始空间的前4行拿出来,用来做自由空间层!
% 所以差分计算时,i和j都是从4开始
for i = 1:4
for j = 1:N
Density(i,j) = 0.5*Density(i,j);
lame1(i,j) = 0;
lame2(i,j) = lame2(i,j);
end
end
%%% 开始有限差分的计算 %%%
for k = 1:K % 时间是最外层循环:相当于总的迭代次数/传播的时间
fprintf('迭代计算开始,当前是第%d次"时间"大循环!\n',k)
mibinbin = k;
% AEA 自由边界设置:
for i = 1:N
Q(i,4) = 0;
end
% 差分计算:各点的速度更新
for i = 4:(N-4)
for j = 4:(N-4)
% 区域边界的设置
if i <= 4 + layer/space_x
dx(i) = (2*VP(i,j)/layer)*log(1/coefficientR)*((4+layer/space_x-i)*space_x/layer)^4;
end
if i >= N-4-layer/space_x
dx(i) = (2*VP(i,j)/layer)*log(1/coefficientR)*((i-(N-4-layer/space_x))*space_x/layer)^4;
end
if j >= N-4-layer/space_x % 400 - 4 - 10/0.5 = 346 每一个i下,j要在346之后才会不等于0
%fprintf('第%d次"行循环"已进入j>=346阶段,当前:j=%d\n',i,j);
%pause(1);
dy(j) = (2*VP(i,j)/layer)*log(1/coefficientR)*((j-(N-4-layer/space_x))*space_x/layer)^4;
end
% 速度迭代计算
U_x(i,j) = ( (1-0.5*sample_t*dx(i))/(1+0.5*sample_t*dx(i)))*U_x(i,j) + ...
(1/(1+0.5*sample_t*dx(i)))*(1/Density(i,j))*(sample_t/space_x)*...
( C1*(P(i+1,j)-P((i),j))+C2*( P((i+2),j)-P((i-1),j))); % 已检查
U_y(i,j) = ((1-0.5*sample_t*dy(j))/(1+0.5*sample_t*dy(j)))*U_y(i,j) + ...
(1/(1+0.5*sample_t*dy(j)))*(1/Density(i,j))*(sample_t/space_z)* ...
( C1*(R(i,j)-R(i,j-1))+C2*(R(i,(j+1))-R(i,(j-2))));
U(i,j) = U_x(i,j) + U_y(i,j);
V_x(i,j) = ((1-0.5*sample_t*dx(i))/(1+0.5*sample_t*dx(i)))*V_x(i,j) + ...
(1/(1+0.5*sample_t*dx(i)))*(1/Density(i,j))*(sample_t/space_x)*...
( C1*(R(i,j)-R(i-1,j))+C2*(R((i+1),j)-R(i-2,j)));
V_y(i,j) = ((1-0.5*sample_t*dy(j))/(1+0.5*sample_t*dy(j)))*V_y(i,j) + ...
(1/(1+0.5*sample_t*dy(j)))*(1/Density(i,j))*(sample_t/space_z)* ...
( C1*(Q(i,(j+1))-Q(i,j))+C2*( Q(i,(j+2))-Q(i,(j-1))));
V(i,j) = V_x(i,j) + V_y(i,j);
end
end
% 差分计算:各点的应力更新
for i = 4:(N-4)
for j = 4:(N-4)
if i <= 4 + layer/space_x
dx(i) = (2*VP(i,j)/layer)*log(1/coefficientR)*((4+layer/space_x-i)*space_x/layer)^4;
end
if i >= N-4-layer/space_x
dx(i) = (2*VP(i,j)/layer)*log(1/coefficientR)*((i-(N-4-layer/space_x))*space_x/layer)^4;
end
if j >= N-4-layer/space_x
dy(j) = (2*VP(i,j)/layer)*log(1/coefficientR)*((j-(N-4-layer/space_x))*space_x/layer)^4;
end
% 中心震源的位置:
V(200,4) = 100*(1-2*(pi*fm*(k-1000)*sample_t)^2)*...
exp(-(pi*fm*(k-1000)*sample_t)^2);
% 震源的设置:
P_x(i,j) = ((1-0.5*sample_t*dx(i))/(1+0.5*sample_t*dx(i)))*P_x(i,j) + ...
(1/(1+0.5*sample_t*dx(i)))*(lame1(i,j)+2*lame2(i,j))*(sample_t/space_x)*...
(C1*(U((i),j)-U(i-1,j))+C2*(U((i+1),j)-U((i-2),j)));
P_y(i,j) = ((1-0.5*sample_t*dy(j))/(1+0.5*sample_t*dy(j)))*P_y(i,j) + ...
(1/(1+0.5*sample_t*dy(j)))*lame1(i,j)*(sample_t/space_z)*...
(C1*(V(i,j)-V(i,(j-1))) + C2*( V(i,(j+1))-V(i,(j-2))));
P(i,j) = P_x(i,j) + P_y(i,j);
Q_x(i,j) = ((1-0.5*sample_t*dx(i))/(1+0.5*sample_t*dx(i)))*Q_x(i,j) + ...
(1/(1+0.5*sample_t*dx(i)))*lame1(i,j)*(sample_t/space_x)*...
(C1*(U((i),j)-U(i-1,j))+C2*(U((i+1),j)-U((i-2),j)));
Q_y(i,j) = ((1-0.5*sample_t*dy(j))/(1+0.5*sample_t*dy(j)))*Q_y(i,j) + ...
(1/(1+0.5*sample_t*dy(j)))*(lame1(i,j)+2*lame2(i,j))*(sample_t/space_z)*...
(C1*(V(i,j)-V(i,(j-1)))+C2*(V(i,j+1)-V(i,(j-2))));
Q(i,j) = Q_x(i,j) + Q_y(i,j);
R_x(i,j) = ((1-0.5*sample_t*dx(i))/(1+0.5*sample_t*dx(i)))*R_x(i,j) + ...
(1/(1+0.5*sample_t*dx(j)))*lame2(i,j)*(sample_t/space_x)*...
(C1*(V(i+1,j)-V((i),j)) + C2*( V((i+2),j)-V((i-1),j)));
R_y(i,j) = ((1-0.5*sample_t*dy(j))/(1+0.5*sample_t*dy(j)))*R_y(i,j) + ...
(1/(1+0.5*sample_t*dy(j)))*lame2(i,j)*(sample_t/space_z)*...
(C1*(U(i,(j+1))-U(i,j)) + C2*(U(i,(j+2))-U(i,(j-1))));
R(i,j) = R_x(i,j) + R_y(i,j);
end
end
% 130ms时的波场快照:k = t*20
if k == 10
figure('name','总速度V的波场快照');
colormap(gray);
imagesc(V')
figure('name','速度分量V_x的波场快照');
colormap(gray);
imagesc(V_x');
figure('name','速度分量V_y的波场快照');
colormap(gray);
imagesc(V_y');
break;
end
end
toc
xlswrite('result_rayleigh.xls', V', 'sheet1')
xlswrite('result_rayleigh.xls', V_x', 'sheet2')
xlswrite('result_rayleigh.xls', V_y', 'sheet3')