【问题标题】:Abaqus Python script -- Reading 'TENSOR_3D_FULL' data from *.odb fileAbaqus Python 脚本——从 *.odb 文件中读取“TENSOR_3D_FULL”数据
【发布时间】: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


【解决方案1】:

这就是您获得IndexError 的原因。应变(显然)在积分点计算;根据ABQ 脚本参考指南

一个 SymbolicConstant 指定输出在元素中的位置。可能的值是:

NODAL,指定在节点处计算的值。

INTEGRATION_POINT,指定在积分点计算的值。

ELEMENT_NODAL,指定通过在积分点计算的外推结果获得的值。

CENTROID,指定通过在积分点计算的外推结果获得的质心值。

因此,为了使用您的代码,您应该使用position= ELEMENT_NODAL 获取结果

ROIrefCoords = refCoordinates.getSubset(region=ROINodeSet,position= ELEMENT_NODAL)

ROIStr.values[0].data

然后您将获得一个包含张量的 6 个独立分量的数组。


替代解决方案

要读取节点集的时间序列结果,您可以使用函数xyPlot.xyDataListFromField()。我注意到这个函数比使用 odbread 快得多。代码也更短,唯一的缺点是您必须获得 abaqus 许可证才能使用它(与 odbread 相比,它与 abaqus python 一起工作,只需要安装的 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)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-24
    • 1970-01-01
    • 2021-12-29
    • 1970-01-01
    • 1970-01-01
    • 2021-05-19
    • 1970-01-01
    相关资源
    最近更新 更多