-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwriteMailMeshFiles.py
More file actions
278 lines (250 loc) · 9.22 KB
/
writeMailMeshFiles.py
File metadata and controls
278 lines (250 loc) · 9.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
import os
strut = {
'ffx': {
# 'xs': {
# 'min': 91,
# 'max': 121,
# 'body': 40
# },
's': {
'min': 116,
'max': 152,
'body': 55
},
'm': {
'min': 143,
'max': 205,
'body': 82
},
'l': {
'min': 195,
'max': 311,
'body': 136
}
},
'std': {
'xxs': {
'min': 59,
'max': 76
},
'xs': {
'min': 75,
'max': 96
},
's': {
'min': 90,
'max': 125
},
'm': {
'min': 116,
'max': 178
},
'l': {
'min': 169,
'max': 283
}
}
}
uJointBodyLength = 10
uJointRodLength = 13
# def elong(load, elastMod, area, len):
# return ((load * len) / (elastMod * area))
eBody = 7.0e4; # N/mm2
eRod = 1.85e5; # N/mm2
knobLength = 15.0
bodyRadIn = 3.0
# bodyLength
# rodLength = 10.0
def range2(first, last, inc = 1, prec = 1.0e-4):
x = first
xs = []
while (x <= last):
xs.append(x)
x += inc
print(x, xs[-1], last)
if ((last - xs[-1]) > prec):
print(x)
xs.append(last)
return xs
def elemLengths(strutType, size, length, elemLength = 1.0):
mm2m = 0.001
# bodyLength = strut[strutType][size]['min'] + knobLength
bodyLength = strut[strutType][size]['body'] + uJointBodyLength + 3.0 + knobLength
rodLength = length - bodyLength
nelsBody = round(bodyLength / elemLength) # number of elements on body
nelsRod = round(rodLength / elemLength) # number of elements on rod
# elemLengthAvg = round((bodyLength / nelsBody) + (rodLength / nelsRod) / 2)
elBodyLength = bodyLength / nelsBody
elRodLength = rodLength / nelsRod
bodyLength *= mm2m
rodLength *= mm2m
elBodyLength *= mm2m
elRodLength *= mm2m
print(bodyLength, rodLength, elBodyLength, elRodLength)
return bodyLength, rodLength, elBodyLength, elRodLength
# def strutCoords(strutType, size, length, nelsBody = 20, nelsRod = 20):
def strutCoords(strutType, size, length, elemLength):
# elBodyLength, elRodLength = elemLengths(strutType, size, length, nelsBody, nelsRod)
bodyLength, rodLength, elBodyLength, elRodLength = elemLengths(strutType, size, length, elemLength = elemLength)
bodyCoords = []
rodCoords = []
mm2m = 0.001
length *= mm2m
# allCoords = []
# for ii in range(nelsBody + 1):
# bodyLength = strut[strutType][size]['min'] + knobLength
# rodLength = length - bodyLength
# print('length:', length)
# print(bodyLength, rodLength, elBodyLength, elRodLength)
for zBody in range2(0.0, bodyLength, elBodyLength):
# zBody = ii * elBodyLength
coords = (0.0, 0.0, zBody)
bodyCoords.append(coords)
# allCoords.append(coords)
# for ii in range(nelsRod + 1):
for zRod in range2(zBody + elRodLength, length, elRodLength):
# coords = (0.0, 0.0, zBody + ii * elRodLength)
coords = (0.0, 0.0, zRod)
# allCoords.append(coords)
rodCoords.append(coords)
print(len(bodyCoords), len(rodCoords))
return bodyCoords, rodCoords
# def strutMesh(strutType, size, length, separator = ' ', nelsBody = 20, nelsRod = 20):
def strutMesh(strutType, size, length, separator = ' ', elemLength = 5.0):
# bodyCoords, rodCoords = strutCoords(strutType, size, length, nelsBody = 20, nelsRod = 20)
bodyCoords, rodCoords = strutCoords(strutType, size, length, elemLength = elemLength)
eol = '\r\n'
nodesStr = 'COOR_3D' + eol
elemsStr = 'SEG2' + eol
# for ii in range(nelsBody):
nodeCount = 1
elemCount = 1
elemNodeLabels = []
bodyElemGroup = []
rodElemGroup = []
for coords in bodyCoords:
nodeLabel = 'N' + str(nodeCount)
nodesStr += nodeLabel + separator
# nodesStr += separator + str(coord)
nodesStr += "{0: >014f}".format(coords[0]) + separator
nodesStr += "{0: >014f}".format(coords[1]) + separator
nodesStr += "{0: >014f}".format(coords[2])
nodesStr += eol
elemNodeLabels.append(nodeLabel)
if (nodeCount > 1):
elemLabel = 'E' + str(elemCount)
elemsStr += elemLabel + separator + elemNodeLabels[0] + separator + elemNodeLabels[1] + eol
bodyElemGroup.append(elemLabel)
# if (nodeCount % 2 == 0):
elemNodeLabels = [elemNodeLabels[1]]
nodeCount += 1
elemCount += 1
for coords in rodCoords:
nodeLabel = 'N' + str(nodeCount)
nodesStr += nodeLabel
for coord in coords:
nodesStr += separator + str(coord)
nodesStr += eol
elemNodeLabels.append(nodeLabel)
elemLabel = 'E' + str(elemCount)
elemsStr += elemLabel + separator + elemNodeLabels[0] + separator + elemNodeLabels[1] + eol
rodElemGroup.append(elemLabel)
elemNodeLabels= [elemNodeLabels[1]]
nodeCount += 1
elemCount += 1
nodesStr += 'FINSF' + eol
elemsStr += 'FINSF' + eol
bodyElemGroupStr = ''
elemCount = 1
for elemLabel in bodyElemGroup:
if (elemCount % 8 == 0):
bodyElemGroupStr += eol
bodyElemGroupStr += elemLabel + separator
elemCount += 1
bodyElemGroupStr += eol
# bodyElemGroupStr += '%' + eol
rodElemGroupStr = ''
elemCount = 1
for elemLabel in rodElemGroup:
if (elemCount % 8 == 0):
rodElemGroupStr += eol
rodElemGroupStr += elemLabel + separator
elemCount += 1
rodElemGroupStr += eol
# rodElemGroupStr += '%' + eol
# print('bodyElemGroupStr:', bodyElemGroupStr)
# print('rodElemGroupStr:', rodElemGroupStr)
groupNosStr = ''
groupNosStr += 'GROUP_NO NOM = BCEnd' + eol
# groupNosStr += 'BCEnd' + separator + 'N1' + eol
groupNosStr += 'N1' + eol
groupNosStr += 'FINSF' + eol
groupNosStr += 'GROUP_NO NOM = LoadEnd' + eol
# groupNosStr += 'LoadEnd' + separator + 'N' + str(len(bodyCoords) + len(rodCoords)) + eol
groupNosStr += 'N' + str(len(bodyCoords) + len(rodCoords)) + eol
groupNosStr += 'FINSF' + eol
# rodElemGroup += 'FINSF' + eol
# rodElemGroup += '' + eol
return nodesStr, elemsStr, groupNosStr, bodyElemGroupStr, rodElemGroupStr
# nodesStr, elemsStr = strutMesh(strutType = 'ffx', size = 's', length = 120.0, separator = ' ', nelsBody = 20, nelsRod = 20)
def strutMeshStr(strutType = 'ffx', size = 's', length = 120.0, separator = ' ' , elemLength = 3.3):
# nodesStr, elemsStr, groupNosStr, bodyElemsGroupStr, rodElemGroupStr = strutMesh(strutType = 'ffx', size = 's', length = 120.0, separator = ' ' , elemLength = 3.3)
nodesStr, elemsStr, groupNosStr, bodyElemsGroupStr, rodElemGroupStr = strutMesh(strutType = strutType, size = size, length = length, separator = separator , elemLength = elemLength)
eol = '\r\n'
meshStr = ''
# meshStr += 'TITRE'
# meshStr += eol
meshStr += '%'
meshStr += eol
meshStr += '% Beam mesh for TSF strut ' + strutType + separator + size + separator + str(length) + eol
meshStr += '%'
meshStr += eol
meshStr += nodesStr
meshStr += '%' + eol
meshStr += elemsStr
meshStr += '%' + eol
meshStr += groupNosStr
meshStr += '%' + eol
meshStr += 'GROUP_MA NOM = Body'
meshStr += eol
# meshStr += 'Body' + eol
meshStr += bodyElemsGroupStr
# meshStr += '%' + eol
meshStr += 'FINSF' + eol
meshStr += 'GROUP_MA NOM = Rod'
meshStr += eol
meshStr += rodElemGroupStr
meshStr += 'FINSF' + eol
meshStr += '%' + eol
meshStr += 'FIN'
meshStr += eol
# print(nodesStr, elemsStr)
# print(meshStr)
return meshStr
def meshFile(dirPath, strutType = 'ffx', size = 's', length = 120.0, separator = ' ' , elemLength = 1.0):
# meshStr = strutMeshStr(strutType = 'ffx', size = 's', length = 120.0, separator = ' ' , elemLength = 3.3)
meshStr = strutMeshStr(strutType = strutType, size = size, length = length, separator = separator , elemLength = elemLength)
fileName = 'strut_' + strutType + '_' + size + '_' + str(length) + '.mail'
filePath = dirPath + '/' + fileName
with open(filePath, 'w') as f1:
f1.write(meshStr)
return filePath
# F:\far\uom\draft\TSF\struts\fe
# filePath = r'F:/far/uom/draft/TSF/struts/fe/test0.mail'
# meshFile(dirPath, strutType = 'ffx', size = 's', length = 130.0, separator = ' ' , elemLength = 2.0)
# results for small ffx struts at lengths of 116, 135 & 142 (mm): 13.7, 6.5, 5.3
def main(dirPath):
ffxStrut = strut['ffx']
for strutSize in ffxStrut.keys():
ffxStrut0 = ffxStrut[strutSize]
dirPath1 = os.path.join(dirPath, strutSize)
if not os.path.isdir(dirPath1):
os.mkdir(dirPath1)
#print(dirPath1)
for strutLength in range(ffxStrut0['min'], ffxStrut0['max'] + 1, 1):
dirPath2 = os.path.join(dirPath1, str(strutLength))
if not os.path.isdir(dirPath2):
os.mkdir(dirPath2)
meshFile(dirPath2, strutType = 'ffx', size = strutSize, length = strutLength, separator = ' ' , elemLength = 1.0)
dirPath = r'/home/fzf/projects/ca/py/tests/beam/buckling/strut'
main(dirPath)