Pythonic interface to files generated by MAPDL
Project description
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')
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')
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')
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)
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:
- Install Visual C++
See here for a list of which Python versions correspond to which Visual C++ version
- Install the development version of pymapdl-reader to your Python environment
Navigate to the project’s top level (the same directory as this README)
run pip install -e .
License and Acknowledgments
The ansys-mapdl-reader library is licensed under the MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file ansys_mapdl_reader-0.54.1.tar.gz
.
File metadata
- Download URL: ansys_mapdl_reader-0.54.1.tar.gz
- Upload date:
- Size: 640.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9ae69f8c674e111ed46628f55296c25ef4ec1ec603eda9edb39bc49895dfe13 |
|
MD5 | 13e3957120b2d81f58566489bf8382a1 |
|
BLAKE2b-256 | ed618cb241af91e1e9ce8f348047a2c4d63a0e2e6e29b3b9329c5bc2bc9a0d8d |
File details
Details for the file ansys_mapdl_reader-0.54.1-cp312-cp312-win_amd64.whl
.
File metadata
- Download URL: ansys_mapdl_reader-0.54.1-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 1.2 MB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb41ab0d904dbdf2c78abf67bc122586247f625e78ebc0bbd377983aceee25fb |
|
MD5 | 793ec0db4799d00b5b5aace4dd7a8a86 |
|
BLAKE2b-256 | 4198063009a9f4241bbb63ee527d867dc9f14b4ec7786ef9c4eba5da038e69d1 |
File details
Details for the file ansys_mapdl_reader-0.54.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: ansys_mapdl_reader-0.54.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 4.4 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7766adaf69adbb1aa29dbdf81f27045b743cbd7f056552fb979bbaf8f9306b5e |
|
MD5 | 143257ce40297f88fa0a907acb004a29 |
|
BLAKE2b-256 | c390aeb037ee04f3e1a1ee92cc411aa346eb548ab38819be0139cdebde0bbcb4 |
File details
Details for the file ansys_mapdl_reader-0.54.1-cp312-cp312-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: ansys_mapdl_reader-0.54.1-cp312-cp312-macosx_10_9_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.12, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba6d811e854026130f618be038528578068a89bd533c66e470d297666be20c07 |
|
MD5 | f2a60c96f9c8ebb29b53fd2995080115 |
|
BLAKE2b-256 | e72550a1b08ff8fed366de6290594214c7325338010981b64471e394044bb91a |
File details
Details for the file ansys_mapdl_reader-0.54.1-cp312-cp312-macosx_10_9_universal2.whl
.
File metadata
- Download URL: ansys_mapdl_reader-0.54.1-cp312-cp312-macosx_10_9_universal2.whl
- Upload date:
- Size: 1.9 MB
- Tags: CPython 3.12, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9568c12bb50efd1529720a3c45b59bf4a4ed64bb5e3aa180025751e625647752 |
|
MD5 | e4bdfed4ac86d29ff16fb28d54461a6a |
|
BLAKE2b-256 | ed3d87d8cf1debe91838c8a4fd261c45fb45c5bd0ecfe0e2fa8d789161f76df1 |
File details
Details for the file ansys_mapdl_reader-0.54.1-cp311-cp311-win_amd64.whl
.
File metadata
- Download URL: ansys_mapdl_reader-0.54.1-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 1.2 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f44496cedde256eefa3cdfc56900e5eb18e5faff2e4591be584c34245f4ee67e |
|
MD5 | 7f6b6afc6bf06e49dad8f27278d97239 |
|
BLAKE2b-256 | 9876c139ecbc3e8f4dce1ca401463490adc0f07cbd7c7e6c49b9ee4193990be9 |
File details
Details for the file ansys_mapdl_reader-0.54.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: ansys_mapdl_reader-0.54.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 4.5 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22f8f2548267e92ec8ca069136a05c1a2eb05db12a6f9d3ecb3b02b6f89520b1 |
|
MD5 | 0455a6b085d1641e6c6d0282b84bce40 |
|
BLAKE2b-256 | b5677502757be8389a56f87e7db79e58d1cbbcf3aee1af047689aa9b8f5f407b |
File details
Details for the file ansys_mapdl_reader-0.54.1-cp311-cp311-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: ansys_mapdl_reader-0.54.1-cp311-cp311-macosx_10_9_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.11, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54a12d3eac49d6416c07a40d9d22dea1c5ce61cd0d8bb5812c50517dc0ea38f6 |
|
MD5 | 4f5ba1f9b6427a3b3eb0757bb209f299 |
|
BLAKE2b-256 | 3c3534823fd361b4d5b60504c7c38f9d4ad98cf02e89a286776bb6f1426de1f9 |
File details
Details for the file ansys_mapdl_reader-0.54.1-cp311-cp311-macosx_10_9_universal2.whl
.
File metadata
- Download URL: ansys_mapdl_reader-0.54.1-cp311-cp311-macosx_10_9_universal2.whl
- Upload date:
- Size: 1.9 MB
- Tags: CPython 3.11, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb381c1efab68df61b9d220b8bc05697576d9a2498bf5dceaf26e99616339aaa |
|
MD5 | 9c8cfe0028b0df173a8d24bc5ee36e89 |
|
BLAKE2b-256 | 8860ae190f2e2858366ccd87b16c5aa2c4f699caeb31e440ef7f0aba06b86061 |
File details
Details for the file ansys_mapdl_reader-0.54.1-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: ansys_mapdl_reader-0.54.1-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 1.2 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7f6c1d5ff8aa67838731f8d5b16b0eace355730c31152baf58e331abfb9abf6 |
|
MD5 | 9dbb7453efcb682cb2d2f90fc553292c |
|
BLAKE2b-256 | ea7e06dfa2178d62045061ba9a3ff98a5d4e972029d32b8861cf7155b53c5823 |
File details
Details for the file ansys_mapdl_reader-0.54.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: ansys_mapdl_reader-0.54.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 4.3 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ef034967c669d6e86b038915e462d3429c27025140f3cfa3a1f4e3c9b809907 |
|
MD5 | 4b1f20fd808467374eec88c7d2783e3e |
|
BLAKE2b-256 | 79aea81b5afefbf5af9fbe2d689ebcc77d5509b9f5e1e7270276694ecb13e517 |
File details
Details for the file ansys_mapdl_reader-0.54.1-cp310-cp310-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: ansys_mapdl_reader-0.54.1-cp310-cp310-macosx_10_9_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.10, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1c27ad42915261b5f85344a4cbdec9f810badf6637c1d560626b90dd252a1c3 |
|
MD5 | 55647de844404c4b4a8a65e87dcde3bd |
|
BLAKE2b-256 | d63485aff333ade2b42a3977e983b0173377a724f41abfd780c9128c40e70dcd |
File details
Details for the file ansys_mapdl_reader-0.54.1-cp310-cp310-macosx_10_9_universal2.whl
.
File metadata
- Download URL: ansys_mapdl_reader-0.54.1-cp310-cp310-macosx_10_9_universal2.whl
- Upload date:
- Size: 1.9 MB
- Tags: CPython 3.10, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9739a53801c946069f9085a016255a4b1781e4eff50aaec250cadf9ea5af6cd8 |
|
MD5 | bb1c63195d8d3a8856c876bbf1df9b2c |
|
BLAKE2b-256 | 41f3811306a544cb77d6f159a431a9cfa6d828acf961883a73b11e4b1fe5da2a |
File details
Details for the file ansys_mapdl_reader-0.54.1-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: ansys_mapdl_reader-0.54.1-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 1.2 MB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7d8c13cf74f023bd331203b487291d759f853e9868686a443b4a22cb20d4bbe |
|
MD5 | d2dcff8b07434a91b54f590199aea074 |
|
BLAKE2b-256 | 34e030c6a4cb6514272939e25ecfb7084f227dbaa753f10b6e9cf9591adb0d9b |
File details
Details for the file ansys_mapdl_reader-0.54.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: ansys_mapdl_reader-0.54.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 4.3 MB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e49b9c84affbeec7c417d60739f5d487b39cca3eaf57eeeb321afa27fed17aab |
|
MD5 | d140edc51469952971f242e9552d83b3 |
|
BLAKE2b-256 | 6e98727fb3e45d2601829f5eb07e990b0a02d869d1aa3437f011db5555a49a96 |
File details
Details for the file ansys_mapdl_reader-0.54.1-cp39-cp39-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: ansys_mapdl_reader-0.54.1-cp39-cp39-macosx_10_9_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.9, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b7b16d3d7d44d7bdf67d9da5eaaaa63c18cba0991bac55d23fe60d732522952 |
|
MD5 | dc6b0ce6111a7d6127656c7a97c1f21c |
|
BLAKE2b-256 | a9d97423ede23a94ee7fb67997fe56e55394f2a44872d89bca86a4c4bdee7531 |
File details
Details for the file ansys_mapdl_reader-0.54.1-cp39-cp39-macosx_10_9_universal2.whl
.
File metadata
- Download URL: ansys_mapdl_reader-0.54.1-cp39-cp39-macosx_10_9_universal2.whl
- Upload date:
- Size: 1.9 MB
- Tags: CPython 3.9, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7c5fdec2ebc57c3a20c706fdaf8e3216d2f42e822bc3ed3dd05c63828f7dd5d |
|
MD5 | 477d9b9f4199d5b4b8912dda710a0d24 |
|
BLAKE2b-256 | 5966130400975c251c2d834945b3ba57415e95398c01c51ea31b294d9eb36e58 |
File details
Details for the file ansys_mapdl_reader-0.54.1-cp38-cp38-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: ansys_mapdl_reader-0.54.1-cp38-cp38-macosx_10_9_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.8, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6204dab63039c7f529c6979dce6a0e7ba83e04a5df65dfc68aee0bf5c4eec609 |
|
MD5 | 05ac64f1e0236c9d09b3082808660c4c |
|
BLAKE2b-256 | 0128625c79e0185d488f730a00b07dbd7396fdcd942a2a5c058d17260e97714e |
File details
Details for the file ansys_mapdl_reader-0.54.1-cp38-cp38-macosx_10_9_universal2.whl
.
File metadata
- Download URL: ansys_mapdl_reader-0.54.1-cp38-cp38-macosx_10_9_universal2.whl
- Upload date:
- Size: 1.9 MB
- Tags: CPython 3.8, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e0a089ad81b68ee75c4e8f6c4a95b87200d9f942c3ae33046702e958fccb69b |
|
MD5 | 3bc680a0716b6e585a1daf97ed4cb3b7 |
|
BLAKE2b-256 | 45f44eb6aaab9dcfeba1d60dcf116541e2f4d0c4d193d9d26b207b7ddf258242 |
File details
Details for the file ansys_mapdl_reader-0.54.1-cp37-cp37m-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: ansys_mapdl_reader-0.54.1-cp37-cp37m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.7m, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6aa630bd7e5703146c78ce9824775b3f1990517c19484bc7fc8ee40f03043bdf |
|
MD5 | 48f8a9be31c44c1fe7c91dcf6d911d09 |
|
BLAKE2b-256 | 6d4630193cc7dfa6651afdb5bcf1ec8daf505594a37cc556ab70853cbebeecc3 |