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