Skip to main content

Pythonic interface to files generated by MAPDL

Project description

PyAnsys pypi PyPIact GH-CI MIT black pre-commit.ci status

This is the legacy module for reading in binary and ASCII files generated from MAPDL.

This Python module allows you to extract data directly from binary ANSYS v14.5+ files and to display or animate them rapidly using a straightforward API coupled with C libraries based on header files provided by ANSYS.

The ansys-mapdl-reader module supports the following formats:

  • *.rst - Structural analysis result file

  • *.rth - Thermal analysis result file

  • *.emat - Element matrix data file

  • *.full - Full stiffness-mass matrix file

  • *.cdb or *.dat - MAPDL ASCII block archive and Mechanical Workbench input files

Please see the PyMAPDL-Reader Documentation for the full documentation.

Installation

Installation through pip:

pip install ansys-mapdl-reader

You can also visit pymapdl-reader to download the source or releases from GitHub.

Examples

Loading and Plotting a 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 ansys.mapdl import reader as pymapdl_reader
from ansys.mapdl.reader import examples

# Sample *.cdb
filename = examples.hexarchivefile

# Read ansys archive file
archive = pymapdl_reader.Archive(filename)

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

# Create a vtk 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 another program that uses VTK.

# Load this from vtk
import pyvista as pv
grid = pv.UnstructuredGrid('hex.vtu')
grid.plot()

Loading the Result File

This example reads in binary results from a modal analysis of a beam from ANSYS.

# Load the reader from pyansys
from ansys.mapdl import reader as pymapdl_reader
from ansys.mapdl.reader import examples

# Sample result file
rstfile = examples.rstfile

# Create result object by loading the result file
result = pymapdl_reader.read_binary(rstfile)

# Beam natural frequencies
freqs = result.time_values
>>> print(freq)
[ 7366.49503969  7366.49503969 11504.89523664 17285.70459456
  17285.70459457 20137.19299035]

Get the 1st bending mode shape. Results are ordered based on the sorted node numbering. Note that results are zero indexed

>>> nnum, disp = result.nodal_solution(0)
>>> print(disp)
[[ 2.89623914e+01 -2.82480489e+01 -3.09226692e-01]
 [ 2.89489249e+01 -2.82342416e+01  2.47536161e+01]
 [ 2.89177130e+01 -2.82745126e+01  6.05151053e+00]
 [ 2.88715048e+01 -2.82764960e+01  1.22913304e+01]
 [ 2.89221536e+01 -2.82479511e+01  1.84965333e+01]
 [ 2.89623914e+01 -2.82480489e+01  3.09226692e-01]
 ...

Plotting Nodal Results

As the geometry of the model is contained within the result file, you can plot the result without having to load any additional geometry. Below, displacement for the first mode of the modal analysis beam is plotted using VTK.

# Plot the displacement of Mode 0 in the x direction
result.plot_nodal_solution(0, 'x', label='Displacement')
https://github.com/ansys/pymapdl-reader/blob/main/doc/source/images/hexbeam_disp_small.png

Results can be plotted non-interactively and screenshots saved by setting up the camera and saving the result. This can help with the visualization and post-processing of a batch result.

First, get the camera position from an interactive plot:

>>> cpos = result.plot_nodal_solution(0)
>>> print(cpos)
[(5.2722879880979345, 4.308737919176047, 10.467694436036483),
 (0.5, 0.5, 2.5),
 (-0.2565529433509593, 0.9227952809887077, -0.28745339908049733)]

Then generate the plot:

result.plot_nodal_solution(0, 'x', label='Displacement', cpos=cpos,
                           screenshot='hexbeam_disp.png',
                           window_size=[800, 600], interactive=False)

Stress can be plotted as well using the below code. The nodal stress is computed in the same manner that ANSYS uses by to determine the stress at each node by averaging the stress evaluated at that node for all attached elements. For now, only component stresses can be displayed.

# Display node averaged stress in x direction for result 6
result.plot_nodal_stress(5, 'Sx')
https://github.com/ansys/pymapdl-reader/blob/main/doc/source/images/beam_stress_small.png

Nodal stress can also be generated non-interactively with:

result.plot_nodal_stress(5, 'Sx', cpos=cpos, screenshot=beam_stress.png,
                       window_size=[800, 600], interactive=False)

Animating a Modal Solution

Mode shapes from a modal analysis can be animated using animate_nodal_solution:

result.animate_nodal_solution(0)
Modal shape animation

If you wish to save the animation to a file, specify the movie_filename and animate it with:

result.animate_nodal_solution(0, movie_filename='/tmp/movie.mp4', cpos=cpos)

Reading a Full File

This example reads in the mass and stiffness matrices associated with the above example.

# Load the reader from pyansys
from ansys.mapdl import reader as pymapdl_reader
from scipy import sparse

# load the full file
fobj = pymapdl_reader.FullReader('file.full')
dofref, k, m = fobj.load_km()  # returns upper triangle only

# make k, m full, symmetric matrices
k += sparse.triu(k, 1).T
m += sparse.triu(m, 1).T

If you have scipy installed, you can solve the eigensystem for its natural frequencies and mode shapes.

from scipy.sparse import linalg

# condition the k matrix
# to avoid getting the "Factor is exactly singular" error
k += sparse.diags(np.random.random(k.shape[0])/1E20, shape=k.shape)

# Solve
w, v = linalg.eigsh(k, k=20, M=m, sigma=10000)

# System natural frequencies
f = np.real(w)**0.5/(2*np.pi)

print('First four natural frequencies')
for i in range(4):
    print '{:.3f} Hz'.format(f[i])
First four natural frequencies
1283.200 Hz
1283.200 Hz
5781.975 Hz
6919.399 Hz

Developing on Windows

This package is designed to be developed on Linux, and if you need to develop on Windows you will need to install your own C++ compiler. We recommend:

  1. Install Visual C++
    1. See here for a list of which Python versions correspond to which Visual C++ version

  2. Install the development version of pymapdl-reader to your Python environment
    1. Navigate to the project’s top level (the same directory as this README)

    2. run pip install -e .

License and Acknowledgments

The ansys-mapdl-reader 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

ansys_mapdl_reader-0.56.0.tar.gz (644.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

ansys_mapdl_reader-0.56.0-cp314-cp314-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.14Windows x86-64

ansys_mapdl_reader-0.56.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

ansys_mapdl_reader-0.56.0-cp314-cp314-macosx_10_15_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.14macOS 10.15+ x86-64

ansys_mapdl_reader-0.56.0-cp314-cp314-macosx_10_15_universal2.whl (1.8 MB view details)

Uploaded CPython 3.14macOS 10.15+ universal2 (ARM64, x86-64)

ansys_mapdl_reader-0.56.0-cp313-cp313-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.13Windows x86-64

ansys_mapdl_reader-0.56.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

ansys_mapdl_reader-0.56.0-cp313-cp313-macosx_10_13_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.13macOS 10.13+ x86-64

ansys_mapdl_reader-0.56.0-cp313-cp313-macosx_10_13_universal2.whl (1.8 MB view details)

Uploaded CPython 3.13macOS 10.13+ universal2 (ARM64, x86-64)

ansys_mapdl_reader-0.56.0-cp312-cp312-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.12Windows x86-64

ansys_mapdl_reader-0.56.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

ansys_mapdl_reader-0.56.0-cp312-cp312-macosx_10_13_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

ansys_mapdl_reader-0.56.0-cp312-cp312-macosx_10_13_universal2.whl (1.8 MB view details)

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

ansys_mapdl_reader-0.56.0-cp311-cp311-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.11Windows x86-64

ansys_mapdl_reader-0.56.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

ansys_mapdl_reader-0.56.0-cp311-cp311-macosx_10_9_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

ansys_mapdl_reader-0.56.0-cp311-cp311-macosx_10_9_universal2.whl (1.8 MB view details)

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

ansys_mapdl_reader-0.56.0-cp310-cp310-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.10Windows x86-64

ansys_mapdl_reader-0.56.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

ansys_mapdl_reader-0.56.0-cp310-cp310-macosx_10_9_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

ansys_mapdl_reader-0.56.0-cp310-cp310-macosx_10_9_universal2.whl (1.8 MB view details)

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

File details

Details for the file ansys_mapdl_reader-0.56.0.tar.gz.

File metadata

  • Download URL: ansys_mapdl_reader-0.56.0.tar.gz
  • Upload date:
  • Size: 644.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for ansys_mapdl_reader-0.56.0.tar.gz
Algorithm Hash digest
SHA256 53c57c243679cbdc9cf4503fa693e4db49b6140386fae5e00043c5a569b9a751
MD5 204981df16ff6682346e567519d07f84
BLAKE2b-256 b85de7c107aa847e32c388e37cccd7b7911f4f3a5c6825fbe575d7209ee60095

See more details on using hashes here.

File details

Details for the file ansys_mapdl_reader-0.56.0-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.56.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 c49c7d22da4df67be971f506389b0b5611fbd84833617254a960b5a63a918ca0
MD5 1187c005abcc4391c483f4c6807bfdea
BLAKE2b-256 102f58169dae10b9e9ddc423e9f345014303415515e7fd94f28058c2a8e0c055

See more details on using hashes here.

File details

Details for the file ansys_mapdl_reader-0.56.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.56.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 6a0ff82da871000df40091aaa1475ff8de8d833ba350c4a50d51fbcef1f4c452
MD5 f0aa0efd6a974d521d20fae5a6d6aed5
BLAKE2b-256 f7a89673768a664d675e50aabf44fdad3c02859f257adad3ba0cfe35a6f31c9e

See more details on using hashes here.

File details

Details for the file ansys_mapdl_reader-0.56.0-cp314-cp314-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.56.0-cp314-cp314-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 c97327b7a8245d73a6ff8b74b488a3270fea8fdbdc15baaee32b9336cfc6e304
MD5 4653f426ef45172ac2f4226a3763f00e
BLAKE2b-256 ecfda90c322275efb88369f843297ca2022620a7385986e9e247c5bea4a9c509

See more details on using hashes here.

File details

Details for the file ansys_mapdl_reader-0.56.0-cp314-cp314-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.56.0-cp314-cp314-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 df1cbae29b1e8ac5b3947c867fc6f6afdbf53dde3df28d44a1b5acf92c8daab8
MD5 684a35a8fd1df770752b1516259140bf
BLAKE2b-256 c06e65e6b94779eb58064fa2eae6f72696af97734102980c9ce1a60a3bd5b07e

See more details on using hashes here.

File details

Details for the file ansys_mapdl_reader-0.56.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.56.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 4c5870f3ff3eec25be9f4f9c9840e0829506c1a3c4bd03cd167888712b94459a
MD5 ee58aff7459806c83cae464b83de5cef
BLAKE2b-256 0fcbe7c2590f86854694cc048bf2a68e490f60297decee758009326ab16f2911

See more details on using hashes here.

File details

Details for the file ansys_mapdl_reader-0.56.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.56.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 d8f121ce7392f4d6cf59936747a2f9001058cf74e9a068d2aa3e1f60c5734a93
MD5 9ba826b51802e8678d02a3b4c86a21d3
BLAKE2b-256 15479b88829ea0a9e8cd1c69a42564529fe5ecec8f5e6bdb9494343066f007e7

See more details on using hashes here.

File details

Details for the file ansys_mapdl_reader-0.56.0-cp313-cp313-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.56.0-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 3f4c60d9a8ad6642aa4bdc4d0d0a7e45ef9c2dd74b3c6d5d659df5a96b3c1780
MD5 53d5da9fcb6c46b1c218a203488a136e
BLAKE2b-256 fc44b48b7316f2fc6c525339c686fdd44c5ea5ff3f73122b2f93660603ada630

See more details on using hashes here.

File details

Details for the file ansys_mapdl_reader-0.56.0-cp313-cp313-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.56.0-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 148ba6497d4e2b1b4330961a83dd57f9c1fb5437c89511752d2eebee2db8c395
MD5 fbbfa342732dc16435de5925a63d0fa0
BLAKE2b-256 c2dfcadd3846ff457221b4ae27dcef910ac632751899c36e411a56c01599f843

See more details on using hashes here.

File details

Details for the file ansys_mapdl_reader-0.56.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.56.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 2f1ac457a1ac350a1c4b066a6bca323c582ba1e8d3bd8404b9a205c562a1bd02
MD5 5c860b84363a48c3e38281ba20a605f2
BLAKE2b-256 af30547f6af8cfb3496ed98f62de585d4c98bf63ce9c593fee4b57875e1968bc

See more details on using hashes here.

File details

Details for the file ansys_mapdl_reader-0.56.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.56.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 efee1d582755b7ee2a8bede7b7671e9547ab0be29d7d82e978c9095f9fd1c05b
MD5 badab696cefc4d57473dd5e7787637ce
BLAKE2b-256 d2fd7094c1ee10d98387701dd160d7c1280fd08c7818afe29e91f01a8e489610

See more details on using hashes here.

File details

Details for the file ansys_mapdl_reader-0.56.0-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.56.0-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 74f468c8dcd1aea4641ee98be8c671480281dac85f3f6a75f978e78fac4da657
MD5 f7fa25c7b78137630f157afaa38f2831
BLAKE2b-256 5ff6e420f7ea59c9e37c23015518d40411e1b0e2db423fdc9596b7d4041e248b

See more details on using hashes here.

File details

Details for the file ansys_mapdl_reader-0.56.0-cp312-cp312-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.56.0-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 b05f55e27e606de4b43a4c16dcce3bc5ae7019427a44f416367c825c037cfdde
MD5 6156211d53b83cf35144f343c0d9bcb6
BLAKE2b-256 ae8e91564afc6a4fcb4307afc3e245a579eb0834bc368dce44a6fadcbe9619e6

See more details on using hashes here.

File details

Details for the file ansys_mapdl_reader-0.56.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.56.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 fdc13b30a2f68c52d6f37ca21bc9e0c5809c88785ade7b368cc2e48490722084
MD5 b2956c27b1539b8a6c979acfb286ed32
BLAKE2b-256 6438ef811944012d18d1601aad8ee0db573463a5eb372fd5541253f4def76d4d

See more details on using hashes here.

File details

Details for the file ansys_mapdl_reader-0.56.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.56.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 1cd03626e21242f56198bc6972addeb21ef98423754e0f8c8529357d749d5b5d
MD5 9cf0f49868f10859696eccfcdb5811f7
BLAKE2b-256 a3cd46ec4c24d8d31f53a8670c61e27664bcbbc9b8ad79216a8366e0591a7435

See more details on using hashes here.

File details

Details for the file ansys_mapdl_reader-0.56.0-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.56.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 d0eb9539ea162964386dda8e5e420d22b43656b8d5db380b8d84eec174bb0529
MD5 7f6495ccae99cd4a99d7e971b5f5540b
BLAKE2b-256 a1e09bf2a7acbb3e88e82e47ef3effbe91ae19128bcd7481f172e402aebb9044

See more details on using hashes here.

File details

Details for the file ansys_mapdl_reader-0.56.0-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.56.0-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 073e98963a1908ac0023a04500bfa03ccb40a48a228fb099560b7fe042a225cd
MD5 b9ea86c2b15fa75add0ff831baadf1b2
BLAKE2b-256 c952026821012b0efa19cf7eee83be60c8526b4556abe8abe7b0b5315ffc2cbd

See more details on using hashes here.

File details

Details for the file ansys_mapdl_reader-0.56.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.56.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a00ee511ce6ae2cd98603029d6fbf481030d32234a1795fba5847895408948df
MD5 21c3fd74dad80c4c7f735eac06a884cf
BLAKE2b-256 d62785ff6e30c0347b37b7056a1f305b5df785bc790afcc1384a8e8cb1e9dc5f

See more details on using hashes here.

File details

Details for the file ansys_mapdl_reader-0.56.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.56.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 2c386eb90a0e326db19cc101145b2006a2a18eeb97cf2a13101a049feb8bcf9b
MD5 396a2740d45b80e9081737b211472a31
BLAKE2b-256 f2bcc6743e533dfa3002fc27eda8476fa833ea1f4fbd38127e658840d3268c8a

See more details on using hashes here.

File details

Details for the file ansys_mapdl_reader-0.56.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.56.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 bf609e861b5dd5875e33bf79725849594f92ebc98460cf94439ff3fce4856335
MD5 c17ce9a78527e67c0b2a5bbdb316af3c
BLAKE2b-256 29e9af9d88cb913085fc9e9ceb10b9a55bcf4feba29874fe47c816cdc51ef41b

See more details on using hashes here.

File details

Details for the file ansys_mapdl_reader-0.56.0-cp310-cp310-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.56.0-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 3025353523403e36021c431a1e49eeea2bd36db21bb2a02527bec4bda976b82e
MD5 05950a8f4c38fe7b1b1ed5b9e0dbc222
BLAKE2b-256 0d61ea79da08d589d5c1d724704e403ffed6e136d57e494b1985679a7ab0c410

See more details on using hashes here.

Supported by

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