【发布时间】:2017-08-07 22:45:47
【问题描述】:
我想要什么:节点处的应变值 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
'乐'
ROIStr.type
TENSOR_3D_FULL
OIStr.description
'对数应变分量'
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'路径到.odb').rootAssembly.nodeSets['ROI'])'
当我对 VECTOR 对象使用相同的代码时,例如节点位移的“U”或节点坐标的“COORD”,一切正常。
错误发生在第一个循环中。因此,它不是在错误发生之前循环几个循环的情况。
问题:有谁知道上面代码中的错误是什么原因?
【问题讨论】:
-
第一个 for 循环(未缩进)的目的是什么?在这里,您还将遇到 IndexError,因为您使用索引 i1+1 迭代步数。另请注意,
NumofFrames = 0 for v in odb.steps["Step-1"].frames: NumofFrames = NumofFrames + 1可以简化为NumofFrames = len(odb.steps["Step-1"].frames) -
第二个 循环遍历所有帧是多余的。它在复制粘贴代码时到达那里。
-
作为调试的一个步骤,尝试打印出
strain = ROIStr.values[0]的结果,其中索引0是硬编码的。 -
@Mechanician 你必须使用位置
ELEMENT_NODAL得到你的结果 -
@David 谢谢;使用 ELEMENT_NODAL 有效。
标签: python-3.x abaqus