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!
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!