-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmpl.py
256 lines (214 loc) · 7.73 KB
/
mpl.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
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
PI = np.pi
class LambWaveSymmetric:
d = 1 # half thickness of the plate
C = 1 # arbitrary constant
xi = 1 # wave number (changing)
omega = 1 # angular frequency (changing)
v = 0.33 # Poisson's ratio https://zh.wikipedia.org/zh-cn/%E6%B3%8A%E6%9D%BE%E6%AF%94
c_P = 1 # speed of P wave
k = (2*(1-v)/(1-2*v))**(1/2) # (eq.26, P. 312)
c_S = c_P/k # speed of SV wave (eq.26, P. 312)
@property
def eta_P(self):
"""(eq.83, P.325)"""
return np.sqrt(self.omega**2/self.c_P**2-self.xi**2+0j)
@property
def eta_S(self):
"""(eq.83, P.325)"""
return np.sqrt(self.omega**2/self.c_S**2-self.xi**2+0j)
@property
def f(self):
"""frequency (before eq.103, P.328)"""
return self.omega/(2*PI)
@property
def xi_(self):
"""(before eq.103, P.328)"""
return self.xi*self.d
@property
def D(self):
"""(eq.101, P.328)"""
return (self.xi**2-self.eta_S**2)**2*np.cos(self.eta_P*self.d)*np.sin(self.eta_S*self.d)+4*self.xi**2*self.eta_P*self.eta_S*np.sin(self.eta_P*self.d)*np.cos(self.eta_S*self.d)
@property
def Omega(self):
"""(before eq.103, P.328)"""
return self.omega*self.d/self.c_S
@property
def eta_P_(self):
"""(eq.105, P.328)"""
return np.sqrt(self.Omega**2/self.k**2-self.xi_**2+0j)
@property
def eta_S_(self):
"""(eq.105, P.328)"""
return np.sqrt(self.Omega**2-self.xi_**2+0j)
@property
def D_(self):
"""(eq.108, P.328)"""
return (self.xi_**2-self.eta_S_**2)**2*np.cos(self.eta_P_)*np.sin(self.eta_S_)+4*self.xi_**2*self.eta_P_*self.eta_S_*np.sin(self.eta_P_)*np.cos(self.eta_S_)
def get_scatter(self):
"""
perform non-linear root search to find a set of
(xi, omega) that satisfy D(xi, omega) = 0
"""
d_xi = .001
d_omega = .001
self.xi = np.arange(0, 5, d_xi)
self.omega = np.arange(0, 5, d_omega)
self.xi, self.omega = np.meshgrid(self.xi, self.omega)
indices = np.where(np.abs(self.D_ - 0) < 0.01)
# indices = (indices[1]*d_xi*self.d, indices[0]*d_omega*self.d/self.c_S)
xi = indices[1]
omega = indices[0]
xi_ = xi*d_xi*self.d
Omega = omega*d_omega*self.d/self.c_S
return xi_, Omega
def c_div_cS(self, Omega, xi_):
"""use the root (Omega, xi_) found to calculate c/c_S"""
# (eq.103, P.328)
xi = xi_/self.d
omega = Omega*self.c_S/self.d
# (before eq.112, P.330)
c = omega/xi
return c/self.c_S
def fd(self, Omega):
"""use the root (Omega) found to calculate fd"""
# (before eq.112, P.330)
omega = Omega*self.c_S/self.d
fd = omega/(2*PI)*self.d
return fd
def get_xi_and_omega_by_fd(self, fd):
"""use fd to calculate omega and xi
Args:
fd (float): frequency in Hz, get by dispersion curve
"""
xi_, Omega = self.get_scatter()
c_div_cS = self.c_div_cS(Omega, xi_)
_fd = self.fd(Omega)
# find the closest fd in the scatter set
index = np.argmin(np.abs(_fd-fd))
fd = _fd[index] # scalar
c_div_cS = c_div_cS[index] # scalar
omega = fd*2*PI/self.d
xi = omega/c_div_cS*self.c_S # (before eq.112, P.330)
return xi, omega
class LambWaveAntiSymmetric:
"""Different in equation D and D_"""
d = 1 # half thickness of the plate
C = 1 # arbitrary constant
xi = 1 # wave number (changing)
omega = 1 # angular frequency (changing)
v = 0.33 # Poisson's ratio https://zh.wikipedia.org/zh-cn/%E6%B3%8A%E6%9D%BE%E6%AF%94
c_P = 1 # speed of P wave
k = (2*(1-v)/(1-2*v))**(1/2) # (eq.26, P. 312)
c_S = c_P/k # speed of SV wave (eq.26, P. 312)
@property
def eta_P(self):
"""(eq.83, P.325)"""
return np.sqrt(self.omega**2/self.c_P**2-self.xi**2+0j)
@property
def eta_S(self):
"""(eq.83, P.325)"""
return np.sqrt(self.omega**2/self.c_S**2-self.xi**2+0j)
@property
def f(self):
"""frequency (before eq.103, P.328)"""
return self.omega/(2*PI)
@property
def xi_(self):
"""(before eq.103, P.328)"""
return self.xi*self.d
@property
def D(self):
"""(eq.115, P.331)"""
return (self.xi**2-self.eta_S**2)**2*np.sin(self.eta_P*self.d)*np.cos(self.eta_S*self.d)+4*self.xi**2*self.eta_P*self.eta_S*np.cos(self.eta_P*self.d)*np.sin(self.eta_S*self.d)
@property
def Omega(self):
"""(before eq.103, P.328)"""
return self.omega*self.d/self.c_S
@property
def eta_P_(self):
"""(eq.105, P.328)"""
return np.sqrt(self.Omega**2/self.k**2-self.xi_**2+0j)
@property
def eta_S_(self):
"""(eq.105, P.328)"""
return np.sqrt(self.Omega**2-self.xi_**2+0j)
@property
def D_(self):
"""(eq.117, P.331)"""
return (self.xi_**2-self.eta_S_**2)**2*np.sin(self.eta_P_)*np.cos(self.eta_S_)+4*self.xi_**2*self.eta_P_*self.eta_S_*np.cos(self.eta_P_)*np.sin(self.eta_S_)
def get_scatter(self):
"""
for loop xi_(xi) value and Omega(omega) value to find the combination that makes D_ = 0
"""
d_xi = .001
d_omega = .001
self.xi = np.arange(0, 5, d_xi)
self.omega = np.arange(0, 5, d_omega)
self.xi, self.omega = np.meshgrid(self.xi, self.omega)
indices = np.where(np.abs(self.D_ - 0) < 0.01)
xi = indices[1]
omega = indices[0]
xi_ = xi*d_xi*self.d
Omega = omega*d_omega*self.d/self.c_S
return xi_, Omega
def c_div_cS(self, Omega, xi_):
# (eq.103, P.328)
xi = xi_/self.d
omega = Omega*self.c_S/self.d
# (before eq.112, P.330)
c = omega/xi
return c/self.c_S
def fd(self, Omega):
# (before eq.112, P.330)
omega = Omega*self.c_S/self.d
fd = omega/(2*PI)*self.d
return fd
def get_xi_and_omega_by_fd(self, fd):
"""use fd to calculate omega and xi
Args:
fd (float): frequency in Hz, get by dispersion curve
"""
xi_, Omega = self.get_scatter()
c_div_cS = self.c_div_cS(Omega, xi_)
_fd = self.fd(Omega)
# find the closest fd in the scatter set
index = np.argmin(np.abs(_fd-fd))
fd = _fd[index] # scalar
c_div_cS = c_div_cS[index] # scalar
omega = fd*2*PI/self.d
xi = omega/c_div_cS*self.c_S # (before eq.112, P.330)
return xi, omega
def nonlinear_root_search():
lw = LambWaveSymmetric()
# lw = LambWaveAntiSymmetric()
xi_, Omega = lw.get_scatter()
fig, ax = plt.subplots()
ax.scatter(xi_, Omega, s=1)
# ax.invert_xaxis()
ax.set_xlabel(r'$\operatorname{Im}\bar{\xi}$')
ax.set_ylabel(r'$\Omega$')
plt.show()
def dispersion_curve():
# lw = LambWaveSymmetric()
lw = LambWaveAntiSymmetric()
xi_, Omega = lw.get_scatter()
c_cS = lw.c_div_cS(Omega, xi_)
fd = lw.fd(Omega)
fig, ax = plt.subplots()
ax.scatter(fd, c_cS, s=1)
ax.set_ylim(0, 3)
ax.set_xlabel(r'$fd$')
ax.set_ylabel(r'$c/c_S$')
plt.show()
def get_sample():
lw = LambWaveSymmetric()
# lw = LambWaveAntiSymmetric()
xi, omega = lw.get_xi_and_omega_by_fd(0.2)
print(f"xi={xi}",f"omega={omega}")
if __name__ == '__main__':
# nonlinear_root_search()
dispersion_curve()
# get_sample()