Abaqus Python Scripting: How Difficult Is It?
Abaqus Python Scripting: How Difficult Is It?
https://info.simuleon.com/blog/abaqus-python-scripting-how-di…TN2rKGwFpLEmlWvVuh82XDocTMNsdDUVUkjE2rku26jtptNkag5UCQ2Z-8yqw Página 1 de 12
Abaqus python scripting: how difficult is it? 18/11/21, 8:12 a. m.
Example model
As an example, I’ll use a bending beam, since it is simple and mechanical
engineers tend to like it . The model is created in Abaqus/CAE. The Posts by Tag
beam is constrained on one side, while a pressure is applied to the top.
Abaqus (143)
Steel material properties are used.
Events & Announcements (42)
Tips, Tricks & Approaches (30)
software (24)
Non-Linear (13)
See all
Recent Posts
Abaqus python scripting: how
difficult is it?
Meshing Complex Geometries in
Figure 1: Model set-up. Abaqus
Join our Online Training: Element
Various modifications to this model will be made using scripts. Selection
Axisymmetric analysis on
Level 1: exactly repeat what is done 3DEXPERIENCE platform:
before abstraction shapes and FEM
Reps
The simplest scripts to create, are those in which you exactly repeat
Join our Online Training:
something that is done before. This can be creating a material with specific
'Concrete Modelling’
properties (for a specific model name), creating a reference model, or doing
postprocessing (when all names are the same). In those cases, we can
simply record a macro. This can be done via file --> macro manager.
Most Popular Posts
6 Tips solving non convergence
with Abaqus FEA
Converting Engineering Stress-
https://info.simuleon.com/blog/abaqus-python-scripting-how-di…TN2rKGwFpLEmlWvVuh82XDocTMNsdDUVUkjE2rku26jtptNkag5UCQ2Z-8yqw Página 2 de 12
Abaqus python scripting: how difficult is it? 18/11/21, 8:12 a. m.
Click on Create to make a new Macro, name it and choose whether it will be
stored in the Home directory, or in the current work directory. Macros in the
home directory are always accessible by the user and therefore more
suitable for general purposes, macros in the work directory are only
available in the current work directory and therefore more suitable for
specific applications.
Figure 3: Macro manager dialog box and create Macro dialog box. In this
case there are no existing macros. Once they are created, they will be listed
in the Macro Manager.
https://info.simuleon.com/blog/abaqus-python-scripting-how-di…TN2rKGwFpLEmlWvVuh82XDocTMNsdDUVUkjE2rku26jtptNkag5UCQ2Z-8yqw Página 3 de 12
Abaqus python scripting: how difficult is it? 18/11/21, 8:12 a. m.
After clicking Continue make the (modification to) the model you are
interested in and stop the recording. In this case we will create a material
named steel with linear elastic properties. The createSteelMaterial macro
appears in the Macro Manager. If we delete the current steel material model
and run the macro, the material will be recreated. Similarly, if we open a new
model database and run the macro, the material will be created.
https://info.simuleon.com/blog/abaqus-python-scripting-how-di…TN2rKGwFpLEmlWvVuh82XDocTMNsdDUVUkjE2rku26jtptNkag5UCQ2Z-8yqw Página 4 de 12
Abaqus python scripting: how difficult is it? 18/11/21, 8:12 a. m.
Figure 4: Original version of the macro, and an alternative version of the last
section where model name, material name, Young’s modulus and Poisson’s
ratio can easily be modified.
It is possible to make it more ‘fancy’ by adding a title etc; check the manual
for the available options.
https://info.simuleon.com/blog/abaqus-python-scripting-how-di…TN2rKGwFpLEmlWvVuh82XDocTMNsdDUVUkjE2rku26jtptNkag5UCQ2Z-8yqw Página 5 de 12
Abaqus python scripting: how difficult is it? 18/11/21, 8:12 a. m.
We will now save the file under a different name, as a python script (.py
extension). All macros except the one we are currently interested in, can be
removed. Do leave the import statements at the top of the file. Remove the
line containing ‘def’ and the indentation of the rest of the lines, so the code is
https://info.simuleon.com/blog/abaqus-python-scripting-how-di…TN2rKGwFpLEmlWvVuh82XDocTMNsdDUVUkjE2rku26jtptNkag5UCQ2Z-8yqw Página 6 de 12
Abaqus python scripting: how difficult is it? 18/11/21, 8:12 a. m.
no longer inside a function. We can then add the loop, a for-loop. In python,
the syntax is as you can see in Figure 8. As you can see, there is no code to
denote the end of the for-loop; this is clear because the indentation stops.
Indentation is therefore very important in python.
Figure 8: Code to run the model with stiffness from 150000 to 250000 and
increments of 25000. It would be more elegant to define a name for the job,
as was done in the previous section for the model name and material name.
This version is shown since it has least modifications to the original code.
The variable i takes all variables in the range of 150,000 up to and excluding
250,001 with increments of 25,000. This variable is then used to specify the
stiffness (first line in the loop) and to define the job name. With this method,
the jobs all have a different and sensible name and data is not overwritten.
In cases like this, you typically want to wait for the first job to complete
before starting the second one. The function waitForCompletion does this.
Only a few modifications to the macro therefore allow us to run a number of
models without any further interference from the user.
Figure 9: Excerpt from macro to change the surface on which the load is
applied using default settings.
You can choose how Abaqus defines geometry in replay files: via
COORDINATE, INDEX or COMPRESSEDINDEX (the default). You can set
this to coordinate by entering:
session.journalOptions.setValues(replayGeometry=COORDINATE)
in the command line interface. [The command line interface takes the same
space as the message area, underneath the viewport. It is hidden by
default, and can be accessed by clicking on the >>>-icon left of the
message area.].
Figure 10: Excerpt from macro to change the surface on which the load is
applied, using replayGeometry=COORDINATE
The code is now understood and modified more easily: if a different face is
to be found, we can fill in the X- Y- and Z-coordinate of a point on this face.
This point should not be shared with other faces.
https://info.simuleon.com/blog/abaqus-python-scripting-how-di…TN2rKGwFpLEmlWvVuh82XDocTMNsdDUVUkjE2rku26jtptNkag5UCQ2Z-8yqw Página 8 de 12
Abaqus python scripting: how difficult is it? 18/11/21, 8:12 a. m.
This means the script will be longer. In this example of a very simple model,
when changing the geometry I already had 58 lines of code (excluding
import statements),
+31(0) 85 0498 165 compared to at most 15
[email protected] previous
for the examples. For English
more complex models that have multiple parts, contact conditions etc., this
will be a lot more. We will need to use the technique shown before (level 4)
toSIMULIA
locate relevant locationsSIMULIA
Software and make the script applicable
Training to a new
FEA Consultancy Industries Knowledge Center
>
>
>
>
>
geometry as well. How difficult or easy that is to do, depends on the
Events in geometry
Supportthat Blog
are to beAbout us more Shop
>
>
https://info.simuleon.com/blog/abaqus-python-scripting-how-di…TN2rKGwFpLEmlWvVuh82XDocTMNsdDUVUkjE2rku26jtptNkag5UCQ2Z-8yqw Página 9 de 12
Abaqus python scripting: how difficult is it? 18/11/21, 8:12 a. m.
Conclusion
Getting started with python scripting does not have to be challenging: the
difficulty depends on the problem at hand. A macro is typically a good
starting point for a script. The closer the intended result is to the macro, the
easier it will be to script. Changing parameters tends to be simple, changing
geometry tends to be hard, especially if the script should be generally
applicable and there is limited knowledge on the to be expected geometry.
Discover more on Abaqus Scripting at our training course, find more details
below.
Discover More
Topics: Abaqus, python scripting
First Name*
Last Name*
https://info.simuleon.com/blog/abaqus-python-scripting-how-di…N2rKGwFpLEmlWvVuh82XDocTMNsdDUVUkjE2rku26jtptNkag5UCQ2Z-8yqw Página 10 de 12
Abaqus python scripting: how difficult is it? 18/11/21, 8:12 a. m.
Email*
Comment*
protección de reCAPTCHA
Privacidad - Términos
https://info.simuleon.com/blog/abaqus-python-scripting-how-di…N2rKGwFpLEmlWvVuh82XDocTMNsdDUVUkjE2rku26jtptNkag5UCQ2Z-8yqw Página 11 de 12
Abaqus python scripting: how difficult is it? 18/11/21, 8:12 a. m.
https://info.simuleon.com/blog/abaqus-python-scripting-how-di…N2rKGwFpLEmlWvVuh82XDocTMNsdDUVUkjE2rku26jtptNkag5UCQ2Z-8yqw Página 12 de 12