-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC14_geoPRECISE.py
2053 lines (1695 loc) · 67.7 KB
/
C14_geoPRECISE.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
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
"""
This code piece creates the Concept 14 geometric shape. The input json
file should have the following shape:
{
"C14" : {
"airfoil dat file location" : "/home/ben/foilshapes/E335.txt",
"chord [in]" : 12,
"num arcs" : 5,
"num arc points" : 30,
"arc type" : "exponential",
"arc type notes" : "'exponential', '90%t', or 'hinge_point'",
"shell thickness [mm]" : 0.8,
"flex start [x/c]" : 0.5,
"tongue start [in]" : 1.0,
"tongue start [in]_notes" : "distance before flex start",
"mouth start [in]" : 2.0,
"mouth start [in]_notes" : "distance before flex start",
"TE wall start [x/c]" : 0.95,
"mouth clearance [mm]" : 1.0,
"fillet side length [mm]" : 1.0,
"Notes" : " ",
"show plot" : false,
"write dxf" : false,
"show legend" : true,
"all black" : false,
"dxf file path" : "/home/ben/Desktop/",
"dxf file name" : "c14"
}
}
"""
import airfoil_db as adb
import numpy as np
import json
import dxf
import deflect
import os
from scipy import interpolate as itp
from scipy import optimize as opt
from shapely.geometry import polygon as poly
from matplotlib import pyplot as plt
# function that reads in a json file as a dictionary
def read_json(filename):
# import json file
json_string=open(filename).read()
vals = json.loads(json_string)
return vals
# simplify a json dictionary
def simplify(vals):
# initialize dictionary
dicti = {}
# transfer vals
in2mm = 25.4
dicti["c"] = vals["C14"]["chord [in]"]
dicti["n"] = vals["C14"]["num arcs"]
dicti["np"] = vals["C14"]["num arc points"]
dicti["at"] = vals["C14"]["arc type"]
dicti["ac"] = vals["C14"]["arc concave"]
dicti["t"] = vals["C14"]["shell thickness [mm]"] / dicti["c"] / in2mm
dicti["f"] = vals["C14"]["flex start [x/c]"]
dicti["to"] = dicti["f"] - np.abs(vals["C14"]["tongue start [in]"]) \
/ dicti["c"]
dicti["mo"] = dicti["f"] - np.abs(vals["C14"]["mouth start [in]"]) \
/ dicti["c"]
if dicti["to"] < dicti["mo"]:
raise ValueError("Tongue cannot extend beyond mouth start")
dicti["tw"] = vals["C14"]["TE wall start [x/c]"]
dicti["mt"] = vals["C14"]["mouth clearance [mm]"] / dicti["c"] / in2mm
dicti["fi"] = vals["C14"]["fillet side length [mm]"] / dicti["c"] / in2mm
dicti["da"] = vals["C14"]["deflection angle [deg]"]
dicti["dty"] = vals["C14"]["deflection type"]
dicti["th"] = vals["C14"]["hinge at top"]
dicti["sk"] = vals["C14"]["skip wing box"]
return dicti
# function that determines the midpoint between points
def midpt(x,y):
# create x[i] and x[i+1] arrays
x0 = x[:-1]
x1 = x[1:]
# create y[i] and y[i+1] arrays
y0 = y[:-1]
y1 = y[1:]
# find the midpoint between each point
midx = (x0+x1)/2.0
midy = (y0+y1)/2.0
return midx,midy
# function that creates an (+) inward offset of a given line
def offset(x,y,d):
# create x[i] and x[i+1] arrays
x0 = x[:-1]
x1 = x[1:]
# create y[i] and y[i+1] arrays
y0 = y[:-1]
y1 = y[1:]
# get the midpoints of the given line
midx,midy = midpt(x,y)
# determine the offset x and y values for each midpoint
offx = midx - d*(y1-y0)/( (x0-x1)**2.0 + (y0-y1)**2.0 )**0.5
offy = midy + d*(x1-x0)/( (x0-x1)**2.0 + (y0-y1)**2.0 )**0.5
return offx,offy
# determine where a set of x y coordinates intersect
def intersections(x,y):
# initialize intersection info
insct = []
# run through each panel and determine if the panel intersects any other
for i in range(x.shape[0]-1): # 40,41): #
for j in range(x.shape[0]-1): # 157,158): #
# ignore if same panel
if not i == j and not (i == j+1 or i==j-1):
# determine the slope and intercept of both lines
mi = (y[i+1]-y[i])/(x[i+1]-x[i])
mj = (y[j+1]-y[j])/(x[j+1]-x[j])
bi = y[i] - mi * x[i]
bj = y[j] - mj * x[j]
# determine where these lines intersect
x_int = (bj - bi) / (mi - mj)
y_int = mi * x_int + bi
# find which direction is forward
if x[i] < x[i+1]:
i0 = i; i1 = i+1
else:
i0 = i+1; i1 = i
if x[j] < x[j+1]:
j0 = j; j1 = j+1
else:
j0 = j+1; j1 = j
# determine if the intersection occurs between the two lines
if y[i] < y[i+1]:
iy0 = i; iy1 = i+1
else:
iy0 = i+1; iy1 = i
if y[j] < y[j+1]:
jy0 = i; jy1 = j+1
else:
jy0 = j+1; jy1 = j
# define boolean checks
in_ix = x_int >= x[i0] and x_int <= x[i1]
in_iy = y_int >= y[iy0] and y_int <= y[iy1]
in_jx = x_int >= x[j0] and x_int <= x[j1]
in_jy = y_int >= y[jy0] and y_int <= y[jy1]
if in_ix and in_iy and in_jx and in_jy:
insct.append(np.array([x_int,y_int,i,j]))
# make insct a numpy array
insct = np.array(insct)
# remove duplicate x values
k = 0
while k < insct.shape[0]:
repeats = np.argwhere(insct[k,0]==insct[:,0])
# print(repeats); print(insct)
removed = 0
for index in repeats:
if not index[0] == k:
# print(index[0],k)
insct = np.delete(insct,index[0]+removed,axis=0)
removed -= 1
k += 1
return insct
# remove intersections
def de_intersect(x,y,it):
# check if only one intersection, or more
if it.shape[0] == 1:
# initialize de-intersected lists
num = int(np.abs(it[0][2]-it[0][3]))
ix = np.zeros((num+2,))
iy = np.zeros((num+2,))
# add the intersection point
ix[0] = it[0][0]
iy[0] = it[0][1]
# add other points
ind_max = int(np.max(np.array([it[0][2],it[0][3]])))
ind_min = int(np.min(np.array([it[0][2],it[0][3]])))
ix[1:-1] = x[ind_min+1:ind_max+1]
iy[1:-1] = y[ind_min+1:ind_max+1]
# add the intersection point
ix[-1] = it[0][0]
iy[-1] = it[0][1]
else:
# determine where to start and end
if it[0][0] < it[1][0]:
end_max = int(np.max(np.array([it[0][2],it[0][3]])))
end_min = int(np.min(np.array([it[0][2],it[0][3]])))
str_max = int(np.max(np.array([it[1][2],it[1][3]])))
str_min = int(np.min(np.array([it[1][2],it[1][3]])))
else:
end_max = int(np.max(np.array([it[1][2],it[1][3]])))
end_min = int(np.min(np.array([it[1][2],it[1][3]])))
str_max = int(np.max(np.array([it[0][2],it[0][3]])))
str_min = int(np.min(np.array([it[0][2],it[0][3]])))
# initialize de-intersected lists
top = end_min - str_min; bot = str_max - end_max
ix = np.zeros((top + bot + 3,))
iy = np.zeros((top + bot + 3,))
# add top points
ix[1:top+1] = x[str_min+1:end_min+1]
iy[1:top+1] = y[str_min+1:end_min+1]
# add top points
ix[top+2:-1] = x[end_max+1:str_max+1]
iy[top+2:-1] = y[end_max+1:str_max+1]
if it[0][0] < it[1][0]:
# add the intersection point
ix[0] = it[1][0]
iy[0] = it[1][1]
# add the intersection point
ix[top+1] = it[0][0]
iy[top+1] = it[0][1]
# add the intersection point
ix[-1] = it[1][0]
iy[-1] = it[1][1]
else:
# add the intersection point
ix[0] = it[0][0]
iy[0] = it[0][1]
# add the intersection point
ix[top+1] = it[1][0]
iy[top+1] = it[1][1]
# add the intersection point
ix[-1] = it[0][0]
iy[-1] = it[0][1]
return ix,iy
# function that creates an offset with the kinks removed
# assume closed shape
def inner(x,y,d):
# find offset curve
offx,offy = offset(x,y,d)
# plt.axis("equal")
# plt.plot(x,y)
# plt.plot(offx,offy)
# plt.show()
# find where the intersections occur
itrsc = intersections(offx,offy)
# remove them
ix,iy = de_intersect(offx,offy,itrsc)
return ix,iy
# create camberline and interpolation thereoof
def camberline(xy):
# initialize camberline arrays
xy["cx"] = np.zeros((xy["tx"].shape[0],))
xy["cy"] = np.zeros((xy["ty"].shape[0],))
xy["cl"] = np.zeros((xy["tx"].shape[0],))
summation = 0
# cycle through the points and determine where the camberline is situated
for i in range(xy["cx"].shape[0]):
# determine x and y values
xmid = (xy["tx"][i] + xy["bx"][i]) /2.
ymid = (xy["ty"][i] + xy["by"][i]) /2.
# save to cx and cy arrays
xy["cx"][i] = xmid
xy["cy"][i] = ymid
# add length
if not i == 0:
summation += ((xy["cx"][i] - xy["cx"][i-1])**2. + \
(xy["cy"][i] - xy["cy"][i-1])**2.)**0.5
xy["cl"][i] = summation
# create interpolation of camberline
xy["c"] = itp.interp1d(xy["cx"],xy["cy"],kind="cubic")
# create derivative of camberline
xy["dc"] = (xy["cy"][1:] - xy["cy"][:-1]) / (xy["cx"][1:] - xy["cx"][:-1])
return
# create top and bottom interpolation of a set of xy points ( assume airfoil)
def interpolate(x,y,make_camberline=False):
# find middle point
i_mid = int(x.shape[0]/2)
# split arrays accordingly
if x.shape[0] % 2 == 0:
top_x = np.flip(x[:i_mid])
top_y = np.flip(y[:i_mid])
bot_x = x[i_mid:]
bot_y = y[i_mid:]
else:
top_x = np.flip(x[:i_mid+1])
top_y = np.flip(y[:i_mid+1])
bot_x = x[i_mid:]
bot_y = y[i_mid:]
if top_x[0] == top_x[1]:
top_x[1] -= 1e-10
# points = np.zeros((x.shape[0],2))
# points[:,0] = x
# points[:,1] = y
# # create airfoil shape
# add = {}
# add["geometry"] = {}
# add["geometry"]["type"] = "outline_points"
# add["geometry"]["outline_points"] = points
# # initialize airfoil database
# foil = adb.Airfoil("foil",add)
# def ytop(x):
# return foil.get_camber(x) + foil.get_thickness(x)
# def ybot(x):
# return foil.get_camber(x) - foil.get_thickness(x)
# create interpolations
T = itp.interp1d(top_x,top_y,kind="cubic")
B = itp.interp1d(bot_x,bot_y,kind="cubic")
# save to dictionary
I = {}
I["t"] = T # ytop #
I["b"] = B # ybot #
I["x"] = x
I["y"] = y
I["tx"] = top_x
I["ty"] = top_y
I["bx"] = bot_x
I["by"] = bot_y
I["imid"] = i_mid
# determine camber line of airfoil
if make_camberline:
camberline(I)
return I
# determine where te line is
def te_triangle(xy,info):
# initialize triangle arrays
tri_x = np.zeros((4,),dtype=np.ndarray)
tri_y = np.zeros((4,),dtype=np.ndarray)
# find linear interpolated point where wall meets skin
yw_top = xy["t"](info["tw"])
yw_bot = xy["b"](info["tw"])
# find linear interpolated point where skinned wall meets skin
yskw_top = xy["t"](info["tw"]-info["t"])
yskw_bot = xy["b"](info["tw"]-info["t"])
# save points to tri arrays
for i in range(tri_x.shape[0]):
if i == 0:
# add top part of triangle
x = np.linspace(np.max(xy["tx"]),info["tw"],num=10)
y = xy["t"](x)
# add to tri
tri_x[i] = x
tri_y[i] = y
elif i == 1:
# add side part of triangle
tri_x[i] = np.array([info["tw"],info["tw"]])
tri_y[i] = np.array([yw_top,yw_bot])
elif i == 2:
# add bottom part of triangle
x = np.linspace(np.max(xy["bx"]),info["tw"],num=10)
y = xy["b"](x)
# add to tri
tri_x[i] = x
tri_y[i] = y
else:
# add skin thickness wall to left of triangle
xvalue = info["tw"] - info["t"]
tri_x[i] = np.array([xvalue,xvalue])
tri_y[i] = np.array([yskw_top,yskw_bot])
return tri_x,tri_y
# determine where a y location is on a line
def get_y_loc(x_loc,x,y):
# determine which indices block in the arc
it = 0
while x[it] < x_loc:
it += 1
# determine percent along between camberline indices
perc = (x_loc - x[it-1]) / (x[it] - x[it-1])
y_loc = perc*(y[it] - y[it-1]) + y[it-1]
return y_loc,perc,it
# a function that implements the bisection method to find a root
def Bisect(Fun,xl,xu, Err = 1e-5, maxiter = 1000):
# initialize a large number so the err is less than
E = 10000000
# initialize the icounter
i = 0
# if the given values do not encompass the root, throw error
if not Fun(xl)*Fun(xu) < 0:
raise ValueError("Upper and lower limits do not encompass a root")
# make xrold
xrold = 100
# till threshold error is reached, continue
while(E > Err and i < maxiter):
# estimate xr
xr = (xl + xu) / 2
# determine which subinterval has the root
funmult = Fun(xl) * Fun(xr)
if funmult < 0:
xu = xr
elif funmult > 0:
xl = xr
else: # funmult = 0
return xr
# calculate Err
if xrold != 0:
E = abs( (xr - xrold) / xrold )
# return xrold
xrold = xr
# add counter value
i += 1
# return the root
return xr
# function that given a point on the camberline, finds where the normal
# to this "line" (with dc/dx) will pass the top or bottom of the innerskin
def intersect(xy,it,xp,yp,is_top=True):
if xy["dc"][it] == 0.0:
xval = xp
else:
# determine inverse slope
a = -1. / xy["dc"][it]
# determine y intercept of this line
b = yp - a*xp
# solve for if top or bottom
if is_top:
loc = "t"
else:
loc = "b"
# define function to use with Bisect method
def func(x):
return (a*x+b) - xy[loc](x)
# determine the x value at which this intersection occurs
low = np.min(xy["cx"]+0.05)
hi = np.max(xy["cx"])
xval = Bisect(func,low,hi)
return xval
# function that determines where a circle center is given a slope and point
# that passes through the center, as well as two points on the circle
def center(xt,yt,xb,yb,r,get_concave):
# determine center using two points and a radius
x3 = (xt + xb) / 2.
y3 = (yt + yb) / 2.
dx = xb - xt; dy = yb - yt
q = (dx**2. + dy**2.)**0.5
d = ((r**2.)-(q/2)**2.)**0.5
x1 = x3 - d*dy/q
y1 = y3 + d*dx/q
x2 = x3 + d*dy/q
y2 = y3 - d*dx/q
# initialize boolean to check for where the circle center should be
x_before = x1 < xt
if (x_before and get_concave) or (not x_before and not get_concave):
x_cent = x1; y_cent = y1
else:
x_cent = x2; y_cent = y2
return x_cent, y_cent
# function that determines the angle on a circle
# from np.pi to -np.pi
def get_theta(xc,yc,xp,yp):
# determine the x and y lengths to be used to find the theta value
xlen = xp - xc
ylen = yp - yc
# determine theta value
theta = np.arctan2(ylen,xlen)
return theta
# function that determines where a point is on an interpolation
# range given a point and radius from that point to the interpolated point
def get_point(xy,xc,yc,r,is_concave,is_top=True):
# solve for if top or bottom
if is_top:
loc = "t"
else:
loc = "b"
# get minimum and maximum of the search range
if is_concave:
minx = xc
maxx = np.max(xy[loc+"x"])
else:
minx = np.min(xy[loc+"x"])
maxx = xc
# create function to be used to bracket the root
def func(x):
return (xc-x)**2. + (yc-xy[loc](x))**2. - r**2.
# determine x location
x_root = Bisect(func,minx,maxx)
y_root = xy[loc](x_root)
return x_root,y_root
# create arcs
def arcs(xy,info,shift=0.0):
# initialize arcs arrays first index is 0 arc 1 skin
x_arc = np.zeros((2,info["n"],info["np"]))
y_arc = np.zeros((2,info["n"],info["np"]))
# initialize arcs top and bottom coordinates arrays
# [i][ ][ ] 0 - top, 1 - bottom
# [ ][i][ ] 0 -> 1 from LE to TE
# [ ][ ][i] 0 - arc on left (LE), 1 - arc on right (TE)
info["xpt"] = np.zeros((2,info["n"],2))
info["ypt"] = np.zeros((2,info["n"],2))
# determine where flex starts on camberline
x_flex = info["f"]
y_flex,p_flex,ifx = get_y_loc(x_flex,xy["cx"],xy["cy"])
# determine "length" value at flex start
l_flex = p_flex*(xy["cl"][ifx] - xy["cl"][ifx-1]) + xy["cl"][ifx-1]
# determine where te wall starts on camberline
x_end = info["tw"] - info["t"]
y_end,p_end,ie = get_y_loc(x_end,xy["cx"],xy["cy"])
# determine "length" value at te wall
l_end = p_end*(xy["cl"][ie] - xy["cl"][ie-1]) + xy["cl"][ie-1]
# cycle through each arc
for i in range(info["n"]): # 2): #
# set up x location
if "a0" in info and "a1" in info:
start = info["a0"]
else:
start = info["f"]
x_loc = start + xy["arcdx"] * (i+1) + shift
# determine y location
y_loc,perc,it = get_y_loc(x_loc,xy["cx"],xy["cy"])
# get x and y value where the intersection occurs
x_top = intersect(xy,it,x_loc,y_loc)
x_bot = intersect(xy,it,x_loc,y_loc,is_top=False)
y_top = xy["t"](x_top)
y_bot = xy["b"](x_bot)
# various types of arcs:
if info["at"][-2:] == "%t":
# determine local arc radius
r_loc = ((x_top-x_bot)**2. + (y_top-y_bot)**2.)**0.5
r_loc /= 2.
size_arc = float(info["at"].split("%")[0])/100.
# determine resized arc radius as local is 90% of the diameter
r_res = r_loc / size_arc
# determine where the circles center is
x_cent,y_cent = center(x_top,y_top,x_bot,y_bot,r_res,info["ac"])
elif info["at"] == "hinge_point":
# get flex point of camberline
x_cam_flex = info["f"]
# if convex desired, put hinge point at te wall... fix this
if not info["ac"]:
x_cam_flex = info["tw"]
y_cam_flex = xy["c"](x_cam_flex)
# determine arc radius as avg of top and bottom to hingepoint
r_res_t = ((x_top-x_cam_flex)**2. + (y_top-y_cam_flex)**2.)**0.5
r_res_b = ((x_bot-x_cam_flex)**2. + (y_bot-y_cam_flex)**2.)**0.5
r_res = (r_res_t + r_res_b) / 2.
# determine where the circles center is
x_cent,y_cent = center(x_top,y_top,x_bot,y_bot,r_res,info["ac"])
elif info["at"] == "reversed_exp":
# determine local arc radius
r_loc = ((x_top-x_bot)**2. + (y_top-y_bot)**2.)**0.5
r_loc /= 2.
# determine "length" value at locale
l_loc = perc*(xy["cl"][it] - xy["cl"][it-1]) + xy["cl"][it-1]
# determine resized arc radius
r_res = r_loc * (l_end-l_flex) / (l_loc-l_flex)
# determine where the circles center is
x_cent,y_cent = center(x_top,y_top,x_bot,y_bot,r_res,info["ac"])
else:
# determine local arc radius
r_loc = ((x_top-x_bot)**2. + (y_top-y_bot)**2.)**0.5
r_loc /= 2.
# determine "length" value at locale
l_loc = perc*(xy["cl"][it] - xy["cl"][it-1]) + xy["cl"][it-1]
# determine resized arc radius
r_res = r_loc * (l_end-l_flex) / (l_end-l_loc)
# determine where the circles center is
x_cent,y_cent = center(x_top,y_top,x_bot,y_bot,r_res,info["ac"])
# determine where circle starts
theta_t = get_theta(x_cent,y_cent,x_top,y_top)
theta_b = get_theta(x_cent,y_cent,x_bot,y_bot)
# if convex desired, shift theta values
if not info["ac"]:
theta_b += 2.*np.pi
# create array of angles and radii
theta = np.linspace(theta_b,theta_t,info["np"])
r = np.full(theta.shape,r_res)
# calculate arc x y coordinates
# if convex desired, switch theta values
mult = 1.
if not info["ac"]: mult *= -1.
x_arc[0][i] = r * np.cos(theta) + x_cent
y_arc[0][i] = r * np.sin(theta) + y_cent
# find where the "thickened" arcs lie
r_thick = r_res + mult * info["t"]
# determine where top and bottom of skinned arcs are located
xs_top,ys_top = get_point(xy,x_cent,y_cent,r_thick,info["ac"])
xs_bot,ys_bot = get_point(xy,x_cent,y_cent,r_thick,info["ac"],\
is_top=False)
# determine where skinned arc starts
theta_sk_t = get_theta(x_cent,y_cent,xs_top,ys_top)
theta_sk_b = get_theta(x_cent,y_cent,xs_bot,ys_bot)
# # if convex desired, shift theta values
if not info["ac"]:
theta_sk_b += 2.*np.pi
# create array of angles and radii
theta_sk = np.linspace(theta_sk_b,theta_sk_t,info["np"])
r_thick_arr = np.full(theta_sk.shape,r_thick)
# calculate arc skin x y coordinates
x_arc[1][i] = r_thick_arr * np.cos(theta_sk) + x_cent
y_arc[1][i] = r_thick_arr * np.sin(theta_sk) + y_cent
# # save top and bottom x y values to the points arrays in info
# [i][ ][ ] 0 - top, 1 - bottom
# [ ][i][ ] 0 -> 1 from LE to TE
# [ ][ ][i] 0 - arc on left (LE), 1 - arc on right (TE)
info["xpt"][0][i][0] = x_arc[0][i][-1]
info["xpt"][1][i][0] = x_arc[0][i][0]
info["xpt"][0][i][1] = x_arc[1][i][-1]
info["xpt"][1][i][1] = x_arc[1][i][0]
info["ypt"][0][i][0] = y_arc[0][i][-1]
info["ypt"][1][i][0] = y_arc[0][i][0]
info["ypt"][0][i][1] = y_arc[1][i][-1]
info["ypt"][1][i][1] = y_arc[1][i][0]
return x_arc,y_arc
# create a cubic bezier curve from two xy arrays over 4 points
def Bezier_Cubic(x,y,n = 30):
# initialize bezier arrays
xbz = np.zeros((n,))
ybz = np.zeros((n,))
# for loop to determine the x and y coordinates at each point
for i in range(n):
# determine t value (fraction of number of points)
t = ( i / (n-1) )
# determine the Bezier values in x and y coordinates
xbz[i] = (1-t)**3*x[0] + 3*(1-t)**2*t*x[1] + 3*(1-t)*t**2*x[2] + t**3*x[3]
ybz[i] = (1-t)**3*y[0] + 3*(1-t)**2*t*y[1] + 3*(1-t)*t**2*y[2] + t**3*y[3]
return xbz,ybz
# create outer mouth structure
def make_mouth(O,I,om,info):
# initialize mouth array
x_mouth = np.zeros((6,),dtype=np.ndarray)
y_mouth = np.zeros((6,),dtype=np.ndarray)
# create lower lip line
# find where the flex starts as an interpolated point outer
x_fx_o = info["f"]
y_fx_o,p_fx_o,i_fx_o = get_y_loc(x_fx_o,O["bx"],O["by"])
# save value so info to be used in a later function
info["outer"] = {}; info["outer"]["start"] = [x_fx_o,y_fx_o,i_fx_o]
# find where the flex starts as an interpolated point inner
x_fx_i = info["f"]
y_fx_i,p_fx_i,i_fx_i = get_y_loc(x_fx_i,I["bx"],I["by"])
# create lower lip
x_mouth[0] = np.array([x_fx_o,x_fx_i])
y_mouth[0] = np.array([y_fx_o,y_fx_i])
# create bottom of inner mouth
x_mouth[1] = np.linspace(info["mo"],info["f"],num=15)
y_mouth[1] = I["b"](x_mouth[1])
y_mouth[1][-1] = y_fx_i
# create back of inner mouth
# find where the mouth starts as an interpolated point outer mouth
x_ms_om = info["mo"]
y_ms_om,p_ms_om,i_ms_om = get_y_loc(x_ms_om,om["bx"],om["by"])
# find where the mouth starts as an interpolated point inner
x_ms_i = info["mo"]
y_ms_i,p_ms_i,i_ms_i = get_y_loc(x_ms_i,I["bx"],I["by"])
y_ms_i = y_mouth[1][0]
# initialize back outer mouth
x_mouth[2] = np.array([x_ms_om,x_ms_i])
y_mouth[2] = np.array([y_ms_om,y_ms_i])
# create top of inner mouth
x_mouth[3] = np.linspace(info["mo"],info["f"],num=15)
y_mouth[3] = om["b"](x_mouth[3])
# find where flex starts as an interpolated point outer mouth
x_fx_om = info["f"]
y_fx_om,p_fx_om,i_fx_om = get_y_loc(x_fx_om,om["bx"],om["by"])
y_mouth[3][-1] = y_fx_om
y_mouth[3][0] = y_ms_om
# create "upper lip" line
# find where flex starts as an interpolated point outer mouth
x_fx_om = info["f"]
y_fx_om,p_fx_om,i_fx_om = get_y_loc(x_fx_om,om["bx"],om["by"])
# find where the flex starts as an interpolated point top inner
x_fx_ti = info["f"]
y_fx_ti,p_fx_ti,i_fx_ti = get_y_loc(x_fx_ti,I["tx"],I["ty"])
# create upper lip
x_mouth[4] = np.array([x_fx_ti,x_fx_om])
y_mouth[4] = np.array([y_fx_ti - info["fi"],y_fx_om])
# create fillet from upper lip to inner airfoil
# find where the fillet ends as an interpolated point top inner
x_fi_ti = info["f"] + info["fi"]*1.1
y_fi_ti,p_fi_ti,i_fi_ti = get_y_loc(x_fi_ti,I["tx"],I["ty"])
# initialze point arrays to get the bezier curve
x_points = np.array([x_fx_ti,x_fx_ti,(x_fx_ti+x_fi_ti)/2.,x_fi_ti])
y_points = np.array([y_fx_ti - info["fi"],(y_fx_ti - info["fi"]+y_fi_ti)\
/2.,(y_fx_ti+y_fi_ti)/2.,y_fi_ti])
# create fillet using a bezier curve maker
x_mouth[5],y_mouth[5] = Bezier_Cubic(x_points,y_points)
return x_mouth,y_mouth
# create tongue tip geometry
def tongue_tip(O,I,ot,it,info):
# initialize mouth array
x_tongue = np.zeros((6,),dtype=np.ndarray)
y_tongue = np.zeros((6,),dtype=np.ndarray)
# create a bezier curve from tongue tip to the bottom of first arc
# find interpolation point where flex starts on inner tongue
x_fx_it = info["f"]
y_fx_it,p_fx_it,i_fx_it = get_y_loc(x_fx_it,it["bx"],it["by"])
# create points for the bezier curve
y_start,_,_ = get_y_loc( x_fx_it+.03,it["bx"],it["by"])
y_end,__,__ = get_y_loc(info["xpt"][1][0][0]-.03,I["bx"],I["by"])
# create bezier curve
xpts = np.array([x_fx_it,x_fx_it+.03,info["xpt"][1][0][0]-.03,\
info["xpt"][1][0][0]])
ypts = np.array([y_fx_it,y_start,y_end,\
info["ypt"][1][0][0]])
x_tongue[0],y_tongue[0] = Bezier_Cubic(xpts,ypts,n=60)
# create top of tongue tip
# find where the tongue starts inner tongue
x_ts_it = info["to"]
y_ts_it,p_ts_it,i_ts_it = get_y_loc(x_ts_it,it["bx"],it["by"])
x_tongue[1] = np.linspace(info["to"],info["f"],num=15)
y_tongue[1] = it["b"](x_tongue[1])
y_tongue[1][0] = y_ts_it
y_tongue[1][-1] = y_fx_it
# create very tip of tongue (flat face towards LE)
# find where the tongue starts outer tongue
x_ts_ot = info["to"]
y_ts_ot,p_ts_ot,i_ts_ot = get_y_loc(x_ts_ot,ot["bx"],ot["by"])
# save to tongue tip
x_tongue[2] = np.array([x_ts_it,x_ts_ot])
y_tongue[2] = np.array([y_ts_it,y_ts_ot])
# create curve of tongue bottom
# create an offset curve
x_tongue[3],y_tongue[3] = offset(x_tongue[0],y_tongue[0],-info["t"])
# create outer tongue bottom
x_tongue[4] = np.linspace(info["to"],x_tongue[3][0],num=15)
y_tongue[4] = ot["b"](x_tongue[4])
y_tongue[4][ 0] = y_ts_ot
y_tongue[4][-1] = y_tongue[3][0]
# create line to fix discontinuity between bezier tongue bottom curve
# and outer airfoil shape
# determine the outer airfoil interpolation point from first arc bottom pt
x_j_o = info["xpt"][1][0][0]
y_j_o,p_j_o,i_j_o = get_y_loc(x_j_o,O["bx"],O["by"])
# save to tongue tip
x_tongue[5] = np.array([x_tongue[3][-1],x_j_o])
y_tongue[5] = np.array([y_tongue[3][-1],y_j_o])
# save value so info to be used in a later function
info["outer"]["end"] = [x_j_o,y_j_o,i_j_o]
return x_tongue,y_tongue
# create roofs and floors
def roofs_n_floors(I,info,x_fillet,y_tri_top,y_tri_bot):
# initialize mouth array
# [i][ ] 0 - roof, 1 - floor
# [ ][i] 0 -> 1, LE -> TE
# NOTE [1][0] will remain empty
x_rofl = np.zeros((2,info["n"]+1),dtype=np.ndarray)
y_rofl = np.zeros((2,info["n"]+1),dtype=np.ndarray)
# cycle between roof and floor
for i in range(x_rofl.shape[0]):
# cycle through each arc and determine the roof and or floor
for j in range(x_rofl.shape[1]):
# if solving the roof
if i == 0:
# determine start
if j == 0:
# determine the xy location of the fillet end
x_f_i = x_fillet
y_f_i,p_f_i,i_f_i = get_y_loc(x_f_i,I["tx"],I["ty"])
xstart = x_fillet
ystart = y_f_i
istart = i_f_i
else:
# determin xy location and index of arc begin
x_f_i = info["xpt"][0][j-1][1]
y_f_i,p_f_i,i_f_i = get_y_loc(x_f_i,I["tx"],I["ty"])
xstart = x_f_i
ystart = info["ypt"][0][j-1][1]
istart = i_f_i
# determine end
if j == info["n"]:
# determine the xy location of the fillet end
x_f_i = info["tw"] - info["t"]
y_f_i,p_f_i,i_f_i = get_y_loc(x_f_i,I["tx"],I["ty"])
xend = x_f_i
yend = y_tri_top
iend = i_f_i
else:
# determin xy location and index of arc begin
x_f_i = info["xpt"][0][j][0]
y_f_i,p_f_i,i_f_i = get_y_loc(x_f_i,I["tx"],I["ty"])
xend = x_f_i
yend = info["ypt"][0][j][0]
iend = i_f_i
# solve for points
x_rofl[i][j] = np.linspace(xstart,xend,num=10)
y_rofl[i][j] = I["t"](x_rofl[i][j])
# add the start y
y_rofl[i][j][0] = ystart
# add end y
y_rofl[i][j][-1] = yend
# if solving for the floors (excluding first)
elif j >= 1:
# determine start
# determin xy location and index of arc begin
x_f_i = info["xpt"][1][j-1][1]
y_f_i,p_f_i,i_f_i = get_y_loc(x_f_i,I["bx"],I["by"])
xstart = x_f_i
ystart = info["ypt"][1][j-1][1]
istart = i_f_i
# determine end
if j == info["n"]:
# determine the xy location of the fillet end
x_f_i = info["tw"] - info["t"]
y_f_i,p_f_i,i_f_i = get_y_loc(x_f_i,I["bx"],I["by"])
xend = x_f_i
yend = y_tri_bot
iend = i_f_i
else:
# determin xy location and index of arc begin
x_f_i = info["xpt"][1][j][0]
y_f_i,p_f_i,i_f_i = get_y_loc(x_f_i,I["bx"],I["by"])
xend = x_f_i
yend = info["ypt"][1][j][0]
iend = i_f_i
# solve for points
x_rofl[i][j] = np.linspace(xstart,xend,num=10)
y_rofl[i][j] = I["b"](x_rofl[i][j])
# add the start y
y_rofl[i][j][0] = ystart
# add end y
y_rofl[i][j][-1] = yend
return x_rofl,y_rofl
# determine where a linear line crosses an interpolation line
def crossing(xy,m,b,is_top=True):
# solve for if top or bottom
if is_top:
loc = "t"
else:
loc = "b"
# create function to find where the crossing occurs
def func(x):
return m*x+b - xy[loc](x)
# set min and max values for bisect
minx = np.min(xy[loc+"x"])
maxx = np.max(xy[loc+"x"])
# run bisect function to find point
x_cross = Bisect(func,minx,maxx)
# solve for the y value and the index of the crossing
y_cross = xy[loc](x_cross)
_,_,i_cross = get_y_loc(x_cross,xy[loc+"x"],xy[loc+"y"])
return x_cross,y_cross,i_cross
# create wing box
def wing_box(I,im,info):
# initialize wing box info
x_box = np.zeros((26,),dtype=np.ndarray)
y_box = np.zeros((26,),dtype=np.ndarray)