Abaqus Python 脚本 -- 从 *.odb 文件读取 'TENSOR_3D_FULL' 数据
Abaqus Python script -- Reading 'TENSOR_3D_FULL' data from *.odb file
我想要的:节点处的应变值LE11、LE22、LE12
我的脚本是:
#!/usr/local/bin/python
# coding: latin-1
# making the ODB commands available to the script
from odbAccess import*
import sys
import csv
odbPath = "my *.odb path"
odb = openOdb(path=odbPath)
assembly = odb.rootAssembly
# count the number of frames
NumofFrames = 0
for v in odb.steps["Step-1"].frames:
NumofFrames = NumofFrames + 1
# create a variable that refers to the reference (undeformed) frame
refFrame = odb.steps["Step-1"].frames[0]
# create a variable that refers to the node set ‘Region Of Interest (ROI)’
ROINodeSet = odb.rootAssembly.nodeSets["ROI"]
# create a variable that refers to the reference coordinate ‘REFCOORD’
refCoordinates = refFrame.fieldOutputs["COORD"]
# create a variable that refers to the coordinates of the node
# set in the test frame of the step
ROIrefCoords = refCoordinates.getSubset(region=ROINodeSet,position= NODAL)
# count the number of nodes
NumofNodes =0
for v in ROIrefCoords.values:
NumofNodes = NumofNodes +1
# looping over all the frames in the step
for i1 in range(NumofFrames):
# create a variable that refers to the current frame
currFrame = odb.steps["Step-1"].frames[i1+1]
# looping over all the frames in the step
for i1 in range(NumofFrames):
# create a variable that refers to the strain 'LE'
Str = currFrame.fieldOutputs["LE"]
ROIStr = Str.getSubset(region=ROINodeSet, position= NODAL)
# initialize list
list = [[]]
# loop over all the nodes in each frame
for i2 in range(NumofNodes):
strain = ROIStr.values [i2]
list.insert(i2,[str(strain.dataDouble[0])+";"+str(strain.dataDouble[1])+\
";"+str(strain.dataDouble[3]))
# write the list in a new *.csv file (code not included for brevity)
odb.close()
我得到的错误是:
应变 = ROIStr.values [i2]
IndexError:序列索引超出范围
附加信息:
ROIStr 的详细信息:
ROIStr.name
'LE'
ROIStr.type
TENSOR_3D_FULL
OIStr.description
'Logarithmic strain components'
ROIStr.componentLabels
('LE11', 'LE22', 'LE33', 'LE12', 'LE13', 'LE23')
ROIStr.getattribute
'getattribute of openOdb(r'path to .odb').steps['Step-1'].frames[1].fieldOutputs['LE'].getSubset(position=INTEGRATION_POINT, region=openOdb(r'path to.odb').rootAssembly.nodeSets['ROI'])'
当我对 VECTOR 对象使用相同的代码时,例如 'U' 节点位移或 'COORD' 节点坐标,一切正常。
错误发生在第一个循环中。因此,它不是在错误发生之前循环多个循环的情况。
问题:有谁知道是什么导致了以上代码的错误?
这是您获得 IndexError
的原因。应变(显然)是在积分点处计算的;根据 ABQ 脚本参考指南:
A SymbolicConstant specifying the position of the output in the element. Possible values are:
NODAL
, specifying the values calculated at the nodes.
INTEGRATION_POINT
, specifying the values calculated at the integration points.
ELEMENT_NODAL
, specifying the values obtained by extrapolating results calculated at the integration points.
CENTROID
, specifying the value at the centroid obtained by extrapolating results calculated at the integration points.
因此,为了使用您的代码,您应该使用 position= ELEMENT_NODAL
获得结果
ROIrefCoords = refCoordinates.getSubset(region=ROINodeSet,position= ELEMENT_NODAL)
与
ROIStr.values[0].data
然后您将得到一个包含张量的 6 个独立分量的数组。
备选方案
要读取节点集的时间序列结果,您可以使用函数 xyPlot.xyDataListFromField()
。我注意到这个函数比使用 odbread 快得多。代码也更短,唯一的缺点是您必须获得 abaqus 许可证才能使用它(与使用 abaqus python
的 odbread 相比,它只需要安装版本的 abaqus 并且不需要获得网络执照)。
对于您的应用程序,您应该执行以下操作:
from abaqus import *
from abaqusConstants import *
from abaqusExceptions import *
import visualization
import xyPlot
import displayGroupOdbToolset as dgo
results = session.openOdb(your_file + '.odb')
# without this, you won't be able to extract the results
session.viewports['Viewport: 1'].setValues(displayedObject=results)
xyList = xyPlot.xyDataListFromField(odb=results, outputPosition=NODAL, variable=((
'LE', INTEGRATION_POINT, ((COMPONENT, 'LE11'), (COMPONENT, 'LE22'), (
COMPONENT, 'LE33'), (COMPONENT, 'LE12'), )), ), nodeSets=(
'ROI', ))
(当然还要加上LE13
等)
您将获得 xyData
的列表
type(xyList[0])
<type 'xyData'>
包含每个节点和每个输出所需的数据。因此它的大小将是
len(xyList)
number_of_nodes*number_of_requested_outputs
其中列表的前 number_of_nodes
个元素是每个节点的 LE11,然后是 LE22,依此类推。
然后您可以将其转换为 NumPy 数组:
LE11_1 = np.array(xyList[0])
将是第一个节点的 LE11,尺寸为:
LE.shape
(NumberTimeFrames, 2)
也就是说,对于每个时间步长,您都有时间和输出变量。
NumPy 数组也很容易写入文本文件(查看 numpy.savetxt
)。
我想要的:节点处的应变值LE11、LE22、LE12
我的脚本是:
#!/usr/local/bin/python
# coding: latin-1
# making the ODB commands available to the script
from odbAccess import*
import sys
import csv
odbPath = "my *.odb path"
odb = openOdb(path=odbPath)
assembly = odb.rootAssembly
# count the number of frames
NumofFrames = 0
for v in odb.steps["Step-1"].frames:
NumofFrames = NumofFrames + 1
# create a variable that refers to the reference (undeformed) frame
refFrame = odb.steps["Step-1"].frames[0]
# create a variable that refers to the node set ‘Region Of Interest (ROI)’
ROINodeSet = odb.rootAssembly.nodeSets["ROI"]
# create a variable that refers to the reference coordinate ‘REFCOORD’
refCoordinates = refFrame.fieldOutputs["COORD"]
# create a variable that refers to the coordinates of the node
# set in the test frame of the step
ROIrefCoords = refCoordinates.getSubset(region=ROINodeSet,position= NODAL)
# count the number of nodes
NumofNodes =0
for v in ROIrefCoords.values:
NumofNodes = NumofNodes +1
# looping over all the frames in the step
for i1 in range(NumofFrames):
# create a variable that refers to the current frame
currFrame = odb.steps["Step-1"].frames[i1+1]
# looping over all the frames in the step
for i1 in range(NumofFrames):
# create a variable that refers to the strain 'LE'
Str = currFrame.fieldOutputs["LE"]
ROIStr = Str.getSubset(region=ROINodeSet, position= NODAL)
# initialize list
list = [[]]
# loop over all the nodes in each frame
for i2 in range(NumofNodes):
strain = ROIStr.values [i2]
list.insert(i2,[str(strain.dataDouble[0])+";"+str(strain.dataDouble[1])+\
";"+str(strain.dataDouble[3]))
# write the list in a new *.csv file (code not included for brevity)
odb.close()
我得到的错误是:
应变 = ROIStr.values [i2]
IndexError:序列索引超出范围
附加信息:
ROIStr 的详细信息:
ROIStr.name
'LE'
ROIStr.type
TENSOR_3D_FULL
OIStr.description
'Logarithmic strain components'
ROIStr.componentLabels
('LE11', 'LE22', 'LE33', 'LE12', 'LE13', 'LE23')
ROIStr.getattribute
'getattribute of openOdb(r'path to .odb').steps['Step-1'].frames[1].fieldOutputs['LE'].getSubset(position=INTEGRATION_POINT, region=openOdb(r'path to.odb').rootAssembly.nodeSets['ROI'])'
当我对 VECTOR 对象使用相同的代码时,例如 'U' 节点位移或 'COORD' 节点坐标,一切正常。
错误发生在第一个循环中。因此,它不是在错误发生之前循环多个循环的情况。
问题:有谁知道是什么导致了以上代码的错误?
这是您获得 IndexError
的原因。应变(显然)是在积分点处计算的;根据 ABQ 脚本参考指南:
A SymbolicConstant specifying the position of the output in the element. Possible values are:
NODAL
, specifying the values calculated at the nodes.
INTEGRATION_POINT
, specifying the values calculated at the integration points.
ELEMENT_NODAL
, specifying the values obtained by extrapolating results calculated at the integration points.
CENTROID
, specifying the value at the centroid obtained by extrapolating results calculated at the integration points.
因此,为了使用您的代码,您应该使用 position= ELEMENT_NODAL
ROIrefCoords = refCoordinates.getSubset(region=ROINodeSet,position= ELEMENT_NODAL)
与
ROIStr.values[0].data
然后您将得到一个包含张量的 6 个独立分量的数组。
备选方案
要读取节点集的时间序列结果,您可以使用函数 xyPlot.xyDataListFromField()
。我注意到这个函数比使用 odbread 快得多。代码也更短,唯一的缺点是您必须获得 abaqus 许可证才能使用它(与使用 abaqus python
的 odbread 相比,它只需要安装版本的 abaqus 并且不需要获得网络执照)。
对于您的应用程序,您应该执行以下操作:
from abaqus import *
from abaqusConstants import *
from abaqusExceptions import *
import visualization
import xyPlot
import displayGroupOdbToolset as dgo
results = session.openOdb(your_file + '.odb')
# without this, you won't be able to extract the results
session.viewports['Viewport: 1'].setValues(displayedObject=results)
xyList = xyPlot.xyDataListFromField(odb=results, outputPosition=NODAL, variable=((
'LE', INTEGRATION_POINT, ((COMPONENT, 'LE11'), (COMPONENT, 'LE22'), (
COMPONENT, 'LE33'), (COMPONENT, 'LE12'), )), ), nodeSets=(
'ROI', ))
(当然还要加上LE13
等)
您将获得 xyData
type(xyList[0])
<type 'xyData'>
包含每个节点和每个输出所需的数据。因此它的大小将是
len(xyList)
number_of_nodes*number_of_requested_outputs
其中列表的前 number_of_nodes
个元素是每个节点的 LE11,然后是 LE22,依此类推。
然后您可以将其转换为 NumPy 数组:
LE11_1 = np.array(xyList[0])
将是第一个节点的 LE11,尺寸为:
LE.shape
(NumberTimeFrames, 2)
也就是说,对于每个时间步长,您都有时间和输出变量。
NumPy 数组也很容易写入文本文件(查看 numpy.savetxt
)。