Accessing Abaqus Database Using Python Scripting

Embed Size (px)

Citation preview

  • 7/22/2019 Accessing Abaqus Database Using Python Scripting

    1/4

    Accessing Abaqus Database Using Python Scripting

    Matteo [email protected]

    December 18, 2012

    1 Introduction

    This short tutorial shows how to access the history output database of Abaqus in a convenient wayusing Python scripting. This is very useful when a large amount of data needs to be extractedfor sophisticated post-processing purposes. As a complement it is also shown how the process of

    starting the analysis and gathering the data can be completely automated using Shell scriptingunder Linux OS.Before getting started, I want to point out that this is NOT an introduction neither to Python norto Abaqus. It is only a tutorial on how to have things up and running quickly and painlessly whendealing with a lot of output data for sophisticated post processing. I have written the routines bymyself, so maybe it is not the most efficient/elegant way of doing it, but it works.

    If you have any comment/suggestion/improvement to this material, do not hesitate to contact me!

    2 Accessing History Output Database

    In order to access a History Output database, this must be created when setting the analysis. Isuppose that if you are reading this guide you are familiar with that, so theres no need to explainhow to do it. You should also be familiar with the fact that all the analysis results are containedin the Abaqus .odbfile. This is a database that can be easily accessed using Python.

    In order to do so, you need to create a .pyfile, say report.py, and place it in the same folder ofyour.odbfile. What follows is a script that I created that is able to read nodal data from the .odbfile, and it successively writes them to a .dat file that is more convenient to use with Matlab forexample (dont worry, I am going to explain every single line of it).

    1 # i m p o rt d a t a b a se2 from odbAccess import 3

    4 # d at a d e c l a r a t i o n5 A = [ ]6 f = o p e n ( , r )7 c o n t = 08 f o r l i n e i n f . r e a d l i n e s ( ) :9 A. append( l i n e )10 c on t = c on t + 1

    1

  • 7/22/2019 Accessing Abaqus Database Using Python Scripting

    2/4

    11

    12 l i n e s n u m b e r = c o n t13 n od ev ec = r a ng e ( 0 , l i ne s n um be r , 1 )14

    15 # o u t p u t f i l e16 d i s p F i l e = open ( , w )17

    18 # p o i n t e r s19 odb = openOdb ( p at h= )20 s te p = odb . s t ep s [ ]21

    22 # g e t d at a23 c o n t = 024 f o r e l em en t i n nodevec :25 r e gi o n = s t ep . h i st o ry R eg i on s [Node . +s t r (A[ 0 ] [ : ] ) ]26 v a r i a b l e = r e g i o n . h i s t or y O u tp u t s [ ] . dat a27 f o r t im e , d a t a i n v a r i a b l e [ 1 : ] :28 d i s p F i l e . w r i t e ( % 10.4E % ( d a t a ) )29 d i s p F i l e . w r i t e ( \n )30 c on t = c on t + 131

    32 # o u t pu t f i l e c l o s u r e33 d i s p F i l e . c l o s e ( )34 f . c l o s e ( )

    Listing 1: Python script to access history output database

    Lets get down to the code now. The first thing to do is to import the .odb database

    1 from odbAccess import

    After that, the code reads the nodes number from a text file (, where WEmeans with extension) and I arrange them into an array (nodevec)

    1 A = [ ]2 f = o p e n ( , r )3 c o n t = 04 f o r l i n e i n f . r e a d l i n e s ( ) :5 A. append( l i n e )6 c on t = c on t + 17

    8 l i n e s n u m b e r = c o n t9 n o d e v ec = r a n g e ( 0 , l i n es n u m b er , 1 )

    At this point the output file where the data should be saved for post processing is declared

    1 d i s p F i l e = open ( , w )

    The core of the procedure resides then in pointing in the right direction, i.e. to the right region ofthe database where the data of our interest are shown. This is done with the following commands

    2

  • 7/22/2019 Accessing Abaqus Database Using Python Scripting

    3/4

    1 odb = openOdb ( p at h= )2 s te p = odb . s t ep s [ ]

    It is worth noting that the names associated with the database, and the step, are exactly the names

    that you have assigned to these entities back when you build the model.

    To actually get to the data we want we need to go down the pointers road a little bit more. Thiscan be accomplished by two nested for loops

    1 c o n t = 02 f o r e l em en t i n nodevec :3 r e gi o n = s t ep . h i st o ry R eg i on s [Node . +s t r (A[ 0 ] [ : ] ) ]4 v a r i a b l e = r e g i o n . h i s t or y O u tp u t s [ ] . dat a5 f o r t im e , d a t a i n v a r i a b l e [ 1 : ] :6 d i s p F i l e . w r i t e ( % 10.4E % ( d a t a ) )7 d i s p F i l e . w r i t e ( \n )8 c on t = c on t + 1

    Again, the part name is the same you have assigned when building the FE model, while the variablename is the name of the variable you want to retrieve. For example, if you need the displacementin the x2 direction, you would use U2. As a side note, with this technique you can also get the timevector by accessing the time entry in the variable array, instead of the data entry.

    The last two lines of the script only serve to close files opened during the extraction procedure.

    1 d i s p F i l e . c l o s e ( )2 f . c l o s e ( )

    3 Analysis Automation

    The script written above can be launched from terminal by typing

    /path/to/abaqus/executable python report.py

    It can then be noted that it is far more convenient to automate the procedure of

    1. Launch the FE analysis

    2. Launch data extraction

    The automation is particularly useful when launching FE analysis in series. In order to do so, shellscripting can be used. As a side note, this part assumes you are running abaqus under Linux OS.You must be aware that the automation procedure must be changed when using Windows OS.

    3

  • 7/22/2019 Accessing Abaqus Database Using Python Scripting

    4/4

    1 a b q p a t h = p a t h / t o / a b a q us / ex e c u t a b l e / 2 PARAM= 3 #4 # it h a n a l y s is5 # 6 #

    7 cd p a t h / t o / it h / a n a l y s i s / f o l d e r /8 $ a b q pa t h j o b= cpus= $PARAM in te ra c ti ve9 s l ee p 1 s10 rm .11 rm 12 mv . odb output . odb13 t i me $ a b q pa t h p yt ho n r e p o r t . p y14 echo e \n15 echo e 16 echo E x t r a c t i o n c o m pl e t e d 17 echo e \ n18 s l ee p 1 s19 echo e \n20 echo e 21 echo e J o b Ter mi n a ted 22 echo e \ n

    Note the keyword interactivewhen launching the FE simulation. This is a trick to let the com-puter finish the analysis before extracting the data. Also note the trick in renaming the .odbdatabase in order to use the same python function for all the analysis (without having to changethe code for each analysis, provided you need the same data over the same region of the model).The code above can be repeated for every analysis that you need to run, and will save you a lotof time, especially if you need to deal with repeated FE analyses from which you need to performsophisticated data post-processing (that Abaqus CAE cannot perform).

    I used this code effectively to perform 2D and 3D Fourier transforms for Lamb wave propagation

    in composite plate, and it worked like a charm! Well, I hope you found this tutorial useful! Again,if you have any hint on how to improve this, please contact me!

    4