×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Write python script that extracts max stress from .odb files

Write python script that extracts max stress from .odb files

Write python script that extracts max stress from .odb files

(OP)
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!

RE: Write python script that extracts max stress from .odb files

(OP)
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()

RE: Write python script that extracts max stress from .odb files

Your question is exactly the example in the documentation on python scripting

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources