导入test.odb,提取单元编号和对应mises应力值,输出到txt中,已测试,可用;
版本:abaqus2021
#####################################
from abaqus import *
from abaqusConstants import *
from textRepr import *
import odbAccess
import numpy as np
myOdb = odbAccess.openOdb(r"C:\abaqus_odb\test.odb", readOnly=False)
myFrames = myOdb.steps["Step-1"].frames
time = []
data = []
myField = myFrames[1].fieldOutputs
tempField = [myFrames[1].frameValue,]
#prettyPrint(tempField)
myValues = myField["S"].values
#prettyPrint(len(myValues))
#prettyPrint(myValues[0])
#为各个单元各类型结果
#({'baseElementType': 'C3D8R',
# 'conjugateData': None,
# 'conjugateDataDouble': 'unknown',
# 'data': 'ndarray object',
# 'dataDouble': 'unknown',
# 'elementLabel': 378,
# 'face': None,
# 'instance': 'OdbInstance object',
# 'integrationPoint': 1,
# 'inv3': -145263.0,
# 'localCoordSystem': None,
# 'localCoordSystemDouble': 'unknown',
# 'magnitude': None,
# 'maxInPlanePrincipal': 0.0,
# 'maxPrincipal': -77848.1,
# 'midPrincipal': -1208860.0,
# 'minInPlanePrincipal': 0.0,
# 'minPrincipal': -2340410.0,
# 'mises': 1959440.0,
# 'nodeLabel': None,
# 'outOfPlanePrincipal': 0.0,
# 'position': INTEGRATION_POINT,
# 'precision': SINGLE_PRECISION,
# 'press': 1209040.0,
# 'sectionPoint': None,
# 'tresca': 2262570.0,
# 'type': TENSOR_3D_FULL})
#>>
#prettyPrint(myValues[0].mises)
temp = []
element_Label = []
i=0
while i < len(myValues):
mises_value = myValues[i].mises
element_Label_value = myValues[i].elementLabel
#print(mises_value)
if mises_value is not None:
temp.append(mises_value)
if element_Label_value is not None:
element_Label.append(element_Label_value)
#print(temp)
i +=1
data = list(zip(element_Label, temp))
#print(data[0])
#list1 = ['a', 'b', 'c']
#list2 = [1, 2, 3]
#data = list(zip(list1, list2))
lines = []
with open("C:\\Users\\\output.txt", 'w') as f:
# 遍历数据,将每行数据格式化为一个字符串
for d in data:
# 使用 join 函数将 temp 和 element_Label 以制表符为分隔符连接到一起
line = '\t'.join([str(x) for x in d])
# 将字符串添加到字符串列表中
lines.append(line)
result = '\n'.join(lines)
f.writelines(result)