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.52.16.tar.gz (639.6 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.52.16-cp311-cp311-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.11Windows x86-64

ansys_mapdl_reader-0.52.16-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.52.16-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.52.16-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.52.16-cp310-cp310-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.10Windows x86-64

ansys_mapdl_reader-0.52.16-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.52.16-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.52.16-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.52.16-cp39-cp39-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.9Windows x86-64

ansys_mapdl_reader-0.52.16-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.52.16-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.52.16-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.52.16-cp38-cp38-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.8Windows x86-64

ansys_mapdl_reader-0.52.16-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

ansys_mapdl_reader-0.52.16-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.52.16-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.52.16-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.52.16.tar.gz.

File metadata

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

File hashes

Hashes for ansys-mapdl-reader-0.52.16.tar.gz
Algorithm Hash digest
SHA256 b5a56dc8d8d67366b8cee8a3db3451fd08f810ae250d35b760331ce21d847864
MD5 4e50604f18287df73a037ca6cc945ec5
BLAKE2b-256 fca5e9001455c1c54e92fc96ccf297c9a3702d0c51f07ab3ef723ca4333038bd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.52.16-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 372853f5e12e1b75ce4eb7051160dc5f2ef4e58f74964e58d44d0201bed6b7ef
MD5 4aeef4521e9da0e862e205985bf57108
BLAKE2b-256 8b271114bd213b93533b50f3ad36386e192d2b86608f5fefb6a21fc2e712360d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.52.16-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 66e9d33e9bc016533ec25e0f6c4c305fc0a4e42eeef61a8712e6ec0f61079501
MD5 cd69e71474540856132d0b08ae568678
BLAKE2b-256 a842c04586b5dddf75bc29ed9932efdc25e5de8895e09985aba1093bd30d224a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.52.16-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 f33a5a0fbfc9526325ff84d323a34c191d36abf71665ca4c031b9f74a45fb4fc
MD5 861ab590af700a696ec7dc3e1a028d34
BLAKE2b-256 d1db117b9baedfffab0c794d15d4a5825db544b905e0bf160900d241f3c8cdf4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.52.16-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 c24c1bdb929c1e7c0077561d58c0f652092f31d176e8090f24f7afe7d3f3d3e0
MD5 05b34ab3dafbd66c3d9c258d18227b57
BLAKE2b-256 665bb24f6242ab73124ae8bc6ceb3e5642e6179884b2387a2123a13f1783235e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.52.16-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 4334b11c0e9902c9e64a9b1600c27f520325893221b2685626b6de90f4b53206
MD5 9b780909505eba72a8163b012a13e8f6
BLAKE2b-256 53a3b1844b5c061e0812f84f62504c3e7337d0f031cb5b2a4d052a1b1a947134

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.52.16-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 66e61a09a0012d592126679f0971681317607c185a543c9323cb5795a4ae32d1
MD5 3c1d2148910e4c6862793e97521c3d25
BLAKE2b-256 036770773f0f467e5c1038570e6b5e3ff0334e13f5353ad85522e2f7e10b7b8b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.52.16-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 5f61b8e8fa04423ad633199877cee67c77dae341cb1e902a90a6a5a111ceca8b
MD5 6b6ebe054efaba4e03211a9606bec5f4
BLAKE2b-256 7927406ce61c910e88ae867da2b2b3a8e70ca5b853dfe0b30fa2d73a4f044e38

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.52.16-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 91e76fb8f7a6647fa98a0a09f2b2c2fef671f85afcbf8c556d3a39f901c6734d
MD5 bb42270dfcd4fc37f2a924404bbb7503
BLAKE2b-256 cf9a3183a6e158f61e3acbad59124646db5caed943fb729457be43618640e851

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.52.16-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 9de55649ff0921cadae26b974677aa4141afd5a0de790f2a94bc9813577b6003
MD5 d0c2900da4ddf13314f51ae064507de2
BLAKE2b-256 5cb8bdbdb2a0e47fdec64b02688e7414e43e33c47946c2a89ed8894fa627eabf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.52.16-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 da24e6c354f89fb5a904594650cc0f1943ec5f9a196ec51750b2072e79cfb1ca
MD5 7ed0620b82125b61bf81d126f177b474
BLAKE2b-256 95683b29fa7dbc10ac09491276f84ed8faefc6815aabfddcadcd914634a10989

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.52.16-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 519ac32d6f87616d4bae91befa29b287533b01541889cb0960beb96050f0be7e
MD5 ff6ad38718ac72d91b6017325a765973
BLAKE2b-256 25482be156a5dad0629916de08db5f0245b1f63a9dc1e066a55caf912de5ff2f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.52.16-cp39-cp39-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 f4df594d12e8d53963635c4500346332afd22334d49cb8286e722adc8f408280
MD5 a4df4d75c76283fb106593466d8b561e
BLAKE2b-256 fd4e14d7a205eb736d853a67bc3915055e3d160297f1cdc10d37a9889bc13839

See more details on using hashes here.

File details

Details for the file ansys_mapdl_reader-0.52.16-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.52.16-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 19e33f66d21a5061543ba7df7ff4b8beec47a6409cc221b50e9f3bd88b98bdc1
MD5 b010b0796901617384ba74d3b13c4059
BLAKE2b-256 05101931c6ca0d22604301898b7e98012a81aa8370ecf24eac0478cf7719bd91

See more details on using hashes here.

File details

Details for the file ansys_mapdl_reader-0.52.16-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.52.16-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1851c6bf2c7eb43ddc28052fb933455062ba53ef915895709cdf8e9b0536fb89
MD5 f25310bd455cab395dafbddb2dd984bf
BLAKE2b-256 88352ba37eaca11a87b4d6a825adfc5c9fac1bb0b4b8fd29d521a68bcec37fa1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.52.16-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 8415c8f06ca454b06679788b69b276ab536c302a98d7faeccbbaf3a79caca4d4
MD5 88d4df161a33b60c16726908e9052ccb
BLAKE2b-256 a4e9cb2c61c1ba1b6668ca9b3b1a678590fb9bfdf23411cf387293c4812e9eeb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.52.16-cp38-cp38-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 af30de4929bad229a45fd5af37fea9cb1d725d52369c6b849d1adec79ebd0664
MD5 d49b67ca5d8b113f35ae4c6309519482
BLAKE2b-256 826ce2fa991456e3ccd621a46c8627a9ce0fa5254e5b1543b3432954bdde2d46

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ansys_mapdl_reader-0.52.16-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 f2996e77816e03ebbe5e7b90c815254ce59cbe6081551970e3e3b93e634a0553
MD5 d497ee69760bc95fe70270c883f65728
BLAKE2b-256 3c738c9f04e2b2a548477ab2edbdf0d2cd16a9c8ac42ec8b677cc427ce32d9e6

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