python提取abaqus计算结果

在Abaqus的inp文件中,用户可以指定自己感兴趣的数据,并加以输出,追加在工作目录下的.dat文件中,但本文则展示了如何使用Python提取结果数据:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from odbAccess import *
odb=openOdb(path='fraction_0.03_test.odb')
topNodeSet=odb.rootAssembly.instances['PART-1-1'].nodeSets['TOPO']
displacement=odb.steps['Step-1'].frames[-1].fieldOutputs['U']
topDisplacement=displacement.getSubset(region=topNodeSet)
topValues=topDisplacement.values
topcoor=odb.rootAssembly.instances['PART-1-1'].nodeSets['TOPO'].nodes
f=open('XY.dat','w')
for nodeCoordinate in topcoor:
print >>f, nodeCoordinate.coordinates[0],nodeCoordinate.coordinates[1]
f.close

f=open('U1U2.dat','w')
for v in topValues:
f.write(str(v.nodeLabel))
f.write(' ')
f.write(str(v.data[0]))
f.write(' ')
f.write(str(v.data[1]))
f.write('n')
f.close
odb.close()

Using the Python to extract the displacement or someother types of Abaqus data, there are two ways to do this.

1. Using the f.write()

example:

1
2
3
4
5
6
7
8
9
f=open('U1U2.dat','w')
for v in topValues:
f.write(str(v.nodeLabel))
f.write(' ')
f.write(str(v.data[0]))
f.write(' ')
f.write(str(v.data[1]))
f.write('n')
f.close

2. Using the print

1
2
3
4
f=open('XY.dat','w')
for nodeCoordinate in topcoor:
print >>f, nodeCoordinate.coordinates[0],nodeCoordinate.coordinates[1]
f.close

I suggest readers to use the second way, because it is simple and clearly. More importantly, the results can be written into the outfile immediatly if in this way. The first way can also do the same thing, but the results are written into the outfile until you close the Abaqus/CAE software. So the second way print is much more safe than the first one f.write.

NOTE:
The Abaqus6.14 is based on the Python2.7.3.

How to check the version of Python of my Abaqus?
Open the Abaqus/CAE and type the following commands:

1
2
3
>>>import sys
>>>print(sys.version)
2.7.3 (default, May 1 2014, 02:56:01) [MSC v.1600 64 bit (AMD64)]

The figure of the command line interface

There are many differences between Python2 and Python3. The detail can be read here. In this process of the Abaqus data, we only use the old print.