-
Notifications
You must be signed in to change notification settings - Fork 2
/
vabsMain.py
471 lines (417 loc) · 16.6 KB
/
vabsMain.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
from abaqus import *
from math import *
from datetime import *
from subprocess import call
from utilities import *
import os.path
import shutil
import codecs
import time
def VABSMain(recover_flag, gen_inp_only, vabs_inp_name='', abq_inp_name='',
timoshenko_flag='', thermal_flag='', trapeze_flag='',
vlasov_flag='', curve_flag='', k='', oblique_flag='', cos='',
model_recover='', vabs_rec_name='', vabs_inp_name2='',
u='', c='', sf='', sm='', df='', dm='',
gamma='', kappa='', kappa_p=''):
st = datetime.now()
print st.strftime("%m-%d-%Y %H:%M:%S")
if recover_flag == 1:
vabs_input = getVABSInput(
vabs_inp_name, abq_inp_name, timoshenko_flag, thermal_flag,
trapeze_flag, vlasov_flag, curve_flag, k, oblique_flag, cos
)
elif recover_flag == 2:
vabs_input = getRecoverInput(
vabs_rec_name, vabs_inp_name2, model_recover,
u, c, sf, sm, df, dm, gamma, kappa, kappa_p
)
if not gen_inp_only:
try:
print 'Running VABS...'
vabsTimeStart = time.clock()
os.system('VABS ' + vabs_input)
vabsTimeEnd = time.clock()
vabsTime = vabsTimeEnd - vabsTimeStart
print 'VABS TIME: ' + str(vabsTime)
except:
raise WindowsError(
'Unexpected error happened. Please check the Command line window for more information.'
)
return 1
def getVABSInput(
vabs_inp_name, abq_inp_name, timoshenko_flag, thermal_flag,
trapeze_flag, vlasov_flag, curve_flag, ik, oblique_flag, cos
):
if vabs_inp_name == '':
out_file_name = abq_inp_name[:-4] + r'_vabs.dat'
else:
if not '.dat' in vabs_inp_name:
vabs_inp_name = vabs_inp_name + '.dat'
dr = os.path.dirname(abq_inp_name)
out_file_name = os.path.join(dr, vabs_inp_name)
if timoshenko_flag:
timoshenko_flag = 1
else:
timoshenko_flag = 0
if thermal_flag:
thermal_flag = 3
else:
thermal_flag = 0
if trapeze_flag:
trapeze_flag = 1
else:
trapeze_flag = 0
if vlasov_flag:
vlasov_flag = 1
else:
vlasov_flag = 0
if curve_flag:
curve_flag = 1
else:
curve_flag = 0
if oblique_flag:
oblique_flag = 1
else:
oblique_flag = 0
n_coord = []
e_connt = {}
e_list = []
abq_elset = {}
layer_type = {}
distribution = {}
distr_list = {}
orientation = {}
section = {}
material = {}
used_section = []
material_type = {'ISOTROPIC': 0, 'ENGINEERING CONSTANTS': 1,
'ORTHOTROPIC': 2, 'ANISOTROPIC': 2}
keywords = ['*Node', '*Element', '*Elset',
'*Distribution', '*Solid Section',
'*Shell Section', '*Material', '*Density', '*Elastic']
milestone('Reading Abaqus inputs...')
with open(abq_inp_name, 'r') as fin:
key = ''
name = ''
parameter = ''
for line in fin:
line = line.strip()
if line.startswith('**'):
continue
else:
line = line.split(',')
first = line[0].strip()
# Switch key
if first == '':
continue
elif first.startswith('*') and first not in keywords:
key = ''
continue
elif first == '*Node':
key = 'node'
continue
elif first == '*Element':
key = 'element'
continue
elif first == '*Elset':
key = 'elset'
for i, temp in enumerate(line):
if 'elset' in temp:
ei = i
if 'generate' in temp:
parameter = 'generate'
else:
parameter = 'list'
elset = line[ei].split('=')
name = elset[-1] # Abaqus element set name
ma = name.split('/')
ma = ma[0]
if ma not in abq_elset.keys():
abq_elset[ma] = []
if ma not in layer_type.keys():
k = len(layer_type.keys()) + 1
j = ma.rfind('_')
m = ma[:j]
a = ma[j+1:]
if 'p' in a:
a = a[1:]
elif 'n' in a:
a = a.replace('n', '-')
a = a.replace('d', '.')
try:
a = float(a)
layer_type[ma] = [k, m, a]
# {'name': [id, 'material', angle], ...}
except ValueError:
continue
continue
elif first == '*Distribution':
key = 'distribution'
continue
elif first == '*Solid Section' or first == '*Shell Section':
key = ''
for i, temp in enumerate(line):
if 'elset' in temp:
ei = i
elset = line[ei].split('=')
elset = elset[-1]
ma = elset.split('/')
ma = ma[0]
used_section.append(ma)
elif first == '*Material':
key = ''
for i, temp in enumerate(line):
if 'name' in temp:
mi = i
mn = line[mi].split('=')
mn = mn[-1].strip()
if mn not in material.keys():
mid = len(material.keys()) + 1
material[mn] = [mid]
continue
elif first == '*Density':
key = 'density'
continue
elif first == '*Elastic':
if len(material[mn]) < 2: # no density
material[mn].append(1.0) # add default density
key = 'elastic'
tp = 'ISOTROPIC'
for temp in line:
if 'type' in temp:
tp = temp.split('=')[-1].strip()
material[mn].append(material_type[tp])
continue
# Save data
if key == '':
continue
elif key == 'node':
nid = int(first)
x2 = float(line[2].strip())
x3 = float(line[3].strip())
n_coord.append([nid, x2, x3])
elif key == 'element':
n = len(line) - 1 # number of nodes
if n == 3 or n == 6:
line.insert(4, '0')
m = len(line) - 1
zeros = [0] * (9 - m)
eid = line[0].strip()
e_connt[eid] = [int(v.strip()) for v in line[1:]]
# {'eid': [n1, n2, ...], ...}
e_connt[eid] += zeros
e_list.append(int(eid))
elif key == 'elset':
if parameter == 'list':
for e in line:
if e.strip() == '':
continue
abq_elset[ma].append(int(e.strip()))
elif parameter == 'generate':
start = int(line[0].strip())
stop = int(line[1].strip()) + 1
step = int(line[2].strip())
for e in range(start, stop, step):
abq_elset[ma].append(e)
# Abaqus: {'set_name': [e1, e2, ...], ...}
elif key == 'distribution':
eid = str(line[0].strip())
if int(eid) in e_list:
e_list.remove(int(eid))
if eid not in distr_list.keys():
distr_list[eid] = [
1.0, 0.0, 0.0, # a_1, a_2, a_3
float(line[1]), float(line[2]), float(line[3]), # b_1, b_2, b_3
0.0, 0.0, 0.0 # c_1, c_2, c_3
]
# {'element_id': [a_1, ..., c_3], }
elif key == 'density':
d = float(line[0])
# print material
material[mn].append(d)
elif key == 'elastic':
for p in line:
if p.strip() != '':
material[mn].append(float(p.strip()))
# print material[mn]
# print distribution
# print orientation
# print section
# print 'Finish reading Abaqus inputs.'
for k in abq_elset.keys():
if k not in used_section:
del abq_elset[k]
eid_maid = {}
# print abq_elset
for k, v in abq_elset.items():
maid = layer_type[k][0]
for eid in v:
eid_maid[str(eid)] = maid
# print eid_maid
# for k, v in e_connt.items():
# maid = eid_maid[k]
# v.insert(0, maid)
# print 'Writing SwiftComp inputs...'
milestone('Writing VABS inputs...')
with codecs.open(out_file_name, encoding='utf-8', mode='w') as fout:
nnode = len(n_coord)
nelem = len(e_connt)
nmate = len(material)
nlayer = len(layer_type)
# format_flag nlayer
writeFormat(fout, 'dd', [1, nlayer])
fout.write('\n')
# timoshenko_flag recover_flag thermal_flag
writeFormat(fout, 'ddd',
[timoshenko_flag, 0, thermal_flag])
fout.write('\n')
# curve_flag oblique_flag trapeze_flag vlasov_flag
writeFormat(fout, 'd'*4,
[curve_flag, oblique_flag, trapeze_flag, vlasov_flag])
fout.write('\n')
if curve_flag == 1:
writeFormat(fout, 'EEE', ik[0])
fout.write('\n')
if oblique_flag == 1 and timoshenko_flag == 0:
writeFormat(fout, 'EE', cos[0])
fout.write('\n')
# nnode nelem nmate
writeFormat(fout, 'ddd', [nnode, nelem, nmate])
fout.write('\n')
for n in n_coord:
writeFormat(fout, 'dEE', n)
fout.write('\n')
for k, v in e_connt.items():
e = [int(k), ] + v
writeFormat(fout, 'd'*10, e)
fout.write('\n')
for e in e_list:
ma = eid_maid[str(e)]
writeFormat(fout, 'ddE', [int(e), ma, 0.0])
for e, abc in distr_list.items():
ma = eid_maid[str(e)]
t1 = degrees(atan2(abc[5], abc[4])) # b3, b2
if t1 < 0:
t1 += 360.0
if t1 == 360.0:
t1 = 0.0
writeFormat(fout, 'ddE', [int(e), ma, t1])
fout.write('\n')
if nlayer != 0:
for v in layer_type.values():
mn = v[1]
mid = material[mn][0]
v[1] = mid
writeFormat(fout, 'ddE', v)
fout.write('\n')
if nmate != 0:
for i in material.values():
# material_id isotropy
writeFormat(fout, 'dd', [i[0], i[2]])
if i[2] == 0: # isotropic
writeFormat(fout, 'EE', i[3:5])
elif i[2] == 1: # engineering constants
writeFormat(fout, 'EEE', i[3:6])
writeFormat(fout, 'EEE', i[9:12])
writeFormat(fout, 'EEE', i[6:9])
elif i[2] == 2:
if len(i) == 12: # orthotropic
c1111 = i[3]
c1122 = i[4]
c2222 = i[5]
c1133 = i[6]
c2233 = i[7]
c3333 = i[8]
c1212 = i[9]
c1313 = i[10]
c2323 = i[11]
writeFormat(fout, 'E'*6,
[c1111, 0, 0, c1122, 0, c1133])
writeFormat(fout, 'E'*5,
[ c1212, 0, 0, 0, 0])
writeFormat(fout, 'E'*4,
[ c1313, 0, 0, 0])
writeFormat(fout, 'E'*3,
[ c2222, 0, c2233])
writeFormat(fout, 'E'*2,
[ c2323, 0])
writeFormat(fout, 'E'*1,
[ c3333])
elif len(i) == 24: # anisotropic
c1111, c1122, c2222 = i[3], i[4], i[5]
c1133, c2233, c3333 = i[6], i[7], i[8]
c1112, c2212, c3312 = i[9], i[10], i[11]
c1212, c1113, c2213 = i[12], i[13], i[14]
c3313, c1213, c1313 = i[15], i[16], i[17]
c1123, c2223, c3323 = i[18], i[19], i[20]
c1223, c1323, c2323 = i[21], i[22], i[23]
writeFormat(fout, 'E'*6,
[c1111, c1112, c1113, c1122, c1123, c1133])
writeFormat(fout, 'E'*5,
[ c1212, c1213, c2212, c1223, c3312])
writeFormat(fout, 'E'*4,
[ c1313, c2213, c1323, c3313])
writeFormat(fout, 'E'*3,
[ c2222, c2223, c2233])
writeFormat(fout, 'E'*2,
[ c2323, c3323])
writeFormat(fout, 'E'*1,
[ c3333])
writeFormat(fout, 'E', [i[1]])
fout.write('\n')
fout.write('\n')
vabs_input = os.path.basename(out_file_name)
return vabs_input
def getRecoverInput(
vabs_rec_name, vabs_inp_name2, model_recover,
u, c, sf, sm, df, dm, gamma, kappa, kappa_p
):
dr = os.path.dirname(vabs_inp_name2)
fn_ech = vabs_inp_name2 + '.ech'
fn_k = vabs_inp_name2 + '.K'
fn_opt = vabs_inp_name2 + '.opt'
fn_v0 = vabs_inp_name2 + '.v0'
fn_v1s = vabs_inp_name2 + '.v1S'
fn_v22 = vabs_inp_name2 + '.v22'
fn_inp_rec = os.path.join(dr, vabs_rec_name + '.dat')
# shutil.copyfile(vabs_inp_name2, fn_inp_rec)
shutil.copyfile(fn_ech, fn_inp_rec + '.ech')
shutil.copyfile(fn_k, fn_inp_rec + '.K')
shutil.copyfile(fn_opt, fn_inp_rec + '.opt')
shutil.copyfile(fn_v0, fn_inp_rec + '.v0')
if model_recover == 2:
shutil.copyfile(fn_v1s, fn_inp_rec + '.v1S')
shutil.copyfile(fn_v22, fn_inp_rec + '.v22')
with open(fn_inp_rec, 'w') as fout:
with open(vabs_inp_name2, 'r') as fin:
before_change = True
for line in fin:
if before_change:
flags = line.split()
if len(flags) == 3:
flags = [int(flags[0]), 1, int(flags[2])]
writeFormat(fout, 'ddd', flags)
before_change = False
continue
fout.write(line)
writeFormat(fout, 'EEE', u[0])
fout.write('\n')
writeFormat(fout, 'EEE', c[0])
writeFormat(fout, 'EEE', c[1])
writeFormat(fout, 'EEE', c[2])
fout.write('\n')
if model_recover == 3:
# Vlasov model
writeFormat(fout, 'E'*7, gamma[0]+kappa[0]+kappa_p[0])
fout.write('\n')
else:
writeFormat(fout, 'E'*4, [sf[0][0],]+list(sm[0]))
if model_recover == 2:
# Timoshenko model
writeFormat(fout, 'EE', sf[0][1:])
writeFormat(fout, 'E'*6, df[0]+dm[0])
writeFormat(fout, 'E'*6, df[1]+dm[1])
writeFormat(fout, 'E'*6, df[2]+dm[2])
writeFormat(fout, 'E'*6, df[3]+dm[3])
fout.write('\n')
return fn_inp_rec