-
Notifications
You must be signed in to change notification settings - Fork 2
/
readAbaqusInput.py
154 lines (141 loc) · 5.75 KB
/
readAbaqusInput.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
def readAbaqusInput(abq_inp_name):
keywords = ['*NODE', '*ELEMENT', '*ELSET', '*ORIENTATION',
'*DISTRIBUTION', '*SOLID SECTION',
'*SHELL SECTION', '*MATERIAL', '*DENSITY', '*ELASTIC']
n_coord = {}
# {id: [x, y(, z)], ...}
e_connt = {}
# {id: [n1, n2, ...], ...}
e_set = {}
# {'name', [e1, e2, ...], ...}
section = []
# [{'elset': 'name', 'material': 'name', 'orientation': 'name'}, ...]
orientation = {}
# {'name': {'definition': CONSTANT, 'system': CONSTANT(, 'data': [])}, ...}
material = {}
# {'name': {'density': 1.0, 'elastic': []}, ...}
nnode = 0
nelem = 0
with open(abq_inp_name, 'r') as fin:
key = ''
name = ''
argument = ''
for line in fin:
line = line.strip().split(',')
kw = line[0].strip().upper()
if kw.startswith('**'):
continue
elif kw.startswith('*') and kw not in keywords:
key = ''
continue
elif kw.startswith('*NODE'):
key = 'node'
continue
elif kw.startswith('*ELEMENT'):
key = 'element'
continue
elif kw.startswith('*ELSET'):
key = 'eset'
argument = 'list'
for i, arg in enumerate(line):
if 'elset' in arg:
name = arg.split('=')[-1].strip()
if 'generate' in arg:
argument = 'generate'
if not name in e_set.keys():
e_set[name] = []
continue
elif kw.startswith('*ORIENTATION'):
key = ''
definition = 'coordinates'
system = 'rectangular'
for i, arg in enumerate(line):
if 'name' in arg:
name = arg.split('=')[-1].strip()
orientation[name] = {}
for i, arg in enumerate(line):
if 'definition' in arg:
definition = arg.split('=')[-1].strip()
if 'system' in arg:
system = arg.split('=')[-1].strip()
orientation[name]['definition'] = definition
orientation[name]['system'] = system
if definition.upper() == 'OFFSET TO NODE':
key = 'orientation'
orientation[name]['data'] = []
continue
elif kw.startswith('*SOLID SECTION'):
key = ''
orient = ''
sect = {}
for i, arg in enumerate(line):
if 'elset' in arg:
sect['elset'] = arg.split('=')[-1].strip()
if 'material' in arg:
sect['material'] = arg.split('=')[-1].strip()
if 'orientation' in arg:
orient = arg.split('=')[-1].strip()
sect['orientation'] = orient
section.append(sect)
continue
elif kw.startswith('*MATERIAL'):
key = ''
name = line[1].split('=')[1].strip()
mid = len(material.keys()) + 1
material[name] = {'id': mid, 'density': 1.0}
continue
elif kw.startswith('*DENSITY'):
key = 'density'
continue
elif kw.startswith('*ELASTIC'):
key = 'elastic'
tp = 'ISOTROPIC'
for arg in line:
if 'type' in arg or 'TYPE' in arg:
tp = arg.split('=')[-1].strip()
material[name]['elastic'] = [tp]
continue
if key == '':
continue
elif key == 'node':
nid = int(line[0].strip())
coord = []
for c in line[1:]:
coord.append(float(c.strip()))
n_coord[nid] = coord
elif key == 'element':
eid = int(line[0].strip())
connt = []
for n in line[1:]:
connt.append(int(n.strip()))
e_connt[eid] = connt
elif key == 'eset':
if argument == 'list':
for e in line:
if e.strip() == '':
continue
else:
e_set[name].append(int(e.strip()))
elif argument == 'generate':
start = int(line[0].strip())
stop = int(line[1].strip()) + 1
step = int(line[2].strip())
for e in range(start, stop, step):
e_set[name].append(e)
elif key == 'orientation':
if len(line) == 3:
for n in line:
orientation[name]['data'].append(int(n.strip()))
elif len(line) == 2:
orientation[name]['data'].append(int(line[0].strip()))
orientation[name]['data'].append(float(line[1].strip()))
elif key == 'density':
material[name]['density'] = float(line[0].strip())
elif key == 'elastic':
for v in line:
if v.strip() != '':
material[name]['elastic'].append(float(v.strip()))
return n_coord, e_connt, e_set, section, orientation, material
# abq_inp = r'C:\Users\tian50\Documents\Abaqus\Python\Abaqus_SwiftComp_GUI_0720\catia\UpperSKin-Test R26SP3.3D_Section.2.inp'
# n_coord, e_connt, e_set, section, orientation, material = readAbaqusInput(abq_inp)
# print material