Editor’s Note: The other day we got a tech support question. A user was creating lots of STL’s from his Ansys Mechanical results and was tired of clicking so much. They were wondering if we could give them a few hints to get going. Alex Grishen, Matt Sutton, and Joe Woodward all pitched in on the email thread. Then, seeing how useful it was Alex converted it into a PowerPoint that we could share with other users.
A big change in Ansys Mechanical scripting with ACT is the introduction of a recording button. This allows you to record your actions as a starting point for your script. The tutorial also includes links to other resources.
If you find yourself clicking away and thinking, “there has got to be a way to automate this,” then you need to try automation out.
ANSYS Mechanical is a very powerful tool right out of the box. Long gone are the days when an FEA tool was just a solver, and users had to write code to create input files and interpret the results. Most of the time you never have to write anything to effectively use ANSYS Mechanical. But, users can realize significant gains in productivity and access greater functionality through customization. And it is easy to do.
Before we talk about the four options, we need to remember how the tool, ANSYS Mechanical, is actually structured. The interface that users interact with is a version of ANSYS Workbench called ANSYS Mechanical. The interface allows users to connect to geometry, build and modify their model, set up their solution, submit a solve, and review results. The solve itself is done in ANSYS Mechanical APDL. This is the original ANSYS Multiphysics program.
When you press the solve button ANSYS Mechanical writes out commands in the languages used by ANSYS Mechanical APDL, called the ANSYS Parametric Design Language, or APDL. Yes, that is where ANSYS Mechanical APDL got its name. We like to call it MAPDL for short. (Side note: years ago we started a campaign to call it map-dul. It didn’t work.) Once the file is written, MAPDL is started, the file is read in, the solve happens, and all of the requested output files are written. Then ANSYS Mechanical reads those files and shows results to the user.
Customization Tool 1: Command Snippets for Controlling the Solver
Not every capability that is found in ANSYS Mechanical APDL
is exposed in the interface for ANSYS Mechanical. That is not a problem because users can use
the APDL language in ANSYS Mechanical to access the full capability of the
solver. These small pieces of code are
called Snippets and they are added to the tree for your ANSYS Mechanical model. When the solver file is written, ANSYS
Mechanical inserts your snippets into the command stream. Simple and elegant.
PADT has a seminar from back in 2011 that lays it all out. You can find the PowerPoint Presentation here. We do have plans to update this webinar soon.
This approach is used when you want to access capabilities
in the solver that are not supported in the interface but you want to get to
those features and keep track of them from inside your ANSYS Mechanical Model.
If you are not familiar with APDL, find a more “seasoned” user to help you. Or you can teach yourself APDL programming with PADT’s Guide to APDL .
Customization Tool 2: ANSYS Customization Toolkit (ACT) for Controlling the
User Interface and Accessing the Model
As mentioned above, ANSYS Mechanical is used to define the model
and review results. The ANSYS
Customization Toolkit (ACT) is how users customize the user interface, automate
tasks in the interface, add tools to the interface, and access the model
database. This type of customization can be as simple as a new feature, presented
as an app, or it can be used to create a focused tool to streamline a certain
type of simulation – what we call a vertical application.
Unlike APDL, ACT does is not have its own language. It uses
Python and is a collection of Application Programmer Interface (API) calls from
Python. This is a very powerful toolset that increases in capability at every
release. PADT has written stand alone
applications using ACT to reduce simulation time significantly. We have also written
features and apps for ourselves and users that make everyday use of ANSYS
Do note that ACT is supported in most of the major ANSYS
products and more capability is being added across the available programs over
time, not just in ANSYS Mechanical. You can also use ACT to connect ANSYS Mechanical
to in-house or 3rd party software.
Because this is a standard environment, you can share your ACT applications on the ANSYS App Store found here. Take a look and you can see what users have done with ACT across the ANSYS Product suite, including ANSYS Mechanical. PADT has two in the library, one for adding a PID controller to your model and the other is a tool for saving your ANSYS Mechanical APDL database.
Another great aspect of ACT is that it is fully
documented. If you go to the
Customization Suite documentation in the ANSYS help library you can find everything
Customization Tool 3: APDL for Automating the Solve
With Code Snippets we talked about using APDL to access solver functions from ANSYS Mechanical that were not supported in ANSYS Mechanical. You can also use APDL to automate what is going on during the solve. Every capability in the ANSYS solver is accessible through APDL.
The most common usage of APDL is to create a tool that
solves in batch mode. APDL programs are used to carry out tasks without going
back to ANSYS Mechanical. As an example,
maybe you want to solve a load step, save some information from the solve,
export it, read it in to a 3rd party program, modify it, modify some
property in your model, then solve the next load step. You can do all of that
with APDL in batch mode.
This is not for the faint of heart, you are getting into
complex programming with a custom language. But if you take the time, it can be
very powerful. All of the commands are
documented in the ANSYS Mechanical APDL help and details on the language are in
the ANSYS Parametric Design Language Guide. The PADT Blog is full of articles going back
over a decade on using APDL in this way.
Customization Tool 4: User Programable Features in the Solver
One of the most powerful capabilities in the ANSYS Mechanical ADPL solver is the ability for end-users to add their own subroutines. These User Programable Features, or UPF’s, allow you to create your own elements, make custom material models, customize loads, or customize contact behavior.
There are other general purpose FEA tools on the market that
heavily publicize their user elements and user materials and they try to use it
to differentiate themselves from ANSYS. However, ANSYS Mechanical APDL has
always had this capability. Many
universities and companies add new capability to ANSYS using this method.
To learn more about how to do create your own custom version of ANSYS, consult the Programer’s Reference in the ANSYS Help. PADT also has a webinar sharing how to make a custom material here.
The key to successful customization ANSYS is to know your options, understand what you really want to do, and to use the wide range of tools you have available. Everything is documented in the help and this blog has some great examples. Start small with a simple project and work your way up.
Or, you can leverage PADT’s expertise and contract with PADT to do your customization. This is what a half-dozen companies large and small have done over the years. We understand ANSYS, we get engineering, and we know how to program. A perfect combination.
Regardless of how you customize ANSYS Mechanical, you will
find it a rewording experience. Greater
functionality and more efficient usage are only a few lines of custom code
So this is just a quick post to point out a handy feature in ANSYS Workbench, the ACT Console. There are times when you want some functionality in Mechanical that just is not yet there. In this example, a customer wanted the ability to get a text list of all the Named Selections in his model. A quick Python script does just that.
a=ExtAPI.DataModel.AnalysisList #Get the first Analysis if multiple are present
#Put the output file in the "user_files" directory for the project.
#Use the name of the system in case the snippet is
#used on multiple independent systems in the project.
model = ExtAPI.DataModel.Project.Model
nsels = model.NamedSelections #Get the list of Named Selections
if nsels: #Do this if there are any Named Selections
for child in nsels.Children:
So to use a piece of Python code, like this, we use the ACT Console in Mechanical. To access the ACT Console in Mechanical 17.0, or later, just hit this icon in the toolbar.
The Console allows you to type, or paste, text directly into the black command line at the bottom. But if we are going to reuse this code, then the use of Snippets is the way to go. In R17.0 they were called ‘Bookmarks’, but they worked the same way.
When you add a Snippet, a new window allows you to name the snippet and type in, or paste in, your code.
When you hit Apply, your named snippet is added to the list
From then on, to use the snippet you just click on it, and hit ‘Enter’. The text is basically, repasted into the command window, so you can set any variables needed prior to hitting your snippet.
The snippets are persistent and remain in the console, so they are available for all new projects. Using snippets is a great way to reduce time for repetitive tasks, without having to create a full blown ACT extension.
With the introduction of the new ANSYS Mechanical Enterprise, many add-on products that had to be purchased separate, are now included. In these webinars PADT’s engineers will provide an overview of the key applications that users now have easy access to.
Each product will be reviewed by one of PADT’s engineers. The will share the functionality of each tool, discuss some lessons we have learned in using and supporting each tool, and provide a short demonstration. Each session will have time for Questions and Answers.
Sign up for the one you want, or all three. Everyone that registers will receive a link to the recording and to a copy of the slides. So register even if you can not make the specific dates.
Here are the times and links to register:
Overview of ANSYS Rigid Body Dynamics (RBD) and ANSYS Explicit STR
May 19, 2016 (Thu)
11:00 am MST & PDT / 12:00 pm MDT