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.55.2.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.55.2-cp313-cp313-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.13Windows x86-64

ansys_mapdl_reader-0.55.2-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.55.2-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.55.2-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.55.2-cp312-cp312-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.12Windows x86-64

ansys_mapdl_reader-0.55.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

ansys_mapdl_reader-0.55.2-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.55.2-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.55.2-cp311-cp311-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.11Windows x86-64

ansys_mapdl_reader-0.55.2-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.55.2-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.55.2-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.55.2-cp310-cp310-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.10Windows x86-64

ansys_mapdl_reader-0.55.2-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.55.2-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.55.2-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.55.2.tar.gz.

File metadata

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

File hashes

Hashes for ansys_mapdl_reader-0.55.2.tar.gz
Algorithm Hash digest
SHA256 52a458f13ecff41a30768efae703be3111314f721848798b192d6d266a2c5b90
MD5 31ddf9b66cb380d29a4b25a95a96c374
BLAKE2b-256 59a38d98214e3a301dd52ff7525b9040f2de96cadd52139c9c1bdc7f1da53c81

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.55.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 4846268ae777f07b85a6116dd7801a8afd0a6940d388595bf4e5e6882fd7c4e5
MD5 4cc4cc7bdf91058b9b662a159c1694c9
BLAKE2b-256 dbe6230e36717212411ddea836b0dea6a85c185ed782d2fa7444b27df1646049

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.55.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 6ef87376cea5855da6764753da1bc3438761a766ea55f621e8a44a34aabfaeb7
MD5 10355b388092c872c6fef39297097e77
BLAKE2b-256 cf19726dee6ded905c388afcc42a2fbde5c32ea4fad474318e9f63371348b473

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.55.2-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 f60b939ee82141679c95df25dd525832c45c7ffd4313e3c3c089b090f97b155d
MD5 b13f48550cd1c11974e6329e90166f77
BLAKE2b-256 7a74e2de2cc132a33a6f6248aa3f7716ad86c0b3f78a91f7ad23c6b56dc796d8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.55.2-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 980ab608dd8df26b78602eb455ee91b2e623dc217bf0a0d958fb6fd5e3749648
MD5 f405a7f2946f2d834797988e1bdbfb76
BLAKE2b-256 e41a24af546f5241d84c073346a714116de64263fb385a6afab0a85b940dcca4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.55.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 450d0a8fd9e7976e9c3a7d8f1fcfda8871916603f7dff619ec1215b9b301aca1
MD5 2f0c59a2fac23e6be503c67c40ee82a4
BLAKE2b-256 77a356e4e2f010f0fd7e4e5b0d8da3a876acdb15f47ab659ca2b0eaf7b97b8ac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.55.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 93b375327faafa3416d33567fdea1c195060d2c3354a388fed681c4484b6e700
MD5 b602f96bf3897fbb4bbf569a9629d5f0
BLAKE2b-256 73ddd6689e3b1c1ef264dc48ef5d147a8bf22c32f945305514fe4dc3a3e0966b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.55.2-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 6e47e1ce8e9d2a3efff18c6cde8e7846e13c0866d09901061c18dbc12a7d5c33
MD5 d83bb208cffca2a58091181162f86e3e
BLAKE2b-256 5ac3eadb1f0d1d4de2a8313c440706c745b780fe3b615ed51bf8bc7652594a1d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.55.2-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 61d26295e8589a872c7b30a50d1e27760bf1ae34fb3eaa65327b03f99e9b868c
MD5 ef729dd4c6c66a83e561078b48fa0b4b
BLAKE2b-256 debfd851d18972bf2d9c10f4c844c5ca4b080b76da8ef007b3bc0c88227da879

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.55.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 175db3f68746b0a86a8edccb4ceda000f34e04172f9dce10b477fe2afcda7224
MD5 7c7dab3e79e9552d875dfc07a0a18f5b
BLAKE2b-256 7dad7ef1eeec6adc4feace92ce711f0c2d8b96f5a6970c9ee495403e305d19b8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.55.2-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 6dcf0b4977e562f448e5360ef0e44151dbf9cdd21ad91395edc0b3c5b5ed21a3
MD5 1b827efadd6834af2566b8b2f22042c9
BLAKE2b-256 974af145533441475754d34654e4b60c4631e6ea4bca71dcec2ae6f50c6236af

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.55.2-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 1a521dd4cdc826fcbb335dbe52d609998ab8462cc5a7f98027ad012000b0fe1c
MD5 149ba6f706e77df083868c809a8a6b32
BLAKE2b-256 aa4ac72b25c82c98bfa16b4d9f6d0816e3b9d4bc8e1ee420fa16cc35577c439c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.55.2-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 3812429412afe17c002d2985080386afbe0643146d8bd47ff5c4f5cbff647aae
MD5 d89577faeee78bf728809eef5b2235f6
BLAKE2b-256 34306037005bbe2e9ad026f7faf51dc6c16b7656edced82c9325484fba36839c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.55.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d895bcc28cba3f8f2d9302ea98f01c2bf692c3baaeb9d7e89585d7983775b440
MD5 8002cc1c5e10ec76db9dfb33569257b4
BLAKE2b-256 a274877af5124567d3f41391129163abc6bf87a92c433c6599577bb3a35419de

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.55.2-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 d1760855b648ba0b3a1c7224dc34a75971792a5d9d5c29a93b1a8bde73058769
MD5 030a196bc934c22527d584a3063feb58
BLAKE2b-256 2ad78afff813e6506942d1262f20ac0fba0bb000d962e08d5612f001a7c6a0b4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.55.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 5695b387fc3b7b5083e26c94b5790bcd92c356528c99287e6b2f7060642b5c57
MD5 746e6a2d869ba5032480a884d42ac9f2
BLAKE2b-256 9c6e97713ed78597fb837cbc2175e2aef33576d31575b2c1ed227bdec8ae0350

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.55.2-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 635598d41bdb38ba468a19f94de225b7def24033b200e67dc26d2165df6def80
MD5 191ecfafbf989a1496f31e942d98b78a
BLAKE2b-256 e8bf6b931b5f2625cc46e35719625c1a8eece74ba8b8544d92449bc80d83548c

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