Using a Script to Extract Additional Parameters from the Abaqus Output File

If a Python script named userscript_odb.py is detected in the same directory as the reference output database (.odb) file, this script is executed at design time to produce additional output parameters and is executed at run time to update their values. The userscript_odb.py must use the odbaccess module to access the odb file.

The following topics are discussed:

The user script produces a tab-delimited ASCII file called user_params.txt that contains the name of each additional output parameter and its value. This file is parsed by the Abaqus component.

Scalar output is written in the following form:

  • Principal_strain 1.0e-5

  • Principal_stress 100.0

History array output is written in the following form:

My_History_Array ((0, 0), (1, 0.277437))

An Example of a User Script to Extract Additional Parameters

You can include a script that opens an output database, extracts specific parameters from the database, and writes them to an ASCII file.

The following script can extract additional parameters:

"""
userscript_odb.py
Script to open an output database named tennis.odb, extract specific 
parameters from the database, and write them to an ASCII file.
usage:
abaqus python userscript_odb.py
"""
#
import odbAccess
from odbAccess import *
import __main__
import operator
#
# S T A R T
# 
if __name__ == '__main__':
    odbName = 'tennis.odb'
# check if odb file needs version upgrade
    needsUpgrade = odbAccess.isUpgradeRequiredForOdb(upgradeRequiredOdbPath=odbName)

    if(needsUpgrade):
        odbAccess.upgradeOdb (existingOdbPath=odbName,upgradedOdbPath='upgradedOdb')
        myOdb=openOdb('upgradedOdb.odb',readOnly=True)
    else:
        myOdb = openOdb(odbName,readOnly=True)
        
    steps = myOdb.steps
    
    paramsFile = open ('user_params.txt','w')
    
#access and print steps 
for key in steps.keys():
    step = steps[key]
    print 'Processing Step:', step.name
        
#extract a history output array
    historyRegions = step.historyRegions
    for key2 in historyRegions.keys():   
       historyRegion = historyRegions[key2]
                
# compute history location to append to the parameter 
    historylocation = ""
    try:
       historyposition = historyRegion.position
       if(historyposition == NODAL):
           historypoint = historyRegion.point
           historynode = historypoint.node
           historynodelabel = historynode.label
           historylocation = "_" + str(historynodelabel)
       if(historyposition == INTEGRATION_POINT):
           historypoint = historyRegion.point
           historyelement = historypoint.element
           historyelementlabel = historyelement.label
           historylocation = "_" + str(historyelementlabel)
       if(historyposition == WHOLE_ELEMENT):
           historypoint = historyRegion.point
           historyelement = historypoint.element
           historyelementlabel = historyelement.label
           historylocation = "_" + str(historyelementlabel)
       if(historyposition == WHOLE_REGION):
           historylocation = ""
       if(historyposition == WHOLE_MODEL):
           historylocation = "" 
    except:
       historylocation = ""


    historyOutputs = historyRegion.historyOutputs
    for key3 in historyOutputs.keys():
        historyOutput = historyOutputs[key3]                
        paramsFile.write(str(step.name.replace('-','_')) 
        + "__" + str(historyOutput.description.replace(' ','_')) + 
        str(historylocation) + "\t" + str(historyOutput.data) + "\n")
        try:
           values = map(operator.itemgetter(1),historyOutput.data)                          
           paramsFile.write(str(step.name.replace('-','_'))
           + "__Max__" + str(historyOutput.description.replace(' ','_')) + 
           str(historylocation) + "\t" + str(max(values)) + "\n")
           paramsFile.write(str(step.name.replace('-','_'))
           + "__Min__" + str(historyOutput.description.replace(' ','_')) + 
           str(historylocation) + "\t" + str(min(values)) + "\n")
        except:
            pass

#close params file
    paramsFile.close()