User login

Navigation

You are here

Obtain Load-displacement curve from Abaqus/Explicit analysis via Python

Nan Hu's picture

Hi, all,

I'm quite sure we can use Python read displacement and load for certin node set from Abaqus odb result file and then plot X-Y data (That's all I need). I has been struggling for a whole week to find out a good solution. I've many resources out there but nothing has been worked out though. So, I wonder if anyone knows how to address this issue or even share me a link. I really appreciate it!

Thanks.

Aaron 

Comments

Fan Yang's picture

Hi Aaron,

I happened to write some code that may be the kind you want. Please save the following code into a file XX.py and execute the file as:

 

abaqus python XX.py -o *.odb -n nodeLabel -v variableName > filename

 

 

"""

NodeField.py

Author: Fan Yang Dec2011 at Utoronto

Code to extract the values of the specified node

Variables from Field output of an output database.

Usage: abaqus python NodeField.py -odb odbName

       -node Node -var(optional) Var

Requirements:

1. -odb   : Name of the output database.

2. -node  : Node label

3. -var   : Name of the Variable to extract.

            If this parameter is not provided,

            default displacement output will be processed.

4. -help  : Print usage

"""

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

from odbAccess import *

from sys import argv,exit

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

def rightTrim(input,suffix):

    if (input.find(suffix) == -1):

        input = input + suffix

    return input

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

def getNodeHist(odbName,Node,Var):

    """ Print values of the Variable Var(optional) for node Node

    """

    """ Open the output database """

    print 'Extract variable %s for node %d' %(Var,Node)

    odb = openOdb(odbName)

    assembly = odb.rootAssembly

    if Var:

        Variable=Var

    else:

        Variable='U'

        print 'Default displacement output'      

    for step in odb.steps.values():

        print 'Processing Step:', step.name

        print '%6s%10s%14s'%('Frame','Time','Values')

        for frame in step.frames:

            isVarPresent = 0

            Vardata=0.

            lendata=0

            incFrame = -1

            valFrame = 0.

            allFields = frame.fieldOutputs

            if (allFields.has_key(Variable)):

                isVarPresent = 1

                VarSet = allFields[Variable]

                for VarValue in VarSet.values:                

                    if (VarValue.nodeLabel == Node):

                        Vardata = VarValue.data

                        lendata = len(Vardata)

                        incFrame = frame.incrementNumber

                        valFrame = frame.frameValue

                if lendata==1:

                    print '%6d%10f'%(incFrame,valFrame),'%14.7e'%Vardata[0]

                elif lendata==2:

                    print '%6d%10f'%(incFrame,valFrame),'%14.7e %14.7e'%(Vardata[0],Vardata[1])

                elif lendata==3:

                    print '%6d%10f'%(incFrame,valFrame),'%14.7e %14.7e %14.7e'%(Vardata[0],Vardata[1],Vardata[2]) 

    """ Close the output database before exiting the program """

    odb.close()

#==================================================================

# S T A R T

#    

if __name__ == '__main__':

    

    odbName = None

    Node = 0

    Var = None

    argList = argv

    argc = len(argList)

    i=0

    while (i < argc):

        if (argList[i][:2] == "-o"):

            i += 1

            name = argList[i]

            odbName = rightTrim(name,".odb")

        elif (argList[i][:2] == "-n"):

            i += 1

            Nodestr = argList[i]

            Node=int(Nodestr)

        elif (argList[i][:2] == "-v"):

            i += 1

            Var = argList[i]

        elif (argList[i][:2] == "-h"):            

            print __doc__

            exit(0)

        i += 1

    if not (odbName):

        print ' **ERROR** output database name is not provided'

        print __doc__

        exit(1)

    if Node==0:

        print ' **ERROR** Node label is not provided'

        print __doc__

        exit(1)

    getNodeHist(odbName,Node,Var)

brunda's picture

Hi,

It is fairly simple. 

A simple way to learn python scripting for ABAQUS is by reading *.rpy files in your odb folder. Any operation that you do in ABAQUS Visulization module is stored in the file. You can read the file to get an idea on how to fetch and plot the data. Let me know if you have questions

 

 

Use this to fetch the nodal displacements and forces for the nodeset 'ALL NODES'

from abaqusConstants import *
from odbAccess import *
from math import *
import sys

path='<>'
odbfile='*.odb'
outputfile='*.dat'
odb=openOdb('%s/%s'%(path,odbfile))
file1 = open('%s/%s'%(path,outputfile),'w')

#-------------------------------------------------------------------------------
framelen=len(odb.steps['Step-1'].frames)
nodes=odb.rootAssembly.nodeSets[' ALL NODES']

#Displacement

disp=session.xyDataListFromField(odb=odb, outputPosition=NODAL, variable=(('U',NODAL, ((COMPONENT, 'U1'), (COMPONENT, 'U2'), )), ), nodeSets=(' ALL NODES', ))

force=session.xyDataListFromField(odb=odb, outputPosition=NODAL, variable=(('RF',NODAL, ((COMPONENT, 'RF1'), (COMPONENT, 'RF2'), )), ), nodeSets=(' ALL NODES', ))

you can write the data ito .dat file and open it in matlab using 'dlmread' and plot the data

 

 

 

 

Nan Hu's picture

Wow. It look very simple. For the code you present here, is that mean "disp" and "force" will be wrote into dat. file? And if I'm only interested U3 for a specific set, called "V_dis" and RF3 for a set name "V_rea". How should I modify that.

Also, if I want to run this part in my Matlab code to call abaqus run this Python script. How should I do that. 

Thanks for hinting me on this issue. Really appreciate it!

Aaron 

Subscribe to Comments for "Obtain Load-displacement curve from Abaqus/Explicit analysis via Python"

Recent comments

More comments

Syndicate

Subscribe to Syndicate