Interacting with Abaqus

Note: This is not a complete nor comprehensive recipe for all possibilities and options but rather what is needed for the scope of this site. Hence, the focus is on the interaction required and helpful for creating and running scripts in an educational context for the relevant courses.

Prerequisites

  • Abaqus version 2016 or later
  • Any text editor, preferably one that enables syntax highlighting for Python. Note that the editor will not be integrated with debugging anyways.
  • Basic Python knowledge

Starting Abaqus

Starting Abaqus CAE

The most versatile method is simply to

  • start Abaqus Command (typically from the Start menu)
  • navigate to a designated directory for the session
  • run the command:
    abaqus cae

Several optional parameters to the command are available. Relevant examples include

    abaqus cae script=myScript.py     # (running a script at startup)
    abaqus cae noGUI=myScript.py      # (running a script without the GUI)

The latter method is very useful when running many tasks like parameter studies where running a display has no added value but drains resources.

Organizing files and folders

An Abaqus session tends to create a lot of files. Most of theese can be considered temporary data, i.e. files not worth keeping. The files will be generated in the work directory which is by default equal to the directory where abaqus cae was started.

For instance, works will be the work directory following the command C:\temp\works>abaqus cae

Long paths containing non-standard symbols can easilly be a source of problems. For instance, a work directory at

C:\Users\ærlændå\OneDrive\Documents\skole\gløs\Abaqus\Brygging av øl\models\co2 ventil\versjon 10%\

has potentials for great fun on many levels.

Best practice:

  • keep the path simple and and typographically straight forward without spaces, regional typesets and the need for wrapping strings to regular expressions or other coding acrobatics.
  • avoid work directories in the sky (OneDrive etc.) but rather use the drives on the local computer. A bunch of quite large files will be flying forth and back during simulation, and any choke points will slow down the job. Files for storage can always be moved later on.
  • scripts can, however, preferably be located on external and crash-safe locations. You may have invested quite a lot of time on theese...

Executing Abaqus scripts

A script is simply a file containing Abaqus Scripting Interface commands. It can be a significant work of brilliance containing some thousand lines of codes, or just a few lines of commands like this one:

from abaqus import *
from abaqusConstants import *
mdb.Model(name = 'Model-A')  # Creates a new model

If the file path is C:\temp\works\scripts\scriptA.py while the work directory is C:\temp\works\, the script can be run using the following procedures:

  • Abaqus CAE not running: Abaqus Command, with the command
    C:\temp\works>abaqus cae script=scripts\scriptA.py
  • Abaqus CAE running: Main menu -> File -> Run Script...
  • Using the Command line interface in CAE with the command execfile(), either by relative path or complete path:
>>> execfile('scripts\scriptA.py')
The model "Model-A" has been created.
>>> execfile('C:\temp\works\scripts\scriptA.py')
The model "Model-A" has been created.

Writing scripts

  • Scripts can be developed from scratch. This approach can be very efficient when you know the language and the object model. The method is particularilly useful for segments of a script where automatically generated code is not very useful.
  • Templates and examples can be utilized sucessfully in many cases. Templates can provide a basic structure as well as common commands.
  • Many code snippets on this site was developed using the command line interface. The command line interface provides instant exploration of the objects, properties and methods, as well as a way to test the logic of small segments of code.
  • During an Abaqus CAE session, the abaqus.rpy file is continously updated with the commands being exectuted. Relevant code can be copied and adapted to your script.
  • Macro recording is another very useful technique available from: Main menu -> File -> Macro Manager...

Modules

Some standard packages and modules are available, and there are nothing particular to consider when importing these. For instance

import numpy
import math

or alternatively more specific and/or convenient as


from numpy import cos, sin, radians

Write you own modules

Writing custom modules for common tasks can be very useful, see for instance Custom tools for selecting entities

The modules must be located in one of the search path that can be listed by sys.path (just a few shown in the result):

>>> sys.path
['C:\\SIMULIA\\CAE\\2019', 'C:\\SIMULIA\\CAE\\2019\\win_b64',...
 'C:\\temp\\works',... 
 'C:\\SIMULIA\\CAE\\2019\\win_b64\\tools\\SMApy\\python2.7',...
 'C:\\SIMULIA\\CAE\\2019\\win_b64\\tools\\SMApy\\python2.7\\lib\\site-packages\\win32\\lib',...
 'C:\\SIMULIA\\CAE\\2019\\win_b64\\code\\bin', '.']

For example, 'C:\\temp\\works' is one of the search paths as it is the work directory for the session when sys.path was called. Hence, a module will be found when being in the work directory.

You may however want to organize your custom modules somewhere else, for example on a network drive like

C:\\Users\\einstein\\OneDrive\\Abaqus\\customlib

The directory is not on the search path and must be added before it can be imported:

>>> sys.path.append('C:\\Users\\einstein\\OneDrive\\Abaqus\\customlib')
>>> import customtools

To automate further, create a file, for example startup.py, with the following lines:

import sys
sys.path.append('C:\\Users\\einstein\\OneDrive\\Abaqus\\customlib')

and start Abaqus CAE by

C:\temp\works>abaqus cae script=startup.py
TOC Next Prev

Disclaimer:This site is designed for educational purposes only. There are most likely errors, mistakes, typos, and poorly crafted statements that are not detected yet... www.ntnu.edu/employees/nils.p.vedvik

Copyright 2024, All rights reserved