在一些情况下,odb文件中包含有多个instances,instances之间会有节点和单元是重合。很多情况下需要得到该odb模型数据,并将其导入hypermesh进行前处理。如果直接从abaqus中得到odb模型数据的inp输入导入到hypermesh中,会有重合节点和单元报错,然而利用python可以解决该问题。代码参考如下:
################################################
from abaqus import *
from abaqusConstants import *
from viewerModules import *
import math
from odbAccess import *
################################################
myPath='D:/2017/model/*.odb'
datapath='D:/2017/model/'
dataoutput=datapath+'engine.inp'
odb=openOdb(path=myPath)
################################################
myassembly=odb.rootAssembly
myinstances=myassembly.instances
################################################
types=locals()
for instanceEach in myinstances.keys():
name=instanceEach.replace('-','_')
instanceNum.append(name)
types['elemDic_%s'%name]={}
types['nodeDic_%s'%name]={}
types['nodeList_%s'%name]=[]
for elementEach in myinstances[instanceEach].elements:
elementType=elementEach.type
if 'C3D' in elementType:
types['nodeList_%s'%name].extend(list(elementEach.connectivity))
types['elemDic_%s'%name][elementEach.label]=elementEach.connectivity
types['nodeList_%s'%name]=list(set(types['nodeList_%s'%name]))
for nodeEach in myinstances[instanceEach].nodes:
types['nodeDic_%s'%name][nodeEach.label]=nodeEach.coordinates
################################################
k=0
for name in instanceNum:
elemidMin=min(types['elemDic_%s'%name].keys())
elemidMax=max(types['elemDic_%s'%name].keys())
if elemidMin<k:
for elementLabel in types['elemDic_%s'%name].keys():
elemnewid=elementLabel+k
types['elemDic_%s'%name][elemnewid]=types['elemDic_%s'%name].pop(elementLabel)
elemidMax=max(types['elemDic_%s'%name].keys())
k=elemidMax
else:
k=elemidMax
################################################
k=0
for name in instanceNum:
nodeidMin=min(types['nodeList_%s'%name])
nodeidMax=max(types['nodeList_%s'%name])
if nodeidMin<k:
for elementLabel, elementConnect in types['elemDic_%s'%name].items():
elementnewConnect=[]
for connectEach in elementConnect:
connectnewEach=connectEach+k
elementnewConnect.append(connectnewEach)
for nodeEach in types['nodeList_%s'%name]:
nodesOutput[nodeEach+k]=types['nodeDic_%s'%name][nodeEach]
nodeidMax=max(types['nodeList_%s'%name])+k
k=nodeidMax
else:
for nodeEach in types['nodeList_%s'%name]:
nodesOutput[nodeEach]=types['nodeDic_%s'%name][nodeEach]
k=nodeidMax
################################################
typeNum=[]
for name in instanceNum:
for elementLabel, elementConnect in types['elemDic_%s'%name].items():
k=len(elementConnect)
if locals().has_key('typeList%s'%k):
types['typeList%s'%k][elementLabel]=elementConnect
else:
types['typeList%s'%k]={}
typeNum.append(k)
types['typeList%s'%k][elementLabel]=elementConnect
################################################
outputfile=open(dataoutput,'w')
data='*NODE, NSET=NALL'
outputfile.write(str(data))
outputfile.write('\n')
for nodeLabel,nodeCoordinates in nodesOutput.items():
data='%15u%2s%10.5f%2s%10.5f%2s%10.5f'%(nodeLabel, ',', nodeCoordinates[0], ',', nodeCoordinates[1], ',', nodeCoordinates[2])
outputfile.write(str(data))
outputfile.write('\n')
for typeEach in typeNum:
data='*ELEMENT,TYPE=C3D' + str(typeEach) + ',ELSET=C3D'+str(typeEach)
outputfile.write(str(data))
outputfile.write('\n')
for elementLabel, elementconnect in types['typeList%s'%typeEach].items():
data='%15u'%(elementLabel)
for i in range(0,typeEach):
data=data + '%2s%15u'%(',', elementconnect[i])
outputfile.write(str(data))
outputfile.write('\n')
outputfile.close()
################################################
该代码用于导出odb模型数据的所有的3D单元及相关的节点。
免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删