Reputation: 37
I would like to extract the Node set coordinates using a python script. i tried with two different methods: The first from an odb file :
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])
The error displayed is : keyerror : Set-1. knowing that when I defined the same syntax for the coordinates of the instance nodes, it works correctly.
myInstance = odb.rootAssembly.instances['part-1']
The second method is using Mdb commands :
set = mdb.models['Model-1'].rootAssembly.instances['part-1'].sets[Set-1]
It doesn't work too and the error is : Model-1
I would be very grateful if you help me solve this problem
Upvotes: 0
Views: 9202
Reputation: 924
When you assemble the parts (in Assembly Module), you actually assemble the instance of the parts and NOT the part itself. However, you can still access the part information, such as, surfaces, sets, nodes, elements, etc.
For ODB (output database):
You can access Assembly
information using: odb.rootAssembly
.
and the part information through the instance using:
odb.rootAssembly.instances['<instance name>']
.
and directly the part information using: odb.parts['<part name>']
For MDB (model database):
You can access Assembly
information using: mdb.models['<Model name>'].rootAssembly
.
and the instance information using:
mdb.models['<Model name>'].rootAssembly.instances['<instance name>']
and directly the part information using:
mdb.models['<Model name>'].parts['<part name>']
For example, accessing the element set from part and asssembly:
# 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']
Please note that 'PART-1-1'
is instance name for part 'PART-1
.
Upvotes: 1
Reputation: 37
Thank you for your answers.
SatishThorat, I succeed to access to odb file and read the output field in the node set created using this command :
nodeset='SET-2'
mySet = odb.rootAssembly.nodeSets[nodeset]
FYI, the name of the set in the script python should be written in In capital letters "SET-2".
If the node set is created in the Part level, you can use this command :
nodeset='NODESET-2'
mySet = odb.rootAssembly.instances['PART-1-1'].nodeSets[nodeset]
I tried with this command but it didn't work :
nodeset='NODESET-2'
mySet = odb.parts['PART-1-1'].nodeSets[nodeset]
Thanks very much.
Upvotes: 0
Reputation: 1
I used these two functions to generate a set of nodes with the known coordinate of X over a rectangular specimen (You can change the if condition depending on the coordinates of your nodes):
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')
Then, in the odb file you can extract the coordinate of those nodes as well as the displacement (or any other output) with two functions like these: The second function save the result into a csv file. (remember that you should activate COORD in the step to extract the coordinate of the points in the 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=",")
I hope it would be helpful for you.
Upvotes: 0