Skip to Main Content

      

ANSYS BLOG

November 15, 2022

Access the Power of Ansys from the Python World

Python is the world’s most popular programming language, and the Python ecosystem contains an abundance of open source code libraries that developers can freely use to create new solutions. The PyAnsys code library breaks new ground by enabling developers to integrate Ansys-based simulation into their Python-based projects.

One way to look at simulation is this: Simulation delivers insights without the need to perform the real-world tasks that would otherwise deliver those same insights. Stresses can be tested without breaking — or even building — an expensive prototype. The characteristics of a new design — be they thermal, electrical, fluid, or whatever — can be explored without having to create the actual temperatures, pressures, currents, or flows. We can gain the insights that would otherwise have arisen from experience without actually having to create the experience — which is particularly valuable when gaining those insights might take 50 or 100 years or involve destroying multi-million-dollar prototypes.

The only real-world tasks that need to be performed in a world enabled by simulation are the manual tasks associated with configuring, running, and sharing the results of the simulations themselves.

But thanks to PyAnsys and other Ansys solutions that connect the digital thread, even that is changing.

PyAnsys is a family of Python packages that enable users to interact with Ansys products, including MAPDL, AEDT, and others, in an unprecedented manner. The packages provide users with a modern programmable interface through which they can not only script the execution of a wide range of multiphysics simulations using the Ansys simulation stack, but they can also script workflows that incorporate simulation to other automated operations. 

3D polar plot of antenna array output using PyAEDT

3D polar plot of antenna array output using PyAEDT.

Why Python?

So why Python? The Ansys Parametric Design Language (APDL) has long provided extensive scripting and control capabilities for interacting with Ansys products. Individuals can write scripts in APDL (or Mechanical APDL [MAPDL], a finite element analysis program built on APDL), that facilitate setup, execution, and post-processing of simulations. The Ansys Customization Tool Kit (ACT) also provides features for controlling and automating simulations in Ansys Mechanical. But that was just it: One could only use the scripting features of these tools from within the tools. There was no mechanism for interacting programmatically with any Ansys products from outside APDL, MAPDL, or ACT.

That changed in 2016 when a Python developer and Ansys MAPDL user named Alex Kaszynski created a code library that enabled him to interact with MAPDL using Python. The Python language is widely taught in schools and embraced enthusiastically by innumerable developers, and the Python ecosystem has an abundance of public and private code repositories that developers can draw from to create their own applications. Kaszynski posted his code library — called PyMAPDL — to GitHub, the open source online code repository, where interested users could download it and incorporate its functionality into their own projects that involved using MAPDL. 

And download it they did. PyMAPDL was made available at no cost to users — though users intending to interact with Ansys MAPDL needed to license that application — and it soon became clear that Ansys users very much wanted the ability to interact more programmatically with the Ansys simulation stack.

This enthusiasm was clear to Ansys as well, which hired Kaszynski and encouraged him to continue the work he had begun.  

Exhaust manifold mesh postprocessing using  PyFluent

Exhaust manifold mesh post-processing using PyFluent.

PyFluent postprocessing  showing an iso-surface of the velocity of flow in an exhaust manifold

PyFluent post-processing showing an iso-surface of the velocity of flow in an exhaust manifold.

Moving Forward Pythonically

That work today is ongoing. The PyAnsys page on GitHub offers a range of packages that can be used to interact “Pythonically” with Ansys products:

  • Electronics simulation: PyAEDT
  • Solid mechanics simulation: PyMAPDL
  • Fluids simulation: PyFluent, PyFluent-Parametric, PyFluent-Visualization
  • Post processing: PyDPF-Core, PyDPF-Post
  • Materials management: Granta MI BoM Analytics

Additionally, the PyAnsys page on GitHub offers access to a range of shared components that facilitate package interoperability and minimize maintenance.

Because the Python ecosystem provides code libraries with which users can create web applications with customized user interfaces (UIs), PyAnsys products can easily be called from those customized UIs. That ensures that PyAnsys-based projects are very easy to use because users need not be familiar with the UIs associated with each individual Ansys product. Even a Python script that accesses several different Ansys simulation tools can present users with a UI whose only options and input requirements are those that are relevant to the workflow being automated.

The GitHub community has been active in uploading PyAnsys-based projects for others to use, and Ansys has been reviewing the projects and working with developers to incorporate their ideas into new PyAnsys packages. The packages (along with full documentation and code examples) continue to be offered on GitHub as open source libraries under an MIT license.

In addition, the Ansys Developer Experience has been introduced as a digital platform designed to encourage and enable the broader developer ecosystem to interact with Ansys. The platform includes the developer portal, peer-to-peer discussion forums, and access to Ansys documentation and tools intended to enable developers to get up and running quickly. This is the first time that Ansys has dedicated platforms and resources to supporting developers using new and emerging Ansys technologies. The Developer Experience aims to encourage the developer ecosystem to grow and mature, while improving the user experience by more easily accessing relevant resources and getting technical support. 

MAPDL volume plot of a lathe cutter

MAPDL volume plot of a lathe cutter.

MAPDL modal principal stresses of lathe cutter

MAPDL modal principal stresses of lathe cutter.

Real-World Benefits

For users around the world, PyAnsys presents tangible benefits. The engineering team at Bewind GmbH, a German systems design and engineering firm, for example, uses PyAnsys to create a customized, automated workflow to assess fatigue in its wind turbine blades more accurately and effectively. This approach saves significantly on time and costs by using the predictive accuracy of Ansys solvers to validate that the blades are both structurally sound and operationally efficient.

Other companies are already using PyAnsys to automate repetitive, complex simulations, such as those that might be used to train a machine learning (ML) or artificial intelligence (AI) system. Training such systems may require thousands of simulations, and managing the execution and analysis of those simulations becomes significantly easier if execution can be managed programmatically through a Python script. Still other companies are adopting PyAnsys to help ensure that repeated simulations are conducted in exactly the same way so as to reduce the possibility of human error arising from the imperfect repetition of a complex task whose novelty has worn off.

The ability to orchestrate processes using Python also creates opportunities for engineers to rethink the manner in which activities are performed. By breaking a complex workflow into tasks that can be run in parallel using separate resources, for example, a Python script can dramatically reduce the amount of clock time required to complete the workflow. Activities that might previously have required ongoing coordination and hand-offs between a structures team, a fluids team, and a thermal team — each traditionally running simulations sequentially on different tools — can now be captured in a script that can be used in conjunction with other solutions in a connected digital thread to provide the information that all teams need.

For both end users and developers, the availability of PyAnsys packages and the ability to incorporate Ansys simulations into a broader ecosystem of activities opens new doors. Many organizations today are using PyAnsys to automate existing processes, which makes sense because they are the processes that are known and need to be performed in specific ways. But PyAnsys also creates opportunities to integrate the Ansys simulation stack into workflows that may never have been tried before. PyAnsys is yet another Ansys technology that enables interconnected innovation and, ultimately, digital transformation.

Visit the Ansys Developer Experience site. 

See What Ansys Can Do For You

Contact us today

* = Required Field

Thank you for reaching out!

We’re here to answer your questions and look forward to speaking with you. A member of our Ansys sales team will contact you shortly.

Footer Image