Skip to main content

Pythonic interface to MAPDL archive files.

Project description

pypi GH-CI MIT black

Read blocked Ansys MAPDL archive files written from MAPDL using CDWRITE.

This is effectively pymapdl-reader without the binary reader. It’s been isolated to allow greater flexibility in development.

Installation

Installation through pip:

pip install mapdl-archive

Examples

Load and Plot an MAPDL Archive File

ANSYS archive files containing solid elements (both legacy and modern), can be loaded using Archive and then converted to a VTK object.

from mapdl_archive import Archive, examples

# Sample *.cdb
filename = examples.hexarchivefile

# Read ansys archive file
archive = Archive(filename)

# Print raw data from cdb
for key in archive.raw:
   print("%s : %s" % (key, archive.raw[key]))

# Create an unstructured grid from the raw data and plot it
grid = archive.parse_vtk(force_linear=True)
grid.plot(color='w', show_edges=True)

# write this as a vtk xml file
grid.save('hex.vtu')

# or as a vtk binary
grid.save('hex.vtk')
Hexahedral beam

You can then load this vtk file using PyVista or VTK.

import pyvista as pv
grid = pv.UnstructuredGrid('hex.vtu')
grid.plot()

Reading ANSYS Archives

MAPDL archive *.cdb and *.dat files containing elements (both legacy and modern) can be loaded using Archive and then converted to a vtk object:

import mapdl_archive
from mapdl_archive import examples

# Read a sample archive file
archive = mapdl_archive.Archive(examples.hexarchivefile)

# Print various raw data from cdb
print(archive.nnum, archive.nodes)

# access a vtk unstructured grid from the raw data and plot it
grid = archive.grid
archive.plot(color='w', show_edges=True)

You can also optionally read in any stored parameters within the archive file by enabling the read_parameters parameter.

import mapdl_archive
archive = mapdl_archive.Archive('mesh.cdb', read_parameters=True)

# parameters are stored as a dictionary
archive.parameters

Writing MAPDL Archives

Unstructured grids generated using VTK can be converted to ANSYS APDL archive files and loaded into any version of ANSYS using mapdl_archive.save_as_archive in Python followed by CDREAD in MAPDL. The following example using the built-in archive file demonstrates this capability.

import pyvista as pv
from pyvista import examples
import mapdl_archive

# load in a vtk unstructured grid
grid = pv.UnstructuredGrid(examples.hexbeamfile)
script_filename = '/tmp/grid.cdb'
mapdl_archive.save_as_archive(script_filename, grid)

# Optionally read in archive in PyMAPDL and generate cell shape
# quality report
from ansys.mapdl.core import launch_mapdl
mapdl = launch_mapdl()
mapdl.cdread('db', script_filename)
mapdl.prep7()
mapdl.shpp('SUMM')

Resulting ANSYS quality report:

------------------------------------------------------------------------------
           <<<<<<          SHAPE TESTING SUMMARY           >>>>>>
           <<<<<<        FOR ALL SELECTED ELEMENTS         >>>>>>
------------------------------------------------------------------------------
                   --------------------------------------
                   |  Element count        40 SOLID185  |
                   --------------------------------------

 Test                Number tested  Warning count  Error count    Warn+Err %
 ----                -------------  -------------  -----------    ----------
 Aspect Ratio                 40              0             0         0.00 %
 Parallel Deviation           40              0             0         0.00 %
 Maximum Angle                40              0             0         0.00 %
 Jacobian Ratio               40              0             0         0.00 %
 Warping Factor               40              0             0         0.00 %

 Any                          40              0             0         0.00 %
------------------------------------------------------------------------------

Supported Elements

At the moment, only solid elements are supported by the save_as_archive function, to include:

  • vtk.VTK_TETRA

  • vtk.VTK_QUADRATIC_TETRA

  • vtk.VTK_PYRAMID

  • vtk.VTK_QUADRATIC_PYRAMID

  • vtk.VTK_WEDGE

  • vtk.VTK_QUADRATIC_WEDGE

  • vtk.VTK_HEXAHEDRON

  • vtk.VTK_QUADRATIC_HEXAHEDRON

Linear element types will be written as SOLID185, quadratic elements will be written as SOLID186, except for quadratic tetrahedrals, which will be written as SOLID187.

License and Acknowledgments

The mapdl-archive library is licensed under the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mapdl-archive-0.1.5.tar.gz (137.8 kB view hashes)

Uploaded Source

Built Distributions

mapdl_archive-0.1.5-cp312-cp312-win_amd64.whl (386.5 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

mapdl_archive-0.1.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

mapdl_archive-0.1.5-cp312-cp312-macosx_10_9_x86_64.whl (431.9 kB view hashes)

Uploaded CPython 3.12 macOS 10.9+ x86-64

mapdl_archive-0.1.5-cp312-cp312-macosx_10_9_universal2.whl (726.9 kB view hashes)

Uploaded CPython 3.12 macOS 10.9+ universal2 (ARM64, x86-64)

mapdl_archive-0.1.5-cp311-cp311-win_amd64.whl (384.5 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

mapdl_archive-0.1.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

mapdl_archive-0.1.5-cp311-cp311-macosx_10_9_x86_64.whl (431.9 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

mapdl_archive-0.1.5-cp311-cp311-macosx_10_9_universal2.whl (727.8 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64)

mapdl_archive-0.1.5-cp310-cp310-win_amd64.whl (384.6 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

mapdl_archive-0.1.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

mapdl_archive-0.1.5-cp310-cp310-macosx_10_9_x86_64.whl (431.7 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

mapdl_archive-0.1.5-cp310-cp310-macosx_10_9_universal2.whl (727.1 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)

mapdl_archive-0.1.5-cp39-cp39-win_amd64.whl (385.5 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

mapdl_archive-0.1.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

mapdl_archive-0.1.5-cp39-cp39-macosx_10_9_x86_64.whl (432.8 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

mapdl_archive-0.1.5-cp39-cp39-macosx_10_9_universal2.whl (729.1 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64)

mapdl_archive-0.1.5-cp38-cp38-win_amd64.whl (388.1 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

mapdl_archive-0.1.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

mapdl_archive-0.1.5-cp38-cp38-macosx_10_9_x86_64.whl (431.2 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

mapdl_archive-0.1.5-cp38-cp38-macosx_10_9_universal2.whl (726.1 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ universal2 (ARM64, x86-64)

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page