3D S. C OM © D as sa ult S ys tè m es | C on fide nt ial In fo rm at ion | 10 /6 /2 01 5 | r ef .: 3D S_ D oc um en t_ 20 14
Enhance your productivity
by using Abaqus Scripting
Shikta Mishra
Technical Specialist, Simulia Central
3D S. C OM/ SI M U LI A © D as sa ult S ys tè m es | C on fide nt ial In fo rm at ion | 10 /6 /2 01 5 | r ef .: 3D S_ D oc um en t_ 20 14
Motivation
Python Basics
Abaqus Python
Abaqus Object Model
Plug-ins
Demonstration: RSG Dialog Builder
3D S. C OM/ SI M U LI A © D as sa ult S ys tè m es | C on fide nt ial In fo rm at ion | 10 /6 /2 01 5 | r ef .: 3D S_ D oc um en t_ 20 14
Motivation: why customize Abaqus?
Provides automated
environment for experienced
analysts
Provides
advanced analysis functionality
to non-FEA users
C
ustom
iz
ed
application
Customized versions of
Abaqus provide an
effective analysis tool for
a wide range of user
expertise …
Automate repetitive tasks
Model building
Job submission and monitoring
Postprocessing
Prescribe default behavior
Extend functionality
Enhance the interface
Graphical
Nongraphical
3D S. C OM/ SI M U LI A © D as sa ult S ys tè m es | C on fide nt ial In fo rm at ion | 10 /6 /2 01 5 | r ef .: 3D S_ D oc um en t_ 20 14
Why Python?
3D S. C OM/ SI M U LI A © D as sa ult S ys tè m es | C on fide nt ial In fo rm at ion | 10 /6 /2 01 5 | r ef .: 3D S_ D oc um en t_ 20 14
Scripting Language v/s Programming Language
This information is taken from Scripting: Higher Level
Programming for the 21
stCentury
by Ousterhout J.K.
Scripting
Language
Programming
Language
High Level
(# Instr/Stmnt)
Low Level
(# Instr/Stmnt)
Weakly Typed
Strongly Typed
Rapid Development
Rapid Run-Time
Examples: Python,
Tcl, Perl, etc
Examples: C, C++,
Fortran, etc
3D S. C OM/ SI M U LI A © D as sa ult S ys tè m es | C on fide nt ial In fo rm at ion | 10 /6 /2 01 5 | r ef .: 3D S_ D oc um en t_ 20
14
Example using common syntax rules:
# simple example
max = 5; i = 0
x, y, z = 1, 2, 3
while i <= max:
square = i**2 + x*y
cube = i**3 - z
print i, square, cube
i = i + 1 # increment index
for j in ['ASN',1,2]:
pass
print 'The example is completed\
now print a long message'
Semicolon for two statements
blank lines ignored
Comments start with # and continue to the end
of the line
Backslash for line
continuation
Indentation
delimits blocks
(such as loops)
The amount of
indentation is
arbitrary but
must be
consistent for a
block
An empty block is denoted with the pass
statement
The syntax forces the user to write readable
code and enables productivity
3D S. C OM/ SI M U LI A © D as sa ult S ys tè m es | C on fide nt ial In fo rm at ion | 10 /6 /2 01 5 | r ef .: 3D S_ D oc um en t_ 20 14
Python Scripting Style Guide
Suggested style guidelines for writing python scripts
The style guide is available from Knowledge Base Article
QA00000008185
Abaqus provides a style guide to help maintain script consistency.
A consistent style:
Generally makes scripts easier to debug and maintain
Can establish conventions that parallel the object model
3D S. C OM/ SI M U LI A © D as sa ult S ys tè m es | C on fide nt ial In fo rm at ion | 10 /6 /2 01 5 | r ef .: 3D S_ D oc um en t_ 20 14
Accessing Python
From Abaqus/CAE
3D S. C OM © D as sa ult S ys tè m es | C on fide nt ial In fo rm at ion | 10 /6 /2 01 5 | r ef .: 3D S_ D oc um en t_ 20 14
Accessing Python
Use
sys.version
to query the version of Python that is being used
>>>
import sys
>>> sys.version
'2.7.3 (default, May 1 2014, 02:56:01) [MSC v.1600 64 bit (AMD64)]'
From Command Prompt
To quit python interpreter from a command prompt use:
Ctrl Z – Enter (for windows)
3D S. C OM © D as sa ult S ys tè m es | C on fide nt ial In fo rm at ion | 10 /6 /2 01 5 | r ef .: 3D S_ D oc um en t_ 20 14
Running Python
You may not bypass the Abaqus/CAE kernel like this:
abaqus python myscript.py
abaqus script myscript.py
abaqus cae startup = myscript.py
abaqus cae script = myscript.py
abaqus viewer startup = myscript.py
Running
Python
3D S. C OM/ SI M U LI A © D as sa ult S ys tè m es | C on fide nt ial In fo rm at ion | 10 /6 /2 01 5 | r ef .: 3D S_ D oc um en t_ 20 14
Abaqus Scripting Interface Basics
command
line interface
(CLI)
Abaqus/CAE
Abaqus/CAE
kernel
Abaqus/Standard
Abaqus/Explicit
output database file
input file
Python interpreter
replay
files
script
GUI
commands
3D S. C OM/ SI M U LI A © D as sa ult S ys tè m es | C on fide nt ial In fo rm at ion | 10 /6 /2 01 5 | r ef .: 3D S_ D oc um en t_ 20 14
Building Scripts
Macro Manager
Abaqus Replay(.rpy) File
3D S. C OM/ SI M U LI A © D as sa ult S ys tè m es | C on fide nt ial In fo rm at ion | 10 /6 /2 01 5 | r ef .: 3D S_ D oc um en t_ 20 14
Replay File Example
Creating a script that rotates the model in current display
Steps:
1) In Abaqus/CAE rotate the model by a specifying an increment in the
dialog box.
session.currentViewportName.view.rotate(xAngle=10,
yAngle=0,zAngle=0,mode=MODEL
)
2) Cut and paste this command into a new text file. Add a Python statement to loop over the command:
for x in range(36):
session.currentViewportName.view.rotate(xAngle=10,
yAngle=0,zAngle=0, mode=MODEL
)
3D S. C OM/ SI M U LI A © D as sa ult S ys tè m es | C on fide nt ial In fo rm at ion | 10 /6 /2 01 5 | r ef .: 3D S_ D oc um en t_ 20 14
Replay File Example
3D S. C OM/ SI M U LI A © D as sa ult S ys tè m es | C on fide nt ial In fo rm at ion | 10 /6 /2 01 5 | r ef .: 3D S_ D oc um en t_ 20 14
Integrated Development Environment : Abaqus PDE
The IDE built into Abaqus is known as Abaqus
Python Development Environment (PDE)
Separate application
Accessible from within Abaqus/CAE or independently
Step through a Python script running in the Abaqus/CAE
kernel or GUI
3D S. C OM/ SI M U LI A © D as sa ult S ys tè m es | C on fide nt ial In fo rm at ion | 10 /6 /2 01 5 | r ef .: 3D S_ D oc um en t_ 20 14
Abaqus Object Model
The Abaqus Scripting Interface extends Python with new types of objects.
The hierarchy and the relationship between these objects is called the Abaqus Object model.
Object 1 Object 2Object 4 Object 5
17
3D S. C OM/ SI M U LI A © D as sa ult S ys tè m es | C on fide nt ial In fo rm at ion | 10 /6 /2 01 5 | r ef .: 3D S_ D oc um en t_ 2014
The object model describes the relationships between objects.
Use commands to access objects by stepping through the hierarchy of objects in the
object model
cell4 = mdb.models['block'].parts['crankcase'].cells[4]
Abaqus Object Model
A Part owns features,
datums, etc.
A Model owns parts
cell with index 4
part named crankcase
Model database
mdb
Variable cell4
model named
3D S. C OM/ SI M U LI A © D as sa ult S ys tè m es | C on fide nt ial In fo rm at ion | 10 /6 /2 01 5 | r ef .: 3D S_ D oc um en t_ 20 14
Abaqus Object Model
Object Attributes : Members and Methods
Identifying Constructors and Repositories
p = mdb.models['Model-1'].Part(name='Part-1',
dimensionality=THREE_D, type=DEFORMABLE_BODY)
The path to the constructor is
mdb.models['Model-1'].Part
The new Part object is placed into the parts repository
mdb.models['Model-1'].parts['Part-1']
3D S. C OM/ SI M U LI A © D as sa ult S ys tè m es | C on fide nt ial In fo rm at ion | 10 /6 /2 01 5 | r ef .: 3D S_ D oc um en t_ 20 14
Postprocessing with Abaqus Scripting
Output Database Object Model
Contains model data and results data
Results data in the ODB are categorized as Field Data or History Data.
The Odb object is normally available from inside or outside of Abaqus/Viewer or Abaqus/CAE.
Field Data
3D S. C OM/ SI M U LI A © D as sa ult S ys tè m es | C on fide nt ial In fo rm at ion | 10 /6 /2 01 5 | r ef .: 3D S_ D oc um en t_ 20 14
Postprocessing with Abaqus Scripting Interface
In this example a kernel script has been developed to
interact with an output database file through the Abaqus
Scripting Interface
The script searches for the maximum value of von Mises
3D S. C OM © D as sa ult S ys tè m es | C on fide nt ial In fo rm at ion | 10 /6 /2 01 5 | r ef .: 3D S_ D oc um en t_ 20 14
# scr_auto_run1.py
import os
jobs=['auto_job1', 'auto_job2', 'auto_job3']
path = 'C:\\Abaqus6\\Commands\\abq6141'
#path = r'C:\Abaqus6\Commands\abq6141'
#path = 'C:/Abaqus6/Commands/abq6141'
for job in jobs:
print 'job:', job
cmd = '%s job=%s inter' % (path, job)
os.system(cmd)
Same behavior
Job Submission
Example: Auto submit three Abaqus jobs, one-at-a-time
3D S. C OM © D as sa ult S ys tè m es | C on fide nt ial In fo rm at ion | 10 /6 /2 01 5 | r ef .: 3D S_ D oc um en t_ 20 14
# scr_auto_run2.py
import job
jobs=['auto_job1', 'auto_job2', 'auto_job3']
for job in jobs:
job = mdb.JobFromInputFile(
name = job, inputFileName = job + '.inp',
type = ANALYSIS)
job.submit()
job.waitForCompletion()
Job Submission
Example: Auto submit three Abaqus jobs, one-at-a-time (cont’d)
3D S. C OM © D as sa ult S ys tè m es | C on fide nt ial In fo rm at ion | 10 /6 /2 01 5 | r ef .: 3D S_ D oc um en t_ 20 14
Abaqus Environment file (abaqus_v6.env) can contain abaqus scripting interface
commands
onCaeStartup() function
Example: Auto create materials upon opening a CAE session
onJobStartup() function
def onJobStartup():
print 'The job is starting'
onJobCompletion() function
def onJobCompletion ():
print 'The result files have been copied to workdir'
def onCaeStartup():
# Material properties - read them from a file
execfile('my_material_library.py')
3D S. C OM/ SI M U LI A © D as sa ult S ys tè m es | C on fide nt ial In fo rm at ion | 10 /6 /2 01 5 | r ef .: 3D S_ D oc um en t_ 20 14
Plug-ins
Kernel Plug-in
GUI Plug-in
What is a plug-in?
An Abaqus plug-in is a piece of software that is automatically installed into
Abaqus/CAE to extend its functionality.
3D S. C OM/ SI M U LI A © D as sa ult S ys tè m es | C on fide nt ial In fo rm at ion | 10 /6 /2 01 5 | r ef .: 3D S_ D oc um en t_ 20 14
Resources
Knowledge Base Article QA00000008694 (DSx.Client Care:
www.3ds.com/support/knowledge-base
) contains a list of SIMULIA supplied
3D S. C OM/ SI M U LI A © D as sa ult S ys tè m es | C on fide nt ial In fo rm at ion | 10 /6 /2 01 5 | r ef .: 3D S_ D oc um en t_ 20 14
Really Simple GUI
It is an Abaqus/CAE plug-in
Plug-ins → Abaqus → RSG Dialog Builder
Interactive tool for building a Graphical User Interface (GUI)
Includes widgets (controls)
3D S. C OM/ SI M U LI A © D as sa ult S ys tè m es | C on fide nt ial In fo rm at ion | 10 /6 /2 01 5 | r ef .: 3D S_ D oc um en t_ 20 14
RSG Demonstration
Diagram showing definitions
Hit OK to build model, analyze, and display
results, this executes the kernel script
Text entry boxes for
3D S. C OM/ SI M U LI A © D as sa ult S ys tè m es | C on fide nt ial In fo rm at ion | 10 /6 /2 01 5 | r ef .: 3D S_ D oc um en t_ 20 14
Next steps …
•
Find all the upcoming eSeminars from
SIMULIA home page
•
eSeminar Replay: Watch for email with details
•
Register for a Training Class
3ds.com/simulia-training
•
Find all eSeminar replay since 2014 in
3ds.com/slc
•
Register and Attend RUMs
3ds.com/simulia/
3D S. C OM © D as sa ult S ys tè m es | C on fide nt ial In fo rm at ion | 10 /6 /2 01 5 | r ef .: 3D S_ D oc um en t_ 20 14