Skip to main content

Pythonic interface to files generated by MAPDL

Project description

PyAnsys pypi PyPIact GH-CI codecov 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/pyansys/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/pyansys/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.53.0.tar.gz (640.5 kB view details)

Uploaded Source

Built Distributions

ansys_mapdl_reader-0.53.0-cp312-cp312-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.12Windows x86-64

ansys_mapdl_reader-0.53.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

ansys_mapdl_reader-0.53.0-cp312-cp312-macosx_10_9_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.12macOS 10.9+ x86-64

ansys_mapdl_reader-0.53.0-cp312-cp312-macosx_10_9_universal2.whl (1.9 MB view details)

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

ansys_mapdl_reader-0.53.0-cp311-cp311-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.11Windows x86-64

ansys_mapdl_reader-0.53.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

ansys_mapdl_reader-0.53.0-cp311-cp311-macosx_10_9_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

ansys_mapdl_reader-0.53.0-cp311-cp311-macosx_10_9_universal2.whl (1.9 MB view details)

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

ansys_mapdl_reader-0.53.0-cp310-cp310-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.10Windows x86-64

ansys_mapdl_reader-0.53.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

ansys_mapdl_reader-0.53.0-cp310-cp310-macosx_10_9_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

ansys_mapdl_reader-0.53.0-cp310-cp310-macosx_10_9_universal2.whl (1.9 MB view details)

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

ansys_mapdl_reader-0.53.0-cp39-cp39-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.9Windows x86-64

ansys_mapdl_reader-0.53.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

ansys_mapdl_reader-0.53.0-cp39-cp39-macosx_10_9_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

ansys_mapdl_reader-0.53.0-cp39-cp39-macosx_10_9_universal2.whl (1.9 MB view details)

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

ansys_mapdl_reader-0.53.0-cp38-cp38-macosx_10_9_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

ansys_mapdl_reader-0.53.0-cp38-cp38-macosx_10_9_universal2.whl (1.9 MB view details)

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

ansys_mapdl_reader-0.53.0-cp37-cp37m-macosx_10_9_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.7mmacOS 10.9+ x86-64

File details

Details for the file ansys-mapdl-reader-0.53.0.tar.gz.

File metadata

  • Download URL: ansys-mapdl-reader-0.53.0.tar.gz
  • Upload date:
  • Size: 640.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for ansys-mapdl-reader-0.53.0.tar.gz
Algorithm Hash digest
SHA256 c7cd8ae1f2a3d6b86a0e443fc02f9d5139a06f49968672e9e417b98a558b8f5d
MD5 fa9c23f2b6b4e5134920a34c1e27a7c8
BLAKE2b-256 06bee0f49834357b838fda66b353de91aefc8b192ffc48343b7d7f854d2a6ead

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.53.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 6ec0ba7da3463953ef8688b6639ce99e2866edf54792494c81228eccdf617bfa
MD5 5d75955886011256446605d038106091
BLAKE2b-256 a1896503c002e4d268755d775f946920cf936d9ee08197a03206d4c5893e1900

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.53.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e4945065db8bb36ba83341dcdd762c20e60f93fe1d6e917046908cae41261b8f
MD5 9acbb9f7a8eeafdf665dcdde020b2cb3
BLAKE2b-256 f2b89c04fc85eeb901afa0299181772a144e4de2e3ae1b539876cc5196c6ab4f

See more details on using hashes here.

File details

Details for the file ansys_mapdl_reader-0.53.0-cp312-cp312-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.53.0-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 e328139934287fe6589cc4201a98a51b0f10e4876db2bb394cf063bf35828a9b
MD5 5cd0454a5c856f361bbd62a3463eb219
BLAKE2b-256 5549aa32ae4f2b049536cc86fd86c90173d6cad856872f85e7cf0a1a452137bc

See more details on using hashes here.

File details

Details for the file ansys_mapdl_reader-0.53.0-cp312-cp312-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.53.0-cp312-cp312-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 5e3eff1c9e9478f78fe2bb5516b0279587c8a4bbf5b4b5c064aba51d41affced
MD5 9de50589a36c011c7ce6f74d2ebd8448
BLAKE2b-256 87b679eb166c03cebadd511f86b5e5d7d78c1724fb5d63c402010ee59cf9fb1a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.53.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 40a418a7a7da89c1fbe46a022096d168096f79f80e538113cc5b43dc37d7bcb9
MD5 bd35032d68cabe2a0d54f42ddf815afa
BLAKE2b-256 d2067e4da95ca034e89e60a7a76697459950b98095abd2bfe1da0d36e7e95186

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.53.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2ef0c57448f8beabc06145e2f9b7b59d3fb2f0ae9fb5cddfba67b7969b9249b6
MD5 c2e119d869de383cee948b2fb7e3cab4
BLAKE2b-256 db47bbd81c84453ee2961192bfb1a8ada612be196fd8014bb0824172b5aff8cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.53.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 032712a9624974f390d5c2f0f8867e3b78015f7accbd898784cf7e3d992b80ff
MD5 9e9e4b326e1d48ffcf7cc1e0e13d22aa
BLAKE2b-256 80569064cebbad0883b98d227582d91c8c01a70f5e3360dd74fc2151fa1e6319

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.53.0-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 2731c2b73b6d3aafe47343b4d5225ff04346dfca7291855c7f5c031804671d3c
MD5 4377df74c50be1d4c97f79974efd8965
BLAKE2b-256 10b16c53e318dafe3fd65d4f619b85532007cf4d073c6da3a3f5f6e12bda34bf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.53.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 95487623058ba1f287513dbd282b069df2c48e6dfa2adfbe94aec8e374b80266
MD5 ba50e270d955ad63a68639b32f46e4c6
BLAKE2b-256 d71cf42b6d8612a1ad30ec2f2227bddbfd61deb22e9ed7c10150afc8d59ec2ae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.53.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 80cd2eded333358bc2b0e4eb4590dc2fc17e81258f340830cfc901f5f2cd256b
MD5 f3d577c010d60d4ea05801a29dfb324e
BLAKE2b-256 cf47a830117d5483d803e5414bb58208ea92e4759d0dbc9390785033dbc14153

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.53.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 29b362179a7ce4febb1a205068a5ce1852faae95e0bf05eef037a46eee3ec73f
MD5 9384e04826572892e26f9d1b446e5428
BLAKE2b-256 c91dee7349f409183223d084c27b7e54c51260bd7bd9ee2d0190cbd31f417ee7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.53.0-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 a100b0fb0be0d64ad8286cda6a7e70e4fcf80d10424504565a08af22c2484616
MD5 759c4c7f6b05d91ec75310d3c19db3e2
BLAKE2b-256 429732105dca098362ee536ce5ae1860abab0622e92a2364967036342dfb3cd7

See more details on using hashes here.

File details

Details for the file ansys_mapdl_reader-0.53.0-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.53.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 4ebfb62bde448f280aaeed034336ab2641fa3dfbf9ab256f000d15bf43df3cf3
MD5 3831bc5fb622e3d1fc05090a13b1cd7b
BLAKE2b-256 5d6aba9f7f88d7829ad1db64509493264ec21a1020c16abafb81f9e9ccc71ea1

See more details on using hashes here.

File details

Details for the file ansys_mapdl_reader-0.53.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.53.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7e8f63cad6ea9d9646e4573f791c222305121fd6d71acf27ec254ee6cc8d5b62
MD5 da76ac825bf00df23c99c8d8959c6c35
BLAKE2b-256 b240938bdd714631bd97789942f0ce4f3e04e11ff323bce7f1fc5c74b2e0222d

See more details on using hashes here.

File details

Details for the file ansys_mapdl_reader-0.53.0-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.53.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 31596066fdc635ed85e7f0cd61d8e8d8458839d561097fd201c78c0b249a04bf
MD5 4e6019f787a4a182c48f6a5779872dfe
BLAKE2b-256 56d155a776aef5f587671c8728b124048fcfbfcdc605c024b729c5448d24cbc4

See more details on using hashes here.

File details

Details for the file ansys_mapdl_reader-0.53.0-cp39-cp39-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.53.0-cp39-cp39-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 dc7bd910388fe81f6e32cba868e653326758bd810844ae58ad11fdf995c51536
MD5 6137bde8b0a92549f73ab8a4c0aa46eb
BLAKE2b-256 ca3db39134206b04e70d12b77aea52ed47f92e6b2be2bf8ed6bedc3db51bf9cf

See more details on using hashes here.

File details

Details for the file ansys_mapdl_reader-0.53.0-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.53.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 15909da54a9a1a6d802fe9fcbaf64318a9312385a160ebd792a256bb3880e1c4
MD5 640a1a4411d52ac0bf26019151ea50ac
BLAKE2b-256 b6de24d891a760278a4a81b552cbe6f3da26ed0764599cc5f1af3918af7df19c

See more details on using hashes here.

File details

Details for the file ansys_mapdl_reader-0.53.0-cp38-cp38-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.53.0-cp38-cp38-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 0dacef48856116df3bf3e8079fad73e7ed95b6335346a1be098bcc81feeb576d
MD5 a1340370926f83bf3331c90e92c56bd9
BLAKE2b-256 9e48a288d1265da9dea5ac1ef65e842bf6b4b466fe4d7a56556e7e9f88866e2b

See more details on using hashes here.

File details

Details for the file ansys_mapdl_reader-0.53.0-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.53.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 c5e796b474b7968443f6304d00c93b9351cce8dd3aafbaf7643c60a90a3315be
MD5 92f6fdce025c53188a8e0797e4e935af
BLAKE2b-256 41af289e22736e87d9e373b558dd11c93e1f9b23790bec43a00994ff3dd4a775

See more details on using hashes here.

Supported by

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