-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDefine_orientation.py
More file actions
125 lines (101 loc) · 3.73 KB
/
Define_orientation.py
File metadata and controls
125 lines (101 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# =============================================================================
# TexGen: Geometric textile modeller.
# Copyright (C) 2020 Louise Brown
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# =============================================================================
## Script to take centre points from a file named Center_point.dat containing
## points generated by external program (eg Hypermesh).
## These orientations of these points are then extracted from a TexGen model
## and saved in an orientations file JobName.ori
JobName='Job-1'
f1=open('Center_point.dat','r')
f2=open(JobName+'.ori','w')
f2.close
f2=open(JobName+'.ori','a')
S=f1.readline()
while(S!=''):
##### Read central points from 'Center_point.dat' and assign to relative variables.
a=[]
for i in range(len(S)):
if (S[i]==','):
a.append(i)
ele_num=int(S[0:a[0]])
yarn_num=int(S[a[0]+1:a[1]])
x0=float(S[a[1]+1:a[2]])
y0=float(S[a[2]+1:a[3]])
z0=float(S[a[3]+1:len(S)])
##### Define the Orientation of the element and assign to Vector1 and Vector2
Tangent=XYZ()
Loc=XY()
VolumeFraction=None
DistanceToSurface=None
Tolerance=1e-9
Orientation=XYZ()
#### Obtian the fiber direction, Vector1
if (yarn_num==0): #### matrix
Vector1='1.0, 0.0,0.0'
elif (yarn_num==1): #### XYarns[0]
yarn=weave.GetXYarns(0)[0]
Point=XYZ(x0,y0,z0)
flag=CYarn.PointInsideYarn(yarn,Point,Tangent,Loc,VolumeFraction, DistanceToSurface, Tolerance, Orientation)
if (flag==True):
Vector1=str(Orientation)
else:
Vector1='1.0, 0.0,0.0'
elif (yarn_num==2): #### XYarns[1]
yarn=weave.GetXYarns(1)[0]
Point=XYZ(x0,y0,z0)
flag=CYarn.PointInsideYarn(yarn,Point,Tangent,Loc,VolumeFraction, DistanceToSurface, Tolerance, Orientation)
if (flag==True):
Vector1=str(Orientation)
else:
Vector1='1.0, 0.0,0.0'
elif (yarn_num==3): #### YYarns[0]
yarn=weave.GetYYarns(0)[0]
Point=XYZ(x0,y0,z0)
flag=CYarn.PointInsideYarn(yarn,Point,Tangent,Loc,VolumeFraction, DistanceToSurface, Tolerance, Orientation)
if (flag==True):
Vector1=str(Orientation)
else:
Vector1='0.0,1.0, 0.0'
elif (yarn_num==4): #### YYarns[1]
yarn=weave.GetYYarns(1)[0]
Point=XYZ(x0,y0,z0)
flag=CYarn.PointInsideYarn(yarn,Point,Tangent,Loc,VolumeFraction, DistanceToSurface, Tolerance, Orientation)
if (flag==True):
Vector1=str(Orientation)
else:
Vector1='0.0,1.0,0.0'
#### Change Vector1 to a number list.
b=[]
for i in range(len(Vector1)):
if (Vector1[i]==','):
b.append(i)
n1=float(Vector1[0:b[0]])
n2=float(Vector1[b[0]+1:b[1]])
n3=float(Vector1[b[1]+1:len(Vector1)])
Vector1=[n1,n2,n3]
#### Calculate Vector2
Vector2=[Vector1[1],-Vector1[0],0.0]
#### Write the orientation to .ori file
ori_str=str(ele_num)+', '+str(Vector1[0])+', '+str(Vector1[1])+', '+str(Vector1[2])
ori_str=ori_str+', '+str(Vector2[0])+', '+str(Vector2[1])+', '+str(Vector2[2])+'\n'
f2.write(ori_str)
# print ele_num,yarn_num,x0,y0,z0
# print 'Vector1=',Vector1,'Vector2=',Vector2
S=f1.readline()
f1.close
f2.close
f2=open(JobName+'.ori','a')
f2.close
print 'Write Orientation complete !!!'