Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations The Obturator on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write python script that extracts max stress from .odb files

Status
Not open for further replies.

OverWorked453

New member
Feb 15, 2013
12
I am trying to write a python script that determines and extracts the max Mises stress (from an .odb file) on a body in a dynamic simulation. Note that the stress will change with respect to both time and location. It seems like a fairly easy code theoretically - just determine that max stress at every frame and take the maximum of that.

However, I am really struggling with this. Since I'm not able to do it, I tried to write a more simple code that outputs only the max stress at one single frame. And this code does not work either (posted below)! Can someone please help me out? My code it below:


# Define variables:
from odbAccess import *
odb = openOdb('TheJob-1.odb')
step1 = odb.steps['DynamicStep']
# Last frame in step
frame = step1.frames[-1]
# Initialize a variable
max_stress = 0.00
# Sets MisesStress = all displacements in model (MISES)
MisesStress = frame.fieldOutputs['MISESMAX']
# Defines nodes = nodes in node set 'BODY'
nodes = odb.rootAssembly.nodeSets['BODY']
# Sets stress_at_nodes = stress in nodes in set 'BODY'
stress_at_nodes = MisesStress.getSubset(region=nodes)
# Loops over all nodes in set, sets max_Str to maximum MISES STRESS
for StressVal in stress_at_nodes.values:

if StressVal > max_stress:

max_stress = StressVal

#Create text file with Data of interes
outputFile = open('StressOutput.dat','w')
outputFile.write('Maximum Mises Stress in Leg\n')
outputFile.write('%10.4E \n' % (max_stress))
outputFile.close()



But when I run the code it gives a value of 0.0000E+00 in the output file (StressOutput.dat). Since my stress distributing is definitely not zero during this step, something is wrong. Perhaps the "if" statement does not work. I would greatly appreciate help with this code - or reference to an equivalent code that does the same thing for me.

Thanks!
 
Replies continue below

Recommended for you

My apologies - the code above does not show the indentations of my actual code, here it is again:

# Define variables:
from odbAccess import *
odb = openOdb('TheJob-1.odb')
step1 = odb.steps['DynamicStep']
# Last frame in step
frame = step1.frames[-1]
# Initialize a variable
max_stress = 0.00
# Sets MisesStress = all displacements in model (MISES)
MisesStress = frame.fieldOutputs['MISESMAX']
# Defines nodes = nodes in node set 'BODY'
nodes = odb.rootAssembly.nodeSets['BODY']
# Sets stress_at_nodes = stress in nodes in set 'BODY'
stress_at_nodes = MisesStress.getSubset(region=nodes)
# Loops over all nodes in set, sets max_Str to maximum MISES STRESS
for StressVal in stress_at_nodes.values:

if StressVal > max_stress:

max_stress = StressVal

#Create text file with Data of interes
outputFile = open('StressOutput.dat','w')
outputFile.write('Maximum Mises Stress in Leg\n')
outputFile.write('%10.4E \n' % (max_stress))
outputFile.close()
 
Your question is exactly the example in the documentation on python scripting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor