-
Notifications
You must be signed in to change notification settings - Fork 0
/
elliptical_bar_fraser.py
618 lines (523 loc) · 23.8 KB
/
elliptical_bar_fraser.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Compute the dispersion curves of elliptical bars using the collocation method
presented by Fraser in:
Fraser, W. B. (1969). Dispersion of elastic waves in elliptical bars.
*Journal of Sound and Vibration*, 10(2), 247‑260.
https://doi.org/10.1016/0022-460X(69)90199-0
Some details can also be found in:
Fraser, W. B. (1969). Stress wave propagation in rectangular bars.
*International Journal of Solids and Structures*, 5(4), 379‑397.
https://doi.org/10.1016/0020-7683(69)90020-1
Created on Fri Sep 2 13:03:37 2022
@author: dina.zyani
@author: denis.brizard
"""
import numpy as np
from scipy.special import jv #Bessel function (v,z) = (order,arg)
from scipy.optimize import root_scalar
from scipy.linalg import null_space
import matplotlib.pyplot as plt
import warnings
import time
import pickle
import round_bar_pochhammer_chree as round_bar
import ellipticReferenceSolutions as el
from fraser_elliptical import characteristic_matrix
import figutils as fu
def char_func_elliptic_fortran(k, w, R, theta, gamma, c_1, c_2, mode='L',
rEturn='det'):
"""Characteristic function for elliptical bar, with underlying Fortran code
:param float k: wavenumber
:param float w: circular frequency
:param array R: radius of collocation points
:param array theta: angle of collocation points
:param array gamma: angle of normal at collocation points
:param float c_1: velocity
:param float c_2: velocity
:param str mode: wave propagation mode ('L', 'T', 'Bx', 'By')
:param str rEturn: 'det' or 'matrix'
"""
N = len(theta)
A = characteristic_matrix(k, w, N, R, theta, gamma, c_1, c_2, mode)
if mode=='L':
B = A[1:, 1:]
detA = np.linalg.det(B)
elif mode=='T':
ind = list(range(3*N))
ind.remove(N) # XXX reason why indices N and 2*N ?
ind.remove(2*N) # ditto
B = A[np.ix_(ind,ind)]
detA = np.linalg.det(B)
elif mode in ('Bx', 'By'):
B = A
detA = np.linalg.det(A)
if rEturn=='det':
return detA
elif rEturn=='matrix':
return A, B
def char_func_elliptic(k, w, R, theta, gamma, c_1, c_2):
"""Characteristic function for elliptical bar
:param float k: wavenumber
:param float w: circular frequency
:param array R: radius of collocation points
:param array theta: angle of collocation points
:param array gamma: angle of normal at collocation points
:param float c_1: velocity
:param float c_2: velocity
"""
N = len(theta)
c = w/k
cc2 = (c/c_2)**2
cc1 = (c/c_1)**2 # XXX tester si plus rapide ou pas
alpha = k*np.lib.scimath.sqrt(cc1-1)
beta = k*np.lib.scimath.sqrt(cc2-1)
aR = alpha*R #Fraser eq(7)
bR = beta*R #Fraser eq(7)
b2 = beta**2
k2 = k**2
K_ = (1/2)*(b2-k2)/alpha**2
# =============================================================================
# Ces matrices sont issues de l'article de Fraser eq(2)
# =============================================================================
A11_ = np.zeros((N, N), dtype = np.complex128)
A12_ = np.zeros((N, N), dtype = np.complex128)
A13_ = np.zeros((N, N), dtype = np.complex128)
A21_ = np.zeros((N, N), dtype = np.complex128)
A22_ = np.zeros((N, N), dtype = np.complex128)
A23_ = np.zeros((N, N), dtype = np.complex128)
A31_ = np.zeros((N, N), dtype = np.complex128)
A32_ = np.zeros((N, N), dtype = np.complex128)
A33_ = np.zeros((N, N), dtype = np.complex128)
p = np.arange(0, 2*N, 2) # N premières valeurs paires
for ii, nn in enumerate(p):
#bessel
jb = jv(nn+2, bR)
ja = jv(nn+2, aR)
jb_ = jv(nn-2, bR)
ja_ = jv(nn-2, aR)
j1b = jv(nn+1, bR)
j1b_ = jv(nn-1, bR)
#cos et sin
cos1 = np.cos(nn*theta+2*gamma)
cos2 = np.cos(nn*theta-2*gamma)
sin1 = np.sin(nn*theta+2*gamma)
sin2 = np.sin(nn*theta-2*gamma)
cos_1 = np.cos(nn*theta+gamma)
cos_2 = np.cos(nn*theta-gamma)
cos = np.cos(nn*theta)
jc1 = jb*cos1
jc2 = jb_*cos2
js1 = jb*sin1
js2 = jb_*sin2
j1c1 = j1b*cos_1
j1c2 = j1b_*cos_2
A11_[:, ii] = -jc1 + jc2
A12_[:, ii] = jc1+jc2-2*jv(nn, bR)*cos
A13_[:, ii] = ja*cos1+ja_*cos2-2*(2*K_-1)*jv(nn,aR)*cos
A21_[:, ii] = -js1-js2
A22_[:, ii] = js1-js2
A23_[:, ii] = ja*sin1-ja_*sin2
A31_[:, ii] = np.array((j1c1+j1c2)*k/beta)*(1j)
A32_[:, ii] = np.array((j1c1-j1c2)*(b2-k2)/(beta*k))*(1j)
A33_[:, ii] = np.array((-jv(nn+1,aR)*cos_1+jv(nn-1,aR)*cos_2)*2*k/alpha)*(1j)
# A = np.block([[A21_, A22_, A23_], [A11_, A12_, A13_], [A31_, A32_, A33_]])
B = np.concatenate((A21_, A22_, A23_),axis=1)
C = np.concatenate((A11_, A12_, A13_),axis=1)
D = np.concatenate((A31_, A32_, A33_),axis=1)
A = np.concatenate((B, C, D))
detA = np.linalg.det(A[1:,1: ])
return detA
class DispElliptic(round_bar.DetDispEquation):
"""Classe pour la barre elliptique."""
def __init__(self, nu=0.3, E=210e9, rho=7800, a=0.05, e=0.4, N=4,
mode='L', fortran=True):
"""
Initialise variables.
:param float nu: Poisson's ratio [-]
:param float E: Young's modulus [Pa]
:param float rho: density [kg/m3]
:param float a: large radius of ellipse [m]
:param float e: excentricity of elliptical cross section [-]
:param int N: number of collocation points (on quarter cross-section)
:param str mode: type of mode ('L':longitudinal, 'T': torsional)
:param bool fortran: Fortran acceleration for characteristic matrix
"""
mu = E / (2 * (1 + nu)) # coef de Lamé
la = E * nu / ((1 + nu) * (1 - 2 * nu)) # coef de Lamé
c_2 = np.sqrt(mu/rho)
# c_1 = np.sqrt((la+2*mu)/rho)
c_1 = c_2*np.sqrt(2*(1-nu)/(1-2*nu)) # Fraser eq(7)
self.mat = {'E':E, 'rho':rho, 'nu':nu, 'mu':mu, 'la':la}
self.c = {'c_2':c_2, 'c_1':c_1, 'co': np.sqrt(E/rho)}
b = a*np.sqrt(1-e**2) # Fraser eq(4)
self.a = a #b
self.geo = {'e': e, 'b': b, 'N': N,'a':a}
# Collocation points coordinates and midway angles
m = np.arange(1, N+1)
if mode in ('L', 'T'):
theta = (m-1)*np.pi/2/N
theta_mid = (m-0.5)*np.pi/2/N
elif mode in ('Bx', 'By'):
theta = (m-0.5)*np.pi/2/N
theta_mid = m*np.pi/2/N
e2 = e**2
def compute_gamma_R(theta, b=b):
cos2 = np.cos(theta)**2
gamma = -np.arctan((e2*np.sin(2*theta))/(2*(1-e2*cos2))) # Fraser eq(6)
R = b*np.sqrt(1/(1 - e2*cos2)) # Frser eq(5)
return gamma, R
gamma, R = compute_gamma_R(theta)
self.ellipse = {'theta':theta, 'gamma':gamma, 'R':R}
gamid, Rmid = compute_gamma_R(theta_mid)
self.midpoints = {'theta':theta_mid, 'gamma':gamid, 'R':Rmid}
# Characteristic function
if mode in ('T', 'Bx', 'By') and fortran is False:
fortran = True
print('Forcing Fortran=True because equations for %s mode are not written in Python'%mode)
if fortran:
def detfun(k, w):
"""Characteristic determinant function."""
return char_func_elliptic_fortran(k, w, R, theta, gamma,
c_1, c_2, mode=mode, rEturn='det')
else:
def detfun(k, w):
"""Characteristic determinant function."""
return char_func_elliptic(k, w, R, theta, gamma, c_1, c_2)
self.detfun = detfun
self.vectorized = False # detfun is not vectorized
self.dim = {'c':c_2, 'l':b} # for dimensionless variables
self.dimlab = {'c':'c_2', 'l':'b'} # name of dimensionless variables for use un labels
self.mode = mode
self._nature = self._defineAutoReIm4map()
self.surfaceStress = []
# Also define some other useful functions
if fortran:
def matrix(k, w):
"""Characteristic matrix, on collocation points"""
return char_func_elliptic_fortran(k, w, R, theta, gamma,
c_1, c_2, mode=mode, rEturn='matrix')
def matrix2(k, w, theta, b):
"""Characteristic matrix, for other points"""
gamma, R = compute_gamma_R(theta, b)
return char_func_elliptic_fortran(k, w, R, theta, gamma,
c_1, c_2, mode=mode, rEturn='matrix')
self._matrix = matrix
self._matrix2 = matrix2
def _defineAutoReIm4map(self):
"""Define if Re or Im part of characteristic equation should used for
sign maps
"""
if self.mode in ('L', 'T'):
if self.geo['N']%2==1:
if self.mode in ('L'):
nat = 'imag'
elif self.mode in ('T'):
nat = 'real'
elif self.geo['N']%2==0:
if self.mode in ('L'):
nat = 'real'
elif self.mode in ('T'):
nat = 'imag'
elif self.mode in ('Bx', 'By'):
nat = 'real'
return nat
def plot_ellipse(self):
"""Plot elliptical cross section
"""
plt.figure('ellipse')
plt.polar(self.ellipse['theta'], self.ellipse['R'], '.-', label='ellipse')
x = self.ellipse['R']*np.cos(self.ellipse['theta'])
y = self.ellipse['R']*np.sin(self.ellipse['theta'])
# r = np.sqrt(x**2+y**2)
for ii in range(self.geo['N']):
plt.quiver(0, 0, x[ii], y[ii], scale=0.09, color='g')
x_g = self.ellipse['R']*np.cos(self.ellipse['theta']+self.ellipse['gamma'])
y_g = self.ellipse['R']*np.sin(self.ellipse['theta']+self.ellipse['gamma'])
for ii in range(self.geo['N']):
plt.quiver(0, 0, x_g[ii], y_g[ii], scale=0.09, color='r')
def computeSurfaceStress(self, ind, rcond=1e-9, plot=True):
"""Compute surface stresses at collocation points and midpoints
:param int ind: index of (k, w) point on first branch to consider
:param float rcond: relative condition umber (see :func:`scipy.linalg.null_space`)
:param bool plot:
"""
k, w = self.getBranch0(x='k', y='w')
Acp, Bcp = self._matrix(k[ind], w[ind]) # collocation points
Amp, Bmp = self._matrix2(k[ind], w[ind], self.midpoints['theta'], self.geo['b'])
Aro, Bro = self._matrix2(k[ind], w[ind], self.midpoints['theta'], 0) # center point
# Determine solution vector for coefficients An, Bn, Cn for given (k, w)
Z = null_space(Acp, rcond=rcond)
ABC = Z[:,-2] # vector of coefficients An, Bn, Cn (or Dn, En, Fn)
N = self.geo['N']
def computeStress(A, ABC):
"""Compute stresses from characteristic matrix and coefficients vector
:param array A: characteristic matrix, for N given values of (R, theta) and given (k, w)
:param array ABC: solution vector of coefficients An, Bn, Cn for given (k, w)
"""
temp = A*ABC # before last vector should be the right one
tau_t = temp[:N, :]
sig_n = temp[N:2*N, :]
tau_z = temp[2*N:, :]
return sig_n.sum(axis=1), tau_t.sum(axis=1), tau_z.sum(axis=1)
def interleave(aa, bb):
"""Interleave midpoints and collocation points to get a single vector
:param array aa: vector related to collocation points
:param array bb: vector related to midpoints
"""
cc = np.empty((len(aa)+len(bb),), dtype=aa.dtype)
cc[::2] = aa
cc[1::2] = bb
return cc
# Now compute stresses
st_cp = computeStress(Acp, ABC) # at collocation points
st_mp = computeStress(Amp, ABC) # at midpoints
# st_ro = computeStress(Aro, ABC) # at center point WRONG like this!
# Normalize each component wrt value at center point
# => requires equation 2 on Fraser's paper on rectangular bars
surfaceStress = {'sig_n':interleave(st_cp[0], st_mp[0]),
'tau_t':interleave(st_cp[1], st_mp[1]),
'tau_z':interleave(st_cp[2], st_mp[2]),
'theta':interleave(self.ellipse['theta'], self.midpoints['theta']),
'ind':ind}
self.surfaceStress.append(surfaceStress)
def plotSurfaceStress(self, normalize=True, figname=None, cmap='cool'):
"""Plot surface stresses at collocation points and midpoints, for various
values of the circular frequency w
:param bool normalize: normalize stress wrt to abs(max(stress))
:param str figname: prefix for the name of the figure
:param str cmap: colormap in which pick colors
"""
if figname is None:
figname = ''
stress = ('sig_n', 'tau_t', 'tau_z')
labels = ('\\sigma_n', '\\tau_t', '\\tau_z')
colors = {'sig_n':'C0', 'tau_t':'C1', 'tau_z':'C2'}
# Define colors
ncoul = len(self.surfaceStress)
cm = plt.get_cmap(cmap)
colors = [cm(1.*ii/ncoul) for ii in range(ncoul)]
# Plot data
for ii, SS in enumerate(self.surfaceStress):
for st in stress:
if normalize:
if st in ('sig_n', 'tau_t'):
scale = np.max(abs(SS[st]))*np.sign(np.real(SS[st][-1]))
ls = ['.-', '.:']
elif st in ('tau_z'):
scale = np.max(abs(SS[st]))*np.sign(np.imag(SS[st][-1]))
ls = ['.:', '.-']
else:
scale = 1
ls = ['.-', '.-']
plt.figure(figname+st)
plt.subplot(311)
plt.plot(SS['theta'], SS[st].real/scale, ls[0], color=colors[ii], label=SS['ind'])
plt.subplot(312)
plt.plot(SS['theta'], SS[st].imag/scale, ls[1], color=colors[ii], label=SS['ind'])
plt.subplot(313)
plt.plot(SS['theta'], abs(SS[st]/scale), '.--', color=colors[ii], label=SS['ind'])
# Finalize plots
ticks = np.arange(0, 5, 1)*np.pi/8
tickslabels = ['0', '$\\pi/8$', '$\\pi/4$', '$3\\pi/8$', '$\\pi/2$']
for st, llab in zip(stress, labels):
plt.figure(figname+st)
for ii, ylab in zip(range(3), ('Re', 'Im', 'abs')):
plt.subplot(3,1,ii+1)
if ii==0:
plt.title('N=%i'%self.geo['N'])
plt.xticks(ticks, tickslabels)
plt.axhline(y=0, zorder=0, color='0.8')
plt.ylabel('$%s(%s)$'%(ylab, llab))
plt.legend(title='index')
plt.xlabel('$\\theta$ [rad]')
if __name__ == "__main__":
plt.close("all")
# %% Numerical solving: FOLLOW FIRST BRANCH
if True:
e = 0.8
N = 4
modes = ('L', 'T', 'Bx', 'By')
# mode = 'By'
for mode in modes:
Det = DispElliptic(e=e, N=N, mode=mode)
omega = np.linspace(0, 8e5, 500) # Ok pour k<1.208
# omega = np.linspace(0, 1e6, 4000) # trying very small step. Ok pour k<1.2182
follow = False
FR = el.Fraser()
if follow:
Det.followBranch0(omega, itermax=20)
Det.plotFollow()
plt.figure('sign_imag')
plt.plot(Det.b0['k']*Det.geo['b'], Det.b0['c']/Det.c['c_2'], '+-', label='Regula Falsi algo')
# plt.ylim(ymax=1.7, ymin=0.7)
# plt.xlim(xmin=0., xmax=5)
FR.plot(e=[e], ls='+-', figname='sign_imag')
Det.computeKCmap(k=np.linspace(0, 5, 100), c=np.linspace(0.6, 2.2, 100), adim=True)
Det.plotDet('KC', typep='sign', nature='auto', figname=mode, title='%s mode, N=%i'%(mode, N))
FR.plot(e=[e], ls='k.-', figname=mode, branch=mode+'1', x='K', y='C')
FR.plot(e=[e], ls='k.-', figname=mode, branch=mode+'2', x='K', y='C')
#%% Comparaison Fortran/Python + validation Fraser
if False:
e = 0.7
N = 7
##### Calcul
Detpy = DispElliptic(e=e, N=N, fortran=False)
Detfo = DispElliptic(e=e, N=N, fortran=True)
# Calcul Python
k = np.linspace(0.0001, 5/Detpy.geo["b"], 150)
c = np.linspace(0.7*Detpy.c["c_2"], 1.7*Detpy.c["c_2"], 100)
Detpy.computeKCmap(k, c, adim = False)
# Calcul Fortran
k = np.linspace(0.0001, 5/Detfo.geo["b"], 150)
c = np.linspace(0.7*Detfo.c["c_2"], 1.7*Detfo.c["c_2"], 100)
Detfo.computeKCmap(k, c, adim = False)
### Affichage
## montrer que l'on obtient les mêmes courbes de dispersion
#Affichage Python
Detpy.plotDet_KC(figname='cont_imag', colors='tab:blue', lw=3)
Detpy.plotDet_KC(typep="contour", nature='real', figname="cont_real", colors='tab:blue', lw=1)
#Affichage Fortran
Detfo.plotDet_KC(figname='cont_imag', colors='tab:orange', lw=1)
Detfo.plotDet_KC(typep="contour", nature='real', figname="cont_real", colors='tab:orange')
FR = el.Fraser()
FR.plot(e=[e], figname='cont_imag')
FR.plot(e=[e], figname='cont_imag', branch=1)
FR.plot(e=[e], figname='cont_real')
FR.plot(e=[e], figname='cont_real', branch=1)
## montrer les différences (soit graphique, soit valeurs)
levels = np.logspace(-99, 99, 67)
Detpy.plotDet_KC('KC', 'contour', 'abs', level=levels)
Detpy.plotDet_KC('KC', 'contour', 'real', level=levels)
Detpy.plotDet_KC('KC', 'contour', 'imag', level=levels)
Detpy.plotDet_KC('KC', 'contour', 'quotient_abs', level=levels)
#%% Case e=0, comparison with round bar
if False:
e=0
#%% Compute maps for all 4 modes
if False:
modes = ['L']
modes = ['L', 'T', 'Bx', 'By']
N = [3, 4, 5]
N = [3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
e = 0.9
for mode in modes:
print('\n\n'+'*'*10+' mode=%s '%mode+'*'*10)
DET = []
# COMPUTE
for nn in N:
print('='*10+'N=%i'%nn+'='*10)
Det = DispElliptic(e=e, N=nn, fortran=True, mode=mode)
k = np.linspace(0.0001, 5/Det.geo["b"], 150)
c = np.linspace(0.7*Det.c["c_2"], 2.*Det.c["c_2"], 100)
Det.computeKCmap(k, c, adim=False, verbose=False)
DET.append(Det)
# PLOT
for ddet in DET:
title = '%s mode, e=%g, N=%i'%(mode, ddet.geo['e'], ddet.geo['N'])
fn = '%s-e%02gN%02i'%(ddet.mode, ddet.geo['e']*10, ddet.geo['N'])
ddet.plotDet(xy='KC', typep='sign', nature='real',
title=title+', real', figname=fn+'-r')
ddet.plotDet(xy='KC', typep='sign', nature='imag',
title=title+', imag', figname=fn+'-i')
fu.savefigs(path='maps/mode%s'%mode, prefix='map', close=True, overw=True)
# gather pdf figures with pdfjam:
# pdfjam modeT/*.pdf --nup 2x5 --outfile mapsT.pdf
#%% Domaine KW
if False:
e = 0.4
N = 7
Det = DispElliptic(e=0.7, N=7)
Det.plot_ellipse()
FR = el.Fraser()
k = np.linspace(0.0001, 5/Det.geo["b"], 150)
w = np.linspace(0.1, 5e5, 100)
Det.computeKWmap(k, w, adim=False)
Det.plotDet(xy="KW", typep="sign", nature="imag", figname="sign_imag")
FR.plot(x='K', y='W', figname='sign_imag', e=[e])
FR.plot(x='K', y='W', figname='sign_imag', branch='L2', e=[e])
# XXX curves do not overlay... !
# %% Convergence --Résolution numérique
if False:
omega = np.linspace(0, 8e5, 200) # ok pour e=0.5 (sauf N=7!)
omega = np.linspace(0, 8e5, 300) # ok pour e=0.2; 0.3 (sauf N=7!); 0.4 (sauf N=7!)
omega = np.linspace(0, 8e5, 500) # ok pour e=0.1 pour tous les N
omega = np.linspace(0, 1e6, 500)
#omega = np.delete(omega, np.array([68, 69])) # try to "jump" over difficulty!
# omega = np.linspace(0, 5e6, 500)
E = [0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
E = [0., 0.1, 0.2, 0.3]
Nmax = [7]*len(E)
# E = [0.9]
# Nmax = [6]
Nmin = 3
DE = []
njump = {}
# CALCUL
for ee, nmax in zip(E, Nmax):
print('='*10)
print('e=%g'%ee)
print('nmax=%i'%nmax)
# Calcul de toutes les solutions jusqu'à N=Nmax
DElist = []
for nn in range(Nmin, nmax+1):
print('N=%i'%nn)
DEtemp = DispElliptic(e=ee, N=nn)
# resolution numérique
DEtemp.followBranch0(omega, itermax=20, jumpC2=0.004, interp='cubic')
DElist.append(DEtemp)
DE.append(DElist)
njump[ee] = [de.b0['ignoredW'] for de in DElist]
# AFFICHAGE
error = True
plt.close('all')
for ee, nmax, DElist in zip(E, Nmax, DE):
print('='*10)
print('e=%g'%ee)
print('nmax=%i'%nmax)
# Plot dispersion curves
plt.figure('dispcurveE%g'%ee)
plt.title('$e=%g$'%ee)
# plt.figure('gather')
plt.axhline(y=1, color='0.8')
for DEE in DElist:
DEE.plotBranch0(x='W', y='C', figname='dispcurveE%g'%ee, label=DEE.geo['N'])
# DEE.plotBranch0(x='W', y='C', figname='gather', label=DEE.geo['N'])
plt.legend()
plt.ylim(ymin=0.9, ymax=1.7)
if error:
# Take last dispersion curve (Nmax) as reference
DEref = DElist[-1]
wref, cref = DEref.getBranch0(x='W', y='C')
# Plot relative error
plt.figure('erreurE%g'%ee)
plt.title('$e=%g$'%ee)
plt.axhline(y=1e-3, color='0.8')
plt.axhline(y=1e-6, color='0.8')
plt.axhline(y=1e-9, color='0.8')
for DEE in DElist[:-1]:
w, wlab, c, clab = DEE.getBranch0(x='W', y='C', label=True)
err = (c - cref)/cref
plt.semilogy(w, abs(err), '.', label=DEE.geo['N'])
plt.legend()
plt.ylabel('relative error on c/c2')
plt.xlabel(wlab)
# plt.xlim(xmax=4)
plt.figure('gatherDispNmax')
#fu.degrade(len(E))
for ee, nmax, DElist in zip(E, Nmax, DE):
DElist[-1].plotBranch0(x='W', y='C', ls='-', figname='gatherDispNmax', label=ee)
plt.legend()
plt.ylim(ymin=0.9, ymax=1.7)
fu.savefigs(path='convergence', overw=False)
#%% Compute residual stress between collocation points
# Only works for the first branch of longitudinal mode
# (requires followBranch0 method to run successfully)
if False:
Det = DispElliptic(e=0.5, N=6, mode='L')
omega = np.linspace(0, 8e5, 500)
Det.followBranch0(omega, itermax=20, jumpC2=0.004, interp='cubic')
Det.plotFollow()
for ind in range(10, 510, 25):
Det.computeSurfaceStress(ind)
Det.plotSurfaceStress(normalize=True) # normalized=False required for e=0