Thursday 3 August 2017

ODB post processing using python scripts.

Dear All,
Today I will show you how python script can be used to do post processing of ABAQUS output files ODB. ODB is a binary file so unlike other files like input file, message file it cannot be opened directly to look at the results. Python scripts can be used to read the data in the odb files. Lets do it step by step.

You need any odb file and it would be better if you are working with  linux system.  Now follow following steps.

1. Create a python file with . py extension, in my case mark.py and write

import sys
import os
from odbAccess import *
from numpy import savetxt,loadtxt,sort,asarray,zeros
from abaqusConstants import *
import sys
################################################
from odbMaterial import *
from odbSection import *
################################################

# reading the odb file. 
odb=openOdb(path='/home/kishan/Job-1.odb') 
print odb


Some of these are mandatory modules which need to imported to read the abaqus file.
Then open a terminal in the folder where python file is created which in my case is  '/home/kishan'.  Type "abaqus python mark.py". The result will look like something like this

({'analysisTitle': '', 'closed': False, 'customData': python object wrapper, 'description': 'DDB object', 'diagnosticData': 'OdbDiagnosticData object', 'isReadOnly': False, 'jobData': 'JobData object', 'materials': 'Repository object', 'name': '/home/kishan/Desktop/simulation/ICAMS/Ramber_Hydrogen/Ramberg_PBC/Job-1.odb', 'parts': 'Repository object', 'path': '/home/kishan/Job-1.odb', 'profiles': 'Repository object', 'readInternalSets': False, 'rootAssembly': 'OdbAssembly object', 'sectionCategories': 'Repository object', 'sections': 'Repository object', 'sectorDefinition': None, 'steps': 'Repository object', 'userData': 'UserData object'})

The important point to note here is the bracket used which is '})' which means that we can go inside the odb file using 'dot' for example we can write "print odb.steps" to look results related to step.  If you are familiar with object oriented programming then you know what I am talking about.

2. Then let's do "print odb.steps"  so see what happens.  The ouput on screen is 
 {'Step-1': 'OdbStep object'} Which means there is only one step used with name Step-1. please keep in mind that s is capital like in superman.  You will also find that now there is only curly bracket which means we have to put name not instead  of dot. So we will write now "print odb.steps['Step-1']" and the result is
  ({'acousticMass': -1.0, 'acousticMassCenter': (), 'description': '', 'domain': TIME, 'eliminatedNodalDofs': 'NodalDofsArray object', 'frames': 'OdbFrameArray object', 'historyRegions': 'Repository object', 'inertiaAboutCenter': (), 'inertiaAboutOrigin': (), 'loadCases': 'Repository object', 'mass': -1.0, 'massCenter': (), 'name': 'Step-1', 'nlgeom': True, 'number': 1, 'previousStepName': 'Initial', 'procedure': '*COUPLED TEMPERATURE-DISPLACEMENT, STEADY STATE', 'retainedEigenModes': (), 'retainedNodalDofs': 'NodalDofsArray object', 'timePeriod': 2.0, 'totalTime': 0.0})


 3. Now there is same bracket as in step 1 so we will again use dot and lets go in frames "print odb.steps['Step-1'].frames". The result will look something like this 
['OdbFrame object', 'OdbFrame object', 'OdbFrame object', 'OdbFrame object', 'OdbFrame object', 'OdbFrame object', 'OdbFrame object', 'OdbFrame object', 'OdbFrame object']  . There is only square bracket which is new. Now we have to use numbers. Abaqus divides the whole analysis in many increments. If we write 
"print odb.steps['Step-1'].frames[0]" , this means that we are looking at step-1 at the start of step or say at first increment which will corresponds to t=0 time of this step. 

That's it. You all have to do is learn a simple python like reading a file, writing data in file, all loops and look carefully at the brackets. 
  • ({---------------------- use . 
  • {----------------------- use names 
  • []----------------------- use numbers 0 for starting and -1 for end.
I hope that it was useful for you. If you still have some doubts do comment and I will try to answer them as soon as possible   

4 comments:

  1. I requested Kishan to help in extracting maximum PEEQ (among all nodes and for every time frame) from odb file. I made it not only by writing a script for me but also he explained me how to do it step by step. In simple words, he teaches how to fish together with that he gives fish as well. Would you believe what you have to learn is some basics of python and understanding of this blog page is sufficient to do anything in abaqus!!! I didnt believe until he showed it to me, it is true. I wish him to write many more pages in this blog! I request Kishan to make a small video explaining the details of "ODB post processing using python scripts". It will be very helpful to everyone. Wish you all success Kishan.

    ReplyDelete
    Replies
    1. Thanks a lot for this wonderful comment Vijay. Will work on the video soon. Please see if you want me to cover any other topic. I will do my best to give a simplified version. Have a great day and again thanks for comment.

      Delete
  2. Hello everyone,I wrote a python script to extract some values from the odb file, And I want to know how to run automatically this script after each increment

    ReplyDelete
  3. Hi Kisan, Could you help me in doing postprocessing in python? Please get in touch. I also need ur help like u helped vijay. My mail id is me17s008@smail.iitm.ac.in

    ReplyDelete