Académique Documents
Professionnel Documents
Culture Documents
com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
Dassault Systemes Simulia Corp. (SIMULIA) retains the copyright to this document.
These training notes are available by special arrangement from the SIMULIA
Learning Community to the Authorized Party (company or individual) whose
details appear in the watermarked text.
Release of these training notes in PDF format is made with the following
stipulations:
1. The materials are for personal use by the Authorized Party only.
2. The Authorized Party may view and print these training files, but must not
otherwise attempt to modify their contents, or extract content from the files.
R 6.12
Course objectives
Help students to develop a high level understanding of the Abaqus scripting capabilities.
Organize and present the technical details of Python and the Abaqus Scripting Interface.
Expose the strengths and weaknesses of Abaqus scripting.
Encourage the student to use scripting in new ways.
Targeted audience
www.3ds.com | © Dassault Systèmes
Analysts.
Prerequisites
None.
2 days
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
Day 1
Day 2
Legal Notices
The Abaqus Software described in this documentation is available only under license from Dassault
Systèmes and its subsidiary and may be used or reproduced only in accordance with the terms of such
license.
This documentation and the software described in this documentation are subject to change without
prior notice.
Dassault Systèmes and its subsidiaries shall not be responsible for the consequences of any errors or
omissions that may appear in this documentation.
www.3ds.com | © Dassault Systèmes
No part of this documentation may be reproduced or distributed in any form without prior written
permission of Dassault Systèmes or its subsidiary.
© Dassault Systèmes, 2012.
Printed in the United States of America
Abaqus, the 3DS logo, SIMULIA and CATIA are trademarks or registered trademarks of Dassault
Systèmes or its subsidiaries in the US and/or other countries.
Other company, product, and service names may be trademarks or service marks of their respective
owners. For additional information concerning trademarks, copyrights, and licenses, see the Legal
Notices in the Abaqus 6.12 Release Notes and the notices at:
http://www.3ds.com/products/simulia/portfolio/product-os-commercial-programs.
Revision Status
Lesson content:
Overview
Terminology
Types and Languages for Customizing Abaqus
Examples
Abaqus Scripting Interface Basics
www.3ds.com | © Dassault Systèmes
75 minutes
L1.2
Overview (1/5)
A 3rd-party programming language called Python is embedded within the Abaqus product line.
SIMULIA has extended the functionality of Python to provide an interface to Abaqus data.
What we think:
www.3ds.com | © Dassault Systèmes
Postprocessing
Customized
application
of Abaqus provide an
Extend functionality effective analysis tool
Enhance the interface for a wide range of
user expertise …
Graphical
Nongraphical
Provides
advanced analysis functionality
to non-FEA users
L1.4
Overview (3/5)
Repeatability, productivity, and quality to proven workflows and methods throughout the design and
validation process
Customized solutions for specific applications, via customer-preferred interface (web, familiar user
interface, PLM system)
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L1.5
Overview (4/5)
Abaqus/CAE customization
The ASI allows you to customize much of the behavior of Abaqus pre- and postprocessing to suit your
specific requirements.
www.3ds.com | © Dassault Systèmes
Scripts that affect the Graphical User Interface are called GUI scripts. Those that do not are called
kernel scripts. GUI scripts are not discussed in this course.
Analysis customization
Site customization
Hardware, operating system, batch queuing, etc. may be tuned for Abaqus performance.
L1.6
Overview (5/5)
A set of routines, protocols, and tools that makes it easier to develop a software application.
An API to the data used by Abaqus; an extension of the Python programming language.
www.3ds.com | © Dassault Systèmes
Abaqus/CAE kernel
The portion of Abaqus/CAE that interprets the Abaqus Scripting Interface commands to create an
internal representation of the model.
An interface between the user and Abaqus/CAE kernel. The interface allows the user to specify
geometry and select options from dialog boxes.
L1.8
Terminology (2/2)
Programming language
Scripting language
Designed for effective integration with components written in other computer languages.
Customization
Something that has been altered according to individual specifications. Here, we often are referring to a
collection of Abaqus scripts and/or user subroutines.
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L1.9
Types and Languages for Customizing Abaqus (1/4)
Types of customization
Kernel customization
Kernel (nongraphical) scripts allow you to create new functions to perform modeling or
postprocessing tasks
» Record macros
Parametric scripts allow you to generate and execute the results of multiple analyses that differ
only in the values of some of the parameters used in place of input quantities
L1.10
Types and Languages for Customizing Abaqus (2/4)
GUI customization
Dialogs
Applications
Fortran, C
www.3ds.com | © Dassault Systèmes
Python, C++
L1.12
Types and Languages for Customizing Abaqus (4/4)
The input file (.inp) accepts parameter definitions using Python statements in the data lines of
the *PARAMETER option.
www.3ds.com | © Dassault Systèmes
The parametric scripting file (scriptname.psf) uses Python to provide a basis for defining
parametric modeling studies.
The output database file (.odb) can be accessed directly using a Python script.
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L1.13
Example: Postprocessing through Abaqus Scripting Interface
Interface
L1.14
Example: *NMAP
Application
Plug-in to generate multiple spring and/or dashpot elements, or MPC constraints between proximal nodes of
neighboring parts.
www.3ds.com | © Dassault Systèmes
L1.16
Example: Customization through Parametric Studies
Application
Abaqus/CAE
Problem description
L1.18
L1.17
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L1.19
Example: Vertical Application for Roll Pass
L1.20
Example: Vertical Application for Roll Pass
Manages and operates the National Nuclear Security Administration’s (NNSA) Kansas City Plant
L1.22
Example: Web Customization
www.3ds.com | © Dassault Systèmes
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L1.23
Example: Spreadsheet Interface to Abaqus
L1.24
Example: Automated Report Generation
Application
Additional Information
www.3ds.com | © Dassault Systèmes
Scanscot Technology
L1.26
Example: Abaqus Extension—Adjustable Rigid Torus (ART)
commands
2. The command line interface (CLI)
www.3ds.com | © Dassault Systèmes
input file
Abaqus/Standard
Abaqus/Explicit
L1.28
Abaqus Scripting Interface Basics (2/8)
The Abaqus Scripting Interface (ASI) is a Python-based application programming interface (API) to
Abaqus.
Create macros and scripts to automate repetitive pre- and postprocessing tasks.
Aside: Terminology
L1.30
Abaqus Scripting Interface Basics (4/8)
L1.32
Abaqus Scripting Interface Basics (6/8)
You can use the Macro Manager to record a sequence of the generated Abaqus commands in a macro
file.
You may specify a
location for the macro
file when creating a
macro.
www.3ds.com | © Dassault Systèmes
You can also use the Abaqus replay file as the basis for a new script.
The file name for the current session is abaqus.rpy. If multiple sessions of Abaqus/CAE exist,
the file name extension may be numbered, e.g., abaqus.rpy.1.
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L1.33
Abaqus Scripting Interface Basics (7/8)
Steps:
session.currentViewportName.view.rotate(xAngle=10,
www.3ds.com | © Dassault Systèmes
yAngle=0,zAngle=0,mode=MODEL)
for x in range(36):
session.currentViewportName.view.rotate(xAngle=10,
yAngle=0,zAngle=0, mode=MODEL)
L1.34
Abaqus Scripting Interface Basics (8/8)
1. Objectives
a. When you complete this exercise you will be able to extract all the files necessary to complete the
demonstrations and workshops associated with this course
5 minutes
L1.36
Workshop Preliminaries (2/2)
b. Extract all the workshop files from the course tar file by typing
c. The script will install the files into the current working directory. You will be asked to verify this and to
choose which files you wish to install. Choose y for the appropriate lecture series when prompted. Once
you have selected the lecture series, type q to skip the remaining lectures and to proceed with the
installation of the chosen workshops.
5 minutes
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
5.
4.
3.
2.
1.
60 minutes
Create a CAE model.
Understand the commands written to the replay file when creating a CAE model.
L1.37
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L2.1
Lesson 2: Why Python?
Lesson content:
High Level Description of the Language
Why Python?
Growing Python Universe
Running Python
www.3ds.com | © Dassault Systèmes
2 hours
L2.2
High Level Description of the Language (1/4)
Python features
Free: Open Source Software (no restrictions on copying, embedding, selling, etc.)
Interpreted: No lengthy compile and debug cycle; useful for rapid prototyping
www.3ds.com | © Dassault Systèmes
Powerful: Incorporates dynamic typing, high-level built-in objects and tools, library
utilities, 3rd-party extensions, automatic memory management, modules,
classes, exceptions
Brief History
L2.4
High Level Description of the Language (3/4)
Component integration
System utilities
Internet scripting
Database programming
COM
Numeric programming
Graphics
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L2.5
High Level Description of the Language (4/4)
Python references
Online tutorial
www.python.org/doc/current/tut/tut.html
News groups
www.3ds.com | © Dassault Systèmes
comp.lang.python
comp.lang.python.announce
L2.6
Why Python? (1/2)
Scripting Programming
Language Language
www.3ds.com | © Dassault Systèmes
A scripting language is high-level language that executes more operations per language statement that
a language such as C++.
“For the past 15 years a fundamental change has been occurring in the way that people write computer
programs. The change is a transition from system programming languages such as C or C++ to scripting
languages such as Perl or Tcl. Although many people are participating in the change, few people realize that it
is occurring and even fewer people know why it is happening.”
- John Ousterhout (inventor of the Tcl language), 1998
L2.8
Growing Python Universe (1/9)
It is found in application domains as diverse as finance, scientific computing, data visualization, web
development, system administration, etc.
Several top ranked universities like MIT are now introducing Python as a first language to their students.
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L2.9
Growing Python Universe (2/9)
Extensive suite of third-party libraries built around Python built in virtually every domain (we will see some of
them).
It is possible to do scientific computing, internet scripting, building applications using GUI toolkits, file
www.3ds.com | © Dassault Systèmes
Right mix of focus on modern language constructs like OOPS (Object oriented programming) and a design
focused on minimizing programmer overhead.
A Programming Paradigm which is gaining in popularity involves Python code in a flexible outer core mixed
with languages designed for specialized tasks.
L2.10
Growing Python Universe (3/9)
To get a sense of the growing Python universe we take a look at some of the libraries available for
scientific computing.
Python and scientific computing may seem an odd combination: Python is interpreted and scientific
computing requires efficiency so how can the twain meet ?
www.3ds.com | © Dassault Systèmes
Often only the outer shell is Python and internally you make calls to highly optimized libraries like BLAS,
LAPACK, etc..
The flexible outer shell minimizes the development time and calls to native languages provide efficiency.
If efficiency is required for a certain segment of code, compiled languages such as Fortran and C can be
mixed with Python.
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L2.11
Growing Python Universe (4/9)
Python and scientific computing (cont’d) >>> A = matrix('1.0 2.0; 3.0 4.0')
>>> A [[ 1. 2.] [ 3. 4.]]
NumPy is a powerful package for scientific
computing with Python. >>> A.T # transpose
[[ 1. 3.] [ 2. 4.]]
# matrix multiplication
Tools for integrating C/C++ and Fortran code >>> print A*Y
[[19.] [43.]]
Useful linear algebra, Fourier transform, and
random number capabilities. # inverse
>>> print A.I
Symbolic capabilities lead to compact code [[-2. 1. ] [ 1.5 -0.5]]
L2.12
Growing Python Universe (5/9)
SciPy
Depends on NumPy.
Integration (scipy.integrate)
Optimization (optimize)
Interpolation (scipy.interpolate)
Fourier Transforms (scipy.fftpack)
Signal Processing (signal)
Linear Algebra
Statistics
Multi-dimensional image processing (ndimage)
File IO (scipy.io)
SciPy is not shipped with Abaqus but can be installed as per SIMULIA Answers 3993 and 3782
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L2.13
Growing Python Universe (6/9)
Matplotlib
Matplotlib is a Python 2D
plotting library
www.3ds.com | © Dassault Systèmes
L2.14
Growing Python Universe (7/9)
Other libraries:
Sage – Collection of Python utilities for mathematical applicationswith the aim of becoming a viable
open source alternative to Matlab, Maple, Mathematica.
Cython, pyfort, f2py, Jython – Instant inlining or arbitrary mixing of C , Fortran code, java code.
Many more…
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L2.15
Growing Python Universe (8/9)
Web Programming
CGI, Zope, Django, TurboGears, XML
Databases
www.3ds.com | © Dassault Systèmes
ODBC, MySQL
GUI Development
wxPython, tkInter, PyGtk, PyQt
Education
pyBiblio, Software Carpentry Course
Networking
Sockets, Twisted
Software Development
Buildbot, Trac, Roundup, IDEs
L2.16
Growing Python Universe (9/9)
Parsing
re, pyparse, ANTLR, PLY,KWparsing
Game Development
PyGame, PyKyra, 3D Rendering
The utility of learning Python for scripting in Abaqus extends far beyond Abaqus !
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L2.17
Running Python (1/8)
Modules are files that contain statements and organize accessibility to data.
L2.18
Running Python (2/8)
Python Interpreter
.pyc Interpreter
The .pyc file is not machine code, but something that is a bit higher level
The result is a language that is not as fast as C++, but comparable to Java or Perl.
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L2.19
Running Python (3/8)
Interactive
$ abaqus python
>>> print 5**4
625
>>>
To exit: Ctrl-D (on UNIX), Ctrl-Z & Return (on Windows)
www.3ds.com | © Dassault Systèmes
Command line
$ abaqus python -c "print 5**4"
625
Top-level Script
a = 5; b = 4
$ abaqus python mytest.py c = a ** b
625 print c
L2.20
Running Python (4/8)
I. E.g., Abaqus/CAE
Run in interactive
Run as top level mode
script
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L2.21
Running Python (5/8)
The interactive mode will echo data by default. Running from files will not.
L2.22
Running Python (6/8)
An IDE provides an alternative to using a shell command line and text editor for developing and/or
running code
Most IDEs provide text editing (syntax coloring, block folding, method tips), debugger, project manager,
class browser, keyboard shortcuts, toolbars, regular expression debugger, etc.
www.3ds.com | © Dassault Systèmes
The IDE built into Abaqus is known as Abaqus Python Development Environment (PDE)
Separate application
Eclipse is a very powerful IDE and is highly recommended for developing large projects
www.3ds.com | © Dassault Systèmes
a powerful interactive development environment for the Python language with advanced editing,
interactive testing, debugging and introspection features
and a numerical computing environment and popular Python libraries such as NumPy (linear
algebra),SciPy (signal and image processing) or matplotlib (interactive 2D/3D plotting).
L2.24
Running Python (8/8)
The version of Python that comes with Abaqus might not be the latest version that is available from
other sources.
Use the sys.version parameter to query the version of Python that is being used. For example:
www.3ds.com | © Dassault Systèmes
# simple example
max = 5; i = 0 Semicolon for two statements
www.3ds.com | © Dassault Systèmes
x, y, z = 1, 2, 3
blank lines ignored
L2.26
Lexical Conventions and Syntax (2/8)
Identifiers
An identifier is a name that is used to identify objects such as variables, functions, classes, or modules.
Some names are always reserved (Python will raise a syntax error if one is used as an identifier):
Identifiers
Identifiers that start or end with underscore(s) usually have special meanings:
__name__ Starts and ends with two Reserved for special Python
underscores methods
L2.28
Lexical Conventions and Syntax (4/8)
Special symbols
The following special symbols are used in accordance with the rules already
discussed: ' " # \
www.3ds.com | © Dassault Systèmes
Delimiters
The following symbols serve as delimiters for expressions, lists, dictionaries, and parts of statements:
( ) [ ] { } , : . ` = ;
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L2.29
Lexical Conventions and Syntax (5/8)
String literals
Single quote characters or double quote characters are acceptable. For example:
>>> s = 'text'
>>> s = "text"
The same quote character (single or double) must be used at the start and end of the string
www.3ds.com | © Dassault Systèmes
Many standard character escape codes are available. The backslash character is used to escape
special characters. For example, the following will sound the system bell, insert a tab, and print the
word “test”.
'\a\ttest'
Use raw strings to turn off backslash escape sequence. For example:
open(r'c:\dir1\dir2\filename')
L2.30
Lexical Conventions and Syntax (6/8)
Number literals
Long: 123L, 1L
Decimal: decimal.Decimal(2008)
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L2.31
Lexical Conventions and Syntax (7/8)
Documentation string
If specified as a string, the first statement of a module, class, or function definition becomes a
documentation string for that object
Documentation strings are accessible in the __doc__ attribute of an object. They may also be used in
code-browsing and documentation-generation tools.
www.3ds.com | © Dassault Systèmes
Example:
def test():
'this is a test documentation string'
print 'test'
L2.32
Lexical Conventions and Syntax (8/8)
Triple quotes can be used to create a comment block, or comment out a block of code. Note that, unlike
a normal comment, the string is compiled into the .pyc file, although it is inaccessible.
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
60 minutes
b. run Python by using scripts
Workshop 2: Running Python
Lesson content:
Data Types
Operators and Expressions
Workshop 3: Python Types, Operators, and Expressions
Objects
Workshop 4: Investigating Python Objects
www.3ds.com | © Dassault Systèmes
3 hours
L3.2
Data Types (1/17)
List of types
Number: int, long, float, complex, bool
Map: dictionary
Number types
Numbers
Integer (decimal, octal, hexadecimal)*
Example: 1234, 0644, 0x100fea8
Integers Float
Long **
Example:
www.3ds.com | © Dassault Systèmes
Integer Complex
>>> 17643L**11111
463783748290623436091218...
Long
Float
Examples: 3.1415, .0314e2, .0314e+2, .0314e-2
Complex
Examples: z = 2 + 3j, 12.34j
z.real, z.imag * To specify octal or hexadecimal,
precede the value with 0 or 0x
respectively.
L3.4
Data Types (3/17)
Type coercion
If number types differ in an operation, a coercion operation is automatically performed to convert one of
the types to the other (usually the more complex type)
Note: In Python 3.0 (Abaqus uses Python 2.6-2) the default has been changed and the answer to
the above will be 0.66666
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L3.5
Data Types (4/17)
Collection types
Collection
www.3ds.com | © Dassault Systèmes
Sequence Mapping
String List
Tuple
L3.6
Data Types (5/17)
Sequence types
There are three built-in sequence types in Python and an array type implemented in a separate module.
tuple No No No ('a',45,)
string No Yes Yes 'wxyz'
array Yes Yes Yes array((2.3,5.6))
Methods: The type has methods that can be used to manipulate the contents of the
array (e.g., sort(), reverse()).
* private and "magic" methods have not been included in this list, and will also be omitted from the dir() shown
in subsequent slides.
L3.8
Data Types (7/17)
By immutable, we mean that it is not possible to make assignments to the individual items, For
example:
>>> myTuple[3] = 'W'
www.3ds.com | © Dassault Systèmes
Here myTuple[2] is a list object. Since a list is mutable sequence, it can be changed. The tuple
will still contain the same three objects.
L3.10
Data Types (9/17)
>>> dir(myTuple)
[ ]
Small syntactical point: one-element sized tuples require a comma after the element. For example:
www.3ds.com | © Dassault Systèmes
The first argument (optional) defines the type; otherwise, the type is based on the contents of the array.
>>> from array import array
www.3ds.com | © Dassault Systèmes
>>> a = array("d",(4.0,5.0,3.0))
>>> a
array('d',[4.0, 5.0, 3.0])
Array methods:
>>> dir(array)
['append', 'buffer_info', 'byteswap', 'count', 'extend', 'fromfile',
'fromlist', 'fromstring', 'fromunicode', 'index', 'insert', 'itemsize',
'pop', 'read', 'remove', 'reverse', 'tofile', 'tolist', 'tostring',
'tounicode', 'typecode', 'write‘]
L3.12
Data Types (11/17)
A dictionary (also called associative array) is an unordered collection of objects that provides a means of
mapping from one set of arbitrary objects to an associated set of objects.
Keys provide the symbolic location of items. All keys must be immutable objects.
L3.14
Data Types (13/17)
Properties of dictionaries
Change in-place: like lists, size can change without making a copy
Fast retrieval: Python employs optimized hashing algorithms to find the keys.
Values stored in dictionaries are not implicitly ordered relative to one another.
L3.16
Data Types (15/17)
Python has dozens* of built-in data types for providing a variety of features
If it is true that any computer program could be written using only a few basic language features and
data types, then …
www.3ds.com | © Dassault Systèmes
L3.18
Data Types (17/17)
The standard module called types contains the type objects for all of the built-in Python types.
The behavior of an operation depends on the type of object. Taking advantage of Python's run-time
binding can help you develop code that is very general.
www.3ds.com | © Dassault Systèmes
Examples:
L=[1,2,3]
import types
if type(L) == types.ListType:
<do some method>
If type(displayedObject)== OdbType:
do something
>>> type(1L)
If type(displayedObject)== PartType:
<type 'long'>
do something
>>> type((1,2,3))
<type 'tuple'>
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L3.19
Operators and Expressions (1/7)
Mathematical: +, -, *, **, /, %
>>> (5 + 3)/2
4
L3.20
Operators and Expressions (2/7)
Number operations
-x Unary minus
+y Unary plus
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L3.21
Operators and Expressions (3/7)
Sequence operations
Operation Description
s1 + s2 Concatenation
s % d String formatting
s[i] Indexing
s[i:j] Slicing
x in s Membership testing
x not in s
for x in s: Iteration
len(s) Length
L3.22
Operators and Expressions (4/7)
Indexing
>>> a[0]
'a'
>>> a[3]
('A', 'B', 'C')
>>> a[3][1]
'B'
Slicing
s[m:n]
www.3ds.com | © Dassault Systèmes
L3.24
Operators and Expressions (6/7)
Repeat
>>> a = [0,1] * 3
>>> a
[0, 1, 0, 1, 0, 1]
www.3ds.com | © Dassault Systèmes
Length of a sequence
>>> len(a)
6
Concatenation
Dictionary operations
Operation Description
www.3ds.com | © Dassault Systèmes
a in d Membership test
d.has_key(a)
L3.26
Workshop 3: Python Types, Operators, and Expressions
60 minutes
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L3.27
Objects (1/15)
Objects
All the data stored in a Python program is built around the concept of an object. Internally everything in
Python is an Object.
L3.28
Objects (2/15)
Object Identifiers
Identifiers are user-defined names that provide references (pointers) to an object and the type of object
to which it is bound. You can think of Identifier as a variable name.
>>> y = [6,5,7]
The identity of x and y will contain the address of the objects in memory (More on identity later).
>>> id(x)
18975092
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L3.29
Objects (3/15)
Assignments
>>> a = b = 'test'
>>> print a, b
'test' 'test'
In Python you may not refer to an identifier that has not been assigned. You will get a name error. For
example:
>>> print x
Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'x' is not defined
L3.30
Objects (4/15)
Object Type
The type of an object describes the internal representation of the object as well as the methods and
operations that it supports
The type of an object is itself an object, is uniquely defined, and is identical for all instances of an object
The standard module called types contains all of the built-in type objects
Object Value
If an object's value can be modified, the object is said to be mutable. If not, the object is said to be
immutable
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L3.31
Objects (5/15)
x is y
x is not y
www.3ds.com | © Dassault Systèmes
x == y
x != y
L3.32
Objects (6/15)
>>> compare(1,2)
id for x and y = (11288312, 11288300)
x and y have the same type
x is an integer
www.3ds.com | © Dassault Systèmes
>>>
>>> x=[1,2,3]
>>> y=x
>>> compare.compare(x,y)
id for x and y = (2146243648, 2146243648)
x and y are the same object
x and y have the same value
x and y have the same type
x is not an integer
L3.34
Objects (8/15)
The is operator cannot be used to compare the identity of two objects in Abaqus/CAE. This is because
each time an object is accessed, a new wrapper object is created. Each of these Python objects has a
different ID.
>>> m = mdb.models['Model-1']
>>> id(m) > 149395192
>>> m1 = mdb.models['Model-1']
>>> id(m1) > 149339120
>>> m2 = mdb.models['Model-1']
>>> id(m2) > 149395272
>>> m1 is m2
0
>>> m1 == m2
1
In addition to holding a value, type and identity, some objects define data attributes or other objects.
The attribute or dot (.) operator is used to access attributes of an object as shown in the following
example:
>>> f = open('tmp.txt')
>>> f.close() method
>>> f.closed member
True
We will discuss this in greater detail when we discuss object oriented programming.
L3.36
Objects (10/15)
>>> mdb.__members__
['acis', 'adaptivityProcesses', 'annotations', …]
>>> mdb.__methods__
www.3ds.com | © Dassault Systèmes
Object references
Objects are assigned by reference. So if b = a, then b becomes a reference to the object that a refers
to, not to a itself.
L3.38
Objects (12/15)
Usually, the “shared references” that are inherent in Python provide exactly the behavior that you want.
If not, you can avoid sharing objects by explicitly creating copies.
An empty limit slice operation makes a one-level deep (shallow) copy of the sequence. Shallow copy
example:
>>> a = b = [1,2,3]
This is an empty limit slice
>>> c = a[:]
operation that makes a top-level
>>> b.append(4)
copy of the object a.
>>> a
[1, 2, 3, 4]
>>> c
[1, 2, 3]
L3.40
Objects (14/15)
Repetition copy
An repetition operation also makes a one-level deep (shallow) copy of the sequence. Shallow copy
example:
>>> L0 = [1, 2, 3]
2
>>> L1 = L0 * 2
www.3ds.com | © Dassault Systèmes
>>> L2 = [L0] * 2
>>> L0[1] = 0
L1
>>> L1
???
>>> L2
???
1 0
>>> L2[0][1] = 2
>>> L2 3
???
L0
Same as
[L0] + [L0] L2
Same as
[1, 2, 3] + [1, 2, 3]
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L3.41
Objects (15/15)
A standard copy module is available for making shallow copies. It also allows the user to make deep
copies of objects.
Shallow copy: creates a new object but populates it with references to the items contained in the
original.
www.3ds.com | © Dassault Systèmes
Deep copy: creates a new object and recursively copies all of the objects that it contains.
L3.42
Workshop 4: Investigating Python Objects
1. When you complete this workshop you will have a basic understanding of Python objects
www.3ds.com | © Dassault Systèmes
60 minutes
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
Modules
Functions
Exceptions
Conditionals
3 hours
Control Flow
Namespaces
Lesson content:
else:
Control Flow (1/8)
Workshop 6: Modules
statements
statements
statements
statements
if expression:
elif expression:
elif expression:
Common Issues for New Users
L4.2
L4.1
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L4.3
Control Flow (2/8)
Looping
while expression:
statements
for i in sequence:
statements
If elements of the sequence are sequences of uniform size (in this case the size of each must be
three elements each), the following variations of the for loop may be used:
for i, j, k in sequence:
statements
for [i, j, k] in sequence:
statements
L4.4
Control Flow (3/8)
40
Range function returns an array on the fly from 0 to n-1 the specified integer.
>>> range(10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
...
0
1
2
3
4
5
6
7
8
9
L4.6
Control Flow (5/8)
1 20
2 30
3 40
>>>
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L4.7
Control Flow (6/8)
Looping (cont‟d)
i, max = 0, 50
while 1:
if i > max:
break
www.3ds.com | © Dassault Systèmes
else:
print i
i = i + 1
continue – skip the rest of the code in the loop and go to next iteration.
break and continue statements apply to the inner most loop that is being executed. In order to break
out of a deeply nested loop, use an exception (discussed later).
L4.8
Control Flow (7/8)
Looping (cont‟d)
The else statement may be used to execute code only if the loop runs to completion (i.e. not
terminated early). Examples:
i=0
while i < 4:
i=i+1
else:
print 'Done'
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L4.9
Control Flow (8/8)
y = 30 + 30/x
# print (x,y) followed by y spaces and a marker
print '(%03d,%03d):' % (x,y), ' '*y, 'o'
L4.10
Functions (1/8)
Basics
Normally, the order and number of arguments must match the definition
>>> test(1,1,1)
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
TypeError: test() takes exactly 2 arguments (3 given)
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L4.11
Functions (2/8)
Flow of execution
Execution always begins at the first statement. Statements are executed one at a time, in order from
top to bottom
Statements inside a function are not executed until the function is called
L4.12
Functions (3/8)
For example:
def test(a):
b = a
www.3ds.com | © Dassault Systèmes
>>> test(1)
>>> b
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
NameError: name 'b' is not defined
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L4.13
Functions (4/8)
Recursion
... count(n+1)
>>> count(1)
RuntimeError: maximum recursion depth exceeded
Python has a limit on the depth of recursive function calls. The default value is 1000.
L4.14
Functions (5/8)
Recursion (cont‟d)
0! = 1
n! = n * (n-1)!
www.3ds.com | © Dassault Systèmes
def factorial(n):
if n == 0:
return 1
else:
n = long(n)
return n * factorial(n-1)
>>> factorial(69)
17112245242814131137246833888127283909227054489352036939364804092325
7279754140647424000000000000000L
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L4.15
Functions (6/8)
If a function has default arguments, you can omit arguments when calling the function.
www.3ds.com | © Dassault Systèmes
L4.16
Functions (7/8)
When calling a function with keyword arguments, the order of the parameters does not matter.
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L4.17
Functions (8/8)
Fruitful functions
Functions may be used to return values. Values are returned using the return statement.
More than one return statement may be used. The function terminates at the first occurrence.
... return -x
... if x > 0:
... return x
If a function does not execute a return statement, the None object is returned.
L4.18
Workshop 5: Defining a Function for a Series Calculation
60 minutes
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L4.19
Modules (1/6)
A module is a file containing code of related functions, classes, and variables that may be reused.
L4.20
Modules (2/6)
Most of the functionality that is available to a Python user is implemented as a series of modules (e.g., the
Abaqus Scripting Interface)
Module code is executed during import. However, the code is executed only once, regardless of how
many times the import statement is used.
L4.22
Modules (4/6)
Names from the module can be copied into the importer‟s namespace.
All the names can be copied into the importer‟s namespace. This is not normally recommended, as
names can be overwritten. In addition, this style is valid at the module level only, not inside of functions
and methods. Example:
Python searches the list of directories given in sys.path when looking for requested modules.
The first module found in a path that satisfies the import request is used.
If the module is not found in the search path, an ImportError exception is raised.
www.3ds.com | © Dassault Systèmes
The sys.path variable is initialized to directories determined when Abaqus was installed. The search
path is augmented using the environment (operating system) variable PYTHONPATH.
The following lines will return a list of directories that are present in sys.path:
L4.24
Modules (6/6)
Not generally recommended because hard coding the path may restrict behavior or require
constant maintenance.
Add default search path using the path configuration file (packagename.pth)
Lexical scoping is a convention used in a block-structured programming language: a variable can only
be referenced within the block in which it is defined and in blocks contained within that block.
Built-in
Built-in
Global
Enclosing-defs
Local
L4.26
Namespaces (2/6)
Namespace
A name space can be thought of as a space where the variables or identifiers are stored.
When simple variables are assigned, Python changes or creates the name in the closest namespace.
>>> __name__
'__main__'
>>> x=4 ##identifier x is stored in the __main__ namespace
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L4.27
Namespaces (3/6)
Scope
Used to refer to how the namespaces relate to each other and how the user can access each
namespace.
>>>newVariable = x.y.z
www.3ds.com | © Dassault Systèmes
In the example above z is in the scope of y and y is the scope of x. z and y are said to be qualified and
x is unqualified.
In the above the two cases both x and math are unqualified names. When the Python interpreter
encounters an unqualified name, it performs a search as discussed next.
L4.28
Namespaces (4/6)
Built-in (Python)
Predefined names
Global (Module)
Nested (Functions) 1
Names declared global
in a function
Nested (Functions)
Names assigned at top
level of module Local (Functions)
Example
>>> len = 5
>>> def test():
>>> len = 6
>>> print len
Note the global namespace in the preceding slide are the variables defined at the top level of the file, which
can be accessed using the dot notation.
# module test_mod.py
>>>import test_mod
x = 1
>>>test_mod.x
y = [2,2]
1
L4.30
Namespaces (6/6)
Summary
Namespace rules resolve ambiguities when there are multiple occurrences of a name.
Each object has its own namespace (strings, dictionaries, lists, etc.).
www.3ds.com | © Dassault Systèmes
Here the name myList is unqualified, and the name reverse is qualified.
The interactive interpreter executes in the namespace of a special module named __main__.
If an exception is not “caught,” it will stop the program and print a stack trace.
www.3ds.com | © Dassault Systèmes
Why exceptions?
Exceptions are more sophisticated and easier to use than return status codes.
L4.32
Exceptions (2/2)
When the exception is raised, it will stop the program unless caught by the caller.
Examples
>>> 1/0
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ZeroDivisionError: integer division or modulo by zero
www.3ds.com | © Dassault Systèmes
def inverse(x):
try:
print 1/x
except ZeroDivisionError:
print x, 'has no inverse'
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L4.33
Common Issues for New Users (1/3)
Coding style
Using a few rules and applying them consistently for coding will make your code easier for others to
read and maintain.
http://www.python.org/dev/peps/pep-0008
http://www.python.org/dev/peps/pep-0257
The original style guide was written by Guido van Rossum, inventor of Python. It is available at the
following site:
http://www.python.org/doc/essays/styleguide.html
L4.34
Common Issues for New Users (2/3)
Indentation
Mixing tabs with spaces for indentation can cause unpredictable behavior. We recommend using spaces
exclusively, 4 spaces preferred.
Non-fruitful functions
Do not always expect a function to return a result. Some functions return the None object; for
www.3ds.com | © Dassault Systèmes
>>> list1=[1,2,3]
>>> list1
[1, 2, 3]
>>> list2=list1.append(4)
>>> list2
>>> list1
[1, 2, 3, 4]
>>> type(list2)
<type 'None'>
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L4.35
Common Issues for New Users (3/3)
L4.36
Workshop 6: Modules
60 minutes
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L5.1
Lesson 5: More on Abaqus Scripting Basics
Lesson content:
Abaqus PDE
Abaqus Namespaces and Conventions
Resources
Getting Input Interactively
Workshop 7: Creating a Macro and Getting Input interactively
www.3ds.com | © Dassault Systèmes
1.5 hours
L5.2
Abaqus PDE (1/6)
Step through the code line by line, step into a function, and examine variable values.
Access the Python interpreter in the GUI (similar to the kernel CLI).
Standalone
Starting Abaqus PDE
L5.4
L5.3
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
GUI CLI
„p‟
Kernel process
script
in GUI
Breakpoint
Syntax coloring
Step through kernel
L5.6
L5.5
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L5.7
Abaqus PDE (6/6)
Script can be selected by using Main File in PDE GUI, or by specifying the file on the command line
abq pde –script local.py
www.3ds.com | © Dassault Systèmes
L5.8
Abaqus Namespaces and Conventions (1/3)
Abaqus Namespaces
Journaling namespace
A private namespace in which commands issued from the GUI are executed.
CLI namespace
www.3ds.com | © Dassault Systèmes
vp = session.viewports['Viewport: 1']
For the special case of executing a Python script that was created by the Macro Manager:
The general script limitation applies: if the script accesses the functionality of any Abaqus/CAE
module, the commands must be interpreted by the Abaqus/CAE kernel.
The scripts that are created by Abaqus Macro Manager are a collection of Python functions. To
www.3ds.com | © Dassault Systèmes
2. Use File→Run Script and access each function at the command line interface (CLI). You
must know the function names (look at the file).
L5.10
Abaqus Namespaces and Conventions (3/3)
A consistent style:
L5.12
Resources (2/3)
In addition, you can visit the SIMULIA Learning Community (www.3ds.com/simulia-learning) and
browse for more plug-ins.
www.3ds.com | © Dassault Systèmes
L5.14
Getting Input Interactively (1/2)
Overview
The getInput function displays a simple dialog box, along with a specified prompt, in which the user
enters the requested value or values.
The value is returned to the executing script as a string after the user presses the [Enter] key.
Optionally, you can specify a default value to be displayed in the data entry dialog box.
www.3ds.com | © Dassault Systèmes
The getInput function does not provide any error checking; it is the script author's responsibility to
verify the user input.
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L5.15
Getting Input Interactively (2/2)
Example
The getInput function allows the user to enter a value:
from abaqus import *
from math import sqrt
input = getInput('Enter a number:', '9')
number = float(input)
print sqrt(number)
The float function converts the string returned by getInput into a floating point number.
www.3ds.com | © Dassault Systèmes
A list is returned:
L5.16
Workshop 7: Creating a Macro and Getting Input Interactively
1. When you complete this workshop you will be able to create and use an Abaqus macro and request input
interactively using getInputs
www.3ds.com | © Dassault Systèmes
60 minutes
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L6.1
Lesson 6: Abaqus Object Model
Lesson content:
2 ½ hours
L6.2
Introduction to Object Oriented Programming (1/9)
Structured programming
Main
L6.4
Introduction to Object Oriented Programming (3/9)
Model the world as objects which have data or state and behavior or methods
www.3ds.com | © Dassault Systèmes
Object 2
Object 1
Object 3
Object4 Object 5
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L6.5
Introduction to Object Oriented Programming (4/9)
So what is an Object ?
Collection of:
Methods (behaviors, …)
www.3ds.com | © Dassault Systèmes
Each object has its own memory for maintaining state (the members)
You can also think of an object as customized or template types of which multiple copies can be created
at runtime.
L6.6
Introduction to Object Oriented Programming (5/9)
instance variable
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L6.7
Introduction to Object Oriented Programming (6/9)
Example: Class
Methods
def draw(self):
s = self.size * 0.5
L6.8
Introduction to Object Oriented Programming (7/9)
>>> L
[1, 2, 3]
>>> dir(L)
['append', 'count', 'extend', 'index', 'insert', 'pop', 'remove',
'reverse', 'sort']
>>> id(L)
17858620
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L6.9
Introduction to Object Oriented Programming (8/9)
Inheritance - A relationship that defines one entity in terms of another. Class inheritance defines a new
class in terms of one or more parent classes. The new class inherits its interface and implementation
from its parents. The new class is called a subclass or a derived class.
www.3ds.com | © Dassault Systèmes
L6.10
Introduction to Object Oriented Programming (9/9)
Reusability or modularity.
But any object oriented decomposition does not accomplish the above !!
As you gain experience programming, learning the object-oriented features of Python can help you write better
code.
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L6.11
Abaqus Object Model Basics (1/7)
Overview
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.
www.3ds.com | © Dassault Systèmes
Taken from the Abaqus Scripting User's Manual The complete Abaqus object
(available online only) model is too complex to easily
present in a single figure.
L6.12
Abaqus Object Model Basics (2/7)
Basics
etc.
A Model
owns
parts
Ownership implies that if an object is copied, everything owned by that object is also copied. Similarly, if
an object is deleted, everything owned by the object is deleted. This concept is known as a parent-child
relationship in Abaqus/CAE.
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L6.13
Abaqus Object Model Basics (3/7)
Recall that the data encapsulated by an object are called the members of the object.
Recall that the functions that manipulate the data are called methods.
Any Python statement that accesses the Session, Mdb, or Odb is called a command.
L6.14
Abaqus Object Model Basics (4/7)
Use commands to access objects by stepping through the hierarchy of objects in the object model. All
commands mirror the structure of the object model.
Examples:
vp = session.viewports['Viewport: 1']
vp.setValues(origin=(200,0))
www.3ds.com | © Dassault Systèmes
cell4 = mdb.models['block'].parts['crankcase'].cells[4]
The cell with an index of 4 in the part named crankcase in the model named block in the model
database mdb is assigned to the variable cell4.
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L6.15
Abaqus Object Model Basics (5/7)
The Access and Path descriptions in the Abaqus Scripting Reference Manual describe the access to and
interface for each Abaqus object.
www.3ds.com | © Dassault Systèmes
L6.16
Abaqus Object Model Basics (6/7)
Constructor example
p = mdb.models['Model-1'].Part(name='Part-1',
dimensionality=THREE_D, type=DEFORMABLE_BODY)
mdb.models['Model-1'].Part
mdb.models['Model-1'].parts['Part-1']
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L6.17
Abaqus Object Model Basics (7/7)
Some objects have no constructor; Abaqus creates the object for you.
For such objects the initial value of each member can be found in the documentation for setValues
(see the default value).
www.3ds.com | © Dassault Systèmes
The following statement modifies the rendition member of the printOptions object (values of other
members are not changed):
session.printOptions.setValues(rendition=GREYSCALE)
L6.18
The Session Object (1/8)
L6.20
The Session Object (3/8)
Visualization commands
odb = session.openOdb(name='viewer_tutorial.odb')
vp = session.viewports['Viewport: 1']
vp.setValues(displayedObject=odb)
www.3ds.com | © Dassault Systèmes
od = vp.odbDisplay
od.setPrimaryVariable(variableLabel='PEEQ',
outputPosition=INTEGRATION_POINT)
od.display.setValues(plotState=(CONTOURS_ON_DEF,))
The ODB Display object called vp.odbDisplay has the settings for how the output database is
displayed in a viewport.
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L6.21
The Session Object (4/8)
Annotation commands
vp.plotAnnotation(
mdb.Text(name='test run', offset=(70, 110),
text= 'Test Run #146'))
www.3ds.com | © Dassault Systèmes
Print commands
session.pngOptions.setValues(imageSize=(750, 400))
session.printOptions.setValues(rendition=COLOR,
vpDecorations=OFF, vpBackground=OFF)
session.printToFile(fileName='stress', format=PNG,
canvasObjects=(vp,))
L6.22
The Session Object (5/8)
import odbAccess
from abaqus import *
from abaqusConstants import *
import visualization
# Assign a variable to the ODB in the current viewport.
www.3ds.com | © Dassault Systèmes
vp = session.viewports[session.currentViewportName]
odb = vp.displayedObject
# Change background color to white.
session.graphicsOptions.setValues(backgroundColor='#FFFFFF')
# Make the last step and frame the current step and frame.
lastStep = odb.steps.values()[-1] this can be an integer
lastFrame = lastStep.frames[-1] or a frame object
vp.odbDisplay.setFrame(frame=lastFrame)
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L6.23
The Session Object (6/8)
Example (cont'd)
vp.odbDisplay.setDeformedVariable('U')
vp.odbDisplay.setPrimaryVariable(variableLabel='PEEQ',
outputPosition=INTEGRATION_POINT)
vp.odbDisplay.display.setValues(plotState=(CONTOURS_ON_DEF,))
vp.view.fitView()
www.3ds.com | © Dassault Systèmes
vp.viewportAnnotationOptions.setValues(state=OFF)
vp.plotAnnotation(
mdb.Text(name='Text: 1', offset=(30, 8),
text='Equivalent plastic strain at the final\
configuration'))
session.printOptions.setValues(rendition=COLOR,
vpDecorations=OFF, vpBackground=OFF)
session.printToFile(fileName='finalConfig', format=PNG,
canvasObjects=(vp,))
L6.24
The Session Object (7/8)
Example (cont'd)
www.3ds.com | © Dassault Systèmes
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L6.25
The Session Object (8/8)
createViewports()
www.3ds.com | © Dassault Systèmes
tileViewports()
L6.26
The Mdb Object (1/5)
or Abaqus/CAE.
Mdb()
L6.28
The Mdb Object (3/5)
mySketch = myModel.ConstrainedSketch(
name='Sketch A', sheetSize=200.0)
for i in range(len(xyCoordsInner)-1):
mySketch.Line(point1=xyCoordsInner[i],
point2=xyCoordsInner[i+1])
for i in range(len(xyCoordsOuter)-1):
mySketch.Line(point1=xyCoordsOuter[i],
point2=xyCoordsOuter[i+1])
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L6.29
The Mdb Object (4/5)
L6.30
The Mdb Object (5/5)
partInstances = (myInstance,)
myAssembly.seedPartInstance(
regions=partInstances, size=5.0)
myAssembly.generateMesh(regions=partInstances)
www.3ds.com | © Dassault Systèmes
Use the print statement. The state of Abaqus objects can be printed using the print statement. For
example:
L6.32
Exploring Your Data (2/3)
prettyPrint function
>>> from textRepr import *
>>> prettyPrint(odb)
({'analysisTitle': 'Cantilever beam model',
'closed': FALSE,
'customData': None,
'description': 'DDB object',
'diagnosticData': 'OdbDiagnosticData object',
'isReadOnly': FALSE,
www.3ds.com | © Dassault Systèmes
Set default depth - affects textRepr functions and printing Abaqus objects.
>>> session.textReprOptions.setValues(maxRecursionDepth=3)
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L6.33
Exploring Your Data (3/3)
Function signatures:
prettyPrint(object <, maxRecursionDepth, maxElementsInSequence,
significantDigits, _internalMembersMethods>)
printPaths(object <, maxRecursionDepth, maxElementsInSequence,
pathRoot, _internalMembersMethods>)
printTypes(object <, maxRecursionDepth, maxElementsInSequence,
pathRoot, _internalMembersMethods>)
printPathsToFileName(fileName, object <, maxRecursionDepth,
maxElementsInSequence, pathRoot, _internalMembersMethods >)
L6.34
Abaqus Data Types (1/4)
Currently there are about 280 different types. For example, MaterialType,
HomogeneousSolidSectionType, etc.
type(mdb.models['Noname'].materials['Steel'])
<type 'Material'>
import section
s = mdb.models['Noname'].sections['sec-1']
...
...
if type(s) == section.HomogeneousSolidSectionType:
print 'This object is of type HomogeneousSolidSection'
Type objects are found in Python modules. Use the qualified name.
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L6.35
Abaqus Data Types (2/4)
mdb.models['engine'].Material('steel')
steel = mdb.models['engine'].materials['steel']
For example, nodes and elements in meshes are stored in Abaqus arrays.
L6.36
Abaqus Data Types (3/4)
SymbolicConstant
a.setMeshControls(elemShape=QUAD)
Boolean
In Abaqus, the available symbolic constants are ON, OFF, TRUE, FALSE.
Example: A viewport object has a Boolean member named titleBar that specifies if the title bar will be
displayed.
if vp.titleBar:
print "The title bar will be displayed"
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L6.37
Abaqus Data Types (4/4)
Keywords
vp = session.viewports['Viewport: 1']
vp.odbDisplay.contourOptions.setValues(shape=UNDEFORMED)
www.3ds.com | © Dassault Systèmes
L6.38
Abaqus Modules (1/9)
Terminology
The functionality of Abaqus/CAE and Abaqus/Viewer is presented through modules that are accessible
from a pull-down menu (for example, Part, Property, etc).
These modules provide sensible packaging of a graphical user interface and are referred to as
the GUI modules.
www.3ds.com | © Dassault Systèmes
For kernel scripting, functionality is accessible from Python modules that must be imported by the user.
These modules are referred to as kernel modules and have names that are mostly similar to the
GUI module names.
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L6.39
Abaqus Modules (2/9)
Abaqus modules are imported using the import statement, the same as any other Python module.
Importing an Abaqus module does not affect the GUI appearance (for example, which module the GUI is
switched to).
www.3ds.com | © Dassault Systèmes
The caeModules module imports the kernel modules. It has the same effect as
L6.40
Abaqus Modules (3/9)
The module called abaqus defines two root objects of the Abaqus object model:
session
mdb
www.3ds.com | © Dassault Systèmes
L6.42
Abaqus Modules (5/9)
osutils UNIX-like shell utilities that are designed to behave the same on
different platforms
Useful Python modules that are delivered with Abaqus (these modules also do not augment existing objects)
shelve Provides support for persistent objects using a special shelf object
L6.44
Abaqus Modules (7/9)
1. 3.
import moduleName from moduleName import *
4.
import moduleName as pseudoName
www.3ds.com | © Dassault Systèmes
This is an alternate approach that is also recommended for importing Python modules.
Benefits:
Avoids name clashing
Avoids using long identifiers
Example:
import displayGroupOdbToolset as dgo
leaf = dgo.LeafFromElementSets(elementSets=('PART-1-1.E1', ))
session.viewports['Viewport:1'].odbDisplay.displayGroup.replace(
leaf=leaf)
vp.odbDisplay.display.setValues(plotState=(CONTOURS_ON_DEF,))
L6.46
Abaqus Modules (9/9)
Tip: if you want to write scripts that work for non-
osutils Abaqus versions of Python, then do not get in the
habit of using the osutils module.
This is a collection of shell utilities such as move, copy, and removeTree. It is intended to provide
consistent behavior over different platforms.
osutils.chmod
www.3ds.com | © Dassault Systèmes
60 minutes
a. Navigate the Abaqus Scripting Manual
1. When you complete this workshop, you will be able to:
Lesson content:
2 ¾ hours
L7.2
The Odb Object (1/18)
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.
www.3ds.com | © Dassault Systèmes
Field Data
History Data
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L7.3
The Odb Object (2/18)
import visualization
session.openOdb(<odb path>)
www.3ds.com | © Dassault Systèmes
This method allows Abaqus/CAE to keep track of the open output databases:
L7.4
The Odb Object (3/18)
This will not use Abaqus tokens but Abaqus/CAE Session functionality will be unavailable. Odb
object model is same in either case.
www.3ds.com | © Dassault Systèmes
Useful for third party developers. Sometimes can be useful for batch mode on clusters.
Note if both batch mode of execution and Abaqus/CAE functionality is desired use
“abaqus cae –noGUI scriptname”
When you execute outside of Abaqus/CAE typically only one output database is open at a time.
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L7.5
The Odb Object (4/18)
import visualization
odb1 = session.openOdb('/home/job1.odb')
odb2 = session.openOdb('/home/job2.odb')
odb3 = session.openOdb('/home/job3.odb')
for odb in session.odbs.values():
www.3ds.com | © Dassault Systèmes
L7.6
The Odb Object (5/18)
Field Data
steps (type = Repository)
The output data for an Abaqus analysis contains a repository of one or more step objects.
The key to the repository is the name of the step (user defined when building the model).
www.3ds.com | © Dassault Systèmes
crushStep = odb.steps['Crush']
lastStep = odb.steps.values()[-1]
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L7.7
The Odb Object (6/18)
Field Data
frames (type = OdbFrameArray)
Background: Each increment of the analysis that writes output to the output database is called a frame.
firstFrame = crushStep.frames[0]
Standard Python
lastFrame = lastStep.frames[-1] 0th-based indexing
Field Data
History Data
L7.8
The Odb Object (7/18)
Field Data
fieldOutputs (type = Repository)
Background: Different variables can be written to the output database at different frequencies. As a
result, not all frames will contain all of the field output variables.
Field output data objects are stored in the fieldOutputs repository under the Odb frames object.
The key to the repository is the name of the output variable. For example, here we are accessing the
www.3ds.com | © Dassault Systèmes
stress = crushFrame.fieldOutputs['S']
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L7.9
The Odb Object (8/18)
stress = odb.steps['Crush'].frames[-1].fieldOutputs['S']
The field output named S in the last frame of the step named Crush in the output database object called
odb is assigned to the identifier stress.
odb = session.openOdb('/home/job1.odb')
steps = odb.steps
frames = steps[„Crush‟]
stress = frames[-1].fieldOutputs['S']
L7.10
The Odb Object (9/18)
FieldOuptut Object
By default the field output data is output for the full model.
So the FieldOutput object stress in the previous case will include stress values at all the elements in
the model for last frame of step Crush.
It contains a “cloud or array of field value objects” (e.g., stress tensors at each integration point for all
www.3ds.com | © Dassault Systèmes
elements).
Each field value has much information (members) associated with it, for example:
elementLabel, nodeLabel, position, face, integrationPoint,
sectionPoint, type, data, magnitude, mises, tresca, press, inv3,
maxPrincipal, midPrincipal, etc.
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L7.11
The Odb Object (10/18)
Field Data
Given a FieldOutput object (stress), it is easy to extract results
More specific results for a region of the model can be obtained using the getSubset method, which
returns another FieldOutput object.
www.3ds.com | © Dassault Systèmes
L7.12
The Odb Object (11/18)
Field Data
getSubset() method
The getSubset() method can be thought of as a filter to restrict the FieldOutput object to a certain
section of the model.
Possible values for the position argument to the getSubset command are
INTEGRATION_POINT, NODAL, ELEMENT_NODAL, CENTROID.
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L7.13
The Odb Object (12/18)
Field Data
Performance considerations for the getSubset() method
The getSubset() method is used to facilitate efficient random access of the ODB.
As a general rule, the efficiency of the getSubset() method will break down when trying to access
www.3ds.com | © Dassault Systèmes
The performance of the getSubset() method should be evaluated on a case-by-case basis when
accessing data for large regions of a database.
See SIMULIA Answer 4131 for guidelines for improving performance when using the ODB API
L7.14
The Odb Object (13/18)
Operations are performed in the coordinate system that was used to save the data.
All output values for a single point or for some larger region are collected in a historyRegions object.
The historyRegions object is analogous to the frames object for field data.
The key to the repository should describe the portion of the model that is associated with the data. For
example:
www.3ds.com | © Dassault Systèmes
Field Data
History Data
L7.16
The Odb Object (15/18)
History Data
historyRegions (cont'd)
The history region will correspond to one of the following spatial associations:
A node A region
Consistent with this, a default naming style for repository keys is used by Abaqus.
stepObject.historyRegions['Node Part-1-1.415']
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L7.17
The Odb Object (16/18)
History Data
historyRegions (cont'd)
The type of output variable that is requested by the user (prior to submitting the job) will determine the
spatial association. For example:
L7.18
The Odb Object (17/18)
History Data
historyOutputs (type = Repository)
History data is stored in the historyOutputs repository, under the ODB historyRegions object.
This repository contains all the output for a specific point or region for a given step.
Examples:
u2Deflection = endPoint.historyOutputs['U2']
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L7.19
The Odb Object (18/18)
mag = 0
componentLabels = ('U1', 'U2', 'U3')
www.3ds.com | © Dassault Systèmes
Obviously, the operations apply to only the values, not the time.
L7.20
Writing to the Odb (1/2)
External data is data that is prepared outside Abaqus can be added to the ODB file.
Workaround: Create a new .odb file, and write data that is copied from an existing .odb file.
We will walk over some of the ASI Python commands to add data to the ODB
Creating a step
Creating a frame
description='')
uField = myFrame.FieldOutput(name='U',
description='Displacements', type=VECTOR)
nodeLabels = (1, 2, 3, 4, 5, 6)
nodeDisplacements = (
(1.0,2.0,3.0), (4.0,5.0,6.0), (7.0,8.0,9.0),
(10.0,11.0,12.0), (13.0,14.0,15.0), (16.0,17.0,18.0) )
uField.addData(position=NODAL, instance=myInstance,
labels=nodeLabels, data=nodeDisplacements)
L7.22
Examples (1/3)
Field Data
Example 1: Reading some field data
import odbAccess
odb = session.openOdb('indentfoam_std_visco_2.odb')
# Create a variable that refers to the last frame of the first step.
lastFrame = odb.steps['Step-1'].frames[-1]
# Create a variable that refers to the displacement 'U' in the last frame of the first step.
displacement = lastFrame.fieldOutputs['U']
www.3ds.com | © Dassault Systèmes
# Create a variable that refers to the node set 'PUNCH' located at the center of the
# hemispherical punch. The set is associated with the part instance 'PART-1-1'.
center = odb.rootAssembly.instances['PART-1-1'].nodeSets['PUNCH']
# Create a variable that refers to the displacement of the node set in the last frame of the
# first step.
centerDisplacement = displacement.getSubset(region=center)
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L7.23
Examples (2/3)
Field Data
Example 1: Reading some field data (cont’d)
# Finally, print some field output data from each node in the node set
# (a single node in this example).
for v in centerDisplacement.values:
print 'Position = ', v.position
print 'Type = ', v.type
print 'Node label = ', v.nodeLabel
www.3ds.com | © Dassault Systèmes
Position = NODAL
Type = VECTOR
Node label = 1000
X displacement = -8.05730572321e-034
Y displacement = -76.4923706055
Displacement magnitude = 76.4923706055
L7.24
Examples (3/3)
commands
60 minutes
60 minutes
a. combine results from 2 separate fields on the ODB to create a new temporary field
1. When you complete this workshop you will be able to read data from an Abaqus ODB file using scripting
L7.26
L7.25
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L8.1
Lesson 8: Miscellaneous Topics
Lesson content:
Plug-ins
Really Simple GUI (RSG)
Job Monitoring
Custom Data
Setting Abaqus Defaults
www.3ds.com | © Dassault Systèmes
3 hours
L8.2
Plug-ins (1/4)
Kernel plug-in
myUtils.py
def printTime():
import time
t = time.localtime()
print 'The time is: %d:%d' %d/%d/%d' % \
(t[3], t[4], t[1], t[2], t[0])
www.3ds.com | © Dassault Systèmes
time_plugin.py
from abaqusGui import getAFXApp
toolset = getAFXApp().getAFXMainWindow().getPluginToolset()
toolset.registerKernelMenuButton(moduleName='myUtils',
functionName='printTime()',
buttonText='Print Time')
L8.4
Plug-ins (3/4)
The previous example results in adding a button to the top-level plug-ins menu.
myUtils.py must exist and contain a function named printTime and both must be in a directory tree
starting at abaqus_plugins located as described above.
www.3ds.com | © Dassault Systèmes
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L8.5
Plug-ins (4/4)
GUI plug-in
GUI plug-ins execute Abaqus GUI Toolkit commands (details are not addressed in this course).
An alternative to using the Abaqus GUI Toolkit commands is the RSG (Really Simple GUI) Dialog
Builder.
RSG:
www.3ds.com | © Dassault Systèmes
L8.6
Really Simple GUI (1/14)
It is an Abaqus/CAE plug-in
Plug-ins->Really Simple GUI->Create a Dialog...
Drawing program
www.3ds.com | © Dassault Systèmes
Painting program
Abaqus/CAE
Create a Python kernel script to interface between the RSG and Abaqus/CAE
L8.8
Really Simple GUI (3/14)
A shortcut for creating the kernel script is to execute the Abaqus/CAE commands that you want via the
normal Abaqus/CAE GUI
All Python commands necessary to reproduce the action are saved to the replay file in your work
directory
www.3ds.com | © Dassault Systèmes
Python
Includes
commands
option
Replay File
option
Gravity
Material
selection
Cantilever Beam Demo
Created icon
showing definitions
L8.10
L8.9
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
Indent
indenting)
Includes
New name
(Python delineates
in the RSG interface)
(Kernel function name
Kernel Script
GUI keywords
Variables from
Variables
Kernel Script Variable Substitution
L8.12
L8.11
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L8.13
Really Simple GUI (8/14)
Error checking
Check button
Radio buttons
www.3ds.com | © Dassault Systèmes
Text Field
Use raise
L8.14
Really Simple GUI (9/14)
File Selection
Format
www.3ds.com | © Dassault Systèmes
Example
Really Simple GUI (11/14)
Really Simple GUI (10/14)
L8.16
L8.15
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L8.17
Really Simple GUI (12/14)
Limitations
getInput( )
GetWarningReply( )
showAFXInformationDialog( )
Other RSG dialogs
L8.18
Really Simple GUI (13/14)
Use it as a basis for more complex GUIs and circumventing RSG limitations
www.3ds.com | © Dassault Systèmes
I. Pop up dialogs
Summary
Quick to do, just a few hours for simple models and designs
Surface selection
Point selection
Etc.
L8.20
Job Monitoring (1/3)
In some cases you may want to process messages from the analysis while it is running; for example, to
terminate it when a criterion is reached or to plot results as the analysis progresses.
www.3ds.com | © Dassault Systèmes
This is accomplished by writing a callback function and registering it with the monitorManager object.
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L8.21
Job Monitoring (2/3)
Example
The following code will print all the messages from the analysis:
L8.22
Job Monitoring (3/3)
The easiest way to write scripts that perform some action (i.e., change the model, visualize results)
based on the results of the analysis is to have the script wait for the analysis to complete.
In the following example, the script submits myJob1 and waits for it to complete before submitting
myJob2.
www.3ds.com | © Dassault Systèmes
mdb.customData
L8.24
Setting Abaqus Defaults (1/2)
It may contain some optional Python functions that are called by Abaqus, such as:
onCaeStartup()
onCaeGraphicsStartup()
onJobStartup()
onJobCompletion()
Abaqus looks for a file named abaqus_v6.env in site_dir, home_dir, and local_dir and will
execute each one in turn.
If more than one version of the above Python functions is found, each one will be called. In the case of
environment variables, a subsequent definition will overwrite a former definition.
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
L8.25
Setting Abaqus Defaults (2/2)
# Graphics preferences
session.graphicsOptions.setValues(displayLists=ON, dragMode=AS_IS)
# Print preferences
www.3ds.com | © Dassault Systèmes
session.printOptions.setValues(vpDecorations=OFF, vpBackground=OFF,
rendition=COLOR, printCommand='lpr')
# Visualization preferences
def setVisPreferences(module, userData):
from visualization import SHADED, EXTERIOR, CONTINUOUS
session.defaultOdbDisplay.commonOptions.setValues(
renderStyle=SHADED, visibleEdges=EXTERIOR)
session.defaultOdbDisplay.contourOptions.setValues(
contourStyle=CONTINUOUS)
addImportCallback('visualization', setVisPreferences)
L8.26
Workshop 11: Creating Kernel and GUI Scripts
60 minutes
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
60 minutes
1. When you complete this workshop you will be able to:
Workshop 12: Setting Abaqus Defaults
a. use the Abaqus environment file to customize some default settings of Abaqus/CAE
L8.27
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
A1.1
Appendix 1
Lesson content:
Data Types
Objects
Common Issues for New Users
Setting Abaqus Defaults
Objects
www.3ds.com | © Dassault Systèmes
Custom Data
30 minutes
A1.2
Data Types (1/3)
Function Type
arg2= bicycle
File Type
The Python file type is an abstract object that provides a way to access files.
All Python file I/O is performed on abstract file objects, rather than file names.
www.3ds.com | © Dassault Systèmes
The open method does not actually read the file; instead it returns a file object.
Example:
f = open('filename', 'r')
line = f.readline()
f.close()
A1.4
Data Types (3/3)
Traceback Type
The traceback object is created when an exception occurs and contains stack trace information.
This is one type of object that is used by the interpreter and exposed to the user.
Example:
>>> 1+'1'
www.3ds.com | © Dassault Systèmes
An object’s reference count increases when it is assigned a new name or placed in a container.
>>> a = 1 a 1
>>> b = a
>>> c = [b, 2] b
2
c
A1.6
Objects (2/3)
An object’s reference count decreases when a reference is reassigned (or goes out of scope) or when
removed by the del statement.
Python keeps track of low level memory details. When an object’s reference count is zero, an object’s
memory space is reclaimed (a process called garbage collection) and the object is put back on the C-
heap*.
www.3ds.com | © Dassault Systèmes
>>> del a 1
>>> c[1] = b
b
* Actually, some internal optimization occurs: small integers and strings are
cached and are not recreated for each use
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
A1.7
Objects (3/3)
Later versions of Python are equipped with garbage collecting that can handle cyclical references to
objects.
For example, in the code below, the reference count of each does not normally go to zero because of
the cross reference. To address this problem, the interpreter deletes objects based on cycles of
inaccessibility.
www.3ds.com | © Dassault Systèmes
A1.8
Common Issues for New Users
Python creates binary .pyc files from the source .py files when a module is imported. The
.pyc files are recreated on import if the source code changes.
Strictly speaking, Python programs are compiled (translated) to an intermediate form called
bytecode (the .pyc files) which is then run by the interpreter.
This functionality provides a nice tradeoff between development speed and computational
performance.
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
A1.9
Setting Abaqus Defaults (1/3)
Execution environment
Note that abaqus_v6.env is not a module, and names defined at the top level are not available within
the functions. The functions are defined by reading abaqus_v6.env, but are executed in a different
namespace.
Predefined names
www.3ds.com | © Dassault Systèmes
A1.10
Setting Abaqus Defaults (2/3)
abaqus_v6.env (continued)
def onJobCompletion():
import os
extensions = ('res','stt','mdl','prt','abq','pac')
restartDir = savedir + id + '_restart' + os.sep
www.3ds.com | © Dassault Systèmes
if (not os.path.exists(restartDir)):
os.mkdir(restartDir)
for extension in extensions:
fileName = id + '.' + extension
if (os.path.exists(savedir + fileName)):
os.rename(savedir + fileName, restartDir + fileName)
def onJobStartup():
import os, osutils
restartDir = savedir + id + '_restart'
if (os.path.exists(restartDir)):
osutils.removeTree(restartDir)
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
A1.11
Setting Abaqus Defaults (3/3)
Execution environment
Note that abaqus_v6.env is not a module, and names defined at the top level are not available within
the functions. The functions are defined by reading abaqus_v6.env, but are executed in a different
namespace.
Predefined names
www.3ds.com | © Dassault Systèmes
A1.12
Objects
Repetition Copy
An repetition operation also makes a one-level deep (shallow) copy of the sequence. Shallow copy
example:
>>> L0 = [1, 2, 3]
>>> L1 = L0 * 2 2
www.3ds.com | © Dassault Systèmes
>>> L2 = [L0] * 2
>>> L0[1] = 0
>>> L1 L1
[1, 2, 3, 1, 2, 3]
>>> L2
[[1, 0, 3], [1, 0, 3]]
>>> L2[0][1] = 2
>>> L2 1 0
[[1, 2, 3], [1, 2, 3]]
3
L0
Same as
[L0] + [L0]
Same as L2
[1, 2, 3] + [1, 2, 3]
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
A1.13
Custom Data
mdb.customData
Data can be managed like Abaqus data by using the Repository method to map constructor to
repository. In this case:
Example:
>>> from myModule import Axle
>>> mdb.customData.Repository(name='axles', constructor=Axle)
>>> mdb.customData.Axle(name='Axle-1', ... )
mdb.customData.axles['Axle-1']
Side effect is that you can only save objects that Python can pickle (i.e. not Abaqus objects)
If special classes are used to create data, these classes can be pickled, but the modules
containing the class definitions must be available when unpickling the data.
tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@gmail.com tbalaji040@
For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by Balaji Thirupathi. For personal use by
Workshop 1
Creating and Reviewing a Replay File
Goals
When you complete this workshop, you will be able to:
1. Create an Abaqus/CAE model.
2. Understand the commands written to the replay file when creating an
Abaqus/CAE model.
3. Use the replay file to recreate a model.
4. Edit a replay file to modify a model.
Introduction
In this workshop you will create a very simple Abaqus/CAE model and then review the
Abaqus Scripting Interface commands that are written to the replay file. The model is a
square tube with a through hole at one end. It is modeled with shell elements. A free
modal analysis is performed on it. The completed model is shown in Figure W1–1.
Figure W1–1
Preliminaries
1. Start a new session of Abaqus/CAE using the following command:
abaqus cae
where abaqus is the command used to run Abaqus.
2. In the Start Session dialog box, underneath Create Model Database, click With
Standard/Explicit Model.
W1.2
Creating a part
1. Click the Create Part tool.
2. In the Create Part dialog box, name the part Tube.
3. Change the base feature shape to Shell and the type to Extrusion; click
Continue.
4. In the sketcher click the Create Lines: Rectangle tool.
5. For the starting corner enter -10, 10.
6. For the opposite corner enter 10, -10.
7. Click the red X button to quit the rectangle tool.
8. The resulting sketch should look as shown Figure W1–2.
Figure W1–2
9. Click Done.
10. In the Edit Base Extrusion dialog enter 100 for the depth, and click OK.
W1.3
Create a section
1. Click the Create Section tool.
2. In the Create Section dialog box, enter ShellSect as the section name.
3. Switch the Category to Shell and click Continue.
4. Enter 1.0 for the shell thickness and click OK.
Create a step
1. Switch to the Step module. Click the Create Step tool.
2. Enter Modal as the step name.
3. Select Linear Perturbation as the procedure type.
4. Select Frequency and click Continue.
5. Under Number of eigenvalues requested enter the value 10. Click OK.
Create a mesh
1. Switch to the Mesh module. Make sure the Part Object is set to Tube.
2. Click on the Seed Part Instance tool.
3. Assign a global size of 2.
4. Click the Mesh Part tool to generate the mesh.
Create a job
1. Switch to the Job module. Click the Create Job tool.
2. Enter TubeModal as the job name. Click Continue.
3. Click OK in the Edit Job dialog box.
4. Click the Job Manager tool. Click DataCheck and then click Dismiss.
Finishing up
1. From the main menu bar, select File→Save As.
2. Enter tube.cae for the filename and click OK.
3. Exit Abaqus/CAE.
4. Find the file named abaqus.rpy in your working directory.
5. Rename this file to tube.py.
6. This replay file will be used in later workshops. If you have any difficulty
creating this model you may use the file ws_scr_tube_1_answer.py file
that is provided.
W1.4
Task 1
Delete the tube.cae and tube.jnl files. Use the tube.py file to recreate the model.
Enter the following command:
Abaqus/CAE will use the replay file to rebuild the model exactly as it was. Exit CAE.
Task 2
Open the tube.py file in a Python-aware text editor (Abaqus PDE or IDLE). Read
through the file and make note of the commands that were created in it as you built the
model.
Questions:
Which command created the sketch rectangle?
Which command set the length of the tube?
Which command set the thickness of the tube?
Task 3
Edit the tube.py file to make some changes to the model. Do the following:
Change the size of the tube cross section to be 10 by 30 rather than 20 by 20.
Make the length 200.
Run the revised replay file and note the changes to the model. An answer script is
provided in ws_scr_tube_2_answer.py.
Workshop 1 Answers
Creating and Reviewing a Replay File
Answers to questions:
Answers to Task 3
File ws_scr_tube_2_answer.py contains answers to Task 3. The commands to
change are:
Workshop 2
Running Python
Goals
When you complete this workshop, you will be able to:
● Run Python interactively; from the command line and from Abaqus/CAE.
● Run Python by using scripts.
Here, the word abaqus should be the name of the launcher (execution procedure) that is associated with a
particular version of the Abaqus software on your system. Each site may use a slightly different name for
each maintenance release. Typically, the launcher name adheres to a convention that relates to the
maintenance level of the version (for example, abq6121 is usually used for release 6.12-1). If the
appropriate launcher name is not recognized by the system, you will need to fix this.
Troubleshooting Windows Platforms
Windows comes with a command prompt allowing users to run programs from a command-line interface.
The Windows command prompt originated from early versions of MS-DOS and uses the same basic
syntax.
Check to see if the launcher name appears in the directory called:
<your-abaqus-directory>\Commands\
If the launcher name does not exist in this directory as a Windows batch file (.bat extension), then the
name you are using is not appropriate for your installation. If you do not know the appropriate name for
the launcher, speak to the instructor or your systems administrator.
If the name does exist, but it is not recognized by your system, then it is likely that the commands directory
is not defined in the PATH environment variable for your system. If so, set the PATH environment
variable.
The simplest method of setting environment variables is through the System applet in Control Panel.
Depending on your version of Windows, one of the screen shots below should show the lists of user and
system environment variables. To change the value of an existing user variable, select the variable from
the corresponding list and modify the value in the Value field. You use the following steps to create a new
variable:
1. Click the User Variables list to select the type of variable you want to create.
W2.2
2. Replace the Variable field contents with the new variable name that you want to create.
3. Replace the Value field contents with the value that you want to assign to the new variable.
The variable list that you selected will list your new variable.
Tasks
1. Using the Command-line Interactive Mode. Start Abaqus Python at the command-line. Type any
expression such as: "Hello World!" (include the double quote characters). The string should be
echoed when you hit the return key. Try executing other commands such as 2+2 (no quotes here).
Try the expression sin(pi). Why does the latter not work? Try it again after typing the command
W2.3
from math import *. Exit the Python session by typing CTRL-Z on UNIX or CTRL-Z,
RETURN on Windows. Type abaqus python -h for more information.
2. Using the Abaqus/CAE Interactive Mode. Create a text file called run_cae.bat in your present
working directory. Include the following line in the new file:
<your-Abaqus-launcher-name> cae
Save the file and start Abaqus/CAE by double-clicking the file icon. This is a convenient means of
quickly launching Abaqus interactive products while assuring that the associated files are written to
your present working directory. You access the Python interactive mode from the command line
interface as shown below.
Now repeat some of the procedures from task 1. What version of Python are you using? Hint: try
looking at the sys.version object. What version of Abaqus are you using? Hint: try calling
uti.getVersion(). In both cases, you will need to “import” the appropriate module like we did in
task 1 for the math module.
3. Using Programs from the Command-line. With a text editor or a Python IDE, write a simple script
file. The file should contain a single print statement such as: print 'Hello World!' (this time
include single quote characters). Store this statement in a file named file1.py. Now, run this file
by passing it to the Python interpreter program on the system shell’s command line (hint: type
something like abaqus python file1.py). Why does a single quote character work for the
string? Is the .py extension required for the file name?
4. Using Programs from Abaqus/CAE. Repeat task 3 from Abaqus/CAE. You may run scripts by using
the File→Run Script pull-down menu, or by using the execfile() method from the command
line interface. Where does the text get displayed? When Python programs are executed as we have
in steps 3 and 4, we say that we are running them as “top level scripts.”
5. Using Unix-style Script Files. Give the file file1.py executable privileges, and “run it” directly as
an executable. Does the first line need to contain anything special for your platform? For UNIX
platforms, add the #! magic line to the top of file1.py. For Windows platforms, depending on
your installation, you may be able to run your script by (i) typing the file1.py at the command line,
(ii) by typing file1 at the command line (i.e. no file extension required), or (iii) by double clicking
the file icon in Windows Explorer. If any of these do not work, we will address remedies in a later
lecture.
If you have trouble completing this workshop, the file ws_scr_hello_answer.py contains the
answer to the workshop. It is provided for your convenience.
Workshop 3
Python Types, Operators, and Expressions
Goals
When you complete this workshop, you should be comfortable using basic Python types, operators and
expressions. The material for this workshop has been extracted from Chapter 2 of Learning Python, an
excellent introductory text on the language written by Mark Lutz and David Ascher and published by
O’Reilly & Associates, Inc. More practice examples like these may be found in the text.
Tasks
1. The basics. Experiment interactively with the common type operations that were discussed in this
lecture. To get you started, bring up the Python interactive interpreter, type the expressions below, and
try to explain what's happening in each case:
2 ** 16
2 / 5, 2 / 5.0
"spam" + "eggs"
S = "ham"
"eggs " + S
S * 5
S[:0]
"green %s and %s" % ("eggs", S)
('x',)[0]
('x', 'y')[1]
L = [1,2,3] + [4,5,6]
L, L[:], L[:0], L[-2], L[-2:]
([1,2,3] + [4,5,6])[2:4]
[L[2], L[3]]
L.reverse(); L
L.sort(); L
L.index(4)
{'a':1, 'b':2}['b']
D = {'x':1, 'y':2, 'z':3}
D['w'] = 0
D['x'] + D['w']
D[(1,2,3)] = 4
D.keys(), D.values(), D.has_key((1,2,3))
[[]], ["",[],(),{},None]
2. Indexing and slicing. At the interactive prompt, define a list named L that contains 4 strings or
numbers (e.g., L=[0,1,2,3]). Now, let’s experiment with some boundary cases.
W3.2
c) Finally, how does Python handle it if you try to extract a sequence in reverse—with the lower
bound greater than the higher bound (e.g., L[3:1])? Hint: try assigning to this slice (L[3:1] =
['?']) and see where the value is put. Do you think this may be the same phenomenon you saw
when slicing out-of-bounds?
3. Indexing, slicing, and ‘del’. Define another list L with 4 items again, and assign an empty list to one of
its offsets (e.g., L[2] = [])—what happens? Then try assigning an empty list to a slice (L[2:3] =
[])—what happens now? Recall that slice assignment deletes the slice and inserts the new value
where it used to be. The del statement can be used to delete offsets, keys, attributes and names: try
using it on your list to delete an item (e.g., del L[0]). What happens if you del an entire slice (del
L[1:])? What happens when you assign a non-sequence to a slice (L[1:2] = 1)?
>>> D = {}
>>> D[1] = 'a'
>>> D[2] = 'b'
We learned that dictionaries aren’t accessed by offsets; what’s going on here? Does the following
shed any light on the subject? (Hint: strings, integers, and tuples share which type category?)
6. Dictionary indexing. Create a dictionary named D with three entries, for keys "a", "b", and "c".
What happens if you try to index a non-existent key "d" (x = D['d'])? What does Python do if
you try to assign to a non-existent key "d" (e.g., D['d'] = 'spam')? How does this compare to
out-of-bounds assignments and references for lists? Does this sound at all like the rule for variable
names (see lecture 2, slide 46)?
c) Does the append method work for both lists and strings? How about the using the keys method
on lists? (Hint: What does append assume about its target?)
d) Finally, what type of object do you get back when you slice or concatenate two lists or two
strings?
8. String indexing. Define a string S of 4 characters: S = "spam". Then type the following expression:
S[0][0][0][0][0]. Any clues about what’s happening this time? (Hint: recall that a string is a
collection of characters, but Python characters are 1-character strings). Does this indexing expression
still work if you apply it to a list like: ['s', 'p', 'a', 'm']? Why?
9. Immutable types. Define a string S of 4 characters again: S = "spam". Write an assignment which
changes the string to "slam", using only slicing and concatenation. Could you perform the same
operation using just indexing and concatenation? How about index assignment?
Workshop 4
Investigating Python Objects
Goals
When you complete this workshop, you should have a basic understanding of Python objects.
Tasks
1. Type, ID, and Value. Investigate the identity, type, and value of different objects. If you want, try
using code similar to the classroom example below. This code may be found in the file called
ws_scr_compare.py): The functionality may be called at the interactive prompt by importing the
module and then calling the function. For example:
>>> import ws_scr_compare
>>> ws_scr_compare.compare(1., 2)
# ws_scr_compare.py
import types
def compare(x, y):
print 'id for x and y =', (id(x), id(y))
if x is y: print 'x and y are the same object'
if x == y: print 'x and y have the same value'
if type(x) is type(y): # in this case, same as using ==
print 'x and y have the same type'
if type(x) is types.IntType:
print 'x is an integer'
else:
print 'x is not an integer'
2. Attributes. Create a list object (e.g. L=[1,2,3]). What attributes are associated with this object?
Hint: try using the dir() function. Which of these attributes are methods? Which are members?
Try the same for a file object.
3. Copies versus Reference. At the Python command line, try some of the examples from class:
#Immutable objects
>>> a = 1; b = a
>>> a = 2
>>> b
1
# Mutable objects
>>> a = [1, 2, 3]; b = a
>>> a[2] = 4
>>> b
[1, 2, 4]
W4.2
# Empty slice copy
>>> a = b = [1,2,3]
>>> c = a[:]
>>> b.append(4)
>>> a
[1, 2, 3, 4]
>>> c
[1, 2, 3]
#Repetition copy
>>> L0 = [1, 2, 3]
>>> L1 = L0 * 2; L1
[1,2,3,1,2,3]
>>> L2 = [L0] * 2; L2
[[1,2,3],[1,2,3]]
>>> L0[1] = 0
>>> L1
[1, 2, 3, 1, 2, 3]
>>> L2
[[1, 0, 3], [1, 0, 3]]
>>> L2[0][1] = 2
>>> L2
[[1, 2, 3], [1, 2, 3]]
Workshop 5
Defining a Function for a Series Calculation
Goals
When you complete this workshop, you will be able to:
● Use a loop with test operators.
● Create a Python function.
● Work with large integers.
Task 1
Write a function called fib that may be used to print the Fibonacci series up to 10,000. Review the
information in the “Other information” section below if you do not know the definition of the Fibonacci
Series. Put the function in a file called ws_scr_fib.py. Run the script file from within the Python
interpreter and print the series.
Task 2
If you want, try writing the function using two different approaches: with and without recursion (review the
class notes if you need to).
Other information
The Fibonacci series is formed by starting with 0 and 1 and then adding the last two integers to get the
next one: 0, 1, 1, 2, 3, 5, 8, 13, … In general, the series may be defined as follows:
k0 = 0
k1 = 1
kn = kn-1 + kn-2
For example,
0, 1 the series starts like this
0 + 1 = 1 the next term is k0 + k1
So the series is now
0, 1, 1
1 + 1 = 2 the next term is k1 + k2
The series continues...
0, 1, 1, 2
1 + 2 = 3 the next term is k2 + k3
We continue this way to generate the series. For example:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987...
Workshop 5 Answers
Defining a Function for a Series Calculation
Answers
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# OPTION-1: Recursive function to find nth element (slow)
def fib1(n):
if n==0 or n==1:
return 0+n
else:
return fib1(n-1) + fib1(n-2)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# OPTION-2: Utilize fib1() to find series between two integers
def fib2(fromNum, toNum):
n=0
while 1:
fn = fib1(n)
if fn > toNum: break
if fn >= fromNum: print fn,
n = n+1
return
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# OPTION-3: Non-recursive function using large integers
def fib3(fromNum, toNum):
a, b = 0L, 1L
c = a + b
if c > fromNum: print a, b,
while 1:
c = a + b
if c >= toNum: break
if c > fromNum: print c,
a, b = b, c
If you have trouble completing this workshop, the file ws_scr_fib_answer.py contains
the answer to the workshop. It is provided for your convenience.
Note. Integers will not overflow, they will be automatically converted to long integers, so
it is not really necessary to specify a, b = 0L, 1L, the first line of the function could be
a, b = 0, 1
Workshop 6
Modules
Goals
When you complete this workshop, you will be able to:
Import a module using different techniques.
Observe some the inherent behavior different module import techniques.
Tasks
1. Import. Start Python at the command line or by launching Abaqus/CAE. In an editor, look at the file
called ws_scr_modules.py. You should see three functions: test1(), test2(), and
test3(). Access this file interactively by using “import.” To do this, at the interactive command
prompt (either in a system shell or at the Abaqus/CAE CLI), type import ws_scr_modules.
Note that the import will fail if you include the .py file extension. Also, this will fail if your
PYTHONPATH setting does not include the directory where the file is stored. How do you know the
present value of PYTHONPATH? Hint: try looking at the sys.path object.
2. dir(). When the import works, look at what gets returned when typing dir() and
dir(ws_scr_modules). You should see two different lists of attributes, one for the interpreter's
namespace, and the other for the namespace of module ws_scr_modules. The three function
names should be included in one of the lists of attributes. Try calling the function called test3() to
see what it does. For example, type ws_scr_modules.test3(ws_scr_modules).
3. from import *. Type from ws_scr_modules import *. Now check dir() and
dir(ws_scr_modules) again. The three function names should be included in both of the lists of
attributes, because the function names have been imported into the interpreter's namespace.
4. Reload. Do not stop the Python interpreter from task 3. After a successful import, you will notice a
file named ws_scr_modules.pyc in the original directory. When was this file created? Try a
few more imports of the same file and notice if the file modification time changes. Edit and save the
file called ws_scr_modules.py. Try another import. You should notice that now the
modification time of the file called ws_scr_modules.pyc has not changed. Try to “reload” the
file by typing reload(ws_scr_modules). Do this several times and note that the modification
time of the .pyc file changes every time. Finally, try moving the file to a different directory and
importing it again. What happens? The import will fail if the new path is not included in
PYTHONPATH.
5. Top level script: Now instead of importing the file, run the file as a top-level script. Continue to work
within the interactive Python mode. One way to run a top-level script is to use the following
command: execfile('ws_scr_modules.py'). What happens when you do this? You
should see that the test function is executed. Why now and not during import? We will answer this
question soon in an upcoming lecture. The answer is related to the namespace that we are in during an
interactive session. The namespace is called __main__.
Workshop 7
Goals
When you complete this workshop, you will be able to create and use an Abaqus macro
and requests input interactively using getinputs.
Task 1:
Create a macro that adds three materials, in SI units, to Model-1.
Other information
1. Start Abaqus/CAE.
2. Open the Macro Manager (File→Macro Manager).
3. Create a macro named add_SI_Materials.
4. Switch to the Property module, and use the Materials Manager to create three
materials with the following properties:
Steel.
Young's Modulus 200 E 9
Poisson's ratio 0.3
Density 7800
Yield Stress, Plastic Strain 400 E 6, 0.00
420 E 6, 0.02
500 E 6, 0.20
600 E 6, 0.50
Copper
Young's Modulus 110 E 9
Poisson's ratio 0.3
Density 8970
Yield Stress, Plastic Strain 314 E 6, 0.00
W7.2
Aluminum
Young's Modulus 70 E 9
Poisson's ratio 0.35
Density 2700
Yield Stress, Plastic Strain, Temp 270 E 6, 0, 0
300 E 6, 1, 0
243 E 6, 0, 300
270 E 6, 1, 300
5. Stop recording.
6. Exit Abaqus/CAE (do not save changes).
7. In an editor, open the file abaqusMacros.py. Review the file and close it when
completed.
8. Start Abaqus/CAE. Create a new model named Model-2, and run the macro.
Confirm that the materials have been added to Model-1. How can you get the
material from Model-1 to Model-2? What could you do to the macro to create
this material data in the current model?
Note: You will be asked to use the file called abaqusMacros.py again. You
may want to create a backup copy at this time.
Task 2:
Modify the material library macro that you created in Task 1.
Workshop 7 Answers
Task 1:
Create a macro that prompts the user for the name of the model and adds three materials,
in SI units, to the model.
Answers
from abaqus import *
def add_SI_Materials():
import material
m = mdb.models['Model-1'].Material('Steel')
m.Elastic(table=((200.0E9, 0.3), ))
m.Plastic(table=((400.E6, 0.0), (420.E6, 0.02),
(500.E6, 0.2), (600.E6, 0.5)))
m.Density(table=((7800.0, ), ))
m = mdb.models['Model-1'].Material('Aluminum')
m.Elastic(table=((70.0E9, 0.35), ))
m.Plastic(temperatureDependency=ON, table=((270e6,0,0),
(300e6,1.0,0),(243e6,0,300),(270e6,1.0,300)))
m.Density(table=((2700,), ))
m = mdb.models['Model-1'].Material('Copper')
m.Elastic(table=((110e9,.3),))
m.Plastic(table=((314e6,0),))
m.Density(table=((8970,),))
WA7.2
Task 2:
from abaqus import *
def add_SI_Materials():
"""
Add Steel, Copper, Aluminum in SI units
"""
import material
m = mdb.models[name].Material('Steel')
m.Elastic(table=((200.0E9, 0.3), ))
m.Plastic(table=((400.E6, 0.0), (420.E6, 0.02),
(500.E6, 0.2), (600.E6, 0.5)))
m.Density(table=((7800.0, ), ))
m = mdb.models[name].Material('Aluminum')
m.Elastic(table=((70.0E9, 0.35), ))
m.Plastic(temperatureDependency=ON, table=((270e6,0,0),
(300e6,1.0,0),(243e6,0,300),(270e6,1.0,300)))
m.Density(table=((2700,), ))
m = mdb.models[name].Material('Copper')
m.Elastic(table=((110e9,.3),))
m.Plastic(table=((314e6,0),))
m.Density(table=((8970,),))
Workshop 8
Goals
When you complete this workshop, you will be able to:
Navigate the Abaqus Scripting Manual.
Manipulate an object in the viewport using a script.
Task
Examine the documentation for the canvas commands, then write a script to create a
function that takes an output database name as an argument and creates a layout of four
viewports with the following views of the output database: Top, Left, Front, and Iso. You
will use the following commands in your script:
session.openOdb(...)
session.Viewport(...)
session.viewports[name].setValues(...)
session.viewports[name].view.setValues(...)
Other information
The following code is an example of applying a predefined ISO view to an existing
viewport.
isoView = session.views['Iso']
vp = session.viewports['Viewport: 1']
vp.view.setValues(isoView)
The following code is an example of how to open and display an output database in a
viewport.
odb = session.openOdb('w_beam3d.odb')
vp = session.viewports['Viewport: 1']
vp.setValues(displayedObject=odb)
Before continuing, submit the job called w_beam3d (type abaqus j=w_beam3d from the
system shell command line) in order to generate the output database file (w_beam3d.odb)
noted above.
The object session.drawingArea has members ['height', 'origin', 'width'] that can
be used to make the viewports fit into the current application size.
Workshop 8 Answers
Task
Examine the documentation for the session commands, then write a script to create a
function that takes an ODB name as an argument and creates a layout of four viewports
with the following views: Top, Left, Front, and Isometric.
Answers
from abaqus import *
from abaqusConstants import *
import visualization
def cannedLayout(odbPath):
cannedLayout('beam3d.odb')
Workshop 9
Goals
When you complete this workshop, you will be able to read data from an Abaqus ODB
file using scripting commands
Tasks
Read some nodal data from an Abaqus ODB file.
1. Open the file viewer_tutorial.odb in Abaqus/Viewer and review the contents.
Close Abaqus/Viewer. Now open the script file odbRead.py in an editor and
view the contents. What do you think this script does?
2. At the command line, run the script. You should see some nodal displacement
information written to the shell.
3. Modify the script. The script is written with a fixed ODB path and node-set
name. Modify the script to accept a command line argument for the ODB path.
Hint: use argv found in the sys module.
4. Modify the script some more. Add some print statements to provide feedback on
all of the node-sets names that are available in the ODB file that is being opened.
Hint: node-set objects are available at the root assembly and also for each
instance.
Workshop 9 Answers
if len(sys.argv) != 2:
print 'Error, you must supply ODB name at command line'
sys.exit(1)
odbPath = sys.argv[1]
try:
odb = openOdb(path=odbPath)
except IOError, value:
print 'Error:', value
print 3*'\n'
print 'Available steps = ',odb.steps.keys()
lastFrame = odb.steps[odb.steps.keys()[-1]].frame[-1]
displacement = lastFrame.fieldOutputs['U']
nsetNames = odb.rootAssembly.instances['PART-1-1'].nodeSets.keys()
center = odb.rootAssembly.instances['PART-1-1'].nodeSets[nsetNames[4]]
centerDisplacement = displacement.getSubset(region=center)
for v in centerDisplacement.values:
print 'Position = ', v.position,'Type = ',v.type
print 'Node label = ', v.nodeLabel
print 'X displacement = ', v.data[0]
print 'Y displacement = ', v.data[1]
print 'Displacement magnitude =', v.magnitude
odb.close()
Workshop 10
Goals
When you complete this workshop, you will be able to:
Combine results from 2 separate fields on the ODB to create a new temporary
field.
Display the new field in Abaqus/Viewer.
Task
The file w_beam3d.odb contains the displacements of a cantilever beam. In the step
named Down a vertical load was applied, and in the step named Sideways a horizontal
load was applied. Add the displacements and stresses from the last frame of step Down to
the last frame of step Sideways, and display the result in Abaqus/Viewer.
Other information
Write a script that does the following:
Open the file w_beam3d.odb. Use the command session.openOdb.
Assign the ODB object to the variable odb.
Assign the fields from the last frame of each step as follows:
Assign the variable disp1 to the displacement field of the last frame of the
step named Down.
Assign the variable disp2 to the displacement field of the last frame of the
step named Sideways.
Assign the variable stress1 to the stress field of the last frame of the step
named Down.
Assign the variable stress2 to the stress field of the last frame of the step
named Sideways.
Add the two displacement fields to get disp3.
Add the two stress fields to get stress3.
(Note that displacements have the key U, and stresses have the key S.)
W10.2
Plot the contours of the result, using the following commands (where vp refers to the
current viewport).
vp.setValues(displayedObject=odb)
vp.odbDisplay.setPrimaryVariable(field=stress3,
outputPosition=INTEGRATION_POINT,
refinement=(INVARIANT, 'Mises'))
vp.odbDisplay.setDeformedVariable(disp3)
vp.odbDisplay.display.setValues(plotState=(CONTOURS_ON_DEF,))
Workshop 10 Answers
Task
An ODB file is provided named w_beam3d.odb, which contains the displacements of a
cantilever beam. In the step named Down a vertical load was applied, and in the step
named Sideways a horizontal load was applied. Add the displacements and stresses from
the last frame of step Down to the last frame of step Sideways, and display the result in
Abaqus/Viewer.
Answers
from abaqus import *
from abaqusConstants import *
import visualization
frame2 = odb.steps['Sideways'].frames[-1]
disp2 = frame2.fieldOutputs['U']
stress2 = frame2.fieldOutputs['S']
If you have trouble completing this workshop, the file ws_scr_addfields.py contains
the answers to the workshop. It is provided for your convenience.
Workshop 11
Goals
When you complete this workshop, you will be able to transform a replay file into a kernel script and build
a GUI dialog using RSG to run the kernel script. It is recommended you follow the RSG Dialog Builder
tour before starting this workshop.
Tasks
Abaqus/CAE records the commands from the user interface in the replay file. Thus, this file is a good
starting point in creating a kernel script.
W11.2
17. Add a text field (click ). The label text should be Name: and the keyword value partName.
18. Add another text field. The label text should be Width (w):, the type should be Float and the
keyword width.
19. Add another text field. The label text should be Height (h):, the type should be Float and the
keyword height.
20. Add another text field. The label text should be Radius (r):, the type should be Float and the
keyword radius. Your dialog box should look similar to the following:
W11.3
21. Add a second group box (click ) with the title Diagram. In this group box, add an icon (click
) and select the file createPlate.png (click to select the file). If necessary, use the
arrows ( ) to position the Diagram group box above the Parameters group
box.
22. Your dialog box should look similar to the following:
W11.4
24. Change to the second tab (Kernel). Click to load a kernel module and select
createPlateModule.py. Select createPlateFunction in the drop-down function menu.
25. Change to the GUI tabbed page and click to save your plug-in as a Standard plug-in.
Enter createPlate as the directory name and Create Plate… as the menu button name.
Note to where the plug-in files are saved. It should be under your HOME directory, in a folder
named abaqus_plugins.
26. Restart Abaqus/CAE and test the plug-in (Plug-ins→Create Plate).
Workshop 12
Goals
When you complete this workshop, you will be able to use the Abaqus environment file to customize some
default settings of Abaqus/CAE. Before continuing, submit the job called w_new_beam3d (type
abaqus j=w_new_beam3d from the system shell command line) in order to generate the output
database file w_new_beam3d.odb.
Tasks
Use the file called ws_scr_abaqus_v6_general.py to customize Abaqus.
1. Using a text editor, open the two files called ws_scr_abaqus_v6_general.py and
ws_scr_material_library.py. The environment file does many things to customize
Abaqus. Make a list of the things that you think it does. What is the purpose of the material file?
How does the environment file use it?
2. Copy the file ws_scr_abaqus_v6_general.py to abaqus_v6.env. Launch
Abaqus/CAE from the same directory. To verify that the environment file was used, you should
see many variable names written to the shell window and to the Abaqus/CAE message area. In the
message area, you should also see the message: "The model 'my_material' has been
created". If you do not see these things, Abaqus is not using your new environment file.
3. Open the ODB file called w_new_beam3d.odb. Plot a contour of any variable. How are the
contour settings different from the normal defaults?
4. Go to the Property module and look at the materials that are available. Now switch to the model
called my_material and review the materials.
5. Close Abaqus/CAE. At the system shell command line, submit the job called w_beam3d (type
abaqus j=w_beam3d). Can you explain the text that is written to the shell window? Look at
the .log file for the job. You should see some non-standard information written to the end of
this file. Now look at the file called newflat.inp. Where did this file come from and how
does it compare with w_beam3d.inp?
import odbAccess
odbAccess.majorVersion
odbAccess.minorVersion
or, in Abaqus/CAE:
import abaqus
abaqus.majorVersion
abaqus.minorVersion
W12.2
#################################################################
# from the file called ws_scr_abaqus_v6_general.py
#################################################################
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def onCaeStartup():
# Compatibility issues
backwardCompatibility.setValues(includeDeprecated=OFF)
# Graphics preferences
session.graphicsOptions.setValues(displayLists=ON, dragMode=AS_IS,
autoFitAfterRotate=ON)
# Print preferences
session.printOptions.setValues(vpDecorations=OFF, vpBackground=OFF,
rendition=COLOR, printCommand='lpr')
session.psOptions.setValues(date=OFF)
# Visualization preferences
def setVisPreferences(module, userData):
from visualization import SHADED, EXTERIOR, CONTINUOUS
session.defaultOdbDisplay.commonOptions.setValues(
renderStyle=SHADED, visibleEdges=EXTERIOR)
session.defaultOdbDisplay.contourOptions.setValues(
contourStyle=CONTINUOUS)
addImportCallback('visualization', setVisPreferences)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def onJobStartup():
print 'The job is starting'
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def onJobCompletion():
for glob in globals().keys():
if glob != '__builtins__':
print '%s = %s' % (glob, eval(glob))
import os, shutil
flatFilePath = os.path.join(scrdir,"%s_f.inp" % id)
print 'The present value of os.getcwd() is ', os.getcwd()
if os.path.exists(flatFilePath):
newFlatFilePath = os.path.join(savedir, 'newflat.inp')
print 'newFlatFilePath = ',newFlatFilePath
print "A copy of the flat file has been written."
shutil.copyfile(flatFilePath, newFlatFilePath)
W12.3
#################################################################
# ws_scr_abaqus_v6_general.py (cont.)
#################################################################