PyMAPDL Documentation

repository·main·Indexed 17 days ago

https://github.com/ansys/pymapdl

A Python client library (ansys-mapdl-core) providing a Pythonic interface for Ansys MAPDL. It enables remote connectivity via gRPC, direct access to solver data such as meshes and arrays, and object-oriented access to geometry and database objects. The library includes tools for launching MAPDL instances, converting APDL scripts, and managing simulations across Windows, Linux, and macOS, with support for Docker Compose deployment.

Tokens
112.6K
Snippets
384
Records
546
Agent score
64%

What's inside PyMAPDL

  1. Overview of PyMAPDL

    main

    PyMAPDL provides Pythonic access to MAPDL, allowing direct communication with the MAPDL process from Python. The ansys-mapdl-core package provides a comprehensive interface including:

    • Pythonic Commands: Interactive sessions and command execution.
    • Remote Connections: Connect to MAPDL from anywhere via gRPC.
    • Object-Oriented Access: Direct access to MAPDL arrays, meshes, and geometry as Python objects.
    • Low-level Solver Access: Access to the MAPDL solver through APDL math via a SciPy-like interface.

    PyMAPDL is compatible with Jupyter Notebooks, standard Python consoles, and batch mode on Windows, Linux, and macOS.

  2. Overview of the PyMAPDL API

    main

    The PyMAPDL API is centered around the Mapdl class (inheriting from MapdlBase). This class serves as the primary interface for interacting with an ANSYS MAPDL instance using Python. For detailed technical specifications of the API, refer to the ref_mapdl_api documentation.

    from ansys.mapdl.core import Mapdl
    
    # The Mapdl class is the primary entry point for interacting with MAPDL
  3. Overview of PyMAPDL command categories

    main

    PyMAPDL provides Pythonic wrappers for most classic MAPDL commands. These commands are organized into functional groups that correspond to the standard ANSYS workflow. While most commands are wrapped, some may have partial or no native support in PyMAPDL.

    Key command categories include:

    Session and Database

    • Session: General control of the PyMAPDL session.
    • Database: Global operations on the MAPDL database.
    • Graphics: Control over program graphics.
    • APDL: Commands belonging to the ANSYS Parametric Design Language.

    Model Lifecycle

    • Preprocessing (PREP7): Commands for creating and setting up the model.
    • Solution: Commands for loading and solving the model.
    • POST1: Postprocessing results using the database processor.
    • POST26: Postprocessing results using the time-history processor.

    Auxiliary and Specialized Processors

    • AUX2: Examining or manipulating binary files.
    • AUX3: Operating on results files (e.g., deleting sets or changing values).
    • AUX12: Defining radiation options for thermal analyses.
    • AUX15: Reading IGES files for analysis.
    • MAP: Mapping data from external files onto existing geometry.
    • Connection: Reading external CAD files into MAPDL.

    Miscellaneous

    • Miscellaneous: Undocumented miscellaneous commands.
    • Undocumented Inquire: Commands that are undocumented in the official ANSYS Command Reference Guide. Warning: Use these with caution as support is limited.
  4. Explore PyMAPDL extended examples and interoperability patterns

    main

    PyMAPDL supports a wide range of advanced use cases including interoperability with external libraries, machine learning integration, and custom application development. Key patterns demonstrated in the extended examples include:

    • Interoperability: Using PyMAPDL with external meshing libraries like Gmsh.
    • Machine Learning: Implementing reinforcement learning (e.g., Cart Pole Simulation) or generating training data for Ansys Twin Builder static reduced order models (ROM) using PyMAPDL and PyDPF.
    • Application Development: Building custom Python applications with Command Line Interfaces (CLI) or Graphical User Interfaces (GUI) using PySide6 or Dash.
    • Advanced Analysis: Performing stochastic FEA via Monte Carlo simulations, using the Krylov method for harmonic analysis, and automating beam analysis reports.
    • High-Performance Computing: Running PyMAPDL within HPC environments managed by SLURM.
  5. Access Prep7 commands in PyMAPDL

    main
    The Prep7 module provides access to commands used during the pre-processing stage of a MAPDL simulation. This includes commands for defining geometry (areas, volumes, lines, keypoints), materials, element types, meshing, and constraints. Use the Prep7 command group to set up the model before running the solution.
  6. Understand the PyMAPDL API structure

    main

    The PyMAPDL API consists of several public classes, functions, and attributes designed to interact with MAPDL. While many methods wrap or include MAPDL commands, they are implemented in a Pythonic manner to extend existing MAPDL functionality.

    The API is organized into several functional modules:

    • commands: Direct access to MAPDL commands.
    • components: Access to specific MAPDL components.
    • database: Operations related to the MAPDL database.
    • geometry: Geometric modeling commands.
    • helper: Utility functions.
    • information: Commands to retrieve MAPDL information.
    • inline: Inline command execution.
    • krylov: Krylov subspace methods.
    • launcher: Managing MAPDL instances and execution.
    • logging: Logging configuration.
    • mapdl: The core PyMAPDL interface.
    • mesh: Meshing operations.
    • parameters: Parameter management.
    • plotting: Visualization and plotting tools.
    • pool: Managing a pool of MAPDL instances.
    • post: Post-processing commands.
    • plugin: Extension points for adding functionality.
    • solution: Solving and simulation control.
    • xpl: XPL (Extended Programming Language) support.

    For a direct mapping of specific MAPDL commands to their PyMAPDL equivalents, refer to the MAPDL command mapping documentation.

  7. Perform Stochastic Finite Element Method (SFEM) analysis with PyMAPDL

    main

    PyMAPDL can be used to perform Stochastic Finite Element Method (SFEM) analysis, which extends classical deterministic finite element methods to account for randomness and uncertainty in system parameters (geometry, materials, loads) and response parameters (displacement, strain, stress).

    A common approach for implementing SFEM is through Monte Carlo simulation (MCS), which is highly versatile and can be applied to virtually any stochastic analysis problem.

  8. Ways to contribute to PyMAPDL

    main

    You can contribute to the PyMAPDL project through several channels depending on your interest and technical involvement:

    • Answer discussions: Engage with the community to help users and deepen your understanding of the project. No setup required.
    • Post issues: Report bugs, suggest improvements, or request new features via GitHub issues.
    • Write documentation: Improve the project's guides and references.
    • Develop PyMAPDL: Contribute directly to the codebase.

    Important Note for Developers: Before contributing code, you must follow the guidelines in the PyAnsys Developer's Guide, specifically regarding the general contribution process and the project's coding style. Additionally, to ensure proper release note generation, you must adhere to the branch and commit naming conventions defined in the PyAnsys Developer's Guide.

  9. Post-processing commands in Post1

    main
    The Post1 module provides a suite of commands for post-processing results in MAPDL. These commands are organized into several functional categories including animation, setup, controls, status, magnetics, element tables, failure criteria, fatigue, listing, path/surface operations, and result extraction. Use these commands to analyze simulation data after the solution phase is complete.
  10. Manage MAPDL Data Tables in PREP7

    main

    The DataTables class in the ansys.mapdl.core._commands.prep7.data_tables module provides access to MAPDL commands for managing and manipulating data tables during the PREP7 phase. These commands allow you to create, copy, delete, modify, and plot data tables used for storing material, element, or nodal data.

    from ansys.mapdl.core import Mapdl
    
    # Accessing the DataTables command group
    # Note: The specific methods are available via the Mapdl instance
    mapdl = Mapdl()
    # Example usage of available commands:
    # mapdl.cbtmp(...)
    # mapdl.tb(...)
    # mapdl.tblist(...)
  11. Use PyMAPDL modules for different workflows

    main

    PyMAPDL is organized into modules designed for different levels of complexity and performance requirements. You can use these modules to implement:

    • Basic workflows
    • Intermediate workflows
    • Advanced workflows
    • High-performance workflows
  12. Choose the appropriate MAPDL interface

    main

    PyMAPDL connects to MAPDL using one of three interfaces. The choice depends on your Ansys version and performance requirements:

    1. gRPC interface: The default and preferred interface for Ansys 2020 R1 and later. It supports remote management and rapid streaming of mesh, results, and files. It also works with Docker, allowing MAPDL to run on unsupported platforms like macOS.
    2. CORBA interface: A legacy interface for older Ansys versions (e.g., Ansys 17.0). It is slower as it relies on file I/O for most operations. Note: This interface was completely removed in PyMAPDL v0.68 due to lack of support for Python > 3.8.
    3. Console interface: Supports Ansys versions as early as 13.0 on Linux. It exchanges text via the console. Support for this interface is expected to be deprecated in the future.