-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsg2DAirfoil.py
1484 lines (1308 loc) · 61.6 KB
/
sg2DAirfoil.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
# -*- coding: utf-8 -*-
from abaqus import *
from abaqusConstants import *
from part import *
from assembly import *
from mesh import *
from job import *
from utilities import *
import customKernel
import sys
import time
import os
import math
import xml.etree.ElementTree as et
#from convert2sc import *
def createAirfoil(project_name, control_file):
mc = mdb.customData
sec_0 = time.time()
sec_o = sec_0
# Terminate flag
# rf: Read files
# sf: Sketch profile
# st: Sketch partition
# cp: Create part and partition
# ff: Find faces
# im: Import materials
# cs: Create and assign sections
# ao: Assign orientations
# gm: Generate mesh
# cj: Create job and write input
steps = ['rf', 'sf', 'st', 'cp', 'ff', 'im', 'cs', 'ao', 'gm', 'cj']
ns = len(steps)
tnt = 'all'
mesh_size = 0.003
sp_transform = (0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0)
# cwd = os.getcwd() # current working directory
cwd = os.path.dirname(control_file)
os.chdir(cwd)
log_name = os.path.join(cwd, project_name+'.log')
debug_name = os.path.join(cwd, project_name+'.debug')
cae_name = os.path.join(cwd, project_name+'.cae')
model_name = project_name + '_model'
ss_name = project_name + '_sketch_surface'
ps_name = project_name + '_part_surface'
job_name = project_name
abq_input = os.path.join(cwd, job_name+'.inp')
tolerance = 1.0E-05
f_log = open(log_name, 'w')
f_debug = open(debug_name, 'w')
mc.mid_name = {}
mc.mname_id = {}
mc.layups = {} # {id: [total_thickness, [[thickness, layer_type_id], ...]], ...}
mc.lypid_name = {} # {id: 'name'}
mc.lypname_id = {} # {'name': id}
mc.layer_types = {} # {id: [material_id, angle], ...}
mc.lytid_name = {} # {id: 'name}
mc.lytname_id = {} # {'name': id}
# ==========================================================================
# Read files
# ==========================================================================
if (tnt in steps[0:]) or (tnt == 'all'):
time_now = time.strftime('%H:%M:%S', time.localtime())
f_log.write('--> Reading file... ' + time_now + '\n')
milestone('Reading file...')
# print 'Reading file...'
# ----------------------------------------------------------------------
# Read control file
project = et.parse(control_file)
project = project.getroot()
fn_shape = project.find('shapes').text
fn_material = project.find('materials').text
fn_layup = project.find('layups').text
if (not '.xml' in fn_shape) and (not '.XML' in fn_shape):
fn_shape += '.xml'
if (not '.xml' in fn_material) and (not '.XML' in fn_material):
fn_material += '.xml'
if (not '.xml' in fn_layup) and (not '.XML' in fn_layup):
fn_layup += '.xml'
ffn_shape = os.path.join(cwd, fn_shape)
ffn_material = os.path.join(cwd, fn_material)
ffn_layup = os.path.join(cwd, fn_layup)
mc.chord_length = float(project.find('chord_length').text)
mc.twist_angle = float(project.find('twisted_angle').text)
xy_offset = project.find('pitch_axis_yz').text.split()
mc.x_offset = float(xy_offset[0])
mc.y_offset = float(xy_offset[1])
mc.flip = project.find('flip').text
# ----------------------------------------------------------------------
# Read shape file
coord_lps = []
coord_hps = []
sgm_pt_id_lps = [] # [[start_pt, end_pt, layup_id], ...]
sgm_pt_id_hps = []
nwebs = 0
webs = {} # {id: [x, y, angle], ...}
webs_layup = [] # [layup_id, ...]
nfills = 0
fills = {} # {id: [region, material_id], ...}
shape = et.parse(ffn_shape)
assmb = shape.getroot()
for p in assmb:
strct = p.get('structure')
if strct == 'surface':
bl = p.find('baseline')
fmt = bl.get('format')
if fmt == 'lednicer':
lps = bl.find('lps').text.strip().split('\n')
for c in lps:
c = c.split()
coord_lps.append((float(c[0]), float(c[1])))
hps = bl.find('hps').text.strip().split('\n')
for c in hps:
c = c.split()
coord_hps.append((float(c[0]), float(c[1])))
lyp = p.find('layup')
lps = lyp.find('lps').text.strip().split('\n')
for l in lps:
l = l.split()
sgm_pt_id_lps.append([int(l[0]), int(l[1]), int(l[2])])
hps = lyp.find('hps').text.strip().split('\n')
for l in hps:
l = l.split()
sgm_pt_id_hps.append([int(l[0]), int(l[1]), int(l[2])])
elif strct == 'web':
bl = p.find('baseline')
for i, w in enumerate(bl):
w = w.text.split()
webs[i+1] = [float(w[0]), float(w[1]), float(w[2])]
nwebs = len(webs)
lyp = p.find('layup').text.strip().split('\n')
for l in lyp:
webs_layup.append(int(l))
elif strct == 'filling':
for i, f in enumerate(p):
m = f.get('material')
r = f.text
fills[i+1] = [int(r), int(m)]
nfills = len(fills)
# if coord_lps[0] != (0.0, 0.0):
# coord_lps.insert(0, (0.0, 0.0))
# if coord_hps[0] != (0.0, 0.0):
# coord_hps.insert(0, (0.0, 0.0))
# ----------------------------------------------------------------------
# Read materials
tree = et.parse(ffn_material)
mtr_root = tree.getroot()
for mtr in mtr_root:
material_id = int(mtr.find('id').text)
material_name = mtr.find('name').text
material_type = mtr.get('type')
mc.mid_name[material_id] = material_name
mc.mname_id[material_name] = material_id
# ----------------------------------------------------------------------
# Read layups
tree_layup = et.parse(ffn_layup)
root_layup = tree_layup.getroot()
lyt_id = 0
for layup in root_layup:
lyp_id = int(layup.find('id').text)
lyp_name = layup.find('name').text
lyp_data = layup.find('data').text
lyp_data = lyp_data.strip().split('\n')
total_thk = 0.0
temp_layup = []
for l in lyp_data:
l = l.split()
[t, m, a] = [float(l[0]), int(l[1]), float(l[2])]
total_thk += t
lyt_name = mc.mid_name[m] + '_' + str(a)
if lyt_name not in mc.lytname_id.keys():
lyt_id += 1
mc.layer_types[lyt_id] = [m, a]
mc.lytid_name[lyt_id] = lyt_name
mc.lytname_id[lyt_name] = lyt_id
lyp_lyt_id = mc.lytname_id[lyt_name]
temp_layup.append([t, lyp_lyt_id])
mc.layups[lyp_id] = [total_thk, temp_layup]
mc.lypid_name[lyp_id] = lyp_name
mc.lypname_id[lyp_name] = lyp_id
sgm_divpt_lps = []
sgm_divpt_hps = []
try:
for n in range(len(sgm_pt_id_lps) - 1):
ptid = sgm_pt_id_lps[n][1]
c = coord_lps[ptid - 1]
sgm_divpt_lps.append(c)
for n in range(len(sgm_pt_id_hps) - 1):
ptid = sgm_pt_id_hps[n][1]
c = coord_hps[ptid - 1]
sgm_divpt_hps.append(c)
except IndexError:
print 'Please check the dividing point number and the total number of airfoil data points'
coord_lps.reverse()
coord_lps.remove((0.0, 0.0))
coord = coord_lps + coord_hps
# sgm_lps = {}
# sgm_hps = {}
# web_lyp = {}
sec_n = time.time()
f_log.write(' Seconds spent: [{0:8.3f}]s\n'.format((sec_n - sec_o)))
sec_o = sec_n
try:
model = mdb.models[model_name]
except KeyError:
model = mdb.Model(name = model_name)
# ==========================================================================
# Sketch profile
# ==========================================================================
if (tnt in steps[1:]) or (tnt == 'all'):
time_now = time.strftime('%H:%M:%S', time.localtime())
f_log.write('--> Sketching profile... ' + time_now + '\n')
milestone('Sketching profile...')
# print 'Sketching profile...'
trailing_edge = 'Sharp'
fill_side_pts = []
fill_fpt = []
fill_partition_v = []
if coord[-1] == coord[0]: # Open the outline
del coord[-1]
np = len(coord)
pts = tuple(coord)
# ----------------------------------------------------------------------
# Sketch the airfoil surface
sheet_size = mc.chord_length * 2.0
ss = model.ConstrainedSketch(name = ss_name, sheetSize = sheet_size)
sketch = ss
sketch.sketchOptions.setValues(gridOrigin = (0.0, 0.0))
if trailing_edge == 'Straight':
s = sketch.Spline(points = pts)
l = sketch.Line(point1 = pts[-1], point2 = pts[0])
s = (s, l)
elif trailing_edge == 'Sharp':
last_x = (coord[-1][0] + coord[0][0]) / 2.0 # Find the middle of the connecting line between
last_y = (coord[-1][1] + coord[0][1]) / 2.0 # the first and the last point.
pts += ((last_x, last_y),) # Add an extra point.
# print pts
# print len(pts)
s = sketch.Spline(points = pts)
# for i in range(len(sketch.vertices.keys())):
# print sketch.vertices[i]
sketch.FixedConstraint(entity = sketch.vertices[0])
sketch.CoincidentConstraint(entity1 = sketch.vertices[np], # Let the extra point coincide with the first point.
entity2 = sketch.vertices[0])
s = (s,)
elif trailing_edge == 'Round':
pts += ((coord[0][0], coord[0][1]),)
s = sketch.Spline(points = pts)
s = (s,)
cline_h = sketch.ConstructionLine(point1 = (-1.0, 0.0), # Horizontal reference line
point2 = (0.0, 0.0))
sketch.HorizontalConstraint(entity = cline_h)
cline_v = sketch.ConstructionLine(point1 = (0.0, -1.0), # Vertical reference line at the leading edge
point2 = (0.0, 1.0))
sketch.VerticalConstraint(entity = cline_v)
cline_c = sketch.ConstructionLine(point1 = (mc.x_offset, -1.0), # Vertical reference line at the x_offset
point2 = (mc.x_offset, 1.0))
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Make a copy for the mask later
if nwebs != 0:
sm_name = project_name + '_sketch_mask'
sm = model.ConstrainedSketch(name = sm_name,
objectToCopy = model.sketches[ss_name])
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Find dividing points and store construction lines
clines_lps = []
clines_hps = []
for pt in sgm_divpt_lps:
x = pt[0]
y = pt[1]
# if abs(x - 1.0) > tolerance:
dl = sketch.ConstructionLine(point1 = (x, y),
point2 = (x, 0.0))
sketch.VerticalConstraint(entity = dl)
clines_lps.append(dl)
for pt in sgm_divpt_hps:
x = pt[0]
y = pt[1]
# if abs(x - 1.0) > tolerance:
dl = sketch.ConstructionLine(point1 = (x, y),
point2 = (x, 0.0))
sketch.VerticalConstraint(entity = dl)
clines_hps.append(dl)
# Split curves
s0 = s[0]
sketch.breakCurve(curve1 = s0, point1 = (0.0, 0.0),
curve2 = cline_h, point2 = (0.0, 0.0))
g = sketch.geometry
#print g
gk = g.keys()
gk_lps = gk[-2]
gk_hps = gk[-1]
#print gk_lps
#print gk_hps
# --------------------------
# Split low pressure surface
sgm_id_lps_out = []
k = gk_lps
for i in range(len(clines_lps)):
sketch.breakCurve(curve1 = g[k], point1 = sgm_divpt_lps[i],
curve2 = clines_lps[i], point2 = sgm_divpt_lps[i])
g = sketch.geometry
gk = g.keys()
gk_left = gk[-1]
gk_right = gk[-2]
sgm_id_lps_out.append(gk_left)
k = gk_right
sgm_id_lps_out.append(k)
# ---------------------------
# Split high pressure surface
sgm_id_hps_out = []
k = gk_hps
for i in range(len(clines_hps)):
sketch.breakCurve(curve1 = g[k], point1 = sgm_divpt_hps[i],
curve2 = clines_hps[i], point2 = sgm_divpt_hps[i])
g = sketch.geometry
gk = g.keys()
gk_left = gk[-2]
gk_right = gk[-1]
sgm_id_hps_out.append(gk_left)
k = gk_right
sgm_id_hps_out.append(k)
g = sketch.geometry
# ----------------------------
# Flip, Move, Scale and Rotate
g = sketch.geometry
gk = g.keys()
objects_mirror = []
for k in gk:
if k != cline_v.id:
objects_mirror.append(g[k])
objects_all = objects_mirror + [cline_v,]
objects_mirror = tuple(objects_mirror)
objects_all = tuple(objects_all)
if mc.flip == 'Yes':
sketch.mirror(mirrorLine = cline_v,
objectList = objects_mirror)
x_offset_t = mc.x_offset
twist_angle_t = mc.twist_angle
# twist_angle = -1.0 * twist_angle
elif mc.flip == 'No':
x_offset_t = -1.0 * mc.x_offset
twist_angle_t = -1.0 * mc.twist_angle
sketch.move(objectList = objects_all,
vector = (x_offset_t, 0.0))
sketch.scale(objectList = objects_all,
scaleCenter = (0.0, 0.0),
scaleValue = mc.chord_length)
sketch.rotate(objectList = objects_all,
centerPoint = (0.0, 0.0),
angle = twist_angle_t)
g = sketch.geometry
# Get new coordinates of dividing points
sgm_divpt_lps_new = []
for i in sgm_id_lps_out:
vi = g[i].getVertices()
v_near_le = vi[1].coords
v_near_te = vi[0].coords
sgm_divpt_lps_new.append(v_near_le)
sgm_divpt_lps_new.append(v_near_te)
sgm_divpt_hps_new = []
for i in sgm_id_hps_out:
vi = g[i].getVertices()
v_near_le = vi[0].coords
v_near_te = vi[1].coords
sgm_divpt_hps_new.append(v_near_le)
sgm_divpt_hps_new.append(v_near_te)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Make a copy for the fillings later
if nfills != 0:
sf_name = project_name + '_sketch_fill'
sf = model.ConstrainedSketch(name = sf_name,
objectToCopy = model.sketches[ss_name])
# ----------------------------------------------------------------------
# Offset the total thickness of each layup
g = sketch.geometry
sgm_id_lps_in = []
for i, sid in enumerate(sgm_id_lps_out):
s = g[sid]
lyp_id = sgm_pt_id_lps[i][2]
t = mc.layups[lyp_id][0]
if mc.flip == 'No':
sketch.offset(objectList = (s,), distance = t, side = LEFT)
elif mc.flip == 'Yes':
sketch.offset(objectList = (s,), distance = t, side = RIGHT)
g = sketch.geometry
gk = g.keys()
sgm_id_lps_in.append(gk[-1])
g = sketch.geometry
sgm_id_hps_in = []
for i, sid in enumerate(sgm_id_hps_out):
s = g[sid]
lyp_id = sgm_pt_id_hps[i][2]
t = mc.layups[lyp_id][0]
if mc.flip == 'No':
sketch.offset(objectList = (s,), distance = t, side = LEFT)
elif mc.flip == 'Yes':
sketch.offset(objectList = (s,), distance = t, side = RIGHT)
g = sketch.geometry
gk = g.keys()
sgm_id_hps_in.append(gk[-1])
# ----------------------------------------------------------------------
# Trim the trailing edge
g = sketch.geometry
gid_lps = sgm_id_lps_in[-1]
gid_hps = sgm_id_hps_in[-1]
sgm_id_lps_in.remove(sgm_id_lps_in[-1])
sgm_id_hps_in.remove(sgm_id_hps_in[-1])
[new_l, new_h] = trimIntersectCurves(sketch, gid_lps, 2, gid_hps, 1, (1.0, 0.0))
sgm_id_lps_in.append(new_l)
sgm_id_hps_in.append(new_h)
# ----------------------------------------------------------------------
# Get the two vertices for each inner curve
# Get the vertices closer to the outer curve
g = sketch.geometry
v_lps_in = []
for i in sgm_id_lps_in:
# s = segments_offset_curve_lps[i]
s = g[i]
v = s.getVertices()
v_near_le = v[1].coords
v_near_te = v[0].coords
v_lps_in.append([v_near_le, v_near_te])
fill_side_pts.append(v_lps_in[0][0])
v_near_lps = [v_lps_in[0][0]]
for i in range(len(v_lps_in) - 1):
v1 = v_lps_in[i][1]
v2 = v_lps_in[i+1][0]
v0 = sgm_divpt_lps_new[i+1]
d1 = findTwoPointsDistance(v0, v1)
d2 = findTwoPointsDistance(v0, v2)
if d1 < d2:
v_near_lps.append(v1)
elif d1 > d2:
v_near_lps.append(v2)
elif d1 == d2:
v_near_lps.append(v1)
v_near_lps.append(v_lps_in[-1][-1])
v_hps_in = []
for i in sgm_id_hps_in:
# s = segments_offset_curve_hps[i]
s = g[i]
v = s.getVertices()
v_near_le = v[0].coords
v_near_te = v[1].coords
v_hps_in.append([v_near_le, v_near_te])
v_near_hps = [v_hps_in[0][0]]
for i in range(len(v_hps_in) - 1):
v1 = v_hps_in[i][1]
v2 = v_hps_in[i+1][0]
v0 = sgm_divpt_hps_new[i+1]
d1 = findTwoPointsDistance(v0, v1)
d2 = findTwoPointsDistance(v0, v2)
if d1 < d2:
v_near_hps.append(v1)
elif d1 > d2:
v_near_hps.append(v2)
elif d1 == d2:
v_near_hps.append(v1)
v_near_hps.append(v_hps_in[-1][-1])
# Connet inner curve
for i in range(len(v_lps_in) - 1):
v_start = v_lps_in[i][1]
v_end = v_lps_in[i+1][0]
sketch.Line(point1 = v_start, point2 = v_end)
for i in range(len(v_hps_in) - 1):
v_start = v_hps_in[i][1]
v_end = v_hps_in[i+1][0]
sketch.Line(point1 = v_start, point2 = v_end)
g = sketch.geometry
# -----------------------------------------------------------------------
# Sketch the mask
# -----------------------------------------------------------------------
if nwebs != 0:
pt1 = (-mc.chord_length, mc.chord_length)
pt2 = (mc.chord_length, -mc.chord_length)
sm.rectangle(point1 = pt1, point2 = pt2)
gm = sm.geometry
gmk = gm.keys()
objects_mirror = []
for k in gmk:
if k != cline_v.id:
objects_mirror.append(gm[k])
objects_all = objects_mirror + [gm[cline_v.id],]
objects_mirror = tuple(objects_mirror)
objects_all = tuple(objects_all)
if mc.flip == 'Yes':
sm.mirror(mirrorLine = gm[cline_v.id],
objectList = objects_mirror)
x_offset_t = mc.x_offset
twist_angle_t = mc.twist_angle
# twist_angle = -1.0 * twist_angle
elif mc.flip == 'No':
x_offset_t = -1.0 * mc.x_offset
twist_angle_t = -1.0 * mc.twist_angle
sm.move(objectList = objects_all,
vector = (x_offset_t, 0.0))
sm.scale(objectList = objects_all,
scaleCenter = (0.0, 0.0),
scaleValue = mc.chord_length)
sm.rotate(objectList = objects_all,
centerPoint = (0.0, 0.0),
angle = twist_angle_t)
# -----------------------------------------------------------------------
# Sketch the webs
# -----------------------------------------------------------------------
if nwebs != 0:
sw_name = project_name + '_sketch_webs_trim0'
sw = model.ConstrainedSketch(name = sw_name, sheetSize = sheet_size)
sw.sketchOptions.setValues(gridOrigin = (0.0, 0.0))
cline_vw = sw.ConstructionLine(point1 = (0.0, -1.0), # Vertical reference line at the leading edge
point2 = (0.0, 1.0))
ymin = 0.0
ymax = 0.0
for p in coord:
if p[1] < ymin:
ymin = p[1]
if p[1] > ymax:
ymax = p[1]
wcl_id = {}
for k, v in webs.items():
x0 = v[0]
y0 = v[1]
angle = v[2]
angle = math.radians(angle - 90.0)
slope = math.tan(angle)
y1 = 1.5 * ymin
x1 = slope * (y1 - y0) + x0
y2 = 1.5 * ymax
x2 = slope * (y2 - y0) + x0
pt1 = (x1, y1)
pt2 = (x2, y2)
wcl = sw.Line(point1 = pt1, point2 = pt2) # Draw center line of the web
wcl_id[k] = wcl.id
gw = sw.geometry
gwk = gw.keys()
objects_mirror = []
for k in gwk:
if k != cline_vw.id:
objects_mirror.append(gw[k])
objects_all = objects_mirror + [gw[cline_vw.id],]
objects_mirror = tuple(objects_mirror)
objects_all = tuple(objects_all)
if mc.flip == 'Yes':
sw.mirror(mirrorLine = gw[cline_vw.id],
objectList = objects_mirror)
x_offset_t = mc.x_offset
twist_angle_t = mc.twist_angle
# twist_angle = -1.0 * twist_angle
elif mc.flip == 'No':
x_offset_t = -1.0 * mc.x_offset
twist_angle_t = -1.0 * mc.twist_angle
sw.move(objectList = objects_all,
vector = (x_offset_t, 0.0))
sw.scale(objectList = objects_all,
scaleCenter = (0.0, 0.0),
scaleValue = mc.chord_length)
sw.rotate(objectList = objects_all,
centerPoint = (0.0, 0.0),
angle = twist_angle_t)
gw = sw.geometry
web_ept = []
web_eid = []
for k, v in webs.items():
lyp_id = webs_layup[k-1]
tt = mc.layups[lyp_id][0]
t = tt / 2
if mc.flip == 'No':
sw.offset(objectList = (gw[wcl_id[k]],), distance = t, side = LEFT) # Offset the edge near LE
sw.offset(objectList = (gw[wcl_id[k]],), distance = t, side = RIGHT) # Offset the edge near TE
elif mc.flip == 'Yes':
sw.offset(objectList = (gw[wcl_id[k]],), distance = t, side = RIGHT) # Offset the edge near LE
sw.offset(objectList = (gw[wcl_id[k]],), distance = t, side = LEFT) # Offset the edge near TE
gw = sw.geometry
gwk = gw.keys()
# web_id_c = gwk[-3]
web_id_near_le = gwk[-2]
web_id_near_te = gwk[-1]
web_eid.append([web_id_near_le, web_id_near_te])
vle = gw[web_id_near_le].getVertices()
vle1 = vle[0].coords
vle2 = vle[1].coords
vre = gw[web_id_near_te].getVertices()
vte1 = vre[0].coords
vte2 = vre[1].coords
xle = (vle1[0] + vle2[0]) / 2
yle = (vle1[1] + vle2[1]) / 2
xte = (vte1[0] + vte2[0]) / 2
yte = (vte1[1] + vte2[1]) / 2
temp = [(xle, yle), (xte, yte)]
web_ept.append(temp)
sw.Line(point1 = vle1, point2 = vte1)
sw.Line(point1 = vle2, point2 = vte2)
v = gw[wcl_id[k]].getVertices()
v1, v2 = v[0].coords, v[1].coords
fill_partition_v.append([v1, v2])
fill_side_pts.append((xle, yle))
fill_side_pts.append((xte, yte))
sw.delete(objectList = (gw[wcl_id[k]],))
fill_side_pts.append(v_lps_in[-1][-1])
for i in range(len(fill_side_pts)/2):
pt1 = fill_side_pts[2*i]
pt2 = fill_side_pts[2*i+1]
x1, y1 = pt1[0], pt1[1]
x2, y2 = pt2[0], pt2[1]
xf = x1 + (x2 - x1) / 10.0
yf = y1 + (y2 - y1) / 10.0
fill_fpt.append((xf, yf))
sec_n = time.time()
f_log.write(' Seconds spent: [{0:8.3f}]s\n'.format((sec_n - sec_o)))
sec_o = sec_n
# =======================================================================
# Sketch partition
# =======================================================================
if (tnt in steps[2:]) or (tnt == 'all'):
time_now = time.strftime('%H:%M:%S', time.localtime())
f_log.write('--> Sketching partition... ' + time_now + '\n')
milestone('Sketching partition...')
# print 'Sketching partition...'
# Copy the sketch
ssp_name = project_name + '_sketch_surface_layers'
ssp = model.ConstrainedSketch(name = ssp_name,
objectToCopy = model.sketches[ss_name])
sec_3 = sec_o
sec_31 = time.time()
f_log.write(' -> Copy the sketch: ' + str(sec_31 - sec_3) + '\n')
# print ' -> Copy the sketch: ', str(sec_31 - sec_3)
gp = ssp.geometry
ssp.Line(point1 = sgm_divpt_lps_new[0], point2 = v_near_lps[0])
for i in range(1, len(v_near_lps) - 1):
ps = sgm_divpt_lps_new[i]
pe = v_near_lps[i]
ssp.Line(point1 = ps, point2 = pe)
for i in range(1, len(v_near_hps) - 1):
ps = sgm_divpt_hps_new[i]
pe = v_near_hps[i]
ssp.Line(point1 = ps, point2 = pe)
sec_32 = time.time()
f_log.write(' -> Draw segment walls: ' + str(sec_32 - sec_31) + '\n')
# print ' -> Draw segment walls: ', str(sec_32 - sec_31)
gp = ssp.geometry
sgm_lyr_id_lps = []
for i in range(len(sgm_id_lps_out) - 1):
sgm_id = sgm_id_lps_out[i]
sgm_lyr_id_lps.append([sgm_id])
sgm = gp[sgm_id]
lyp_id = sgm_pt_id_lps[i][2]
lyp = mc.layups[lyp_id][1]
t = 0
for j in range(len(lyp) - 1):
t += lyp[j][0]
if mc.flip == 'No':
ssp.offset(objectList = (sgm,), distance = t, side = LEFT)
elif mc.flip == 'Yes':
ssp.offset(objectList = (sgm,), distance = t, side = RIGHT)
gpk = ssp.geometry.keys()
sgm_lyr_id_lps[i].append(gpk[-1])
sgm_lyr_id_lps[i].append(sgm_id_lps_in[i])
sec_33 = time.time()
f_log.write(' -> Draw layers of the lower pressure surface: ' + str(sec_33 - sec_32) + '\n')
# print ' -> Draw layers of the lower pressure surface: ', str(sec_33 - sec_32)
sgm_lyr_id_hps = []
for i in range(len(sgm_id_hps_out) - 1):
sgm_id = sgm_id_hps_out[i]
sgm_lyr_id_hps.append([sgm_id])
sgm = gp[sgm_id]
lyp_id = sgm_pt_id_hps[i][2]
lyp = mc.layups[lyp_id][1]
t = 0
for j in range(len(lyp) - 1):
t += lyp[j][0]
if mc.flip == 'No':
ssp.offset(objectList = (sgm,), distance = t, side = LEFT)
elif mc.flip == 'Yes':
ssp.offset(objectList = (sgm,), distance = t, side = RIGHT)
gpk = ssp.geometry.keys()
sgm_lyr_id_hps[i].append(gpk[-1])
sgm_lyr_id_hps[i].append(sgm_id_hps_in[i])
sec_34 = time.time()
f_log.write(' -> Draw layers of the higher pressure surface: ' + str(sec_34 - sec_33) + '\n')
# print ' -> Draw layers of the higher pressure surface: ', str(sec_34 - sec_33)
gp = ssp.geometry
# Partition sketch for the trailing edge
lyp_id_lps = sgm_pt_id_lps[-1][2]
lyp_id_hps = sgm_pt_id_hps[-1][2]
lyp_lps = mc.layups[lyp_id_lps][1]
lyp_hps = mc.layups[lyp_id_hps][1]
temp_lps_id = sgm_id_lps_out[-1]
temp_hps_id = sgm_id_hps_out[-1]
sgm_lyr_id_lps.append([temp_lps_id])
sgm_lyr_id_hps.append([temp_hps_id])
temp_lps = gp[temp_lps_id]
temp_hps = gp[temp_hps_id]
tl = 0
th = 0
temp_curve_id_list = [temp_lps_id]
for i in range(len(lyp_lps) - 1):
tl += lyp_lps[i][0]
th += lyp_hps[i][0]
if mc.flip == 'No':
ssp.offset(objectList = (temp_lps,), distance = tl, side = LEFT)
ssp.offset(objectList = (temp_hps,), distance = th, side = LEFT)
elif mc.flip == 'Yes':
ssp.offset(objectList = (temp_lps,), distance = tl, side = RIGHT)
ssp.offset(objectList = (temp_hps,), distance = th, side = RIGHT)
gp = ssp.geometry
gpk = gp.keys()
id_1 = gpk[-2]
id_2 = gpk[-1]
[new_id_lps, new_id_hps] = trimIntersectCurves(ssp, id_1, 2, id_2, 1, (1.0, 0.0))
sgm_lyr_id_lps[-1].append(new_id_lps)
sgm_lyr_id_hps[-1].append(new_id_hps)
temp_curve_id_list.append(new_id_lps)
temp_curve_id_list.append(sgm_id_lps_in[-1])
sgm_lyr_id_lps[-1].append(sgm_id_lps_in[-1])
sgm_lyr_id_hps[-1].append(sgm_id_hps_in[-1])
sec_35 = time.time()
f_log.write(' -> Draw layers of the trailing edge: ' + str(sec_35 - sec_34) + '\n')
# print ' -> Draw layers of the trailing edge: ', str(sec_35 - sec_34)
gp = ssp.geometry
for i in range(len(temp_curve_id_list) - 1):
id_1 = temp_curve_id_list[i]
id_2 = temp_curve_id_list[i+1]
v = gp[id_1].getVertices()
v_1 = v[0].coords
v = gp[id_2].getVertices()
v_2 = v[0].coords
ssp.Line(point1 = v_1, point2 = v_2)
sec_36 = time.time()
f_log.write(' -> Draw segment wall of the trailing edge: ' + str(sec_36 - sec_35) + '\n')
# print ' -> Draw segment wall of the trailing edge: ', str(sec_36 - sec_35)
# -----------------------------------------------------------------------
# Sketch partitions for webs
# -----------------------------------------------------------------------
if nwebs != 0:
swp_name = sw_name + '_sketch_webs_layers'
swp = model.ConstrainedSketch(name = swp_name,
objectToCopy = model.sketches[sw_name])
gwp = swp.geometry
web_lyr_pt = [[web_ept[0][0]],[web_ept[1][0]]]
for i in range(len(webs_layup)):
lyp_id = webs_layup[i]
lyp = mc.layups[lyp_id][1]
t = 0.0
for j in range(len(lyp) - 1):
t += lyp[j][0]
if mc.flip == 'No':
swp.offset(objectList = (gwp[web_eid[i][0]],), distance = t, side = RIGHT)
elif mc.flip == 'Yes':
swp.offset(objectList = (gwp[web_eid[i][0]],), distance = t, side = LEFT)
gwp = swp.geometry
gwpk = gwp.keys()
lid = gwpk[-1]
v = gwp[lid].getVertices()
v1 = v[0].coords
v2 = v[1].coords
xm = (v1[0] + v2[0]) / 2
ym = (v1[1] + v2[1]) / 2
web_lyr_pt[i].append((xm, ym))
web_lyr_pt[i].append(web_ept[i][1])
web_lyr_fpt = []
for i in range(len(web_lyr_pt)):
webi = web_lyr_pt[i]
temp = []
for j in range(len(webi) - 1):
vl = webi[j]
vr = webi[j+1]
xm = (vl[0] + vr[0]) / 2
ym = (vl[1] + vr[1]) / 2
temp.append((xm, ym))
web_lyr_fpt.append(temp)
# ----------------------------------------------------------------------
# Sketch partition for fillings
# ----------------------------------------------------------------------
sec_n = time.time()
f_log.write(' Seconds spent: [{0:8.3f}]s\n'.format((sec_n - sec_o)))
sec_o = sec_n
# =======================================================================
# Create part and assembly
# =======================================================================
if (tnt in steps[3:]) or (tnt == 'all'):
time_now = time.strftime('%H:%M:%S', time.localtime())
f_log.write('--> Creating part and assembly... ' + time_now + '\n')
milestone('Creating part and assembly...')
# print 'Creating part and assembly...'
ps_name = project_name + '_part_surface'
ps = createPartYZ(model_name, ps_name)
ps = createFirstShell(model, ps, ss)
ps = partitionPart(model, ps, ssp)
is0_name = ps_name + '-1'
a = model.rootAssembly
a.DatumCsysByDefault(CARTESIAN)
a.Instance(name = is0_name, part = ps, dependent = ON)
pa_name = ps_name
# print pa_name
if nwebs != 0:
sm = model.sketches[sm_name]
sw = model.sketches[sw_name]
swp = model.sketches[swp_name]
pm_name = project_name + '_part_mask'
pw0_name = project_name + '_part_web_trim0'
pm = createPartYZ(model_name, pm_name)
pm = createFirstShell(model, pm, sm)
pw = createPartYZ(model_name, pw0_name)
pw = createFirstShell(model, pw, sw)
pw = partitionPart(model, pw, swp)
# Cut webs by mask
im_name = pm_name + '-1'
iw0_name = pw0_name + '-1'
is1_name = ps_name + '_copy-1'
a.Instance(name = im_name, part = pm, dependent = ON)
a.Instance(name = iw0_name, part = pw, dependent = ON)
a.Instance(name = is1_name, part = ps, dependent = ON)
pw1_name = project_name + '_part_web_trim1'
iw1_name = pw1_name + '-1'
a.InstanceFromBooleanCut(name = pw1_name,
instanceToBeCut = a.instances[iw0_name],
cuttingInstances = (a.instances[im_name],),
originalInstances = DELETE)
pwf_name = project_name + '_part_web'
iwf_name = pwf_name + '-1'
a.InstanceFromBooleanCut(name = pwf_name,
instanceToBeCut = a.instances[iw1_name],
cuttingInstances = (a.instances[is1_name],),
originalInstances = DELETE)
psw_name = pa_name + '_web'
a.InstanceFromBooleanMerge(name = psw_name,
instances = (a.instances[is0_name], a.instances[iwf_name]),
keepIntersections = ON,
originalInstances = DELETE,
domain = GEOMETRY)
del model.parts[ps_name]
del model.parts[pm_name]
del model.parts[pw0_name]
del model.parts[pw1_name]
del model.parts[pwf_name]
pa_name = psw_name
a.regenerate()
if nfills != 0:
pf_name = project_name + '_part_fill_cut0'
pf = createPartYZ(model_name, pf_name)
pf = createFirstShell(model, pf, sf)
d, ff = pf.datums, pf.faces
tf = pf.MakeSketchTransform(sketchPlane = ff[0], sketchUpEdge = d[2],
sketchPlaneSide = SIDE1, origin = (0.0, 0.0, 0.0))
sf1 = model.ConstrainedSketch(name = '__profile__', sheetSize = sheet_size,
transform = tf)
sf1.setPrimaryObject(option = SUPERIMPOSE)
pf.projectReferencesOntoSketch(sketch = sf1, filter = COPLANAR_EDGES)
for vs in fill_partition_v:
pt1, pt2 = vs[0], vs[1]
sf1.Line(point1 = pt1, point2 = pt2)
pf.PartitionFaceBySketch(faces = tuple(ff), sketchUpEdge = d[2], sketch = sf1)
sf1.unsetPrimaryObject()
del sf1
fill_fpt_del = fill_fpt[:]
fill_fpt = {}
for i in range(len(fills.keys())):
fno = fills[i+1][0]
fill_fpt[i+1] = fill_fpt_del[fno-1]
del fill_fpt_del[fno-1]
ff = pf.faces
for pt in fill_fpt_del:
pt = (0.0,) + pt
fff = ff.findAt(coordinates = pt)
pf.RemoveFaces(faceList = (fff,), deleteCells = False)
psw = model.parts[pa_name]
isw_name = psw_name + '-1'
isw1_name = psw_name + '_copy-1'
if1_name = pf_name + '-1'
a.Instance(name = isw1_name, part = psw, dependent = ON)
a.Instance(name = if1_name, part = pf, dependent = ON)
pff_name = project_name + '_part_fill'
iff_name = pff_name + '-1'
a.InstanceFromBooleanCut(name = pff_name,
instanceToBeCut = a.instances[if1_name],
cuttingInstances = (a.instances[isw1_name],),
originalInstances = DELETE)
pswf_name = pa_name + '_fill'
a.InstanceFromBooleanMerge(name = pswf_name,
instances = (a.instances[isw_name], a.instances[iff_name]),
keepIntersections = ON,
originalInstances = DELETE,
domain = GEOMETRY)