PyAnsys is a set of technologies in the Python ecosystem that provide an API,
or application programming interface, to several Ansys flagships products
and data processing frameworks for working with simulation data.
PyMAPDL is one such technology that is offered under PyAnsys umbrella.
In this video, we will discuss:
What is PyMAPDL?
What are its applications and who is it useful for?
How to install and launch PyMAPDL.
Finally, we will run a simple model using PyMAPDL
and demonstrate its interactive plotting capability.
Let’s get started.
Python is a versatile open-source scripting platform that’s used in several applications
such as web development, scientific computing, data science & visualization,
Artificial Intelligence (AI) & Machine Learning (ML) applications to name a few.
On the other hand, Mechanical APDL, or informally shortened as MAPDL,
is an industry-leading general-purpose finite element (FE) solver that is used for structural,
thermal, electro-magnetic, acoustics and other multi-physics simulations.
It also has built-in geometric modeling and meshing capabilities
and supports parametric modeling.
PyMAPDL is a Python API to access the MAPDL solver
and its generated simulation data.
It uses gRPC which stands for Google remote procedure call
which is an open-source remote procedure call system developed by Google.
Using this, it converts Python instruction into APDL commands
that can then be transmitted to an MAPDL instance running anywhere.
This allows a seamless integration between MAPDL and various Python packages
thereby bringing together the best of both worlds.
It allows flexible distribution by enabling users to launch 1, 2
or a pool of MAPDL instances from anywhere, using any device.
It also enables flexible automation due to the ability
to send command scripts to MAPDL directly,
pythonically, or even via legacy scripts.
Due to these advantages, PyMAPDL finds its
use in several applications and engineering workflows.
Let’s look at a few of them and see where PyMAPDL fits in.
FE simulations are powerful, but they have a learning curve.
By using PyMAPDL, developers can build apps in the Python platform
that can condense the workflow and therefore
bring physics-based simulations to a wider audience.
In addition, users can run these apps in
the form of web-apps, mobile apps or even vertical apps
using any device by accessing MAPDL from a remote server.
Another area of interest is product design improvement and optimization.
PyMAPDL gives engineers and scientists the ability to develop optimized, robust products
by combining MAPDL's accurate physics-based simulation
with the rich selection of advanced optimization
and machine learning algorithms available in various Python packages.
In fact, PyMAPDL can be used to train
AI/ML algorithms to predict and validate scenarios
that may not have been considered in the original design.
The possibilities of using PyMAPDL for product improvement, customer engagement,
and reducing time-to-market are limited by one's imagination.
Due to these reasons, PyMAPDL has a wide audience in the form of product engineers,
software developers, researchers, students, and teachers with different personas
finding uses in one or more applications.
PyMAPDL is used to issue APDL commands in Pythonic way.
Therefore, to use PyMAPDL one must install Python
on their local system and have access to either a local installation of MAPDL
or a server with MAPDL installed.
PyMAPDL is supported on Python 3.6 through 3.9
and it is compatible with Ansys MAPDL 17.0 and newer versions.
For best results, we recommend to always use the current release.
We recommend users to refer to “Getting Started” page
on mapdldocs.pyansys.com for most recent information.
It is supported on most integrated development environments
such as Visual Basic, Spyder, or Jupyter Lab.
In this course, we’ll use Jupyter Lab for all our workshops.
Once Python is installed on a system, the easiest way to
install PyMAPDL is to open the Windows command prompt
and type in pip install ansys-mapdl-core.
This installs the current version of PyMAPDL
and once the installation is complete one can verify installation using these commands
These commands launch an instance of MAPDL
and print the details of MAPDL license and version being used.
One can exit this instance by issuing mapdl.exit().
So, the structure of a typical PyMAPDL script looks like this.
One can also specify a working directory and a jobname using this set of commands.
Now let’s begin the workshop where we launch a PyMAPDL instance
and run a program to get a taste of it.
In this demo, we'll setup a parametric model of a rectangular plate with multiple holes.
The plate is modelled as 3-D solid so the thickness of the plate can be parameterized,
one end is fixed, and a pressure load is applied on the other end.
The dimensions of the plate, number of holes and their radius,
the material properties and the pressure applied are all parameterized.
The learning objectives of this demo are:
To launch PyMAPDL on a local machine.
To solve the parametric model using user-specified values.
And to demonstrate interactive plotting of geometry,
mesh, and results in Pythonic interface.
Download the provided Jupyter notebook to a folder on your local system.
In the file browser window type “cmd” to open command prompt.
If Jupyter lab is not installed on the local system you may first install it
by typing the command “pip install jupyterlab”.
Once it is installed, then you may issue the command “jupyter lab” to launch it.
Jupyter lab opens in the default browser, from the file browser you can locate the downloaded Jupyter notebook
and double click it to open in a tab.
As you can see the code and the relevant comments are divided into different cells.
We can either execute each cell individually or execute them all at once.
For this demonstration let’s execute all cells at once.
We can see that the geometry is plotted, and we can interact with it.
PyMAPDL uses PyVTK in the background for interactive CAD plotting.
Once can rotate the part with left mouse button.
Use scroll to zoom in and out.
And shift + LMB to pan.
As we scroll further down, we can see similar interactive plots for mesh and results too.
These interactive plots are supported in other IDEs too.
So far, we have launched an instance of PyMAPDL, ran a model using user-specified parameters
and witnessed how to plot and interact with geometry, mesh, and results.
This concludes the video on overview of PyMAPDL.
We will continue our learning in the next video.