-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSegmentAnalysis.py
More file actions
1785 lines (1064 loc) · 90.1 KB
/
SegmentAnalysis.py
File metadata and controls
1785 lines (1064 loc) · 90.1 KB
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
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from numpy import *
from numpy.fft import *
# from matplotlib.pylab import *
from misc import *
from scipy.ndimage import *
# from skimage.filters import *
import os
from skimage.feature import register_translation
from scipy.ndimage import fourier_shift
import pickle
from Signal import *
StackingFunctions = {}
StackingFunctions['Sum'] = lambda x,y: x+y
StackingFunctions['MaxSum'] = lambda x,y: [x,y][argmax(array([sum(x.ravel()),sum(y.ravel())]))]
StackingFunctions['MaxValue'] = lambda x,y: [x,y][argmax(array([max(x.ravel()),max(y.ravel())]))]
# def ShiftSignal(x,T,fs):
#
# Npad = int(ceil(abs(T)*fs))
#
#
# X = rfft(x,Npad+len(x),axis=-1)
#
# f = linspace(0,fs/2,len(X))
#
# xs = irfft(exp(-1j*2*pi*f*T)*X,axis=-1)
#
# return xs[0:len(x)]
#
# def EstimateProbeDelays(Scans,fsamp,p,h,c=5.92):
#
# M = Scans.shape[0]
# N = Scans.shape[1]
#
# x = abs(hilbert(Scans,axis=2))
#
# W = int(round(fsamp*0.25*h/c))
#
#
# Delays = zeros((M,N))
#
# for m in range(M):
#
# for n in range(N):
#
# T = int(round(fsamp*(2*sqrt((0.5*(n-m)*p)**2 + h**2)/c)))
#
# Delays[m,n] = (argmax(x[m,n,T-W:T+W])+T-W - T)/fsamp
#
#
# return Delays
def CalibrateWedge(Scans,Delays,fsamp,p,c,angle,h):
from scipy.signal import hilbert
from numpy.linalg import lstsq
M,N,L = Scans.shape
sphi = sin(angle*pi/180.)
x = abs(hilbert(Scans,axis=2))
W = int(round(fsamp*0.25*h/c))
T = zeros((M,1))
for m in range(M):
TT = int(round(fsamp*(2*(m*p*sphi + h)/c)))
# print(TT)
T[m] = (argmax(x[m,m,TT-W:TT+W])+TT-W)/fsamp - Delays[m,m]
A = hstack((-2.*ones((M,1)),T))
b = 2*linspace(0,M-1,M).reshape(-1,1)*sphi*p
v = lstsq(A,b)[0]
return v[0],v[1]
def ToCentreAperatureDelay(T,x,th,cw,N,p):
return T + (2/cw)*(x[0]-N*p/2)*sin((pi/180.)*th[0]) + (2/cw)*(x[1]-N*p/2)*sin((pi/180.)*th[1])
def GetAngle(x,m,h,p,phi):
sphi = sin(phi)
cphi = cos(phi)
tphi = sphi/cphi
ntr = array([(h+m*p*sphi)*tphi,h+m*p*sphi])
vtr = array([x-m*p*cphi,h+m*p*sphi])
return (180/pi)*sign(vtr[0]-ntr[0])*arccos(vdot(vtr,ntr)/(norm(vtr)*norm(ntr)))
def CheckBounds(x,bndlist):
return all([(x[i]>=bndlist[i][0])&(x[i]<=bndlist[i][1]) for i in range(len(x))])
def Standardize(x,ax=-1):
return (x-mean(x,axis=ax))/std(x,ax)
def CapRayTrace(Modes,WeldParameters,ProbeParameters={'Pitch':0.6,'NumberOfElements':32},WedgeParameters={'Velocity':2.33,'Height':15.1,'Angle':10.0}):
cw = WedgeParameters['Velocity']
h = WedgeParameters['Height']
phi = WedgeParameters['Angle']*(pi/180)
p = ProbeParameters['Pitch']
N = ProbeParameters['NumberOfElements']
l0 = WeldParameters['Thickness']
l1 = WeldParameters['SideWallPosition']
l2 = WeldParameters['VerticalFL']
l3 = WeldParameters['HorizontalFL']
cs = {'L':5.9,'T':3.24}
c = [cs[m] for m in Modes]
phic = arctan2(l3,l2)
a2 = arcsin(cos(phic)*c[1]/c[2]) - phic
x3 = l1 - l2/2
y3 = -(l3/l2)*(x3 - l1 + l2)
x2 = x3 - (l0-y3)*tan(a2)
a1 = arcsin(c[0]*sin(a2)/c[1])
x1 = x2 - l0*tan(a1)
a0 = arcsin((cw/c[0])*sin(a1))
x0 = (x1-tan(a0)*h)/(cos(phi) + tan(a0)*sin(phi))
print(x3)
# print(x1)
# print(x2)
# print(x3)
if (x0>=-l3/2)&(x0<=N*p+l3/2):
T = 2*(sqrt((x0*cos(phi)-x1)**2 + (h+x0*sin(phi))**2)/cw + sqrt((x2-x1)**2 +l0**2)/c[0] + sqrt((x3-x2)**2 +(y3-l0)**2)/c[1] + (l1-x3)/c[2])
n = array([(h+x0*sin(phi))*tan(phi),h+x0*sin(phi)])
v = array([x1-x0*cos(phi),h+x0*sin(phi)])
th = (180/pi)*sign(v[0]-n[0])*arccos(vdot(v,n)/(norm(v)*norm(n)))
d = {'Delay': T, 'Angle': th, 'Intercept': x0}
else:
d = {}
return d
def PlaneWaveDelays(Path,WeldParameters,ProbeParameters={'Pitch':0.6,'NumberOfElements':32},WedgeParameters={'Velocity':2.33,'Height':15.1,'Angle':10.0}):
from scipy.optimize import minimize
from numpy.random import sample
cw = WedgeParameters['Velocity']
h = WedgeParameters['Height']
phi = WedgeParameters['Angle']*(pi/180)
p = ProbeParameters['Pitch']
N = ProbeParameters['NumberOfElements']
l0 = WeldParameters['Thickness']
l1 = WeldParameters['SideWallPosition']
l2 = WeldParameters['VerticalFL']
l3 = WeldParameters['HorizontalFL']
cs = {'L':5.9,'T':3.24}
cphi = cos(phi)
sphi = sin(phi)
tphi = sphi/cphi
def GetAngles(x,m):
ntr = array([(h+m*p*sphi)*tphi,h+m*p*sphi])
vtr = array([x[0]-m*p*cphi,h+m*p*sphi])
nrc = array([(h+x[-1]*sphi)*tphi,h+x[-1]*sphi])
vrc = array([x[-2]-x[-1]*cphi,h+x[-1]*sphi])
return (180/pi)*sign(vtr[0]-ntr[0])*arccos(vdot(vtr,ntr)/(norm(vtr)*norm(ntr))),(180/pi)*sign(vrc[0]-nrc[0])*arccos(vdot(vrc,nrc)/(norm(vrc)*norm(nrc)))
def ToCentreAperatureDelay(T,x,th):
return T + (2/cw)*(x[0]-N*p/2)*sin((pi/180.)*th[0]) + (2/cw)*(x[1]-N*p/2)*sin((pi/180.)*th[1])
def BCDCB(m,c):
f = lambda x: sqrt((h + sphi*x[7])**2 + (cphi*x[7] - x[6])**2)/cw + sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)/cw + sqrt(l0**2 + (x[5] - x[6])**2)/c[5] + sqrt((x[4] - x[5])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[4])**2/l2**2)/c[4] + sqrt((l1 - x[4])**2 + (-l1*l3 + l2*l3 + l2*x[3] + l3*x[4])**2/l2**2)/c[3] + sqrt((l1 - x[2])**2 + (-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])**2/l2**2)/c[2] + sqrt((x[1] - x[2])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[2])**2/l2**2)/c[1] + sqrt(l0**2 + (x[0] - x[1])**2)/c[0]
J = lambda x: array([-(cphi*m*p - x[0])/(cw*sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)) + (x[0] - x[1])/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)), (x[1] - x[2])/(c[1]*sqrt((x[1] - x[2])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[2])**2/l2**2)) - (x[0] - x[1])/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)), (-l1 + x[2] + l3*(-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])/l2**2)/(c[2]*sqrt((l1 - x[2])**2 + (-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])**2/l2**2)) + (-x[1] + x[2] + l3*(l0*l2 - l1*l3 + l2*l3 + l3*x[2])/l2**2)/(c[1]*sqrt((x[1] - x[2])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[2])**2/l2**2)), (-l1*l3 + l2*l3 + l2*x[3] + l3*x[4])/(c[3]*l2*sqrt((l1 - x[4])**2 + (-l1*l3 + l2*l3 + l2*x[3] + l3*x[4])**2/l2**2)) + (-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])/(c[2]*l2*sqrt((l1 - x[2])**2 + (-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])**2/l2**2)), (x[4] - x[5] + l3*(l0*l2 - l1*l3 + l2*l3 + l3*x[4])/l2**2)/(c[4]*sqrt((x[4] - x[5])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[4])**2/l2**2)) + (-l1 + x[4] + l3*(-l1*l3 + l2*l3 + l2*x[3] + l3*x[4])/l2**2)/(c[3]*sqrt((l1 - x[4])**2 + (-l1*l3 + l2*l3 + l2*x[3] + l3*x[4])**2/l2**2)), (x[5] - x[6])/(c[5]*sqrt(l0**2 + (x[5] - x[6])**2)) - (x[4] - x[5])/(c[4]*sqrt((x[4] - x[5])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[4])**2/l2**2)), -(cphi*x[7] - x[6])/(cw*sqrt((h + sphi*x[7])**2 + (cphi*x[7] - x[6])**2)) - (x[5] - x[6])/(c[5]*sqrt(l0**2 + (x[5] - x[6])**2)), (cphi*(cphi*x[7] - x[6]) + sphi*(h + sphi*x[7]))/(cw*sqrt((h + sphi*x[7])**2 + (cphi*x[7] - x[6])**2))])
bnds = ((m*p*cphi,l1),(m*p*cphi, l1),(l1-l2,l1),(-l3,0.),(l1-l2,l1),(0.,l1),(0., l1),(0.,N*p))
xi = [0.25*(bnds[0][1]-bnds[0][0]),0.5*(bnds[1][1]-bnds[1][0]), 0.5*(bnds[2][1]-bnds[2][0]), 0.5*(bnds[3][1]-bnds[3][0]), 0.75*(bnds[4][1]-bnds[4][0]), 0.75*(bnds[5][1]-bnds[5][0]), 0.35*(bnds[6][1]-bnds[6][0]), 0.5*(bnds[7][1]-bnds[7][0])]
# xi = [(b[0] + sample(1)*(b[1]-b[0]))[0] for b in bnds]
#
# print(bnds)
# print(xi)
res = minimize(f,xi,method='BFGS',jac=J)
# res = minimize(f,xi,method='Newton-CG',jac=J,options={'disp': False, 'xtol': 1e-05, 'eps': 1.4901161193847656e-08, 'return_all': False, 'maxiter': None})
# res = minimize(f,xi,method='BFGS')
print(res.x)
print(bnds)
print(res.success)
print(CheckBounds([res.x[2],res.x[3],res.x[4],res.x[-1]],[bnds[2],bnds[3],bnds[4],bnds[-1]]))
# if (res.success)&(CheckBounds([res.x[2],res.x[3],res.x[4],res.x[-1]],[bnds[2],bnds[3],bnds[4],bnds[-1]])):
if (res.success):
# T = sqrt(res.fun)
T = res.fun
th = GetAngles(res.x,m)
print(ToCentreAperatureDelay(T,res.x,th))
print(th)
d = [T,res.x[-1],th]
else:
d = []
return d
def BCDCBFB(m,c):
f = lambda x: sqrt((h + sphi*x[9])**2 + (cphi*x[9] - x[8])**2)/cw + sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)/cw + sqrt(l0**2 + (x[7] - x[8])**2)/c[7] + sqrt(l0**2 + (x[6] - x[7])**2)/c[6] + sqrt(l0**2 + (x[5] - x[6])**2)/c[5] + sqrt((x[4] - x[5])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[4])**2/l2**2)/c[4] + sqrt((l1 - x[4])**2 + (-l1*l3 + l2*l3 + l2*x[3] + l3*x[4])**2/l2**2)/c[3] + sqrt((l1 - x[2])**2 + (-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])**2/l2**2)/c[2] + sqrt((x[1] - x[2])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[2])**2/l2**2)/c[1] + sqrt(l0**2 + (x[0] - x[1])**2)/c[0]
J = lambda x: array([-(cphi*m*p - x[0])/(cw*sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)) + (x[0] - x[1])/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)), (x[1] - x[2])/(c[1]*sqrt((x[1] - x[2])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[2])**2/l2**2)) - (x[0] - x[1])/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)), (-l1 + x[2] + l3*(-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])/l2**2)/(c[2]*sqrt((l1 - x[2])**2 + (-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])**2/l2**2)) + (-x[1] + x[2] + l3*(l0*l2 - l1*l3 + l2*l3 + l3*x[2])/l2**2)/(c[1]*sqrt((x[1] - x[2])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[2])**2/l2**2)), (-l1*l3 + l2*l3 + l2*x[3] + l3*x[4])/(c[3]*l2*sqrt((l1 - x[4])**2 + (-l1*l3 + l2*l3 + l2*x[3] + l3*x[4])**2/l2**2)) + (-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])/(c[2]*l2*sqrt((l1 - x[2])**2 + (-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])**2/l2**2)), (x[4] - x[5] + l3*(l0*l2 - l1*l3 + l2*l3 + l3*x[4])/l2**2)/(c[4]*sqrt((x[4] - x[5])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[4])**2/l2**2)) + (-l1 + x[4] + l3*(-l1*l3 + l2*l3 + l2*x[3] + l3*x[4])/l2**2)/(c[3]*sqrt((l1 - x[4])**2 + (-l1*l3 + l2*l3 + l2*x[3] + l3*x[4])**2/l2**2)), (x[5] - x[6])/(c[5]*sqrt(l0**2 + (x[5] - x[6])**2)) - (x[4] - x[5])/(c[4]*sqrt((x[4] - x[5])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[4])**2/l2**2)), (x[6] - x[7])/(c[6]*sqrt(l0**2 + (x[6] - x[7])**2)) - (x[5] - x[6])/(c[5]*sqrt(l0**2 + (x[5] - x[6])**2)), (x[7] - x[8])/(c[7]*sqrt(l0**2 + (x[7] - x[8])**2)) - (x[6] - x[7])/(c[6]*sqrt(l0**2 + (x[6] - x[7])**2)), -(cphi*x[9] - x[8])/(cw*sqrt((h + sphi*x[9])**2 + (cphi*x[9] - x[8])**2)) - (x[7] - x[8])/(c[7]*sqrt(l0**2 + (x[7] - x[8])**2)), (cphi*(cphi*x[9] - x[8]) + sphi*(h + sphi*x[9]))/(cw*sqrt((h + sphi*x[9])**2 + (cphi*x[9] - x[8])**2))])
bnds = ((m*p*cphi,l1),(m*p*cphi, l1),(l1-l2,l1),(-l3,0.),(l1-l2,l1),(0,l1),(0., l1),(0., l1),(0., l1),(0.,N*p))
xi = [0.25*(bnds[0][1]-bnds[0][0]),0.5*(bnds[1][1]-bnds[1][0]), 0.5*(bnds[2][1]-bnds[2][0]), 0.5*(bnds[3][1]-bnds[3][0]), 0.75*(bnds[4][1]-bnds[4][0]), 0.75*(bnds[5][1]-bnds[5][0]), 0.5*(bnds[6][1]-bnds[6][0]), 0.25*(bnds[7][1]-bnds[7][0]), 0.1*(bnds[8][1]-bnds[8][0]), 0.5*(bnds[9][1]-bnds[9][0])]
# xi = [(b[0] + sample(1)*(b[1]-b[0]))[0] for b in bnds]
#
# print(bnds)
# print(xi)
res = minimize(f,xi,method='BFGS',jac=J)
# res = minimize(f,xi,method='Newton-CG',jac=J,options={'disp': False, 'xtol': 1e-05, 'eps': 1.4901161193847656e-08, 'return_all': False, 'maxiter': None})
# res = minimize(f,xi,method='BFGS')
print(res.x)
print(res.fun)
print(res.message)
print(res.success)
print(CheckBounds([res.x[2],res.x[3],res.x[4],res.x[-1]],[bnds[2],bnds[3],bnds[4],bnds[-1]]))
# if (res.success)&(CheckBounds([res.x[2],res.x[3],res.x[4],res.x[-1]],[bnds[2],bnds[3],bnds[4],bnds[-1]])):
if (res.success):
# T = sqrt(res.fun)
T = res.fun
th = GetAngles(res.x,m)
# print(th)
print(ToCentreAperatureDelay(T,res.x,th))
print(th)
d = [T,res.x[-1],th]
else:
d = []
return d
def BFBCDCBFB(m,c):
f = lambda x: sqrt((x[10] - x[11]*cphi)**2 + (x[11]*sphi + h)**2)/cw + sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)/cw + sqrt(l0**2 + (x[10] - x[9])**2)/c[9] + sqrt(l0**2 + (x[8] - x[9])**2)/c[8] + sqrt(l0**2 + (x[7] - x[8])**2)/c[7] + sqrt((x[6] - x[7])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[6])**2/l2**2)/c[6] + sqrt((l1 - x[6])**2 + (-l1*l3 + l2*l3 + l2*x[5] + l3*x[6])**2/l2**2)/c[5] + sqrt((l1 - x[4])**2 + (-l1*l3 + l2*l3 + l2*x[5] + l3*x[4])**2/l2**2)/c[4] + sqrt((x[3] - x[4])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[4])**2/l2**2)/c[3] + sqrt(l0**2 + (x[2] - x[3])**2)/c[2] + sqrt(l0**2 + (x[1] - x[2])**2)/c[1] + sqrt(l0**2 + (x[0] - x[1])**2)/c[0]
J = lambda x: array([-(cphi*m*p - x[0])/(cw*sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)) + (x[0] - x[1])/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)), (x[1] - x[2])/(c[1]*sqrt(l0**2 + (x[1] - x[2])**2)) - (x[0] - x[1])/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)), (x[2] - x[3])/(c[2]*sqrt(l0**2 + (x[2] - x[3])**2)) - (x[1] - x[2])/(c[1]*sqrt(l0**2 + (x[1] - x[2])**2)), (x[3] - x[4])/(c[3]*sqrt((x[3] - x[4])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[4])**2/l2**2)) - (x[2] - x[3])/(c[2]*sqrt(l0**2 + (x[2] - x[3])**2)), (-l1 + x[4] + l3*(-l1*l3 + l2*l3 + l2*x[5] + l3*x[4])/l2**2)/(c[4]*sqrt((l1 - x[4])**2 + (-l1*l3 + l2*l3 + l2*x[5] + l3*x[4])**2/l2**2)) + (-x[3] + x[4] + l3*(l0*l2 - l1*l3 + l2*l3 + l3*x[4])/l2**2)/(c[3]*sqrt((x[3] - x[4])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[4])**2/l2**2)), (-l1*l3 + l2*l3 + l2*x[5] + l3*x[6])/(c[5]*l2*sqrt((l1 - x[6])**2 + (-l1*l3 + l2*l3 + l2*x[5] + l3*x[6])**2/l2**2)) + (-l1*l3 + l2*l3 + l2*x[5] + l3*x[4])/(c[4]*l2*sqrt((l1 - x[4])**2 + (-l1*l3 + l2*l3 + l2*x[5] + l3*x[4])**2/l2**2)), (x[6] - x[7] + l3*(l0*l2 - l1*l3 + l2*l3 + l3*x[6])/l2**2)/(c[6]*sqrt((x[6] - x[7])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[6])**2/l2**2)) + (-l1 + x[6] + l3*(-l1*l3 + l2*l3 + l2*x[5] + l3*x[6])/l2**2)/(c[5]*sqrt((l1 - x[6])**2 + (-l1*l3 + l2*l3 + l2*x[5] + l3*x[6])**2/l2**2)), (x[7] - x[8])/(c[7]*sqrt(l0**2 + (x[7] - x[8])**2)) - (x[6] - x[7])/(c[6]*sqrt((x[6] - x[7])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[6])**2/l2**2)), (x[8] - x[9])/(c[8]*sqrt(l0**2 + (x[8] - x[9])**2)) - (x[7] - x[8])/(c[7]*sqrt(l0**2 + (x[7] - x[8])**2)), -(x[10] - x[9])/(c[9]*sqrt(l0**2 + (x[10] - x[9])**2)) - (x[8] - x[9])/(c[8]*sqrt(l0**2 + (x[8] - x[9])**2)), (x[10] - x[11]*cphi)/(cw*sqrt((x[10] - x[11]*cphi)**2 + (x[11]*sphi + h)**2)) + (x[10] - x[9])/(c[9]*sqrt(l0**2 + (x[10] - x[9])**2)), (-cphi*(x[10] - x[11]*cphi) + sphi*(x[11]*sphi + h))/(cw*sqrt((x[10] - x[11]*cphi)**2 + (x[11]*sphi + h)**2))])
bnds = ((m*p*cphi,l1),(m*p*cphi, l1),(m*p*cphi,l1),(m*p*cphi,l1),(l1-l2,l1),(-l3,0.),(l1-l2,l1),(0.,l1),(0., l1),(0., l1),(0., l1),(0.,N*p))
xi = [0.1*(bnds[0][1]-bnds[0][0]),0.2*(bnds[1][1]-bnds[1][0]), 0.3*(bnds[2][1]-bnds[2][0]), 0.4*(bnds[3][1]-bnds[3][0]),0.5*(bnds[4][1]-bnds[4][0]), 0.5*(bnds[5][1]-bnds[5][0]), 0.75*(bnds[6][1]-bnds[6][0]), 0.7*(bnds[7][1]-bnds[7][0]), 0.5*(bnds[8][1]-bnds[8][0]), 0.3*(bnds[9][1]-bnds[9][0]), 0.2*(bnds[10][1]-bnds[10][0]), 0.5*(bnds[11][1]-bnds[11][0])]
# xi = [(b[0] + sample(1)*(b[1]-b[0]))[0] for b in bnds]
#
# print(bnds)
# print(xi)
res = minimize(f,xi,method='BFGS',jac=J)
# res = minimize(f,xi,method='Newton-CG',jac=J,options={'disp': False, 'xtol': 1e-05, 'eps': 1.4901161193847656e-08, 'return_all': False, 'maxiter': None})
# res = minimize(f,xi,method='BFGS')
print(res.x)
print(res.fun)
print(res.message)
print(res.success)
# print(CheckBounds([res.x[2],res.x[3],res.x[4],res.x[-1]],[bnds[2],bnds[3],bnds[4],bnds[-1]]))
print(CheckBounds(res.x,bnds))
# if (res.success)&(CheckBounds([res.x[2],res.x[3],res.x[4],res.x[-1]],[bnds[2],bnds[3],bnds[4],bnds[-1]])):
if (res.success):
# T = sqrt(res.fun)
T = res.fun
th = GetAngles(res.x,m)
# print(th)
print(ToCentreAperatureDelay(T,res.x,th))
print(th)
d = [T,res.x[-1],th]
else:
d = []
return d
C = [cs[cc] for cc in Path[1]]
delayfncts = {}
delayfncts['BCDCB'] = lambda m: BCDCB(m,C)
delayfncts['BCDCBFB'] = lambda m: BCDCBFB(m,C)
delayfncts['BFBCDCBFB'] = lambda m: BFBCDCBFB(m,C)
m = 0
D = []
while (len(D)==0)&(m<=N):
D = delayfncts[Path[0]](m)
print(m)
m += 1
if len(D)>0:
return ToCentreAperatureDelay(D[0],(p*(m-1),D[1]),D[2])
else:
return []
def DirectDelays(Path,Elements,X,Y,WeldParameters,ProbeParameters={'Pitch':0.6,'NumberOfElements':32},WedgeParameters={'Velocity':2.33,'Height':15.1,'Angle':10.0}):
from scipy.optimize import minimize
cw = WedgeParameters['Velocity']
h = WedgeParameters['Height']
phi = WedgeParameters['Angle']*(pi/180)
p = ProbeParameters['Pitch']
N = ProbeParameters['NumberOfElements']
l0 = WeldParameters['Thickness']
l1 = WeldParameters['SideWallPosition']
l2 = WeldParameters['VerticalFL']
l3 = WeldParameters['HorizontalFL']
cs = {'L':5.9,'T':3.24}
cphi = cos(phi)
sphi = sin(phi)
tphi = sphi/cphi
def BackWall(m,c):
f = lambda x: sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)/cw + sqrt((X - x[1])**2 + (Y - l0)**2)/c[1] + sqrt(l0**2 + (x[0] - x[1])**2)/c[0]
J = lambda x: array([-(cphi*m*p - x[0])/(cw*sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)) + (x[0] - x[1])/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)), -(X - x[1])/(c[1]*sqrt((X - x[1])**2 + (Y - l0)**2)) - (x[0] - x[1])/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2))])
bnds = ((m*p*cphi,l1),(m*p*cphi, l1))
xi = (0.25*(bnds[0][1]-bnds[0][0]), 0.5*(bnds[1][1]-bnds[1][0]))
res = minimize(f,xi,method='BFGS',jac=J)
if (res.success)&(CheckBounds([res.x[0],res.x[1]],[bnds[0],bnds[1]])):
T = res.fun
# x = [res.x[0],res.x[1]]
d = T
else:
d = nan
return d
def FrontWall(m,c):
f = lambda x: sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)/cw + sqrt(Y**2 + (X - x[2])**2)/c[2] + sqrt(l0**2 + (x[1] - x[2])**2)/c[1] + sqrt(l0**2 + (x[0] - x[1])**2)/c[0]
J = lambda x: array([-(cphi*m*p - x[0])/(cw*sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)) + (x[0] - x[1])/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)), (x[1] - x[2])/(c[1]*sqrt(l0**2 + (x[1] - x[2])**2)) - (x[0] - x[1])/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)), -(X - x[2])/(c[2]*sqrt(Y**2 + (X - x[2])**2)) - (x[1] - x[2])/(c[1]*sqrt(l0**2 + (x[1] - x[2])**2))])
bnds = ((m*p*cphi,l1-l2),(m*p*cphi, l1-l2),(m*p*cphi,l1-l2))
xi = (0.25*(bnds[0][1]-bnds[0][0]), 0.5*(bnds[1][1]-bnds[1][0]),0.75*(bnds[2][1]-bnds[2][0]))
res = minimize(f,xi,method='BFGS',jac=J)
if (res.success)&(CheckBounds([res.x[0],res.x[1],res.x[2]],[bnds[0],bnds[1],bnds[2]])):
T = res.fun
# x = [res.x[0],res.x[1]]
d = {'Delay':T,'Angle':GetAngle(res.x[0],m,h,p,phi)}
else:
d = {'Delay':nan,'Angle':nan}
return d
def Cap(m,c):
f = lambda x: sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)/cw + sqrt((X - x[2])**2 + (Y*l2 - l1*l3 + l2*l3 + l3*x[2])**2/l2**2)/c[2] + sqrt((x[1] - x[2])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[2])**2/l2**2)/c[1] + sqrt(l0**2 + (x[0] - x[1])**2)/c[0]
J = lambda x: array([-(cphi*m*p - x[0])/(cw*sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)) + (x[0] - x[1])/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)), (x[1] - x[2])/(c[1]*sqrt((x[1] - x[2])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[2])**2/l2**2)) - (x[0] - x[1])/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)), (-X + x[2] + l3*(Y*l2 - l1*l3 + l2*l3 + l3*x[2])/l2**2)/(c[2]*sqrt((X - x[2])**2 + (Y*l2 - l1*l3 + l2*l3 + l3*x[2])**2/l2**2)) + (-x[1] + x[2] + l3*(l0*l2 - l1*l3 + l2*l3 + l3*x[2])/l2**2)/(c[1]*sqrt((x[1] - x[2])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[2])**2/l2**2))])
bnds = ((m*p*cphi,l1),(m*p*cphi, l1),(l1-l2,l1))
xi = (0.25*(bnds[0][1]-bnds[0][0]), 0.5*(bnds[1][1]-bnds[1][0]),0.5*(bnds[2][1]-bnds[2][0]))
res = minimize(f,xi,method='BFGS',jac=J)
if (res.success)&(CheckBounds([res.x[0],res.x[1],res.x[2]],[bnds[0],bnds[1],bnds[2]])):
# T = res.fun
# x = [res.x[0],res.x[1]]
# d = {'Delay':T,'Angle':GetAngle(res.x[0],m,h,p,phi)}
d = res.fun
else:
# d = {'Delay':T,'Angle':nan}
d = nan
return d
def Direct(m,c):
c = c[0]
f = lambda x: 2*sqrt((h + m*p*sphi)**2 + (cphi*m*p - x)**2)/cw + 2*sqrt(Y**2 + (X - x)**2)/c
J = lambda x: 2*(-cphi*m*p + x)/(cw*sqrt((h + m*p*sphi)**2 + (cphi*m*p - x)**2)) + 2*(-X + x)/(c*sqrt(Y**2 + (X - x)**2))
bnds = ((m*p*cphi,l1),(m*p*cphi, l1))
xi = (0.5*(bnds[0][1]-bnds[0][0]))
res = minimize(f,xi,method='BFGS',jac=J)
if (res.success)&(CheckBounds(res.x,bnds)):
T = res.fun
# x = [res.x[0],res.x[1]]
d = {'Delay':T,'Angle':GetAngle(res.x[0],m,h,p,phi)}
else:
d = {'Delay':nan, 'Angle':nan}
return d
DelayFunctions = {}
cf = [cs[cc] for cc in Path[0][1]]
cb = [cs[cc] for cc in Path[1][1]]
#
DelayFunctions['BackWall'] = lambda m,c: BackWall(m,c)
DelayFunctions['Cap'] = lambda m,c: Cap(m,c)
# DelayFunctions['FrontWall'] = lambda m,c: FrontWall(m,c)
# DelayFunctions['Direct'] = lambda m,c: Direct(m,c)
# if Path[0][0] is Path[1][0]:
#
# d = [2*DelayFunctions[Path[0][0]](m,cf) for m in Elements[0]]
#
# else:
df = [ DelayFunctions[Path[0][0]](m,cf) for m in Elements[0]]
db = [ DelayFunctions[Path[1][0]](m,cb) for m in Elements[1]]
# print(df[0])
# print(db[0])
# d = [[(ddf['Delay'] + ddb['Delay'],(ddf['Angle'],ddb['Angle'])) for ddb in db] for ddf in df]
# print(df[0])
d = [[ddf + ddb for ddb in db] for ddf in df]
return d
def SymmetricDelays(Path,Elements,WeldParameters,ProbeParameters={'Pitch':0.6,'NumberOfElements':32},WedgeParameters={'Velocity':2.33,'Height':15.1,'Angle':10.0}):
from scipy.optimize import minimize
cw = WedgeParameters['Velocity']
h = WedgeParameters['Height']
phi = WedgeParameters['Angle']*(pi/180)
p = ProbeParameters['Pitch']
N = ProbeParameters['NumberOfElements']
l0 = WeldParameters['Thickness']
l1 = WeldParameters['SideWallPosition']
l2 = WeldParameters['VerticalFL']
l3 = WeldParameters['HorizontalFL']
cs = {'L':5.9,'T':3.24}
cphi = cos(phi)
sphi = sin(phi)
tphi = sphi/cphi
def SideWallCap(m,c):
f = lambda x: 2*sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)/cw + 2*sqrt((l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2/l2**2)/c[2] + 2*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)/c[1] + 2*sqrt(l0**2 + (x[0] - x[1])**2)/c[0]
J = lambda x: array([2*(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)*(-cphi*m*p + x[0]) + cw*(x[0] - x[1])*sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2))/(c[0]*cw*sqrt(l0**2 + (x[0] - x[1])**2)*sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)), 2*(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)*(-l1 + x[1]) + c[1]*(-x[0] + x[1])*sqrt((l0 - x[2])**2 + (l1 - x[1])**2))/(c[0]*c[1]*sqrt(l0**2 + (x[0] - x[1])**2)*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)), 2*(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)*(-l1*l3 + l2*l3 + l2*x[2] + l3*x[3]) + c[2]*l2*sqrt((l2**2*(l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2)/l2**2)*(-l0 + x[2]))/(c[1]*c[2]*l2*sqrt((l2**2*(l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2)/l2**2)*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)), 2*(l2**2*(-l1 + x[3]) + l3*(-l1*l3 + l2*l3 + l2*x[2] + l3*x[3]))/(c[2]*l2**2*sqrt((l2**2*(l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2)/l2**2))])
# H = lambda x: array([[2*(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)*(-cphi*m*p + x[0]) + cw*(x[0] - x[1])*sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2))*(cphi*m*p - x[0])/(c[0]*cw*sqrt(l0**2 + (x[0] - x[1])**2)*((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)**(3/2)) + 2*(c[0]*sqrt(l0**2 + (x[0] - x[1])**2) + c[0]*(x[0] - x[1])*(-cphi*m*p + x[0])/sqrt(l0**2 + (x[0] - x[1])**2) + cw*(x[0] - x[1])*(-cphi*m*p + x[0])/sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2) + cw*sqrt((h + m*p*sphi)**2 +(cphi*m*p - x[0])**2))/(c[0]*cw*sqrt(l0**2 + (x[0] - x[1])**2)*sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)) + 2*(-x[0] + x[1])*(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)*(-cphi*m*p + x[0]) + cw*(x[0] - x[1])*sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2))/(c[0]*cw*(l0**2 + (x[0] - x[1])**2)**(3/2)*sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)), 2*(c[0]*(-x[0] + x[1])*(-cphi*m*p + x[0])/sqrt(l0**2 + (x[0] - x[1])**2) - cw*sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2))/(c[0]*cw*sqrt(l0**2 + (x[0] - x[1])**2)*sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)) + 2*(x[0] - x[1])*(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)*(-cphi*m*p + x[0]) + cw*(x[0] - x[1])*sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2))/(c[0]*cw*(l0**2 + (x[0] - x[1])**2)**(3/2)*sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)), 0, 0], [2*(c[0]*(-l1 + x[1])*(x[0] - x[1])/sqrt(l0**2 + (x[0] - x[1])**2) - c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2))/(c[0]*c[1]*sqrt(l0**2 + (x[0] - x[1])**2)*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)) + 2*(-x[0] + x[1])*(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)*(-l1 + x[1]) + c[1]*(-x[0] + x[1])*sqrt((l0 - x[2])**2 + (l1 - x[1])**2))/(c[0]*c[1]*(l0**2 + (x[0] - x[1])**2)**(3/2)*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)), 2*(l1 - x[1])*(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)*(-l1 + x[1]) + c[1]*(-x[0] + x[1])*sqrt((l0 - x[2])**2 + (l1 - x[1])**2))/(c[0]*c[1]*sqrt(l0**2 + (x[0] - x[1])**2)*((l0 - x[2])**2 + (l1 - x[1])**2)**(3/2)) + 2*(c[0]*sqrt(l0**2 + (x[0] - x[1])**2) + c[0]*(-l1 + x[1])*(-x[0] + x[1])/sqrt(l0**2 + (x[0] - x[1])**2) + c[1]*(-l1 + x[1])*(-x[0] + x[1])/sqrt((l0 - x[2])**2 + (l1 - x[1])**2) + c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2))/(c[0]*c[1]*sqrt(l0**2 + (x[0] - x[1])**2)*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)) + 2*(x[0] - x[1])*(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)*(-l1 + x[1]) + c[1]*(-x[0] + x[1])*sqrt((l0 - x[2])**2 + (l1 - x[1])**2))/(c[0]*c[1]*(l0**2 + (x[0] - x[1])**2)**(3/2)*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)), 2*(-l0 + x[2])*(-x[0] + x[1])/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)*((l0 - x[2])**2 + (l1 - x[1])**2)) + 2*(l0 - x[2])*(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)*(-l1 + x[1]) + c[1]*(-x[0] + x[1])*sqrt((l0 - x[2])**2 + (l1 - x[1])**2))/(c[0]*c[1]*sqrt(l0**2 + (x[0] - x[1])**2)*((l0 - x[2])**2 + (l1 - x[1])**2)**(3/2)), 0], [0, 2*(-l1 + x[1])*(-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])/(c[2]*l2*sqrt((l2**2*(l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2)/l2**2)*((l0 - x[2])**2 + (l1 - x[1])**2)) + 2*(l1 - x[1])*(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)*(-l1*l3 + l2*l3 + l2*x[2] + l3*x[3]) + c[2]*l2*sqrt((l2**2*(l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2)/l2**2)*(-l0 + x[2]))/(c[1]*c[2]*l2*sqrt((l2**2*(l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2)/l2**2)*((l0 - x[2])**2 + (l1 - x[1])**2)**(3/2)), -2*(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)*(-l1*l3 + l2*l3 + l2*x[2] + l3*x[3]) + c[2]*l2*sqrt((l2**2*(l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2)/l2**2)*(-l0 + x[2]))*(-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])/(c[1]*c[2]*sqrt((l2**2*(l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2)/l2**2)*(l2**2*(l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2)*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)) + 2*(l0 - x[2])*(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)*(-l1*l3 + l2*l3 + l2*x[2] + l3*x[3]) + c[2]*l2*sqrt((l2**2*(l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2)/l2**2)*(-l0 + x[2]))/(c[1]*c[2]*l2*sqrt((l2**2*(l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2)/l2**2)*((l0 - x[2])**2 + (l1 - x[1])**2)**(3/2)) + 2*(c[1]*l2*sqrt((l0 - x[2])**2 + (l1 - x[1])**2) + c[1]*(-l0 + x[2])*(-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])/sqrt((l0 - x[2])**2 + (l1 - x[1])**2) + c[2]*l2**2*sqrt((l2**2*(l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2)/l2**2)*(-l0 + x[2])*(-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])/(l2**2*(l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2) + c[2]*l2*sqrt((l2**2*(l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2)/l2**2))/(c[1]*c[2]*l2*sqrt((l2**2*(l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2)/l2**2)*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)), -(l2**2*(-2*l1 + 2*x[3]) + 2*l3*(-l1*l3 + l2*l3 + l2*x[2] + l3*x[3]))*(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)*(-l1*l3 + l2*l3 + l2*x[2] + l3*x[3]) + c[2]*l2*sqrt((l2**2*(l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2)/l2**2)*(-l0 + x[2]))/(c[1]*c[2]*l2*sqrt((l2**2*(l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2)/l2**2)*(l2**2*(l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2)*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)) + 2*(c[1]*l3*sqrt((l0 - x[2])**2 + (l1 - x[1])**2) + c[2]*l2*sqrt((l2**2*(l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2)/l2**2)*(-l0 + x[2])*(l2**2*(-2*l1 + 2*x[3]) + 2*l3*(-l1*l3 + l2*l3 + l2*x[2] + l3*x[3]))/(2*(l2**2*(l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2)))/(c[1]*c[2]*l2*sqrt((l2**2*(l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2)/l2**2)*sqrt((l0 - x[2])**2 + (l1 - x[1])**2))], [0, 0, 2*l3/(c[2]*l2*sqrt((l2**2*(l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2)/l2**2)) - 2*(l2**2*(-l1 + x[3]) + l3*(-l1*l3 + l2*l3 + l2*x[2] + l3*x[3]))*(-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])/(c[2]*l2*sqrt((l2**2*(l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2)/l2**2)*(l2**2*(l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2)), 2*(l2**2 + l3**2)/(c[2]*l2**2*sqrt((l2**2*(l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2)/l2**2)) - (l2**2*(-2*l1 + 2*x[3]) + 2*l3*(-l1*l3 + l2*l3 + l2*x[2] + l3*x[3]))*(l2**2*(-l1 + x[3]) + l3*(-l1*l3 + l2*l3 + l2*x[2] + l3*x[3]))/(c[2]*l2**2*sqrt((l2**2*(l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2)/l2**2)*(l2**2*(l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2))]])
bnds = ((m*p*cphi,l1-l2),(m*p*cphi, l1),(-l3,l0),(l1-l2,l1))
# xi = (0.5*(bnds[0][1]-bnds[0][0]), 0.5*(bnds[1][1]-bnds[1][0]), 0.5*(bnds[2][1]-bnds[2][0]), 0.5*(bnds[3][1]-bnds[3][0]),0.75*(bnds[4][1]-bnds[4][0]),0.5*(bnds[5][1]-bnds[5][0]),(0.5*(bnds[6][1]-bnds[6][0])))
xi = (0.25*(bnds[0][1]-bnds[0][0]), 0.5*(bnds[1][1]-bnds[1][0]), 0.5*(bnds[2][1]-bnds[2][0]),0.5*(bnds[3][1]-bnds[3][0]))
# res = minimize(f,xi,method='Newton-CG',jac=J,hess=H,options={'disp': False, 'xtol': 1e-03, 'eps': 1.4901161193847656e-08, 'return_all': False, 'maxiter': None})
res = minimize(f,xi,method='BFGS',jac=J)
if (res.success)&(CheckBounds([res.x[2],res.x[3]],[bnds[2],bnds[3]])):
# T = sqrt(res.fun)
T = res.fun
ntr = array([(h+m*p*sphi)*tphi,h+m*p*sphi])
vtr = array([res.x[0]-m*p*cphi,h+m*p*sphi])
# nrc = array([(h+n*p*sphi)*tphi,h+n*p*sphi])
# vrc = array([res.x[-1]-n*p*cphi,h+n*p*sphi])
th = (180/pi)*sign(vtr[0]-ntr[0])*arccos(vdot(vtr,ntr)/(norm(vtr)*norm(ntr)))
x = [res.x[0],res.x[1],res.x[3]]
d = {'Delay':T,'Angle':th,'x':[res.x[0],res.x[1],res.x[3]],'y':res.x[2]}
else:
d = {}
# T = nan
# th = nan
# x = nan
# y = nan
#
# d = {'Delay':T}
return d
def CapSideWall(m,c):
f = lambda x: 2*sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)/cw + 2*sqrt((l1 - x[2])**2 + (-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])**2/l2**2)/c[2] + 2*sqrt((x[1] - x[2])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[2])**2/l2**2)/c[1] + 2*sqrt(l0**2 + (x[0] - x[1])**2)/c[0]
J = lambda x: array([2*(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)*(-cphi*m*p + x[0]) + cw*(x[0] - x[1])*sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2))/(c[0]*cw*sqrt(l0**2 + (x[0] - x[1])**2)*sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)), 2*(x[1] - x[2])/(c[1]*sqrt((x[1] - x[2])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[2])**2/l2**2)) - 2*(x[0] - x[1])/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)), 2*(c[1]*sqrt((l2**2*(x[1] - x[2])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[2])**2)/l2**2)*(l2**2*(-l1 + x[2]) + l3*(-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])) + c[2]*sqrt((l2**2*(l1 - x[2])**2 + (-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])**2)/l2**2)*(l2**2*(-x[1] + x[2]) + l3*(l0*l2 - l1*l3 + l2*l3 + l3*x[2])))/(c[1]*c[2]*l2**2*sqrt((l2**2*(l1 - x[2])**2 + (-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])**2)/l2**2)*sqrt((l2**2*(x[1] - x[2])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[2])**2)/l2**2)), 2*(-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])/(c[2]*l2*sqrt((l2**2*(l1 - x[2])**2 + (-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])**2)/l2**2))])
bnds = ((m*p*cphi,l1-l2),(m*p*cphi, l1),(l1-l2,l1),(-l3,l0))
# xi = (0.5*(bnds[0][1]-bnds[0][0]), 0.5*(bnds[1][1]-bnds[1][0]), 0.5*(bnds[2][1]-bnds[2][0]), 0.5*(bnds[3][1]-bnds[3][0]),0.75*(bnds[4][1]-bnds[4][0]),0.5*(bnds[5][1]-bnds[5][0]),(0.5*(bnds[6][1]-bnds[6][0])))
xi = (0.25*(bnds[0][1]-bnds[0][0]), 0.5*(bnds[1][1]-bnds[1][0]), 0.5*(bnds[2][1]-bnds[2][0]),0.5*(bnds[3][1]-bnds[3][0]))
res = minimize(f,xi,method='BFGS',jac=J)
if (res.success)&(CheckBounds([res.x[2],res.x[3]],[bnds[2],bnds[3]])):
# T = sqrt(res.fun)
T = res.fun
ntr = array([(h+m*p*sphi)*tphi,h+m*p*sphi])
vtr = array([res.x[0]-m*p*cphi,h+m*p*sphi])
# nrc = array([(h+n*p*sphi)*tphi,h+n*p*sphi])
# vrc = array([res.x[-1]-n*p*cphi,h+n*p*sphi])
th = (180/pi)*sign(vtr[0]-ntr[0])*arccos(vdot(vtr,ntr)/(norm(vtr)*norm(ntr)))
x = [res.x[0],res.x[1],res.x[3]]
d = {'Delay':T,'Angle':th,'x':[res.x[0],res.x[1],res.x[2]],'y':res.x[3]}
else:
d = {}
# T = nan
# th = nan
# x = nan
# y = nan
#
# d = {'Delay':T}
return d
DelayFunctions = {}
c = [cs[cc] for cc in Path[1]]
DelayFunctions['SideWallCap'] = lambda m,c: SideWallCap(m,c)
DelayFunctions['CapSideWall'] = lambda m,c: CapSideWall(m,c)
d = [DelayFunctions[Path[0]](m,c) for m in Elements]
return d
def Delays(Path,Elements,WeldParameters,ProbeParameters={'Pitch':0.6,'NumberOfElements':32},WedgeParameters={'Velocity':2.33,'Height':15.1,'Angle':10.0}):
from scipy.optimize import minimize
cw = WedgeParameters['Velocity']
h = WedgeParameters['Height']
phi = WedgeParameters['Angle']*(pi/180)
p = ProbeParameters['Pitch']
N = ProbeParameters['NumberOfElements']
l0 = WeldParameters['Thickness']
l1 = WeldParameters['SideWallPosition']
l2 = WeldParameters['VerticalFL']
l3 = WeldParameters['HorizontalFL']
cs = {'L':5.9,'T':3.24}
cphi = cos(phi)
sphi = sin(phi)
tphi = sphi/cphi
def Corner(m,n,c):
# T Minimization
f = lambda x: sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)/cw + sqrt((h + n*p*sphi)**2 + (cphi*n*p - x[3])**2)/cw + sqrt(x[2]**2 + (l1 - x[3])**2)/c[2] + sqrt((l0 - x[2])**2 + (l1 - x[1])**2)/c[1] + sqrt(l0**2 + (x[0] - x[1])**2)/c[0]
J = lambda x: array([-(cphi*m*p - x[0])/(cw*sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)) + (x[0] - x[1])/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)), -(l1 - x[1])/(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)) - (x[0] - x[1])/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)), x[2]/(c[2]*sqrt(x[2]**2 + (l1 - x[3])**2)) - l0/(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)) + x[2]/(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)), -(cphi*n*p - x[3])/(cw*sqrt((h + n*p*sphi)**2 + (cphi*n*p - x[3])**2)) - (l1 - x[3])/(c[2]*sqrt(x[2]**2 + (l1 - x[3])**2))])
H = lambda x: array([[-(cphi*m*p - x[0])**2/(cw*((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)**(3/2)) + 1/(cw*sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)) + 1/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)) + (-x[0] + x[1])*(x[0] - x[1])/(c[0]*(l0**2 + (x[0] - x[1])**2)**(3/2)), -1/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)) + (x[0] - x[1])**2/(c[0]*(l0**2 + (x[0] - x[1])**2)**(3/2)), 0, 0], [-1/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)) - (-x[0] + x[1])*(x[0] - x[1])/(c[0]*(l0**2 + (x[0] - x[1])**2)**(3/2)), -(l1 - x[1])**2/(c[1]*((l0 - x[2])**2 + (l1 - x[1])**2)**(3/2)) + 1/(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)) + 1/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)) - (x[0] - x[1])**2/(c[0]*(l0**2 + (x[0] - x[1])**2)**(3/2)), -(l0 - x[2])*(l1 - x[1])/(c[1]*((l0 - x[2])**2 + (l1 - x[1])**2)**(3/2)), 0], [0, -l0*(l1 - x[1])/(c[1]*((l0 - x[2])**2 + (l1 - x[1])**2)**(3/2)) + x[2]*(l1 - x[1])/(c[1]*((l0 - x[2])**2 + (l1 - x[1])**2)**(3/2)), -x[2]**2/(c[2]*(x[2]**2 + (l1 - x[3])**2)**(3/2)) + 1/(c[2]*sqrt(x[2]**2 + (l1 - x[3])**2)) - l0*(l0 - x[2])/(c[1]*((l0 - x[2])**2 + (l1 - x[1])**2)**(3/2)) + x[2]*(l0 - x[2])/(c[1]*((l0 - x[2])**2 + (l1 - x[1])**2)**(3/2)) + 1/(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)), x[2]*(l1 - x[3])/(c[2]*(x[2]**2 + (l1 - x[3])**2)**(3/2))], [0, 0, x[2]*(l1 - x[3])/(c[2]*(x[2]**2 + (l1 - x[3])**2)**(3/2)), -(cphi*n*p - x[3])**2/(cw*((h + n*p*sphi)**2 + (cphi*n*p - x[3])**2)**(3/2)) + 1/(cw*sqrt((h + n*p*sphi)**2 + (cphi*n*p - x[3])**2)) - (l1 - x[3])**2/(c[2]*(x[2]**2 + (l1 - x[3])**2)**(3/2)) + 1/(c[2]*sqrt(x[2]**2 + (l1 - x[3])**2))]])
# T**2 Minization
# f = lambda x: (c[0]*c[1]*c[2]*(sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2) + sqrt((h + n*p*sphi)**2 + (cphi*n*p - x[3])**2)) + c[0]*c[1]*cw*sqrt(x[2]**2 + (l1 - x[3])**2) + c[0]*c[2]*cw*sqrt((l0 - x[2])**2 + (l1 - x[1])**2) + c[1]*c[2]*cw*sqrt(l0**2 + (x[0] - x[1])**2))**2/(c[0]**2*c[1]**2*c[2]**2*cw**2)
#
# J = lambda x: array([(2*(-cphi*m*p + x[0])/(cw*sqrt((h + m*p*sphi)**2 + (-cphi*m*p + x[0])**2)) + 2*(x[0] - x[1])/(c[0]*sqrt(l0**2 + (-x[0] + x[1])**2)))*(sqrt((h + m*p*sphi)**2 + (-cphi*m*p + x[0])**2)/cw + sqrt((h + n*p*sphi)**2 + (-cphi*n*p + x[3])**2)/cw + sqrt(x[2]**2 + (l1 - x[3])**2)/c[2] + sqrt((l0 - x[2])**2 + (l1 - x[1])**2)/c[1] + sqrt(l0**2 + (-x[0] + x[1])**2)/c[0]), (2*(-l1 + x[1])/(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)) + 2*(-x[0] + x[1])/(c[0]*sqrt(l0**2 + (-x[0] + x[1])**2)))*(sqrt((h + m*p*sphi)**2 + (-cphi*m*p + x[0])**2)/cw + sqrt((h + n*p*sphi)**2 + (-cphi*n*p + x[3])**2)/cw + sqrt(x[2]**2 + (l1 - x[3])**2)/c[2] + sqrt((l0 - x[2])**2 + (l1 - x[1])**2)/c[1] + sqrt(l0**2 + (-x[0] + x[1])**2)/c[0]), (2*x[2]/(c[2]*sqrt(x[2]**2 + (l1 - x[3])**2)) + 2*(-l0 + x[2])/(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)))*(sqrt((h + m*p*sphi)**2 + (-cphi*m*p + x[0])**2)/cw + sqrt((h + n*p*sphi)**2 + (-cphi*n*p + x[3])**2)/cw + sqrt(x[2]**2 + (l1 - x[3])**2)/c[2] + sqrt((l0 - x[2])**2 + (l1 - x[1])**2)/c[1] + sqrt(l0**2 + (-x[0] + x[1])**2)/c[0]), (2*(-cphi*n*p + x[3])/(cw*sqrt((h + n*p*sphi)**2 + (-cphi*n*p + x[3])**2)) + 2*(-l1 + x[3])/(c[2]*sqrt(x[2]**2 + (l1 - x[3])**2)))*(sqrt((h + m*p*sphi)**2 + (-cphi*m*p + x[0])**2)/cw + sqrt((h + n*p*sphi)**2 + (-cphi*n*p + x[3])**2)/cw + sqrt(x[2]**2 + (l1 - x[3])**2)/c[2] + sqrt((l0 - x[2])**2 + (l1 - x[1])**2)/c[1] + sqrt(l0**2 + (-x[0] + x[1])**2)/c[0])])
#
# H = lambda x: array([[((-cphi*m*p + x[0])/(cw*sqrt((h + m*p*sphi)**2 + (-cphi*m*p + x[0])**2)) + (x[0] - x[1])/(c[0]*sqrt(l0**2 + (-x[0] + x[1])**2)))*(2*(-cphi*m*p + x[0])/(cw*sqrt((h + m*p*sphi)**2 + (-cphi*m*p + x[0])**2)) + 2*(x[0] - x[1])/(c[0]*sqrt(l0**2 + (-x[0] + x[1])**2))) + (2*(-cphi*m*p + x[0])*(cphi*m*p - x[0])/(cw*((h + m*p*sphi)**2 + (-cphi*m*p + x[0])**2)**(3/2)) + 2/(cw*sqrt((h + m*p*sphi)**2 + (-cphi*m*p + x[0])**2)) + 2/(c[0]*sqrt(l0**2 + (-x[0] + x[1])**2)) + 2*(-x[0] + x[1])*(x[0] - x[1])/(c[0]*(l0**2 + (-x[0] + x[1])**2)**(3/2)))*(sqrt((h + m*p*sphi)**2 + (-cphi*m*p + x[0])**2)/cw + sqrt((h + n*p*sphi)**2 + (-cphi*n*p + x[3])**2)/cw + sqrt(x[2]**2 + (l1 - x[3])**2)/c[2] + sqrt((l0 - x[2])**2 + (l1 - x[1])**2)/c[1] + sqrt(l0**2 + (-x[0] + x[1])**2)/c[0]), (-2/(c[0]*sqrt(l0**2 + (-x[0] + x[1])**2)) + 2*(x[0] - x[1])**2/(c[0]*(l0**2 + (-x[0] + x[1])**2)**(3/2)))*(sqrt((h + m*p*sphi)**2 + (-cphi*m*p + x[0])**2)/cw + sqrt((h + n*p*sphi)**2 + (-cphi*n*p + x[3])**2)/cw + sqrt(x[2]**2 + (l1 - x[3])**2)/c[2] + sqrt((l0 - x[2])**2 + (l1 - x[1])**2)/c[1] + sqrt(l0**2 + (-x[0] + x[1])**2)/c[0]) + ((-l1 + x[1])/(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)) + (-x[0] + x[1])/(c[0]*sqrt(l0**2 + (-x[0] + x[1])**2)))*(2*(-cphi*m*p + x[0])/(cw*sqrt((h + m*p*sphi)**2 + (-cphi*m*p + x[0])**2)) + 2*(x[0] - x[1])/(c[0]*sqrt(l0**2 + (-x[0] + x[1])**2))), (x[2]/(c[2]*sqrt(x[2]**2 + (l1 - x[3])**2)) + (-l0 + x[2])/(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)))*(2*(-cphi*m*p + x[0])/(cw*sqrt((h + m*p*sphi)**2 + (-cphi*m*p + x[0])**2)) + 2*(x[0] - x[1])/(c[0]*sqrt(l0**2 + (-x[0] + x[1])**2))), (2*(-cphi*m*p + x[0])/(cw*sqrt((h + m*p*sphi)**2 + (-cphi*m*p + x[0])**2)) + 2*(x[0] - x[1])/(c[0]*sqrt(l0**2 + (-x[0] + x[1])**2)))*((-cphi*n*p + x[3])/(cw*sqrt((h + n*p*sphi)**2 + (-cphi*n*p + x[3])**2)) + (-l1 + x[3])/(c[2]*sqrt(x[2]**2 + (l1 - x[3])**2)))], [(-2/(c[0]*sqrt(l0**2 + (-x[0] + x[1])**2)) + 2*(-x[0] + x[1])**2/(c[0]*(l0**2 + (-x[0] + x[1])**2)**(3/2)))*(sqrt((h + m*p*sphi)**2 + (-cphi*m*p + x[0])**2)/cw + sqrt((h + n*p*sphi)**2 + (-cphi*n*p + x[3])**2)/cw + sqrt(x[2]**2 + (l1 - x[3])**2)/c[2] + sqrt((l0 - x[2])**2 + (l1 - x[1])**2)/c[1] + sqrt(l0**2 + (-x[0] + x[1])**2)/c[0]) + (2*(-l1 + x[1])/(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)) + 2*(-x[0] + x[1])/(c[0]*sqrt(l0**2 + (-x[0] + x[1])**2)))*((-cphi*m*p + x[0])/(cw*sqrt((h + m*p*sphi)**2 + (-cphi*m*p + x[0])**2)) + (x[0] - x[1])/(c[0]*sqrt(l0**2 + (-x[0] + x[1])**2))), ((-l1 + x[1])/(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)) + (-x[0] + x[1])/(c[0]*sqrt(l0**2 + (-x[0] + x[1])**2)))*(2*(-l1 + x[1])/(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)) + 2*(-x[0] + x[1])/(c[0]*sqrt(l0**2 + (-x[0] + x[1])**2))) + (2*(-l1 + x[1])*(l1 - x[1])/(c[1]*((l0 - x[2])**2 + (l1 - x[1])**2)**(3/2)) + 2/(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)) + 2/(c[0]*sqrt(l0**2 + (-x[0] + x[1])**2)) + 2*(-x[0] + x[1])*(x[0] - x[1])/(c[0]*(l0**2 + (-x[0] + x[1])**2)**(3/2)))*(sqrt((h + m*p*sphi)**2 + (-cphi*m*p + x[0])**2)/cw + sqrt((h + n*p*sphi)**2 + (-cphi*n*p + x[3])**2)/cw + sqrt(x[2]**2 + (l1 - x[3])**2)/c[2] + sqrt((l0 - x[2])**2 + (l1 - x[1])**2)/c[1] + sqrt(l0**2 + (-x[0] + x[1])**2)/c[0]), (2*(-l1 + x[1])/(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)) + 2*(-x[0] + x[1])/(c[0]*sqrt(l0**2 + (-x[0] + x[1])**2)))*(x[2]/(c[2]*sqrt(x[2]**2 + (l1 - x[3])**2)) + (-l0 + x[2])/(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2))) + 2*(l0 - x[2])*(-l1 + x[1])*(sqrt((h + m*p*sphi)**2 + (-cphi*m*p + x[0])**2)/cw + sqrt((h + n*p*sphi)**2 + (-cphi*n*p + x[3])**2)/cw + sqrt(x[2]**2 + (l1 - x[3])**2)/c[2] + sqrt((l0 - x[2])**2 + (l1 - x[1])**2)/c[1] + sqrt(l0**2 + (-x[0] + x[1])**2)/c[0])/(c[1]*((l0 - x[2])**2 + (l1 - x[1])**2)**(3/2)), (2*(-l1 + x[1])/(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)) + 2*(-x[0] + x[1])/(c[0]*sqrt(l0**2 + (-x[0] + x[1])**2)))*((-cphi*n*p + x[3])/(cw*sqrt((h + n*p*sphi)**2 + (-cphi*n*p + x[3])**2)) + (-l1 + x[3])/(c[2]*sqrt(x[2]**2 + (l1 - x[3])**2)))], [(2*x[2]/(c[2]*sqrt(x[2]**2 + (l1 - x[3])**2)) + 2*(-l0 + x[2])/(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)))*((-cphi*m*p + x[0])/(cw*sqrt((h + m*p*sphi)**2 + (-cphi*m*p + x[0])**2)) + (x[0] - x[1])/(c[0]*sqrt(l0**2 + (-x[0] + x[1])**2))), ((-l1 + x[1])/(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)) + (-x[0] + x[1])/(c[0]*sqrt(l0**2 + (-x[0] + x[1])**2)))*(2*x[2]/(c[2]*sqrt(x[2]**2 + (l1 - x[3])**2)) + 2*(-l0 + x[2])/(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2))) + 2*(-l0 + x[2])*(l1 - x[1])*(sqrt((h + m*p*sphi)**2 + (-cphi*m*p + x[0])**2)/cw + sqrt((h + n*p*sphi)**2 + (-cphi*n*p + x[3])**2)/cw + sqrt(x[2]**2 + (l1 - x[3])**2)/c[2] + sqrt((l0 - x[2])**2 + (l1 - x[1])**2)/c[1] + sqrt(l0**2 + (-x[0] + x[1])**2)/c[0])/(c[1]*((l0 - x[2])**2 + (l1 - x[1])**2)**(3/2)), (x[2]/(c[2]*sqrt(x[2]**2 + (l1 - x[3])**2)) + (-l0 + x[2])/(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)))*(2*x[2]/(c[2]*sqrt(x[2]**2 + (l1 - x[3])**2)) + 2*(-l0 + x[2])/(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2))) + (-2*x[2]**2/(c[2]*(x[2]**2 + (l1 - x[3])**2)**(3/2)) + 2/(c[2]*sqrt(x[2]**2 + (l1 - x[3])**2)) + 2*(-l0 + x[2])*(l0 - x[2])/(c[1]*((l0 - x[2])**2 + (l1 - x[1])**2)**(3/2)) + 2/(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)))*(sqrt((h + m*p*sphi)**2 + (-cphi*m*p + x[0])**2)/cw + sqrt((h + n*p*sphi)**2 + (-cphi*n*p + x[3])**2)/cw + sqrt(x[2]**2 + (l1 - x[3])**2)/c[2] + sqrt((l0 - x[2])**2 + (l1 - x[1])**2)/c[1] + sqrt(l0**2 + (-x[0] + x[1])**2)/c[0]), (2*x[2]/(c[2]*sqrt(x[2]**2 + (l1 - x[3])**2)) + 2*(-l0 + x[2])/(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)))*((-cphi*n*p + x[3])/(cw*sqrt((h + n*p*sphi)**2 + (-cphi*n*p + x[3])**2)) + (-l1 + x[3])/(c[2]*sqrt(x[2]**2 + (l1 - x[3])**2))) + 2*x[2]*(l1 - x[3])*(sqrt((h + m*p*sphi)**2 + (-cphi*m*p + x[0])**2)/cw + sqrt((h + n*p*sphi)**2 + (-cphi*n*p + x[3])**2)/cw + sqrt(x[2]**2 + (l1 - x[3])**2)/c[2] + sqrt((l0 - x[2])**2 + (l1 - x[1])**2)/c[1] + sqrt(l0**2 + (-x[0] + x[1])**2)/c[0])/(c[2]*(x[2]**2 + (l1 - x[3])**2)**(3/2))], [((-cphi*m*p + x[0])/(cw*sqrt((h + m*p*sphi)**2 + (-cphi*m*p + x[0])**2)) + (x[0] - x[1])/(c[0]*sqrt(l0**2 + (-x[0] + x[1])**2)))*(2*(-cphi*n*p + x[3])/(cw*sqrt((h + n*p*sphi)**2 + (-cphi*n*p + x[3])**2)) + 2*(-l1 + x[3])/(c[2]*sqrt(x[2]**2 + (l1 - x[3])**2))), ((-l1 + x[1])/(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)) + (-x[0] + x[1])/(c[0]*sqrt(l0**2 + (-x[0] + x[1])**2)))*(2*(-cphi*n*p + x[3])/(cw*sqrt((h + n*p*sphi)**2 + (-cphi*n*p + x[3])**2)) + 2*(-l1 + x[3])/(c[2]*sqrt(x[2]**2 + (l1 - x[3])**2))), (x[2]/(c[2]*sqrt(x[2]**2 + (l1 - x[3])**2)) + (-l0 + x[2])/(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)))*(2*(-cphi*n*p + x[3])/(cw*sqrt((h + n*p*sphi)**2 + (-cphi*n*p + x[3])**2)) + 2*(-l1 + x[3])/(c[2]*sqrt(x[2]**2 + (l1 - x[3])**2))) - 2*x[2]*(-l1 + x[3])*(sqrt((h + m*p*sphi)**2 + (-cphi*m*p + x[0])**2)/cw + sqrt((h + n*p*sphi)**2 + (-cphi*n*p + x[3])**2)/cw + sqrt(x[2]**2 + (l1 - x[3])**2)/c[2] + sqrt((l0 - x[2])**2 + (l1 - x[1])**2)/c[1] + sqrt(l0**2 + (-x[0] + x[1])**2)/c[0])/(c[2]*(x[2]**2 + (l1 - x[3])**2)**(3/2)), ((-cphi*n*p + x[3])/(cw*sqrt((h + n*p*sphi)**2 + (-cphi*n*p + x[3])**2)) + (-l1 + x[3])/(c[2]*sqrt(x[2]**2 + (l1 - x[3])**2)))*(2*(-cphi*n*p + x[3])/(cw*sqrt((h + n*p*sphi)**2 + (-cphi*n*p + x[3])**2)) + 2*(-l1 + x[3])/(c[2]*sqrt(x[2]**2 + (l1 - x[3])**2))) + (2*(-cphi*n*p + x[3])*(cphi*n*p - x[3])/(cw*((h + n*p*sphi)**2 + (-cphi*n*p + x[3])**2)**(3/2)) + 2/(cw*sqrt((h + n*p*sphi)**2 + (-cphi*n*p + x[3])**2)) + 2*(-l1 + x[3])*(l1 - x[3])/(c[2]*(x[2]**2 + (l1 - x[3])**2)**(3/2)) + 2/(c[2]*sqrt(x[2]**2 + (l1 - x[3])**2)))*(sqrt((h + m*p*sphi)**2 + (-cphi*m*p + x[0])**2)/cw + sqrt((h + n*p*sphi)**2 + (-cphi*n*p + x[3])**2)/cw + sqrt(x[2]**2 + (l1 - x[3])**2)/c[2] + sqrt((l0 - x[2])**2 + (l1 - x[1])**2)/c[1] + sqrt(l0**2 + (-x[0] + x[1])**2)/c[0])]])
bnds = ((m*p*cphi,m*p*cphi + tan(arcsin(cw/c[0]))*(h + m*p*sphi)),(m*p*cphi,l1),(0.,l0),(n*p*cphi, l1-l2))
xi = (0.5*(bnds[0][1]-bnds[0][0]), 0.5*(bnds[1][1]-bnds[1][0]), 0.5*(bnds[2][1]-bnds[2][0]), 0.5*(bnds[3][1]-bnds[3][0]))
res = minimize(f,xi,method='Newton-CG',jac=J,hess=H,options={'disp': False, 'xtol': 1e-05, 'eps': 1.4901161193847656e-08, 'return_all': False, 'maxiter': None})
# res = minimize(f,xi,method='BFGS',jac=J)
if (res.success)&(res.fun>0.)&(CheckBounds(res.x,bnds)):
# T = sqrt(res.fun)
T = res.fun
ntr = array([(h+m*p*sphi)*tphi,h+m*p*sphi])
vtr = array([res.x[0]-m*p*cphi,h+m*p*sphi])
nrc = array([(h+n*p*sphi)*tphi,h+n*p*sphi])
vrc = array([res.x[-1]-n*p*cphi,h+n*p*sphi])
th = ((180/pi)*sign(vtr[0]-ntr[0])*arccos(vdot(vtr,ntr)/(norm(vtr)*norm(ntr))), (180/pi)*sign(vrc[0]-nrc[0])*arccos(vdot(vrc,nrc)/(norm(vrc)*norm(nrc))))
# th = ( arccos(dot(vtr.transpose(),ntr)[0]/(sqrt(dot(ntr,ntr.transpose())[0])*sqrt(dot(vtr,vtr.transpose())[0]))), arccos(dot(vrc,nrc.transpose())[0]/(sqrt(dot(nrc,nrc.transpose())[0])*sqrt(dot(vrc,vrc.transpose())[0]))))
else:
T = nan
th = nan
return T,th
def SideWallCap(m,n,c):
# f = lambda x: sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)/cw + sqrt((h + n*p*sphi)**2 + (cphi*n*p - x[5])**2)/cw + sqrt(l0**2 + (x[4] - x[5])**2)/c[4] + sqrt((l0 - x[3])**2 + (l1 - x[4])**2)/c[3] + sqrt((l1 - x[2])**2 + (-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])**2/l2**2)/c[2] + sqrt((x[1] - x[2])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[2])**2/l2**2)/c[1] + sqrt(l0**2 + (x[0] - x[1])**2)/c[0]
# J = lambda x: array([-(cphi*m*p - x[0])/(cw*sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)) + (x[0] - x[1])/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)), (x[1] - x[2])/(c[1]*sqrt((x[1] - x[2])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[2])**2/l2**2)) - (x[0] - x[1])/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)), (-l1 + x[2] + l3*(-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])/l2**2)/(c[2]*sqrt((l1 - x[2])**2 + (-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])**2/l2**2)) + (-x[1] + x[2] + l3*(l0*l2 - l1*l3 + l2*l3 + l3*x[2])/l2**2)/(c[1]*sqrt((x[1] - x[2])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[2])**2/l2**2)), -(l0 - x[3])/(c[3]*sqrt((l0 - x[3])**2 + (l1 - x[4])**2)) + (-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])/(c[2]*l2*sqrt((l1 - x[2])**2 + (-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])**2/l2**2)), (x[4] - x[5])/(c[4]*sqrt(l0**2 + (x[4] - x[5])**2)) - (l1 - x[4])/(c[3]*sqrt((l0 - x[3])**2 + (l1 - x[4])**2)), -(cphi*n*p - x[5])/(cw*sqrt((h + n*p*sphi)**2 + (cphi*n*p - x[5])**2)) - (x[4] - x[5])/(c[4]*sqrt(l0**2 + (x[4] - x[5])**2))])
# H = lambda x: array([[-(cphi*m*p - x[0])**2/(cw*((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)**(3/2)) + 1/(cw*sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)) + 1/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)) + (-x[0] + x[1])*(x[0] - x[1])/(c[0]*(l0**2 + (x[0] - x[1])**2)**(3/2)), -1/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)) + (x[0] - x[1])**2/(c[0]*(l0**2 + (x[0] - x[1])**2)**(3/2)), 0, 0, 0, 0], [-1/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)) - (-x[0] + x[1])*(x[0] - x[1])/(c[0]*(l0**2 + (x[0] - x[1])**2)**(3/2)), (-x[1] + x[2])*(x[1] - x[2])/(c[1]*((x[1] - x[2])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[2])**2/l2**2)**(3/2)) + 1/(c[1]*sqrt((x[1] - x[2])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[2])**2/l2**2)) + 1/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)) - (x[0] - x[1])**2/(c[0]*(l0**2 + (x[0] - x[1])**2)**(3/2)), (x[1] - x[2])*(x[1] - x[2] - l3*(l0*l2 - l1*l3 + l2*l3 + l3*x[2])/l2**2)/(c[1]*((x[1] - x[2])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[2])**2/l2**2)**(3/2)) - 1/(c[1]*sqrt((x[1] - x[2])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[2])**2/l2**2)), 0, 0, 0], [0, (-x[1] + x[2])*(-x[1] + x[2] + l3*(l0*l2 - l1*l3 + l2*l3 + l3*x[2])/l2**2)/(c[1]*((x[1] - x[2])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[2])**2/l2**2)**(3/2)) - 1/(c[1]*sqrt((x[1] - x[2])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[2])**2/l2**2)), (1 + l3**2/l2**2)/(c[2]*sqrt((l1 - x[2])**2 + (-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])**2/l2**2)) + (-l1 + x[2] + l3*(-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])/l2**2)*(l1 - x[2] - l3*(-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])/l2**2)/(c[2]*((l1 - x[2])**2 + (-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])**2/l2**2)**(3/2)) + (1 + l3**2/l2**2)/(c[1]*sqrt((x[1] - x[2])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[2])**2/l2**2)) + (-x[1] + x[2] + l3*(l0*l2 - l1*l3 + l2*l3 + l3*x[2])/l2**2)*(x[1] - x[2] - l3*(l0*l2 - l1*l3 + l2*l3 + l3*x[2])/l2**2)/(c[1]*((x[1] - x[2])**2 + (l0*l2 - l1*l3 + l2*l3 + l3*x[2])**2/l2**2)**(3/2)), l3/(c[2]*l2*sqrt((l1 - x[2])**2 + (-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])**2/l2**2)) - (-l1 + x[2] + l3*(-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])/l2**2)*(-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])/(c[2]*l2*((l1 - x[2])**2 + (-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])**2/l2**2)**(3/2)), 0, 0], [0, 0, l3/(c[2]*l2*sqrt((l1 - x[2])**2 + (-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])**2/l2**2)) + (l1 - x[2] - l3*(-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])/l2**2)*(-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])/(c[2]*l2*((l1 - x[2])**2 + (-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])**2/l2**2)**(3/2)), -(l0 - x[3])**2/(c[3]*((l0 - x[3])**2 + (l1 - x[4])**2)**(3/2)) + 1/(c[3]*sqrt((l0 - x[3])**2 + (l1 - x[4])**2)) + 1/(c[2]*sqrt((l1 - x[2])**2 + (-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])**2/l2**2)) - (-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])**2/(c[2]*l2**2*((l1 - x[2])**2 + (-l1*l3 + l2*l3 + l2*x[3] + l3*x[2])**2/l2**2)**(3/2)), -(l0 - x[3])*(l1 - x[4])/(c[3]*((l0 - x[3])**2 + (l1 - x[4])**2)**(3/2)), 0], [0, 0, 0, -(l0 - x[3])*(l1 - x[4])/(c[3]*((l0 - x[3])**2 + (l1 - x[4])**2)**(3/2)), 1/(c[4]*sqrt(l0**2 + (x[4] - x[5])**2)) + (-x[4] + x[5])*(x[4] - x[5])/(c[4]*(l0**2 + (x[4] - x[5])**2)**(3/2)) - (l1 - x[4])**2/(c[3]*((l0 - x[3])**2 + (l1 - x[4])**2)**(3/2)) + 1/(c[3]*sqrt((l0 - x[3])**2 + (l1 - x[4])**2)), -1/(c[4]*sqrt(l0**2 + (x[4] - x[5])**2)) + (x[4] - x[5])**2/(c[4]*(l0**2 + (x[4] - x[5])**2)**(3/2))], [0, 0, 0, 0, -1/(c[4]*sqrt(l0**2 + (x[4] - x[5])**2)) - (-x[4] + x[5])*(x[4] - x[5])/(c[4]*(l0**2 + (x[4] - x[5])**2)**(3/2)), -(cphi*n*p - x[5])**2/(cw*((h + n*p*sphi)**2 + (cphi*n*p - x[5])**2)**(3/2)) + 1/(cw*sqrt((h + n*p*sphi)**2 + (cphi*n*p - x[5])**2)) + 1/(c[4]*sqrt(l0**2 + (x[4] - x[5])**2)) - (x[4] - x[5])**2/(c[4]*(l0**2 + (x[4] - x[5])**2)**(3/2))]])
# bnds = ((m*p*cphi,m*p*cphi + tan(arcsin(cw/c[0]))*(h + m*p*sphi)),(l1-l2 - l0*l2/l3, l1),(l1-l2,l1),(0.,l0),(n*p*cphi,l1),(n*p*cphi,n*p*cphi + tan(arcsin(cw/c[4]))*(h + n*p*sphi)))
# bnds = ((m*p*cphi,m*p*cphi + tan(arcsin(cw/c[0]))*(h + m*p*sphi)),(m*p*cphi, l1),(l1-l2,l1),(0.,l0),(n*p*cphi,l1),(n*p*cphi,n*p*cphi + tan(arcsin(c[4]/cw))*(h + n*p*sphi)))
f = lambda x: sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)/cw + sqrt((h + n*p*sphi)**2 + (cphi*n*p - x[6])**2)/cw + sqrt(l0**2 + (x[5] - x[6])**2)/c[5] + sqrt((l0 - x[4])**2 + (l1 - x[5])**2)/c[4] + sqrt((l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[4] + l3*x[3])**2/l2**2)/c[3] + sqrt((l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2/l2**2)/c[2] + sqrt((l0 - x[2])**2 + (l1 - x[1])**2)/c[1] + sqrt(l0**2 + (x[0] - x[1])**2)/c[0]
J = lambda x: array([-(cphi*m*p - x[0])/(cw*sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)) + (x[0] - x[1])/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)), -(l1 - x[1])/(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)) - (x[0] - x[1])/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)), (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])/(c[2]*l2*sqrt((l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2/l2**2)) - (l0 - x[2])/(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)), (-l1 + x[3] + l3*(-l1*l3 + l2*l3 + l2*x[4] + l3*x[3])/l2**2)/(c[3]*sqrt((l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[4] + l3*x[3])**2/l2**2)) + (-l1 + x[3] + l3*(-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])/l2**2)/(c[2]*sqrt((l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2/l2**2)), -(l0 - x[4])/(c[4]*sqrt((l0 - x[4])**2 + (l1 - x[5])**2)) + (-l1*l3 + l2*l3 + l2*x[4] + l3*x[3])/(c[3]*l2*sqrt((l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[4] + l3*x[3])**2/l2**2)), (x[5] - x[6])/(c[5]*sqrt(l0**2 + (x[5] - x[6])**2)) - (l1 - x[5])/(c[4]*sqrt((l0 - x[4])**2 + (l1 - x[5])**2)), -(cphi*n*p - x[6])/(cw*sqrt((h + n*p*sphi)**2 + (cphi*n*p - x[6])**2)) - (x[5] - x[6])/(c[5]*sqrt(l0**2 + (x[5] - x[6])**2))])
H = lambda x: array([[-(cphi*m*p - x[0])**2/(cw*((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)**(3/2)) + 1/(cw*sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)) + 1/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)) + (-x[0] + x[1])*(x[0] - x[1])/(c[0]*(l0**2 + (x[0] - x[1])**2)**(3/2)), -1/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)) + (x[0] - x[1])**2/(c[0]*(l0**2 + (x[0] - x[1])**2)**(3/2)), 0, 0, 0, 0, 0], [-1/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)) - (-x[0] + x[1])*(x[0] - x[1])/(c[0]*(l0**2 + (x[0] - x[1])**2)**(3/2)), -(l1 - x[1])**2/(c[1]*((l0 - x[2])**2 + (l1 - x[1])**2)**(3/2)) + 1/(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)) + 1/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)) - (x[0] - x[1])**2/(c[0]*(l0**2 + (x[0] - x[1])**2)**(3/2)), -(l0 - x[2])*(l1 - x[1])/(c[1]*((l0 - x[2])**2 + (l1 - x[1])**2)**(3/2)), 0, 0, 0, 0], [0, -(l0 - x[2])*(l1 - x[1])/(c[1]*((l0 - x[2])**2 + (l1 - x[1])**2)**(3/2)), 1/(c[2]*sqrt((l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2/l2**2)) - (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2/(c[2]*l2**2*((l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2/l2**2)**(3/2)) - (l0 - x[2])**2/(c[1]*((l0 - x[2])**2 + (l1 - x[1])**2)**(3/2)) + 1/(c[1]*sqrt((l0 - x[2])**2 + (l1 - x[1])**2)), l3/(c[2]*l2*sqrt((l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2/l2**2)) + (l1 - x[3] - l3*(-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])/l2**2)*(-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])/(c[2]*l2*((l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2/l2**2)**(3/2)), 0, 0, 0], [0, 0, l3/(c[2]*l2*sqrt((l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2/l2**2)) - (-l1 + x[3] + l3*(-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])/l2**2)*(-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])/(c[2]*l2*((l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2/l2**2)**(3/2)), (1 + l3**2/l2**2)/(c[3]*sqrt((l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[4] + l3*x[3])**2/l2**2)) + (-l1 + x[3] + l3*(-l1*l3 + l2*l3 + l2*x[4] + l3*x[3])/l2**2)*(l1 - x[3] - l3*(-l1*l3 + l2*l3 + l2*x[4] + l3*x[3])/l2**2)/(c[3]*((l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[4] + l3*x[3])**2/l2**2)**(3/2)) + (1 + l3**2/l2**2)/(c[2]*sqrt((l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2/l2**2)) + (-l1 + x[3] + l3*(-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])/l2**2)*(l1 - x[3] - l3*(-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])/l2**2)/(c[2]*((l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[2] + l3*x[3])**2/l2**2)**(3/2)), l3/(c[3]*l2*sqrt((l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[4] + l3*x[3])**2/l2**2)) - (-l1 + x[3] + l3*(-l1*l3 + l2*l3 + l2*x[4] + l3*x[3])/l2**2)*(-l1*l3 + l2*l3 + l2*x[4] + l3*x[3])/(c[3]*l2*((l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[4] + l3*x[3])**2/l2**2)**(3/2)), 0, 0], [0, 0, 0, l3/(c[3]*l2*sqrt((l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[4] + l3*x[3])**2/l2**2)) + (l1 - x[3] - l3*(-l1*l3 + l2*l3 + l2*x[4] + l3*x[3])/l2**2)*(-l1*l3 + l2*l3 + l2*x[4] + l3*x[3])/(c[3]*l2*((l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[4] + l3*x[3])**2/l2**2)**(3/2)), -(l0 - x[4])**2/(c[4]*((l0 - x[4])**2 + (l1 - x[5])**2)**(3/2)) + 1/(c[4]*sqrt((l0 - x[4])**2 + (l1 - x[5])**2)) + 1/(c[3]*sqrt((l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[4] + l3*x[3])**2/l2**2)) - (-l1*l3 + l2*l3 + l2*x[4] + l3*x[3])**2/(c[3]*l2**2*((l1 - x[3])**2 + (-l1*l3 + l2*l3 + l2*x[4] + l3*x[3])**2/l2**2)**(3/2)), -(l0 - x[4])*(l1 - x[5])/(c[4]*((l0 - x[4])**2 + (l1 - x[5])**2)**(3/2)), 0], [0, 0, 0, 0, -(l0 - x[4])*(l1 - x[5])/(c[4]*((l0 - x[4])**2 + (l1 - x[5])**2)**(3/2)), 1/(c[5]*sqrt(l0**2 + (x[5] - x[6])**2)) + (-x[5] + x[6])*(x[5] - x[6])/(c[5]*(l0**2 + (x[5] - x[6])**2)**(3/2)) - (l1 - x[5])**2/(c[4]*((l0 - x[4])**2 + (l1 - x[5])**2)**(3/2)) + 1/(c[4]*sqrt((l0 - x[4])**2 + (l1 - x[5])**2)), -1/(c[5]*sqrt(l0**2 + (x[5] - x[6])**2)) + (x[5] - x[6])**2/(c[5]*(l0**2 + (x[5] - x[6])**2)**(3/2))], [0, 0, 0, 0, 0, -1/(c[5]*sqrt(l0**2 + (x[5] - x[6])**2)) - (-x[5] + x[6])*(x[5] - x[6])/(c[5]*(l0**2 + (x[5] - x[6])**2)**(3/2)), -(cphi*n*p - x[6])**2/(cw*((h + n*p*sphi)**2 + (cphi*n*p - x[6])**2)**(3/2)) + 1/(cw*sqrt((h + n*p*sphi)**2 + (cphi*n*p - x[6])**2)) + 1/(c[5]*sqrt(l0**2 + (x[5] - x[6])**2)) - (x[5] - x[6])**2/(c[5]*(l0**2 + (x[5] - x[6])**2)**(3/2))]])
# bnds = ((m*p*cphi,m*p*cphi + tan(arcsin(cw/c[0]))*(h + m*p*sphi)),(m*p*cphi, l1),(l1-l2,l1),(0.,l0),(n*p*cphi,l1),(n*p*cphi,l1))
bnds = ((m*p*cphi,l1-l2),(m*p*cphi, l1),(0.,l0),(l1-l2,l1),(0.,l0),(n*p*cphi,l1),(n*p*cphi,l1-l2))
xi = (0.5*(bnds[0][1]-bnds[0][0]), 0.5*(bnds[1][1]-bnds[1][0]), 0.5*(bnds[2][1]-bnds[2][0]), 0.5*(bnds[3][1]-bnds[3][0]),0.75*(bnds[4][1]-bnds[4][0]),0.5*(bnds[5][1]-bnds[5][0]),(0.5*(bnds[6][1]-bnds[6][0])))
res = minimize(f,xi,method='Newton-CG',jac=J,hess=H,options={'disp': False, 'xtol': 1e-03, 'eps': 1.4901161193847656e-08, 'return_all': False, 'maxiter': None})
if (res.success)&(CheckBounds([res.x[2]],[bnds[2]])):
# T = sqrt(res.fun)
T = res.fun
ntr = array([(h+m*p*sphi)*tphi,h+m*p*sphi])
vtr = array([res.x[0]-m*p*cphi,h+m*p*sphi])
nrc = array([(h+n*p*sphi)*tphi,h+n*p*sphi])
vrc = array([res.x[-1]-n*p*cphi,h+n*p*sphi])
th = ((180/pi)*sign(vtr[0]-ntr[0])*arccos(vdot(vtr,ntr)/(norm(vtr)*norm(ntr))), (180/pi)*sign(vrc[0]-nrc[0])*arccos(vdot(vrc,nrc)/(norm(vrc)*norm(nrc))))
else:
T = nan
th = nan
return T,th
def MultiSkipCorner(m,n,c):
f = lambda x: sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)/cw + sqrt((h + n*p*sphi)**2 + (cphi*n*p - x[5])**2)/cw + sqrt(l0**2 + (x[4] - x[5])**2)/c[4] + sqrt((l0 - x[3])**2 + (l1 - x[4])**2)/c[3] + sqrt(x[3]**2 + (l1 - x[2])**2)/c[2] + sqrt(l0**2 + (x[1] - x[2])**2)/c[1] + sqrt(l0**2 + (x[0] - x[1])**2)/c[0]
J = lambda x: array([-(cphi*m*p - x[0])/(cw*sqrt((h + m*p*sphi)**2 + (cphi*m*p - x[0])**2)) + (x[0] - x[1])/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)), (x[1] - x[2])/(c[1]*sqrt(l0**2 + (x[1] - x[2])**2)) - (x[0] - x[1])/(c[0]*sqrt(l0**2 + (x[0] - x[1])**2)), -(l1 - x[2])/(c[2]*sqrt(x[3]**2 + (l1 - x[2])**2)) - (x[1] - x[2])/(c[1]*sqrt(l0**2 + (x[1] - x[2])**2)), -l0/(c[3]*sqrt((l0 - x[3])**2 + (l1 - x[4])**2)) + x[3]/(c[3]*sqrt((l0 - x[3])**2 + (l1 - x[4])**2)) + x[3]/(c[2]*sqrt(x[3]**2 + (l1 - x[2])**2)), (x[4] - x[5])/(c[4]*sqrt(l0**2 + (x[4] - x[5])**2)) - (l1 - x[4])/(c[3]*sqrt((l0 - x[3])**2 + (l1 - x[4])**2)), -(cphi*n*p - x[5])/(cw*sqrt((h + n*p*sphi)**2 + (cphi*n*p - x[5])**2)) - (x[4] - x[5])/(c[4]*sqrt(l0**2 + (x[4] - x[5])**2))])
bnds = ((m*p*cphi,l1-l2),(m*p*cphi,l1-l2),(m*p*cphi,l1-l2),(0.,l0),(n*p*cphi,l1),(n*p*cphi,l1-l2))
xi = (0.25*(bnds[0][1]-bnds[0][0]),0.5*(bnds[1][1]-bnds[1][0]),0.75*(bnds[2][1]-bnds[2][0]),0.5*(bnds[3][1]-bnds[3][0]),0.5*(bnds[4][1]-bnds[4][0]),0.25*(bnds[5][1]-bnds[5][0]))
# bnds = ((m*p*cphi,m*p*cphi + tan(arcsin(cw/c[0]))*(h + m*p*sphi)),(m*p*cphi,l1),(0.,l0),(n*p*cphi, l1-l2))
#
# xi = (0.25*(bnds[0][1]-bnds[0][0]), 0.5*(bnds[1][1]-bnds[1][0]), 0.5*(bnds[2][1]-bnds[2][0]), 0.5*(bnds[3][1]-bnds[3][0]))
# res = minimize(f,xi,method='Newton-CG',jac=J,hess=H,options={'disp': False, 'xtol': 1e-05, 'eps': 1.4901161193847656e-08, 'return_all': False, 'maxiter': None})
# print(bnds)
res = minimize(f,xi,method='BFGS',jac=J)
# res = minimize(f,xi,method='BFGS')
#
# print(res.x)
print(res.message)
if (res.success)&(CheckBounds(res.x,bnds)):
# T = sqrt(res.fun)
T = res.fun
ntr = array([(h+m*p*sphi)*tphi,h+m*p*sphi])
vtr = array([res.x[0]-m*p*cphi,h+m*p*sphi])
nrc = array([(h+n*p*sphi)*tphi,h+n*p*sphi])
vrc = array([res.x[-1]-n*p*cphi,h+n*p*sphi])
th = ((180/pi)*sign(vtr[0]-ntr[0])*arccos(vdot(vtr,ntr)/(norm(vtr)*norm(ntr))), (180/pi)*sign(vrc[0]-nrc[0])*arccos(vdot(vrc,nrc)/(norm(vrc)*norm(nrc))))
# th = ( arccos(dot(vtr.transpose(),ntr)[0]/(sqrt(dot(ntr,ntr.transpose())[0])*sqrt(dot(vtr,vtr.transpose())[0]))), arccos(dot(vrc,nrc.transpose())[0]/(sqrt(dot(nrc,nrc.transpose())[0])*sqrt(dot(vrc,vrc.transpose())[0]))))
else:
T = nan
th = nan
return T,th
DelayFunctions = {}
DelayFunctions['Corner'] = lambda m,n,c: Corner(m,n,c)
DelayFunctions['SideWallCap'] = lambda m,n,c: SideWallCap(m,n,c)
DelayFunctions['MultiSkipCorner'] = lambda m,n,c: MultiSkipCorner(m,n,c)
c = [cs[cc] for cc in Path[1]]
d = [[ DelayFunctions[Path[0]](m,n,c) for n in Elements[1] ] for m in Elements[0] ]
return d
class FMC:
def __init__(self,ascans,fsamp=25.,defaultwp={'Thickness':30., 'VerticalFL': 8.0, 'HorizontalFL': 8.0, 'SideWallPosition': 34.16}, weldtype='L',probeid='5L32',wedgeid='L10'):
self.PathList = []
self.PathList.append([('Cap',('T','T','T')),('Cap',('L','T','T'))])
# self.PathList.append([('Cap',('T','T','T')),('Cap',('L','L','L'))])
# self.PathList.append([('Cap',('L','L','T')),('Cap',('L','L','L'))])
self.PathList.append([('Cap',('T','L','T')),('Cap',('T','L','L'))])
# self.PathList.append([('Cap',('L','L','T')),('Cap',('L','L','L'))])
# self.PathList.append()
Wedge = {}
Wedge['L10'] = {'Height':15.12,'Angle':10.,'Velocity':2.32,'Impedance':{'Longitudinal':2.32*1.04,'Transverse':2.32*1.04/2}}
Wedge['Black'] = {'Height':6.4,'Angle':31.6,'Velocity':2.32,'Impedance':{'Longitudinal':2.32*1.04,'Transverse':2.32*1.04/2}}
Probe = {}
Probe['5L32'] = {'Pitch':0.6,'NumberOfElements':32,'CentreFrequency':5.0}
self.PieceParameters = {'Velocity':{'Longitudinal':5.92,'Transverse':3.24}, 'Impedance':{'Longitudinal':5.92*7.8,'Transverse':3.24*7.8}}
self.WeldType = weldtype
self.WedgeParameters = Wedge[wedgeid]
self.ProbeParameters = Probe[probeid]
self.SamplingFrequency = fsamp
self.LoadAScans(ascans,defaultwp)
#
# DelayFunction = {}
#
# DelayFunction['L'] = lambda pth: LWeldDelays(pth,self.WeldParameters,self.ProbeParameters,self.WedgeParameters)
#
# self.DelayFunction = DelayFunction[weldtype]
#
# self.FusionLine = []
def LoadAScans(self,inpt,defaultwp):
# from Civa import LoadAScansFromTxt
#
# loader = {}
# loader['civa'] = lambda x: LoadAScansFromTxt(x).astype(float)