Abaqus ODB Python Script: Extract Results Without the GUI

Abaqus ODB Python Script: Extract Results Without the GUI

Table of Contents

You finished a long run, and now you need one number out of it: the peak von Mises stress in a weld toe, the reaction force history at a boundary, the displacement of one node across 200 frames. Clicking through the Visualization module works once. It stops working when you have forty jobs, or when a reviewer asks you to repeat the extraction next month with a slightly different mesh.

An Abaqus ODB Python script solves that properly. The ODB is just a database with a documented object tree, and Abaqus ships a Python interpreter that can read it directly. This guide shows the object tree, two ways to run the script, working code for field and history output, and the mistakes that cause most of the errors people hit on their first attempt.

What an Abaqus ODB Python script actually does

An .odb file is a binary results database. It holds the model (parts, instances, node and element sets), and the results, organised as steps, then frames, then field and history output.

The odbAccess module gives you read access to that structure. You open the file, walk down to the output you want, and write it wherever you need it: CSV, a text report, a NumPy array, a database. No viewport, no XY data manager, no clicking.

Two important limits before you start. First, odbAccess is read-mostly; you can add field output to an ODB, but you cannot change the analysis results that are already in it. Second, you can only read what the job actually wrote. If *OUTPUT, FIELD did not include PEEQ, no script will recover it, and you will have to re-run the job. Getting those requests right before you submit is covered in our guide to Abaqus field output vs history output.

Two ways to run the script, and the licence difference

abaqus python: the lightweight route

abaqus python extract.py

This starts the Abaqus Python interpreter directly. You get odbAccess, abaqusConstants, and the standard library. You do not get mdb, session, or anything to do with viewports and images.

The practical advantage is licensing: this route does not check out an Abaqus/CAE token. On a shared licence pool that matters. If all you do is read numbers out of an ODB, use this.

abaqus cae -noGUI: the full kernel

abaqus cae -noGUI=extract.py

This starts the full CAE kernel without a window, so session and mdb are available. You need it for anything that touches the viewport: printing PNGs of contour plots, using session.XYDataFromHistory, writing report files with session.writeFieldReport, or building a model and submitting it in the same script. It consumes a CAE token for as long as it runs.

One more thing worth checking before you debug anything else, because it changes your syntax: the Python version. Abaqus 2023 and earlier ship Python 2.7. Abaqus 2024 and later ship Python 3. Confirm it on your install rather than guessing:

abaqus python -c "import sys; print(sys.version)"

The ODB object tree you need to know

Almost every script is a walk down the same path:

  • odb
    • rootAssembly
      • instances['PART-1-1'] → nodes, elements, nodeSets, elementSets
      • nodeSets['TOP_FACE']
      • elementSets['WELD']
    • steps['Step-1']
      • frames[-1] → fieldOutputs['S'] → .values, .bulkDataBlocks
      • historyRegions['Node PART-1-1.5'] → historyOutputs['U2'] → .data

Field output is spatial: one value per node or integration point, per frame. History output is temporal: a list of (time, value) pairs at a point or for the whole model. Picking the wrong one is the most common reason a script returns an empty list.

When you are not sure what is inside a file, print the keys first. This is the fastest debugging habit in ODB scripting:

from odbAccess import openOdb

odb = openOdb('Job-1.odb', readOnly=True)
print(odb.rootAssembly.instances.keys())
print(odb.rootAssembly.nodeSets.keys())
print(odb.steps.keys())

step = odb.steps[odb.steps.keys()[-1]]
print(len(step.frames), 'frames')
print(step.frames[-1].fieldOutputs.keys())
print(step.historyRegions.keys())
odb.close()

A working script: von Mises stress to CSV

This pulls integration point stress from the last frame, limited to one element set, and writes it to CSV.

from odbAccess import openOdb
from abaqusConstants import *
import csv

odb  = openOdb('Job-1.odb', readOnly=True)
step = odb.steps['Step-1']
frame = step.frames[-1]

region = odb.rootAssembly.instances['PART-1-1'].elementSets['WELD']
stress = frame.fieldOutputs['S'].getSubset(region=region,
                                           position=INTEGRATION_POINT)

f = open('mises.csv', 'w')          # Python 2: open('mises.csv', 'wb')
w = csv.writer(f)
w.writerow(['element', 'ip', 'mises', 'pressure', 's11'])
for v in stress.values:
    w.writerow([v.elementLabel, v.integrationPoint,
                v.mises, v.press, v.data[0]])
f.close()
odb.close()

A few notes on this. readOnly=True stops Abaqus from writing a lock file and from silently upgrading the database. getSubset is what keeps the loop small; without it you iterate every element in the model. And v.data is the raw component array, ordered S11, S22, S33, S12, S13, S23 for a 3D element, while v.mises and v.press are invariants Abaqus computes for you.

If you want nodal values instead, be careful which position you ask for. Stress lives at integration points, so position=NODAL returns nothing. Use position=ELEMENT_NODAL to get values extrapolated to the element corners, and accept that neighbouring elements will disagree at shared nodes. NODAL is correct for genuinely nodal fields such as U, RF, and NT11.

Pulling history output: reaction force and displacement versus time

History output is cheaper to write and much cheaper to read, so request it for anything you plan to plot against time.

odb  = openOdb('Job-1.odb', readOnly=True)
step = odb.steps['Step-1']

for rname, region in step.historyRegions.items():
    for oname, out in region.historyOutputs.items():
        if oname.startswith('RF'):
            print(rname, oname)
            for t, val in out.data:
                print('%10.5f %14.6e' % (t, val))
odb.close()

Region names are generated by Abaqus and look like Node PART-1-1.5, Element PART-1-1.12 Int Point 1, or Assembly ASSEMBLY. Do not hardcode them from memory. Print historyRegions.keys() once and copy the real string, or match it with startswith as above.

Finding peak stress and where it happened

A frequent request is the maximum over the whole history, plus its location. The direct version is a nested loop:

peak, where = -1.0e30, None
for frame in step.frames:
    for v in frame.fieldOutputs['S'].values:
        if v.mises > peak:
            peak = v.mises
            where = (frame.frameValue, v.elementLabel, v.integrationPoint)
print('peak mises %.3f at time %.4f, element %d, ip %d'
      % (peak, where[0], where[1], where[2]))

This is correct and perfectly fine for a few hundred thousand values. It becomes slow on large models, because every FieldValue object is created in Python one at a time.

Making it fast on large models

For big ODBs, use bulkDataBlocks instead of .values. It returns the data as arrays rather than per-value Python objects, which is normally one to two orders of magnitude faster:

import numpy as np

field = step.frames[-1].fieldOutputs['S']
for block in field.bulkDataBlocks:
    mises = np.array(block.mises)
    labels = np.array(block.elementLabels)
    i = mises.argmax()
    print(labels[i], mises[i])

Three more habits that cut runtime a lot: request output only on the sets you care about in the job itself, use a smaller output frequency instead of every increment, and open the ODB once and extract everything you need in that single pass. Opening and closing a large file repeatedly is often the real bottleneck, not the loop.

If extraction is slow because the jobs are slow, the fix is upstream of scripting. Our HPC service runs Abaqus and ANSYS jobs on dedicated hardware, which also means your post-processing scripts run next to the ODB instead of across a network share.

Common mistakes that break ODB scripts

  • Running the script with system Python. import odbAccess fails with ImportError in any Python that is not Abaqus’s own. Use abaqus python or abaqus cae -noGUI.
  • Lowercase set names. Abaqus stores assembly and instance set names in uppercase. nodeSets['top_face'] raises a KeyError; nodeSets['TOP_FACE'] works.
  • Looking for an instance set at assembly level. A set defined on a part lives under instances['PART-1-1'].nodeSets. A set defined in the Assembly module lives under rootAssembly.nodeSets. They are different dictionaries.
  • Asking for NODAL stress. Returns an empty subset. Use ELEMENT_NODAL or INTEGRATION_POINT.
  • Forgetting odb.close(). On Windows the file stays locked, and the next job that tries to write it fails.
  • Reading an ODB from an older release. You get a version error. Convert it first with abaqus upgrade -job new_name -odb old_name.
  • Opening an ODB while the job is still running. Results can be incomplete or the file can be locked. Wait for the job to finish, or read the .sta file for progress instead.
  • Mixing Python 2 and 3 syntax. print x, dict.keys() indexing, and open(..., 'wb') for the csv module all behave differently between the two. Check your version first.

Ready-to-use models and scripts

If you would rather start from working code than build it from scratch, these packages include the scripts and the models they run on:

For the broader scripting context, see our guide on Python scripting in Abaqus. The official reference for the objects used here is the Abaqus Scripting User’s Guide chapter on reading from an output database, and there is a minimal field data example in the same manual.

FAQ

Can I read an ODB file with normal Python outside Abaqus?

Not with odbAccess, which only exists inside the Abaqus Python installation. The usual workaround is a two-step pipeline: run a small script under abaqus python that writes CSV, NPZ, or JSON, then do the analysis and plotting in your own Python with pandas and matplotlib. That also keeps your analysis code free of Python 2 constraints on older Abaqus releases.

Does an Abaqus ODB Python script use a licence token?

abaqus python does not check out an Abaqus/CAE token, so it is the better choice on a shared pool. abaqus cae -noGUI does, for the whole duration of the script. Solver tokens are unrelated; reading results does not need them.

Why does my field output subset come back empty?

Three usual causes, in order of likelihood: the position is wrong for that variable, such as NODAL for S; the set name does not match exactly, including uppercase; or the output variable was never requested in the job. Print fieldOutputs.keys() for that frame to confirm the variable exists before debugging the region.

How do I get stress at a specific node rather than an element?

Request position=ELEMENT_NODAL and subset by a node set. You will get one value per element attached to that node, so average them yourself if you need a single number, and remember that a large spread between them is a mesh refinement signal, not a scripting problem.

Can a script write new results back into the ODB?

Yes, within limits. You can add your own field output to an existing frame with frame.FieldOutput(...) and addData(...), which is how people store derived quantities such as a fatigue damage parameter and then contour them in Viewer. Open the ODB without readOnly=True for this, and keep a backup copy, because a failed write can leave the file unusable.

Where to go from here

Start small. Write a ten-line script that opens one of your own ODBs and prints the keys at each level. Once you can see the tree, the rest is bookkeeping: pick the step, pick the frame, subset the region, read the values.

The payoff shows up on the second project, not the first. Extraction that is scripted is repeatable, reviewable, and survives a mesh change without an afternoon of clicking.

The same logic applies on the input side: if you are generating or modifying runs programmatically, it helps to be comfortable with the input file itself. See our guide on how to edit the Abaqus INP file with the Keywords Editor and with Python.

If you want tested scripts and the models that go with them, browse the Abaqus and Python packages in our shop. If you would rather hand over a specific extraction or automation job, we take it on through our simulation and consulting services.

Leave a Reply

Your email address will not be published. Required fields are marked *

Related  articles

Abaqus Integration Point vs Nodal Stress: Why Peaks Differ
Compare integration-point, element-nodal and unique-nodal stress in Abaqus, and check whether a contour peak depends on extrapolation, averaging or mesh size.
Abaqus Linear Perturbation vs General Step: What Actually Changes
Abaqus Linear Perturbation vs General Step: What Actually Changes

You run a frequency extraction after a static step and the frequencies come out the same whether or not the part had yielded. You run a static linear perturbation step and the reaction force is a fraction of what you

Harmonic Response Analysis in ANSYS Workbench: A Practical Guide
Harmonic Response Analysis in ANSYS Workbench: A Practical Guide
How to set up harmonic response analysis in ANSYS Workbench: modal link, frequency range, solution method, damping, loads and results, plus the common mistakes.

See more

Related  Products

See more