-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplacer_c18.py
1755 lines (1419 loc) · 57.2 KB
/
placer_c18.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
import numpy as np
import json
import dxf
import os
import C18_geometry as C18
import zbump_nonmorphing as zmorph
from scipy import interpolate as interp
import machupX as mx
import airfoil_db as adb
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# 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
# read in MachUpX distributions file
def read_dist(filename):
# initialize data dictionary
info = []
# open file
with open(filename,"r") as fn:
col_names = fn.readline()
# read in data
for line in fn:
info.append([float(point) for point in line.split()[2:]])
# make a numpy 2d array
info = np.matrix(info)
# close file
fn.close()
return info
def read_dist_new(filename):
# read in file
dist_dict = read_json(filename)
# fin the length of each list
length = len(dist_dict["chord"])
# initialize array
dist = np.zeros((length,5))
# add parts
dist[:,0] = np.array(dist_dict["cpx"])
dist[:,1] = np.array(dist_dict["cpy"])
dist[:,2] = np.array(dist_dict["cpz"])
dist[:,3] = np.array(dist_dict["chord"])
dist[:,4] = np.array(dist_dict["dihedral"])
return dist
# read in text file
def read_text(filename):
# initialize data dictionary
info = []
# open file
with open(filename,"r") as fn:
# read column names
col_names = fn.readline()
# read in data
for line in fn:
info.append([float(point) for point in line.split()])
# make a numpy 2d array
info = np.array(info)
# split off x and y
x = np.array([info[:,0]])
y = np.array([info[:,1]])
z = np.array([info[:,2]])
# close file
fn.close()
return x,y,z
# create dist dictionary
def get_dist(vals):
# read in distributions file
dist_filename = vals["distributions file"]
if dist_filename[-5:] == ".dist":
dist = read_dist_new(dist_filename)
elif dist_filename[-4:] == ".txt":
dist = read_dist(dist_filename)
# remove all but control point, chord, and dihedral
dist = dist[:,1:7]
dist = np.delete(dist,4,axis=1)
# where the y value is negative (ie, left wing)
# make dihedral negative
for i in range(dist.shape[0]):
if dist[i,1] < 0.0:
dist[i,4] *= -1.
# put units for cpx,cpy,cpz,chord in terms of inches and scale them
dist[:,:4] *= 12. * vals["scale"]
# scale specific values in the vals dictionary
for i in range(len(vals["ducted fan cg [in]"])):
vals["ducted fan cg [in]"][i] *= vals["scale"]
for i in range(len(vals["ducted fan diameter, width, and length [in]"])):
vals["ducted fan diameter, width, and length [in]"][i] *= vals["scale"]
vals["z bump"]["ducted fan cover thickness [in]"] *= vals["scale"]
vals["z bump"]["ducted fan cg shift [in]"] *= vals["scale"]
for i in range(len(vals["z bump"]["span range Behind [in]"])):
vals["z bump"]["span range Behind [in]"][i] *= vals["scale"]
for i in range(len(vals["z bump"]["span range Over [in]"])):
vals["z bump"]["span range Over [in]"][i] *= vals["scale"]
for i in range(len(vals["z bump"]["span range Front [in]"])):
vals["z bump"]["span range Front [in]"][i] *= vals["scale"]
# print(vals["z bump"])
vals["wing tip y start [in]"] *= vals["scale"]
# create dxf file of lines that can be used to define planes
# determine where the "mid point" lies -- index of last negative y value
index = np.max(np.argwhere(dist[:,1] < 0.0)[:,0])
# input a distribution for 0 if not there
if not dist[index+1,1] == 0.0:
# create cubic interpolations of each unit in dist as function of y (span)
cubic = interp.interp1d
x = []; y = []; z = []; c = []; d = []
for i in range(dist.shape[0]):
x.append(dist[i,0])
y.append(dist[i,1])
z.append(dist[i,2])
c.append(dist[i,3])
d.append(dist[i,4])
x_y = cubic(y,x,kind="cubic")
z_y = cubic(y,z,kind="cubic")
c_y = cubic(y,c,kind="cubic")
d_y = cubic(y,d,kind="cubic")
dist = np.insert(dist,index+1,np.array([x_y(0.0),0.0,z_y(0.0),\
c_y(0.0),0.0]),axis=0)
# set start from index
start = index + 1
# create dimension specifier
if vals["dxf"]["2D"]:
dim = "_2D"
else:
dim = "_3D"
# create a folder in the desired directory for output files
folder = vals["dxf"]["file path"]+vals["dxf"]["folder name"]+dim+"/"
# if not os.path.isdir(folder[:-1]):
# os.mkdir(folder[:-1])
# save folder path
vals["C18"]["dxf file path"] = folder
return dist,start,folder
# translate guides
def translate_guides(guides,dist,i):
# translate C18 guides
for q in range(guides.shape[0]):
# mirror across x axis
guides[q][:,0] *= -1
# flip iy and iz
ia = guides[q][:,1] * -1.; guides[q][:,1] = guides[q][:,2] * 1.
guides[q][:,2] = ia * 1.
# rotate by the dihedral
ry = guides[q][:,1]*np.cos(dist[i,4]) + \
guides[q][:,2]*np.sin(dist[i,4])
rz = guides[q][:,2]*np.cos(dist[i,4]) - \
guides[q][:,1]*np.sin(dist[i,4])
guides[q][:,2] = rz; guides[q][:,1] = ry
# shift to the c/4 point
guides[q][:,0] += dist[i,0]
guides[q][:,1] += dist[i,1]
guides[q][:,2] += dist[i,2]
return guides
# determine x shift value
def get_x_shift(i,dist):
# determine slope of plane
m = np.cos(dist[i,4]) / - np.sin(dist[i,4])
# read in y and z values
yval = dist[i,1]
zval = dist[i,2]
# determine intercept and diagonal values
b = zval - m * yval
d = np.abs(b) * np.cos(dist[i,4])
# calculate normal point values ( of origin)
vval = d * np.sin(np.abs(dist[i,4]))
wval = b + d * np.cos(np.abs(dist[i,4]))
# calculate x shift
xshift = ((vval-yval)**2. + (wval-zval)**2.)**0.5
return xshift
# transform the 2D x y arrays for the 2D dxf file
def transform_2D(x,y,dist,i,index,out_arrays=False):
### determine 2D values of the shape
# mirror airfoil across y axis
x2d = -1. * x
# rotate by 90 degrees around origin
rx2d = y*-1.
ry2d = x2d*1.
x2d = rx2d; y2d = ry2d
# determine how much to shift down due to dihedral
# shift back x and y
if not dist[i,4] == 0.0:
# solve for shift value
xshift = get_x_shift(i,dist)
xsshift = get_x_shift(index,dist)
# add x shift and y shift to proper arrays
if out_arrays:
x2d += xsshift
y2d += dist[index,0]
else:
x2d += xshift
y2d += dist[i,0]
return x2d,y2d
# transform the 3D x y z arrays for the 3D dxf file and plotting
def transform_3D(x,y,z,dist,i,index,out_arrays=False):
### determine 3D values of the shape
# mirror across x axis
x3d = -1. * x
# flip iy and iz
a3d = y * -1.; y3d = z * 1.; z3d = a3d * 1.
# rotate by the dihedral
ry3d = y3d*np.cos(dist[i,4]) + z3d*np.sin(dist[i,4])
rz3d = z3d*np.cos(dist[i,4]) - y3d*np.sin(dist[i,4])
z3d = rz3d; y3d = ry3d
# shift to the c/4 point
if out_arrays:
x3d += dist[index,0]
y3d += dist[index,1]
z3d += dist[index,2]
else:
x3d += dist[i,0]
y3d += dist[i,1]
z3d += dist[i,2]
return x3d,y3d,z3d
# make cubic interpolations for later use
def make_interpolations(dist,vals):
# create cubic interpolations of each unit in dist as function of y (span)
cubic = interp.interp1d
x = []; y = []; z = []; c = []; d = []
for i in range(dist.shape[0]):
x.append(dist[i,0])
y.append(dist[i,1])
z.append(dist[i,2])
c.append(dist[i,3])
d.append(dist[i,4])
vals["x(y)"] = cubic(y,x,kind="cubic")
vals["z(y)"] = cubic(y,z,kind="cubic")
vals["c(y)"] = cubic(y,c,kind="cubic")
vals["d(y)"] = cubic(y,d,kind="cubic")
# initialize lengths var list, ismorphing bool list, and section anme list
b = [0.0]
ismorphing = [True]
name = ["bay"]
spec = ["bay"]
# determine lengths
# determine where the fan portion starts
b.append(vals["ducted fan cg [in]"][1]-\
vals["ducted fan diameter, width, and length [in]"][1]/2.)
ismorphing.append(False); name.append("fan"); spec.append("fan")
# determine where the fan portion ends
b.append(vals["ducted fan cg [in]"][1]+\
vals["ducted fan diameter, width, and length [in]"][1]/2.)
ismorphing.append(True); name.append("servo00"); spec.append("sv0")
# determine the servo lengths
n = vals["actuators per semispan"]
for i in range(1,n):
b.append((vals["wing tip y start [in]"] - b[2])/n*i + b[2])
ismorphing.append(True)
name.append("servo{}".format(str(i).zfill(2)))
spec.append("sv{}".format(str(i).zfill(1)))
# add the last two points, the start and end of the wing tips
b.append(vals["wing tip y start [in]"])
ismorphing.append(False); name.append("wingtip"); spec.append("wtp")
b.append(dist[-1,1])
# save to vals
b = np.array(b)
# for j in range(b.shape[0]-1):
# print("{:<8} {:>5.2f} {:>5.2f} {:>5.2f}".format(name[j],b[j],b[j+1],b[j+1]-b[j]))
print("chord at sv[-1] tip is {}".format(vals["c(y)"](b[-2])))
# initialize important things
vals["b"] = b
vals["is morphing"] = ismorphing
vals["name"] = name
vals["spec"] = spec
# create array of kinks start and end values
# determine kink start and end percentages
start = vals["C18"]["flex start [x/c]"]
end = vals["C18"]["TE wall start [x/c]"]
# determine start and end x values
x0 = vals["x(y)"](b) - (start-0.25) * vals["c(y)"](b)
x1 = vals["x(y)"](b) - (end-0.25) * vals["c(y)"](b)
# initialize kink0 and kink1 lists
vals["kink0"] = []; vals["kink1"] = []
# run through each group and determine the min x0 value and max x1
for i in range(x0.shape[0]-1):
vals["kink0"].append(min(x0[i],x0[i+1]))
vals["kink1"].append(max(x1[i],x1[i+1]))
# turn into numpy arrays
vals["kink0"] = np.array(vals["kink0"])
vals["kink1"] = np.array(vals["kink1"])
skin = vals["C18"]["shell thickness [mm]"] / 25.4
n_kinks = vals["C18"]["num kinks"]
# create bool array of whether a straightened kink could be made
greater = vals["kink0"] > vals["kink1"]
skinfit = (vals["kink0"] - vals["kink1"]) > skin * n_kinks
vals["can straighten"] = np.logical_and(greater,skinfit)
return
# create 3d, 2d, and guidecurves
def make_shapes(dist,start,vals):
# # report index after which the airframe can be airfoils
# i_wingtip = np.argwhere(dist[:,1] >= vals["wing tip y start [in]"])[0][0]
# i_wingtip -= start
# print("Airfoils allowed at dist file shape index {}".format(i_wingtip))
print()
# save former values
vals["c0"] = vals["C18"]["chord [in]"]
vals["t0"] = vals["C18"]["tongue start [in]"]
vals["m0"] = vals["C18"]["mouth start [in]"]
# set "max" vals
c_ymax = vals["c(y)"](vals["wing tip y start [in]"])
vals["C18"]["chord [in]"] = c_ymax
vals["C18"]["tongue start [in]"] = c_ymax * vals["t0"]/vals["c0"]
vals["C18"]["mouth start [in]"] = c_ymax * vals["m0"]/vals["c0"]
try:
C18.main(vals)
except:
raise ValueError("C18 geometry cannot be created at wing tip y start"\
+ "with c={0}, t={1}, and m={2}".format(vals["C18"]["chord [in]"],\
vals["C18"]["tongue start [in]"],\
vals["C18"]["mouth start [in]"]))
vals["start"] = start
# report
print("Creating {} shape...".format(vals["distributions file"].split(".")\
[0]))
print()
# initialize counter index
j = 0
first_airfoil = True
# create airfoil shape
add = {}
add["geometry"] = {}
add["geometry"]["type"] = "outline_points"
add["geometry"]["outline_points"] = \
vals["C18"]["airfoil dat file location"]
# initialize airfoil database
foil = adb.Airfoil("foil",add)
coords = foil.get_outline_points()
x = coords[:,0]; y = coords[:,1]
# ensure the airfoil is closed
x0 = x[0]; x1 = x[-1]
if not x0 == x1:
if x0 > x1:
x = np.append(x,x[0])
y = np.append(y,y[0])
else:
x = np.insert(x,0,x[-1])
y = np.insert(y,0,y[-1])
# determine camberline values
x_cam = 0.25; y_cam = 0#foil.get_camber(x_cam)
# Dallin airfoil shape
vals["x zb-af"] = x - x_cam
vals["y zb-af"] = y - y_cam
# save to airfoil shape
x = np.array([x[:100],x[99:]]) - x_cam
y = np.array([y[:100],y[99:]]) - y_cam
# save to vals
vals["x af"] = x
vals["y af"] = y
# initialize pointer list
C18_guides = []; af_guides = []; inn_guides = []
ax = []; ay = []; az = []; afxs = []; afys = []; afzs = []
vals["ton tip"] = []
# initialize part counter
part = 0
# create a dxf file at each plane for the morphing shape
for i in range(start,dist.shape[0]):
# initilize info dictionary to calculate C18
# set values
vals["C18"]["chord [in]"] = dist[i,3]
vals["C18"]["tongue start [in]"] = dist[i,3] * vals["t0"]/vals["c0"]
vals["C18"]["mouth start [in]"] = dist[i,3] * vals["m0"]/vals["c0"]
# determine start and end vals
if dist[i,1] > vals["b"][part+1]:
part += 1
# change kink start and end values
if vals["straighten kinks"] and vals["can straighten"][part] and part == 0:
skink = (dist[i,0] - vals["kink0"][part]) / dist[i,3] + 0.25
ekink = (dist[i,0] - vals["kink1"][part]) / dist[i,3] + 0.25
vals["C18"]["kinks start [x/c]"] = skink
vals["C18"]["kinks end [x/c]"] = ekink
vals["C18"]["straighten TE"] = True
else:
if "kinks start [x/c]" in vals["C18"]:
vals["C18"].pop("kinks start [x/c]",None)
if "kinks end [x/c]" in vals["C18"]:
vals["C18"].pop("kinks end [x/c]",None)
# print(vals["C18"]["chord [in]"],vals["C18"]["tongue start [in]"],\
# vals["C18"]["mouth start [in]"])
# C18.main(vals)
try:
ix,iy,iz,isx,isy,isz,guides,kinksgc = C18.main(vals)
except:
# initialize x y z arrays
ix = x * dist[i,3] #
iy = y * dist[i,3] #
iz = iy * 0.
# if this is the first failed airfoil, make an airfoil of the last
if first_airfoil:
isx = x * dist[i-1,3] #
isy = y * dist[i-1,3] #
isz = iy * 0.
first_airfoil = False
else: # otherwise, make them zeros.
isx = 0.; isy = 0.; isz = 0.
# run through each line and spit out how many points is in the file
num_points = 0
for n in range(ix.shape[0]):
num_points += ix[n].shape[0]
# report file study
print("Airfoil c = {:>7.4f} [in] with {:>4d} points {:>2d}/{}".\
format(dist[i,3],num_points,j,dist.shape[0]-start-1))
extra = " airfoil"; out = " airfoil"
else:
# run through each line and spit out how many points is in the file
num_points = 0
for n in range(ix.shape[0]):
num_points += ix[n].shape[0]
# report file study
print("C18 geo c = {:>7.4f} [in] with {:>4d} points {:>2d}/{}".\
format(dist[i,3],num_points,j,dist.shape[0]-start-1))
extra = ""; out = " out"
# translate guides
guides = translate_guides(guides,dist,i)
kinksgc["inn gc"] = np.array([kinksgc["inn gc"]]) # for future use
kinksgc["inn gc"] = translate_guides( kinksgc["inn gc"],dist,i)[0]
# add to list
C18_guides.append(guides)
inn_guides.append(kinksgc["inn gc"])
vals["ton tip"].append(kinksgc["ton tip"])
# arfoil coords
afx = x * dist[i,3] #
afy = y * dist[i,3] #
afz = y * 0.
# initialize guide curve
af_guide = np.zeros((2,3))
imax = 0
imin = 0
af_guide[0,0] = afx[0][imax]; af_guide[1,0] = afx[1][imin]
af_guide[0,1] = afy[0][imax]; af_guide[1,1] = afy[1][imin]
# translate airfoil guides
af_guide = np.array([af_guide])
translate_guides(af_guide,dist,i)
af_guide = af_guide[0]
# add to list
af_guides.append(af_guide)
# save index for future use
index = i
if not first_airfoil:
index = i-1
### determine 3D values of the shape
ix3d,iy3d,iz3d = transform_3D( ix, iy, iz,dist,i,index)
afx3d,afy3d,afz3d = transform_3D(afx,afy,afz,dist,i,index)
# append original shape for plotting
ax.append(ix3d); ay.append(iy3d); az.append(iz3d)
afxs.append(afx3d); afys.append(afy3d); afzs.append(afz3d)
# increase count
j += 1
# turn guides array into numpy array
C18_guides = np.array(C18_guides)
inn_guides = np.array(inn_guides)
af_guides = np.array(af_guides)
# turn ton tip into interpolations
vals["ton tip"] = np.array(vals["ton tip"])
end = start + vals["ton tip"].shape[0]
dar = []; fx = []; fy = []; bx = []; by = []; j = 0
for i in range(start,end):
dar.append(dist[i,1])
fx.append(vals["ton tip"][j,0,0])
fy.append(vals["ton tip"][j,0,1])
bx.append(vals["ton tip"][j,1,0])
by.append(vals["ton tip"][j,1,1])
j += 1
vals["ton tip x(y)"] = interp.interp1d(dar,fx,kind="cubic")
vals["ton tip y(y)"] = interp.interp1d(dar,fy,kind="cubic")
vals["ton mid x(y)"] = interp.interp1d(dar,bx,kind="cubic")
vals["ton mid y(y)"] = interp.interp1d(dar,by,kind="cubic")
# store for future use
apts = [ax,ay,az]
afpts = [afxs,afys,afzs]
print()
return apts,afpts,C18_guides,af_guides,inn_guides
# create C18 guidecurves dxf file
def C18_guides_dxf(C18_guides,vals,folder,specifier):
# NOTE:
# i -- plane #
# j -- hole #
# k -- guide curve
# l -- x, y, or z value
# run through each "hole" and make guide curves
m = 0
for j in range(C18_guides[0].shape[0]):
# initialize extruder guide curves
x_dxf = np.zeros((C18_guides[0][j].shape[0],),dtype=np.ndarray)
y_dxf = np.zeros((C18_guides[0][j].shape[0],),dtype=np.ndarray)
z_dxf = np.zeros((C18_guides[0][j].shape[0],),dtype=np.ndarray)
# run through each guide curve
for k in range(C18_guides[0][j].shape[0]): # 1): #
# initialize plane lists
x_list = []; y_list = []; z_list = []
# run through each plane
for i in range(C18_guides.shape[0]):
x_list.append(C18_guides[i][j][k][0])
y_list.append(C18_guides[i][j][k][1])
z_list.append(C18_guides[i][j][k][2])
# add to dxf as numpy arrays
x_dxf[k] = np.array(x_list)
y_dxf[k] = np.array(y_list)
z_dxf[k] = np.array(z_list)
# save as a dxf file
if m == 0:
step = "00_"
else:
step = "OP_"
file_location = folder + step + specifier + "_mn"+ str(m).zfill(2)\
+ "_GC"
dxf.dxf(file_location,x_dxf,y_dxf,z_dxf,geometry="spline")
m += 1
return
# create kink guidecurves dxf file
def kink_guides_dxf(kink_guides,vals,folder,specifier):
# NOTE:
# i -- plane #
# j -- hole #
# k -- guide curve
# l -- x, y, or z value
# determine how many kinks guide curves to make
num = kink_guides[0].shape[0] * kink_guides[0][0].shape[0]
# initialize extruder guide curves
x_dxf = np.zeros((num,),dtype=np.ndarray)
y_dxf = np.zeros((num,),dtype=np.ndarray)
z_dxf = np.zeros((num,),dtype=np.ndarray)
# run through each kink and make guide curves
m = 0
for j in range(kink_guides[0].shape[0]):
# run through each guide curve
for k in range(kink_guides[0][j].shape[0]): # 1): #
# initialize plane lists
x_list = []; y_list = []; z_list = []
# run through each plane
for i in range(kink_guides.shape[0]):
x_list.append(kink_guides[i][j][k][0])
y_list.append(kink_guides[i][j][k][1])
z_list.append(kink_guides[i][j][k][2])
# add to dxf as numpy arrays
x_dxf[m] = np.array(x_list)
y_dxf[m] = np.array(y_list)
z_dxf[m] = np.array(z_list)
m += 1
# save as a dxf file
file_location = folder + "04_" + specifier + "_kink_GC"
dxf.dxf(file_location,x_dxf,y_dxf,z_dxf,geometry="spline")
return
# create airfoil wing tip guidecurves dxf file
def af_guides_dxf(af_guides,vals,folder,specifier,typ="main"):
# NOTE:
# i -- plane #
# k -- guide curve
# l -- x, y, or z value
# initialize extruder guide curves
x_dxf = np.zeros((af_guides[0].shape[0],),dtype=np.ndarray)
y_dxf = np.zeros((af_guides[0].shape[0],),dtype=np.ndarray)
z_dxf = np.zeros((af_guides[0].shape[0],),dtype=np.ndarray)
# run through each guide curve
for k in range(af_guides[0].shape[0]): # 1): #
# initialize plane lists
x_list = []; y_list = []; z_list = []
# run through each plane
for i in range(af_guides.shape[0]):
x_list.append(af_guides[i][k][0])
y_list.append(af_guides[i][k][1])
z_list.append(af_guides[i][k][2])
# add to dxf as numpy arrays
x_dxf[k] = np.array(x_list)
y_dxf[k] = np.array(y_list)
z_dxf[k] = np.array(z_list)
# save as a dxf file
if typ == "KIhl":
step = "01_"
elif typ == "LEhl":
step = "02_"
else:
step = "00_"
file_location = folder + step + specifier + "_" + typ + "_GC"
dxf.dxf(file_location,x_dxf,y_dxf,z_dxf,geometry="spline")
return
# create cylinders to help guide pieces together
def make_cylinders(vals,chord=12,is_hole = True,is_bay = False):
# initialize x y z arrays
num = 2 + 2 * is_bay
x = np.zeros((num,),dtype=np.ndarray)
y = np.zeros((num,),dtype=np.ndarray)
z = np.zeros((num,),dtype=np.ndarray)
# initialize is_peg bool
is_peg = not is_hole
# initialize circle radius # 0.3" on 12" chord
rad = 0.3 / 12 + (0.0/25.4*is_hole - 0.5/25.4*is_peg) / chord
# initialize theta array
theta = np.linspace(0,2*np.pi,num=vals["C18"]["num kink points"])
# initialize radius array
r = np.full(theta.shape,rad)
# run through each and create a circle
x_center = 0; y_center = 0
for i in range(2):
# initialize circle center
x_center += vals["C18"]["flex start [x/c]"] / 3.
# save arrays
x[i] = r * np.cos(theta) + x_center
y[i] = r * np.sin(theta) + y_center
z[i] = r * 0.
# save arrays if bay
if is_bay:
x[i+2] = (r+1.0/25.4/chord) * np.cos(theta) + x_center
y[i+2] = (r+1.0/25.4/chord) * np.sin(theta) + y_center
z[i+2] = (r+1.0/25.4/chord) * 0.
# shift back by quarter chord
x -= 0.25
# resize by chord
x *= chord; y *= chord; z *= chord
return x,y,z
# determine start and end shapes for each part of Horizon
def make_parts(dist,vals,airframe_guidecurves):
# draw out airframe guidecurves
C18_afm,af_afm,inn_afm = airframe_guidecurves
# initialize important things
b = vals["b"]
ismorphing = vals["is morphing"]
name = vals["name"]
spec = vals["spec"]
# create new dist array which can have all the b values interpolated
bist = np.zeros((b.shape[0],5))
bist[:,0] = vals["x(y)"](b)
bist[:,1] = b
bist[:,2] = vals["z(y)"](b)
bist[:,3] = vals["c(y)"](b)
bist[:,4] = vals["d(y)"](b)
# run through each b value and determine the index just before in the dist
# file
dist_inds = []
for val in b:
inds = np.argwhere(val <= dist[:,1])[0][0]
dist_inds.append(inds-vals["start"])
dist_inds = np.array(dist_inds)
# initialize to plot lists
xplt = []; yplt = []; zplt = []
# create dxf files for each section
for i in range(len(name)):
# report
print("Creating {:<7} files".format(name[i]))
# ROOT
if ismorphing[i]:
# set values
vals["C18"]["chord [in]"] = bist[i,3]
vals["C18"]["tongue start [in]"] = bist[i,3] * \
vals["t0"]/vals["c0"]
vals["C18"]["mouth start [in]"] = bist[i,3] * \
vals["m0"]/vals["c0"]
# change kink start and end values
if vals["straighten kinks"] and vals["can straighten"][i] and \
name[i] == "bay":
skink = (bist[i,0] - vals["kink0"][i]) / bist[i,3] + 0.25
ekink = (bist[i,0] - vals["kink1"][i]) / bist[i,3] + 0.25
vals["C18"]["kinks start [x/c]"] = skink
vals["C18"]["kinks end [x/c]"] = ekink
vals["C18"]["straighten TE"] = True
else:
skink = vals["C18"]["flex start [x/c]"]
ekink = vals["C18"]["TE wall start [x/c]"]
vals["C18"]["kinks start [x/c]"] = skink
vals["C18"]["kinks end [x/c]"] = ekink
# calculate C18 shape values
ix,iy,iz,isx,isy,isz,guides_rt,kinksgc_rt = C18.main(vals)
# translate guide curve shapes
guides_rt = translate_guides(guides_rt,bist,i)
kinksgc_rt["inn gc"] = np.array([kinksgc_rt["inn gc"]])
kinksgc_rt["inn gc"] = translate_guides(kinksgc_rt["inn gc"],\
bist,i)[0]
# initialize inx and iny and inz
inx = kinksgc_rt["x inner"]; iny = kinksgc_rt["y inner"];inz = 0.*iny
else:
# initialize x y z arrays
ix = vals["x af"] * bist[i,3] #
iy = vals["y af"] * bist[i,3] #
iz = iy * 0.
# initialize guide curve
af_guide_rt = np.zeros((2,3))
imax = 0
imin = 0
af_guide_rt[0,0] = ix[0][imax]; af_guide_rt[1,0] = ix[1][imin]
af_guide_rt[0,1] = iy[0][imax]; af_guide_rt[1,1] = iy[1][imin]
# translate airfoil guide_rts
af_guide_rt = np.array([af_guide_rt])
translate_guides(af_guide_rt,bist,i)
af_guide_rt = af_guide_rt[0]
# initialize cyx and cyy and cyz
cyx,cyy,cyz = make_cylinders(vals,bist[i,3],is_hole=True,is_bay=i==0)
if name[i] == "bay":
pyx,pyy,pyz = make_cylinders(vals,bist[i,3],is_hole=False)
# manipulate arrays based on whether 2D or 3D desired
ix3d,iy3d,iz3d = transform_3D(ix,iy,iz,bist,i,i)
xplt.append(ix3d); yplt.append(iy3d); zplt.append(iz3d)
if vals["dxf"]["2D"]:
ix,iy = transform_2D(ix,iy,bist,i,i)
cyx,cyy = transform_2D(cyx,cyy,bist,i,i)
if ismorphing[i]:
isx,isy = transform_2D(isx,isy,bist,i,i)
inx,iny = transform_2D(inx,iny,bist,i,i)
if name[i] == "bay":
pyx,pyy = transform_2D(pyx,pyy,bist,i,i)
else:
ix = ix3d; iy = iy3d; iz = iz3d
cyx,cyy,cyz = transform_3D(cyx,cyy,cyz,dist,i,vals)
if ismorphing[i]:
isx,isy,isz = transform_3D(isx,isy,isz,bist,i,i)
inx,iny,inz = transform_3D(inx,iny,inz,bist,i,i)
if name[i] == "bay":
pyx,pyy,pyz = transform_3D(pyx,pyy,pyz,bist,i,i)
# create folder for this part
folder = vals["C18"]["dxf file path"]+str(i).zfill(2)+"_"+name[i]+"/"
# specify dxf file type
if ismorphing[i]:
typ = "C18 "
else:
typ = "Airfoil "
airfoil_type = vals["C18"]["airfoil dat file location"].split("/")[-1]\
.split(".")[0]
typ = airfoil_type + " " + typ
# arrange file info for dxf file
file_info = [
typ + "geometry with chord length {:>7.4f} [in]".format(bist[i,2]),
"control point at ({:>7.4f},{:>7.4f},{:>7.4f}) [in]".format(\
bist[i,0],bist[i,1],bist[i,2])
]
# create dxf file
if ismorphing[i]:
step_gm = "OP_"
step_pg = "02_"
else:
step_gm = "00_"
step_pg = "01_"
# main geometry file
dxf.dxf(folder+step_gm+spec[i]+"_main_"+str(i).zfill(2),ix,iy,iz,\
file_info=file_info)
# pegs file
dxf.dxf(folder+step_pg+spec[i]+"_pegs_"+str(i).zfill(2),cyx,cyy,cyz,\
file_info=file_info)
if ismorphing[i]:
# outer geometry file
dxf.dxf(folder+"00_"+spec[i]+"_oute_"+str(i).zfill(2),isx,isy,isz,\
file_info=file_info)
# kinkS hole
dxf.dxf(folder+"01_"+spec[i]+"_KIhl_"+str(i).zfill(2),inx,iny,inz,\
file_info=file_info)
if name[i] == "bay":
# pegs file
dxf.dxf(folder+step_pg+"cen_pegs_"+str(i).zfill(2),pyx,pyy,\
pyz,file_info=file_info)
# TIP
if ismorphing[i]:
# set values
vals["C18"]["chord [in]"] = bist[i+1,3]
vals["C18"]["tongue start [in]"] = bist[i+1,3] * \
vals["t0"]/vals["c0"]
vals["C18"]["mouth start [in]"] = bist[i+1,3] * \
vals["m0"]/vals["c0"]
# change kink start and end values
if vals["straighten kinks"] and vals["can straighten"][i] and\
name[i] == "bay":
skink = (bist[i+1,0] - vals["kink0"][i]) / bist[i+1,3] + 0.25
ekink = (bist[i+1,0] - vals["kink1"][i]) / bist[i+1,3] + 0.25
vals["C18"]["kinks start [x/c]"] = skink
vals["C18"]["kinks end [x/c]"] = ekink
vals["C18"]["straighten TE"] = True
else:
skink = vals["C18"]["flex start [x/c]"]
ekink = vals["C18"]["TE wall start [x/c]"]
vals["C18"]["kinks start [x/c]"] = skink
vals["C18"]["kinks end [x/c]"] = ekink
# calculate C18 shape values
ix,iy,iz,isx,isy,isz,guides_tp,kinksgc_tp = C18.main(vals)
# translate guide curve shapes
guides_tp = translate_guides(guides_tp,bist,i+1)
kinksgc_tp["inn gc"] = np.array([kinksgc_tp["inn gc"]])
kinksgc_tp["inn gc"] = translate_guides(kinksgc_tp["inn gc"]\
,bist,i+1)[0]
# initialize inx and iny and inz
inx = kinksgc_tp["x inner"]; iny = kinksgc_tp["y inner"]
inz = 0.*iny
else:
# initialize x y z arrays
ix = vals["x af"] * bist[i+1,3] #
iy = vals["y af"] * bist[i+1,3] #
iz = iy * 0.
# initialize guide curve
af_guide_tp = np.zeros((2,3))
imax = 0
imin = 0
af_guide_tp[0,0] = ix[0][imax]; af_guide_tp[1,0] = ix[1][imin]
af_guide_tp[0,1] = iy[0][imax]; af_guide_tp[1,1] = iy[1][imin]
# translate airfoil guide_tps
af_guide_tp = np.array([af_guide_tp])
translate_guides(af_guide_tp,bist,i+1)
af_guide_tp = af_guide_tp[0]
# initialize cyx and cyy and cyz
cyx,cyy,cyz = make_cylinders(vals,bist[i+1,3],is_hole=False)
# manipulate arrays based on whether 2D or 3D desired
ix3d,iy3d,iz3d = transform_3D(ix,iy,iz,bist,i+1,i+1)
if vals["dxf"]["2D"]:
ix,iy = transform_2D(ix,iy,bist,i+1,i+1)
cyx,cyy = transform_2D(cyx,cyy,bist,i+1,i+1)
if ismorphing[i]:
isx,isy = transform_2D(isx,isy,bist,i+1,i+1)
inx,iny = transform_2D(inx,iny,bist,i+1,i+1)
else:
ix = ix3d; iy = iy3d; iz = iz3d
cyx,cyy,cyz = transform_3D(cyx,cyy,cyz,bist,i+1,i+1)
if ismorphing[i]:
isx,isy,isz = transform_3D(isx,isy,isz,bist,i+1,i+1)
inx,iny,inz = transform_3D(inx,iny,inz,bist,i+1,i+1)
# arrange file info for dxf file
file_info = [
typ + "geometry with chord length {:>7.4f} [in]".format(bist[i+1,3]),
"control point at ({:>7.4f},{:>7.4f},{:>7.4f}) [in]".format(\
bist[i+1,0],bist[i+1,1],bist[i+1,2])
]
# create dxf file
dxf.dxf(folder+step_gm+spec[i]+"_main_"+str(i+1).zfill(2),ix,iy,iz,\
file_info=file_info)
dxf.dxf(folder+step_pg+spec[i]+"_pegs_"+str(i+1).zfill(2),cyx,cyy,cyz,\
file_info=file_info)
if ismorphing[i]:
dxf.dxf(folder+"00_"+spec[i]+"_oute_"+str(i+1).zfill(2),isx,\
isy,isz,file_info=file_info)
dxf.dxf(folder+"01_"+spec[i]+"_KIhl_"+str(i+1).zfill(2),inx,iny,\
inz,file_info=file_info)
# GUIDE CURVES
# determine start and end indices