我想使用python脚本提取Node集坐标。我尝试了两种不同的方法:第一种方法来自odb文件:
import sys
from odbAccess import *
from abaqus import *
from abaqusConstants import *
import __main__
odb = openOdb('C:/Temp/Job-1.odb')
set = odb.rootAssembly.instances['part-1'].nodeSets['Set-1']
numNodes = len(set.nodes)
partlabel=[];
partxcord=[];
partycord=[];
partzcord=[];
for curNode in a.nodes:
partlabel.append(curNode.label)
partxcord.append(curNode.coordinates[0])
partycord.append(curNode.coordinates[1])
partzcord.append(curNode.coordinates[2])
显示的错误是: keyerror : Set-1。知道当我为实例节点的坐标定义相同的语法时,它正确工作。
myInstance = odb.rootAssembly.instances['part-1']
第二种方法是使用Mdb命令:
set = mdb.models['Model-1'].rootAssembly.instances['part-1'].sets[Set-1]
它也不起作用,错误是:模型1
如果你能帮我解决这个问题,我将非常感激。
发布于 2021-05-29 10:45:25
当你装配零件时(在装配模块中),你实际上组装了零件的实例,而不是零件本身。但是,您仍然可以访问部件信息,如曲面、集、节点、元素等。
For ODB (输出数据库):
您可以使用:Assembly
访问odb.rootAssembly
信息。
并使用以下方法通过实例提供部件信息:
odb.rootAssembly.instances['<instance name>']
。
和直接使用:odb.parts['<part name>']
的零件信息
For MDB (模型数据库):
您可以使用以下方法访问Assembly
信息:
mdb.models['<Model name>'].rootAssembly
。
以及使用以下方法的实例信息:
mdb.models['<Model name>'].rootAssembly.instances['<instance name>']
并直接使用以下方法提供零件信息:
mdb.models['<Model name>'].parts['<part name>']
例如,从部件和集合访问元素集:
# Let's consider, 'ASM_ELSET' is an element set created at the assembly level
# and 'PRT_ELSET' is an element set created at the part 'PART-1'.
# Access assembly level set
aset = odb.rootAssembly.elementSets['ASM_ELSET']
# Access part level set through the instance
pset = odb.rootAssembly.instances['PART-1-1'].elementSets['PRT_ELSET']
请注意,'PART-1-1'
是'PART-1
部件的实例名称。
发布于 2021-04-20 20:58:54
我使用这两个函数在矩形样本上生成一组已知坐标为X的节点(您可以根据节点的坐标更改if条件):
def Functions_Set_Face_AC(Face, Name_Face):
modelName1='Model-1'
mdb.models[modelName1].rootAssembly.Set(faces=Face, name=Name_Face)
mdb.models[modelName1].rootAssembly.Set(name=Name_Face, nodes=mdb.models[modelName1].rootAssembly.sets[Name_Face].nodes)
def Node_Set_X(X, modelName, instanceName):
"""ABAQUS_Fucntion: Set
defines a set of nodes at the front surface of the specimen
input:
X: Level of the surface
(Depending of your coordinate system, it may change. But it should be
in direction of the thichness).
modelName: name of the model
instanceName: name of the instance
"""
X=round(X,6);
FRONT=[];
for i in mdb.models[modelName].rootAssembly.instances[instanceName].faces:
a=i.pointOn[0]
if a[0]== X:
FRONT=FRONT+[mdb.models[modelName].rootAssembly.instances[instanceName].faces.findAt(((a[0],a[1],a[2]),))]
#Assign set
Functions_Set_Face_AC(FRONT, 'FRONT_X')
然后,在odb文件中,您可以提取这些节点的坐标以及位移(或任何其他输出),其中有两个函数:第二个函数将结果保存到csv文件中。(请记住,您应该在步骤中激活COORD,以提取odb中各点的坐标)
# =============================================================================
# Matrix form
# =============================================================================
def Give_FieldVariable_matrixform(COORD1, COORD2, COORD3, U1, U2, U3):
"""Give the field varialbe in the form of [[c1, c2, c3, u1,u2,u3],...]
input:
COORD1, COORD2, COORD3: nodal coordinates
U1, U2, U3: the interested field variable at nodes
Output:
U: a matrix includes coordinate and field variable
Note:
this function helps to save this nodal information into a csv file."""
U=[]
for i in range(0,len(COORD1)):
# coordinate
c1 = COORD1[i][1][1]
c2 = COORD2[i][1][1]
c3 = COORD3[i][1][1]
# Field variable
u1 = U1[i][1][1]
u2 = U2[i][1][1]
u3 = U3[i][1][1]
U.append([c1, c2, c3, u1, u2, u3])
return U
# =============================================================================
# Save to a csv file
# =============================================================================
def Extract_FieldVariable_odb(OdbFile, SetName, csvFile):
"""
This function saves the nodal displacement field of a given set.
Input:
OdbFile: The odb file (string) eg.: 'Job-1.odb'
SetName: the name of your set (string)
csvFile: csv file name (string).
Output:
A csv file including nodal coordinate and dispalcement in a form of:
x, y, z, U1, U2, U3
will be saved in your Work directory
Note:
*** You should first open the visualization ***
*** You should active CCORD in step ***
"""
myOdb = openOdb(path = OdbFile)
nodes=myOdb.rootAssembly.nodeSets[SetName]
framelen=len(myOdb.steps['Step-1'].frames)
U1_Fr=session.xyDataListFromField(odb=myOdb, outputPosition=NODAL, variable=(('U',NODAL, ((COMPONENT, 'U1'), )), ), nodeSets=(SetName, ))
U2_Fr=session.xyDataListFromField(odb=myOdb, outputPosition=NODAL, variable=(('U',NODAL, ((COMPONENT, 'U2'), )), ), nodeSets=(SetName, ))
U3_Fr=session.xyDataListFromField(odb=myOdb, outputPosition=NODAL, variable=(('U',NODAL, ((COMPONENT, 'U3'), )), ), nodeSets=(SetName, ))
COORD1_Fr=session.xyDataListFromField(odb=myOdb, outputPosition=NODAL, variable=(('COORD',NODAL, ((COMPONENT, 'COOR1'), )), ), nodeSets=(SetName, ))
COORD2_Fr=session.xyDataListFromField(odb=myOdb, outputPosition=NODAL, variable=(('COORD',NODAL, ((COMPONENT, 'COOR2'), )), ), nodeSets=(SetName, ))
COORD3_Fr=session.xyDataListFromField(odb=myOdb, outputPosition=NODAL, variable=(('COORD',NODAL, ((COMPONENT, 'COOR3'), )), ), nodeSets=(SetName, ))
Total = Give_FieldVariable_matrixform(COORD1_Fr, COORD2_Fr, COORD3_Fr,
U1_Fr, U2_Fr, U3_Fr)
np.savetxt(csvFile, Total, delimiter=",")
我希望这会对你有帮助。
发布于 2021-07-04 09:56:12
谢谢你的回答。
SatishThorat,我成功地访问了odb文件,并读取了使用以下命令创建的节点集中的输出字段:
nodeset='SET-2'
mySet = odb.rootAssembly.nodeSets[nodeset]
FYI,脚本python中集合的名称应该用大写字母" set -2“来写。
如果节点集是在部件级别创建的,则可以使用以下命令:
nodeset='NODESET-2'
mySet = odb.rootAssembly.instances['PART-1-1'].nodeSets[nodeset]
我试过使用这个命令,但没有成功:
nodeset='NODESET-2'
mySet = odb.parts['PART-1-1'].nodeSets[nodeset]
非常感谢。
https://stackoverflow.com/questions/66916200
复制相似问题