├── .ci └── build_wheels.sh ├── .codespellrc ├── .flake8 ├── .github ├── dependabot.yml ├── stale.yml └── workflows │ └── ci.yml ├── .gitignore ├── .pre-commit-config.yaml ├── AUTHORS ├── CONTRIBUTING.md ├── CONTRIBUTORS.md ├── LICENSE ├── MANIFEST.in ├── Makefile ├── README.rst ├── ansys └── mapdl │ └── reader │ ├── __init__.py │ ├── _mp_keys.py │ ├── _rst_keys.py │ ├── _version.py │ ├── archive.py │ ├── cell_quality.py │ ├── common.py │ ├── cyclic_reader.py │ ├── cython │ ├── _archive.pyx │ ├── _binary_reader.pyx │ ├── _cellqual.pyx │ ├── _parsefull.pyx │ ├── _reader.pyx │ ├── _relaxmidside.pyx │ ├── archive.c │ ├── archive.h │ ├── binary_reader.cpp │ ├── binary_reader.h │ ├── parsefull.c │ ├── parsefull.h │ ├── reader.c │ ├── reader.h │ ├── vtk_support.c │ └── vtk_support.h │ ├── dis_result.py │ ├── elements.py │ ├── emat.py │ ├── errors.py │ ├── examples │ ├── HexBeam.cdb │ ├── TetBeam.cdb │ ├── __init__.py │ ├── downloads.py │ ├── examples.py │ ├── file.full │ ├── file.rst │ └── sector.cdb │ ├── full.py │ ├── mesh.py │ ├── misc.py │ ├── plotting.py │ ├── rst.py │ └── rst_avail.py ├── doc ├── Makefile └── source │ ├── _static │ └── pyansys-logo-black-cropped.png │ ├── api │ ├── archive.rst │ ├── cyclic_result.rst │ ├── emat.rst │ ├── full.rst │ ├── index.rst │ ├── mesh_quality.rst │ ├── misc.rst │ └── rst.rst │ ├── conf.py │ ├── contributing.rst │ ├── getting_started.rst │ ├── images │ ├── ansys_stress.png │ ├── beam_mode_shape.gif │ ├── beam_mode_shape_small.gif │ ├── beam_stress.png │ ├── beam_stress_small.png │ ├── cellqual.png │ ├── hexbeam.png │ ├── hexbeam_disp.png │ ├── hexbeam_disp_small.png │ ├── hexbeam_small.png │ ├── paraview.jpg │ ├── rotor.jpg │ ├── sector.jpg │ ├── solved_km.png │ └── vplot_cylinder.png │ ├── index.rst │ └── user_guide │ ├── archive.rst │ ├── index.rst │ ├── loading_emat.rst │ ├── loading_km.rst │ ├── loading_results.rst │ └── quality.rst ├── examples ├── 00-read_binary │ ├── README.txt │ ├── custom_visualization.py │ ├── load_corner_result.py │ ├── load_shaft_result.py │ ├── load_thermal_result.py │ └── pontoon.py ├── 01-cyclic_results │ ├── README.txt │ ├── academic_sector_nd.py │ ├── academic_sector_stress_strain.py │ └── sector_model.py └── README.txt ├── ignore_words.txt ├── pyproject.toml ├── pytest.ini ├── requirements ├── requirements_doc.txt └── requirements_test.txt ├── setup.py └── tests ├── archive ├── test_archive.py └── test_data │ ├── ErnoRadiation.cdb │ ├── Panel_Transient.dat │ ├── all_solid_cells.cdb │ ├── hypermesh.cdb │ ├── mesh200.cdb │ ├── mixed_missing_midside.cdb │ ├── parm.cdb │ └── workbench_193.cdb ├── conftest.py ├── cyclic_reader ├── academic_rotor │ ├── SET1,1_RSYS0_EPEL.npz │ ├── SET1,1_RSYS0_S,PRIN.npz │ ├── SET1,1_RSYS0_S.npz │ ├── SET1,2_RSYS0_EPEL.npz │ ├── SET1,2_RSYS0_S,PRIN.npz │ ├── SET1,2_RSYS0_S.npz │ ├── SET13,1_RSYS0_EPEL.npz │ ├── SET13,1_RSYS0_S,PRIN.npz │ ├── SET13,1_RSYS0_S.npz │ ├── SET13,2_RSYS0_EPEL.npz │ ├── SET13,2_RSYS0_S,PRIN.npz │ ├── SET13,2_RSYS0_S.npz │ ├── SET2,1_RSYS0_EPEL.npz │ ├── SET2,1_RSYS0_S,PRIN.npz │ ├── SET2,1_RSYS0_S.npz │ ├── SET2,2_RSYS0_EPEL.npz │ ├── SET2,2_RSYS0_S,PRIN.npz │ ├── SET2,2_RSYS0_S.npz │ ├── SET5,1_RSYS0_EPEL.npz │ ├── SET5,1_RSYS0_S,PRIN.npz │ ├── SET5,1_RSYS0_S.npz │ ├── SET5,2_RSYS0_EPEL.npz │ ├── SET5,2_RSYS0_S,PRIN.npz │ ├── SET5,2_RSYS0_S.npz │ └── academic_rotor.rst ├── cyclic_v150.rst ├── cyclic_v182.rst ├── cyclic_v182_w_comp.rst ├── cyclic_x_v182.rst ├── prnsol_d_cyclic_x_full_v182.npz ├── prnsol_d_cyclic_z_full_v182.npz ├── prnsol_p_cyclic_x_full_v182.npz ├── prnsol_s_cyclic_x_full_v182.npz ├── prnsol_s_cyclic_z_full_v182.npz ├── prnsol_s_cyclic_z_full_v182_set_1_1.npz ├── prnsol_u_cyclic_z_full_v182_set_4_2.npz ├── v182_disp.npz ├── v182_presol.npz ├── v182_prnsol_prin.npz ├── v182_prnsol_s.npz └── v182_x_disp.npz ├── elements ├── plane_182_183 │ ├── archive.cdb │ ├── plane182_183.cdb │ ├── plane182_183.rst │ ├── prnsol_s.npy │ ├── prnsol_s_nnum.npy │ ├── prnsol_u.npy │ ├── prnsol_u_nnum.npy │ ├── pymapdl_182_183_42_82.rst │ ├── test_archive_182_183.py │ └── test_plane182_183.py ├── shell181 │ ├── shell181.rst │ ├── shell181_box.rst │ ├── test_shell181.py │ └── test_shell181_element_coord.py ├── shell281 │ ├── MAPDL.inp │ ├── ds.dat │ ├── file.rst │ └── test_shell281.py ├── solid186 │ ├── prnsol_s.txt │ ├── prnsol_s_prin.txt │ ├── prnsol_u.txt │ └── test_solid186.py ├── targe170 │ ├── file.rst │ └── test_targe170.py └── test_solid239_240.py ├── test_beam44.py ├── test_binary_reader.py ├── test_binary_reader_cython.py ├── test_cyclic.py ├── test_dist_rst.py ├── test_emat.py ├── test_full.py ├── test_rst.py ├── testfiles ├── beam44.rst ├── comp_hex_beam.rst ├── cyc12.rst ├── cyc12 │ ├── RSYS0_ROTOR_PRNSOL_BFE.npz │ ├── RSYS0_ROTOR_PRNSOL_EPEL.npz │ └── RSYS0_ROTOR_PRNSOL_EPTH_COMP.npz ├── cyclic_reader │ ├── cyclic_v150.rst │ └── cyclic_v182.rst ├── dist_rst │ ├── blade_stations │ │ ├── ans_xdisp.npz │ │ ├── beam3_0.rst │ │ └── beam3_1.rst │ └── static │ │ ├── build.py │ │ ├── file.rst │ │ ├── file0.rst │ │ ├── file1.rst │ │ ├── file2.rst │ │ └── file3.rst ├── file.emat ├── file.esav ├── file.rth ├── hex_201.rst ├── is16.npz ├── is16.rst ├── link1.rst ├── materials │ ├── file.rst │ └── stress_lim.rst ├── nodal_reaction.npy ├── para │ ├── para0.txt │ ├── para1.txt │ └── para2.txt ├── rst │ ├── README.md │ ├── beam_modal_cantilever.rst │ ├── beam_static_bc.rst │ ├── cyc_stress.npy │ └── cyc_stress.rst ├── shell181_2020R2.rst ├── shell181_2021R1.rst ├── shell281.rst ├── shell63_beam4.rst ├── sparse.full ├── temp_dependent_results.rth ├── temp_v13.npz ├── temp_v13.rst ├── vm1.dat ├── vm1.rst ├── vm273.dat └── vol_test.rst ├── unused_test_examples.py └── unused_test_shell281.py /.ci/build_wheels.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # builds python wheels on docker container and tests installation 3 | 4 | set -e -x 5 | 6 | # build based on python version from args 7 | PYTHON_VERSION="$1" 8 | PYBIN="/opt/python/cp${PYTHON_VERSION//.}-cp${PYTHON_VERSION//.}/bin" 9 | 10 | # build, don't install 11 | cd io 12 | "${PYBIN}/pip" install build 13 | "${PYBIN}/python" -m build --wheel 14 | auditwheel repair dist/ansys_mapdl_reader*.whl 15 | rm -f dist/* 16 | mv wheelhouse/*manylinux* dist/ 17 | -------------------------------------------------------------------------------- /.codespellrc: -------------------------------------------------------------------------------- 1 | [codespell] 2 | skip = *.pyc,*.txt,*.gif,*.png,*.jpg,*.js,*.html,*.doctree,*.ttf,*.woff,*.woff2,*.eot,*.mp4,*.inv,*.pickle,*.ipynb,flycheck*,./.git/*,./.hypothesis/*,*.yml,./doc/build/*,./doc/images/*,./dist/*,*~,.hypothesis*,./doc/source/examples/*,*cover,*.dat,*.mac,\#*,build,./docker/mapdl/v*,./factory/*,./ansys/mapdl/core/mapdl_functions.py,PKG-INFO,*.mypy_cache/*,./docker/mapdl/*,./_unused/* 3 | ignore-words-list = delet,appen,parm,pres,wan,filname,ans,tread,wan,levl,mater,aadd,extrem,imagin,ist,nin,sord,struc,emiss,vise,sur,ect,ther,esy,poin 4 | quiet-level = 3 -------------------------------------------------------------------------------- /.flake8: -------------------------------------------------------------------------------- 1 | [flake8] 2 | exclude = venv, __init__.py, build, doc/source/examples 3 | # To be added after refactoring code to be compliant: E501 4 | select = W191, W291, W293, W391, E115, E117, E122, E124, E125, E225, E231, E301, E303, F401, F403 5 | count = True 6 | max-complexity = 10 7 | max-line-length = 100 8 | statistics = True 9 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "pip" # See documentation for possible values 4 | directory: "/requirements" # Location of package manifests 5 | insecure-external-code-execution: allow 6 | schedule: 7 | interval: "monthly" 8 | labels: 9 | - "Maintenance" 10 | - "Dependencies" 11 | 12 | - package-ecosystem: "github-actions" 13 | directory: "/" 14 | schedule: 15 | interval: "monthly" 16 | -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Number of days of inactivity before an issue becomes stale 2 | daysUntilStale: 90 3 | # Number of days of inactivity before a stale issue is closed 4 | daysUntilClose: 14 5 | # Issues with these labels will never be considered stale 6 | exemptLabels: 7 | - Future 8 | - MAPDL 9 | # Label to use when marking an issue as stale 10 | staleLabel: 11 | - Stale 12 | # Comment to post when marking an issue as stale. Set to `false` to disable 13 | markComment: > 14 | This issue has been automatically marked as stale because it has not had 15 | recent activity. It will be closed if no further activity occurs. Thank you 16 | for your contributions. 17 | # Comment to post when closing a stale issue. Set to `false` to disable 18 | closeComment: > 19 | Closed due to inactivity. Feel free to reopen if there is new information 20 | or interest. 21 | Thank you! -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled source # 2 | ################### 3 | *.pyc 4 | *.pyd 5 | *.c 6 | *.cpp 7 | *.so 8 | *.o 9 | *.cache 10 | 11 | # virtual environment 12 | venv/ 13 | .venv/ 14 | 15 | # OS generated files # 16 | ###################### 17 | .fuse_hidden* 18 | *~ 19 | *swp 20 | 21 | # emacs 22 | flycheck* 23 | 24 | # Old files # 25 | _old/ 26 | 27 | # Pip generated folders # 28 | ######################### 29 | *.egg-info/ 30 | build/ 31 | dist/ 32 | 33 | # MISC 34 | _build/ 35 | pyansys/Interface.py 36 | *.bat 37 | doc/source/examples/* 38 | *.out 39 | *.tar.gz 40 | *.mypy_cache/ 41 | doc/source/sg_execution_times.rst 42 | 43 | # Testing 44 | factory/ 45 | Testing/ 46 | UnitTesting/ 47 | TODO 48 | test.sh 49 | .pytest_cache/ 50 | tests/.coverage 51 | tests/htmlcov 52 | tests/cyclic/htmlcov 53 | .coverage 54 | *,cover 55 | 56 | \#* 57 | .\#* 58 | /.ipynb_checkpoints 59 | 60 | # test scripts 61 | *.sh 62 | *.cmd 63 | wheelhouse/ 64 | 65 | # jupyterlab 66 | node_modules 67 | yarn.lock 68 | jupyterlab/docker/*.tar.gz 69 | examples/.local 70 | .ipynb_checkpoints/ 71 | 72 | # docker 73 | docker/mapdl/v211 74 | 75 | # Visual studio code local settings 76 | .vscode/ -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: https://github.com/psf/black 3 | rev: 25.1.0 4 | hooks: 5 | - id: black 6 | 7 | - repo: https://github.com/pycqa/isort 8 | rev: 6.0.1 9 | hooks: 10 | - id: isort 11 | args: [ 12 | "--profile", "black", 13 | "--force-sort-within-sections", 14 | "--skip-glob", "*__init__.py", 15 | ] 16 | 17 | - repo: https://github.com/PyCQA/flake8 18 | rev: 7.2.0 19 | hooks: 20 | - id: flake8 21 | 22 | - repo: https://github.com/codespell-project/codespell 23 | rev: v2.4.1 24 | hooks: 25 | - id: codespell 26 | 27 | - repo: https://github.com/ansys/pre-commit-hooks 28 | rev: v0.5.2 29 | hooks: 30 | - id: add-license-headers 31 | args: 32 | - --start_year=2021 33 | 34 | # add this eventually 35 | # - repo: https://github.com/pycqa/pydocstyle 36 | # rev: 6.1.1 37 | # hooks: 38 | # - id: pydocstyle 39 | # additional_dependencies: [toml] 40 | # exclude: "tests/" 41 | 42 | - repo: https://github.com/pre-commit/mirrors-clang-format 43 | rev: v20.1.5 44 | hooks: 45 | - id: clang-format 46 | files: | 47 | (?x)^( 48 | ansys/mapdl/reader/cython/[^_].*\.c.* 49 | )$ 50 | 51 | - repo: https://github.com/pre-commit/pre-commit-hooks 52 | rev: v5.0.0 53 | hooks: 54 | - id: check-merge-conflict 55 | - id: debug-statements 56 | - id: trailing-whitespace 57 | exclude: '.*\.(cdb|rst|dat)$' 58 | 59 | - repo: https://github.com/python-jsonschema/check-jsonschema 60 | rev: 0.33.0 61 | hooks: 62 | - id: check-github-workflows 63 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | # This is the list of PyMAPDL Reader's significant contributors. 2 | # 3 | # This file does not necessarily list everyone who has contributed code. 4 | # 5 | # For contributions made under a Corporate CLA, the organization is 6 | # added to this file. 7 | # 8 | # If you have contributed to the repository and want to be added to this file, 9 | # submit a request. 10 | # 11 | # 12 | ANSYS, Inc. 13 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | We absolutely welcome any code contributions and we hope that this 4 | guide will facilitate an understanding of the PyMAPDL-Reader code 5 | repository. It is important to note that while the PyMAPDL-Reader software 6 | package is maintained by Ansys and any submissions will be reviewed 7 | thoroughly before merging, we still seek to foster a community that can 8 | support user questions and develop new features to make this software 9 | a useful tool for all users. As such, we welcome and encourage any 10 | questions or submissions to this repository. 11 | 12 | For the full contributing documentation, please visit [PyMAPDL-Reader 13 | Contributing Guide](https://readerdocs.pyansys.com/contributing.html) 14 | -------------------------------------------------------------------------------- /CONTRIBUTORS.md: -------------------------------------------------------------------------------- 1 | # Contributors 2 | 3 | ## Project Lead 4 | 5 | * [Alex Kaszynski](https://github.com/akaszynski) 6 | 7 | ## Individual Contributors 8 | 9 | * [1990chs](https://github.com/1990chs) 10 | * [beppo-dd](https://github.com/beppo-dd) 11 | * [Camille](https://github.com/clatapie) 12 | * [German](https://github.com/germa89) 13 | * [JackGuyver](https://github.com/JackGuyver) 14 | * [James Derrick](https://github.com/jgd10) 15 | * [Kathy Pippert](https://github.com/PipKat) 16 | * [Maxime Rey](https://github.com/MaxJPRey) 17 | * [NDfp](https://github.com/NDfp) 18 | * [purubcik](https://github.com/purubcik) 19 | * [Raphael Luciano](https://github.com/raph-luc) 20 | * [Roberto Pastor Muela](https://github.com/RobPasMue) 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 - 2025 ANSYS, Inc. and/or its affiliates. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include ansys/mapdl/reader/cython/*.h 2 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Simple makefile to simplify repetitive build env management tasks under posix 2 | 3 | CODESPELL_DIRS ?= ./ 4 | CODESPELL_SKIP ?= "*.pyc,*.txt,*.gif,*.png,*.jpg,*.js,*.html,*.doctree,*.ttf,*.woff,*.woff2,*.eot,*.mp4,*.inv,*.pickle,*.ipynb,flycheck*,./.git/*,./.hypothesis/*,*.yml,./doc/build/*,./doc/images/*,./dist/*,*~,.hypothesis*,./doc/source/examples/*,*cover,*.dat,*.mac,\#*,build,./docker/mapdl/v211,./factory/*,./ansys/mapdl/reader/cython/_reader.c,./ansys/mapdl/reader/cython/_binary_reader.cpp,./ansys/mapdl/reader/cython/_cellqual.c,,./ansys/mapdl/reader/cython/_relaxmidside.c,*.inp,_*.c*,*.mypy_cache/*,*.cdb,./doc/source/examples/*" 5 | CODESPELL_IGNORE ?= "ignore_words.txt" 6 | 7 | all: doctest 8 | 9 | doctest: codespell 10 | 11 | codespell: 12 | @echo "Running codespell" 13 | @codespell $(CODESPELL_DIRS) -S $(CODESPELL_SKIP) -I $(CODESPELL_IGNORE) 14 | 15 | pydocstyle: 16 | @echo "Running pydocstyle" 17 | @pydocstyle ansys.mapdl.reader 18 | 19 | doctest-modules: 20 | @echo "Running module doctesting" 21 | pytest -v --doctest-modules ansys.mapdl.reader 22 | 23 | coverage: 24 | @echo "Running coverage" 25 | @pytest -v --cov ansys.mapdl.reader 26 | 27 | coverage-xml: 28 | @echo "Reporting XML coverage" 29 | @pytest -v --cov ansys.mapdl.reader --cov-report xml 30 | 31 | coverage-html: 32 | @echo "Reporting HTML coverage" 33 | @pytest -v --cov ansys.mapdl.reader --cov-report html 34 | -------------------------------------------------------------------------------- /ansys/mapdl/reader/__init__.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | import appdirs 4 | 5 | # Per contract with Sphinx-Gallery, this method must be available at top level 6 | try: 7 | # for pyvista >= 0.40 8 | from pyvista.plotting.utilities import _get_sg_image_scraper 9 | except ImportError: 10 | from pyvista.utilities.sphinx_gallery import _get_sg_image_scraper 11 | 12 | 13 | from ansys.mapdl.reader import examples 14 | from ansys.mapdl.reader._version import __version__ 15 | from ansys.mapdl.reader.archive import ( 16 | Archive, 17 | save_as_archive, 18 | write_cmblock, 19 | write_nblock, 20 | ) 21 | from ansys.mapdl.reader.cell_quality import quality 22 | from ansys.mapdl.reader.common import read_binary 23 | from ansys.mapdl.reader.misc import Report, _configure_pyvista 24 | 25 | from . import _archive 26 | 27 | # Setup data directory 28 | USER_DATA_PATH = appdirs.user_data_dir(appname="ansys_mapdl_reader", appauthor="Ansys") 29 | 30 | EXAMPLES_PATH = os.path.join(USER_DATA_PATH, "examples") 31 | 32 | # set pyvista defaults 33 | _configure_pyvista() 34 | -------------------------------------------------------------------------------- /ansys/mapdl/reader/_mp_keys.py: -------------------------------------------------------------------------------- 1 | """Contains material property indices 2 | 3 | Obtained from: 4 | /usr/ansys_inc/v212/ansys/customize/include/mpcom.inc 5 | 6 | c ---- MP command labels -------- 7 | c EX = 1, EY = 2, EZ = 3, NUXY= 4, NUYZ= 5, NUXZ= 6, GXY = 7, GYZ = 8, 8 | c GXZ = 9, ALPX=10, ALPY=11, ALPZ=12, DENS=13, MU =14, DAMP=15, KXX =16, 9 | c KYY =17, KZZ =18, RSVX=19, RSVY=20, RSVZ=21, C =22, HF =23, VISC=24, 10 | c EMIS=25, ENTH=26, LSST=27, PRXY=28, PRYZ=29, PRXZ=30, MURX=31, MURY=32, 11 | c MURZ=33, PERX=34, PERY=35, PERZ=36, MGXX=37, MGYY=38, MGZZ=39, EGXX=40, 12 | c EGYY=41, EGZZ=42, SBKX=43, SBKY=44, SBKZ=45, SONC=46, DMPS=47, ELIM=48, 13 | c USR1=49, USR2=50, USR3=51, USR4=52, FLUI=53, ORTH=54, CABL=55, RIGI=56, 14 | c HGLS=57, BVIS=58, QRAT=59, REFT=60, CTEX=61, CTEY=62, CTEZ=63, THSX=64, 15 | c THSY=65, THSZ=66, DMPR=67, LSSM=68, BETD=69, ALPD=70, RH =71, DXX =72, 16 | c DYY =73, DZZ =74, BETX=75, BETY=76, BETZ=77, CSAT=78, CREF=79, CVH =80 17 | 18 | These indices are used when reading in results using ptrMAT from a 19 | binary result file. 20 | """ 21 | 22 | # order is critical here 23 | mp_keys = [ 24 | "EX", 25 | "EY", 26 | "EZ", 27 | "NUXY", 28 | "NUYZ", 29 | "NUXZ", 30 | "GXY", 31 | "GYZ", 32 | "GXZ", 33 | "ALPX", 34 | "ALPY", 35 | "ALPZ", 36 | "DENS", 37 | "MU", 38 | "DAMP", 39 | "KXX", 40 | "KYY", 41 | "KZZ", 42 | "RSVX", 43 | "RSVY", 44 | "RSVZ", 45 | "C", 46 | "HF", 47 | "VISC", 48 | "EMIS", 49 | "ENTH", 50 | "LSST", 51 | "PRXY", 52 | "PRYZ", 53 | "PRXZ", 54 | "MURX", 55 | "MURY", 56 | "MURZ", 57 | "PERX", 58 | "PERY", 59 | "PERZ", 60 | "MGXX", 61 | "MGYY", 62 | "MGZZ", 63 | "EGXX", 64 | "EGYY", 65 | "EGZZ", 66 | "SBKX", 67 | "SBKY", 68 | "SBKZ", 69 | "SONC", 70 | "SLIM", 71 | "ELIM", 72 | "USR1", 73 | "USR2", 74 | "USR3", 75 | "USR4", 76 | "FLUI", 77 | "ORTH", 78 | "CABL", 79 | "RIGI", 80 | "HGLS", 81 | "BVIS", 82 | "QRAT", 83 | "REFT", 84 | "CTEX", 85 | "CTEY", 86 | "CTEZ", 87 | "THSX", 88 | "THSY", 89 | "THSZ", 90 | "DMPR", 91 | "LSSM", 92 | "BETD", 93 | "ALPD", 94 | "RH", 95 | "DXX", 96 | "DYY", 97 | "DZZ", 98 | "BETX", 99 | "BETY", 100 | "BETZ", 101 | "CSAT", 102 | "CREF", 103 | "CVH", 104 | ] 105 | -------------------------------------------------------------------------------- /ansys/mapdl/reader/_version.py: -------------------------------------------------------------------------------- 1 | """Version of ansys-mapdl-reader module. 2 | 3 | On the ``master`` branch, use 'dev0' to denote a development version. 4 | For example: 5 | 6 | version_info = 0, 58, 'dev0' 7 | 8 | """ 9 | 10 | # major, minor, patch 11 | version_info = 0, 56, "dev0" 12 | 13 | # Nice string for the version 14 | __version__ = ".".join(map(str, version_info)) 15 | -------------------------------------------------------------------------------- /ansys/mapdl/reader/cell_quality.py: -------------------------------------------------------------------------------- 1 | """Provides a basic interface to computing the minimum scaled Jacobian 2 | cell quality from VTK unstructured grids. 3 | """ 4 | 5 | import numpy as np 6 | import pyvista as pv 7 | 8 | from ansys.mapdl.reader.misc import vtk_cell_info 9 | 10 | 11 | def quality(grid): 12 | """Compute the minimum scaled Jacobian cell quality of an UnstructuredGrid. 13 | 14 | Negative values indicate invalid cells while positive values 15 | indicate valid cells. Varies between -1 and 1. 16 | 17 | Parameters 18 | ---------- 19 | grid : pyvista.UnstructuredGrid or pyvista.StructuredGrid 20 | Structured or Unstructured Grid from ``pyvista``. 21 | 22 | Examples 23 | -------- 24 | >>> from ansys.mapdl import reader as pymapdl_reader 25 | >>> import pyvista as pv 26 | >>> x = np.arange(-10, 10, 5) 27 | >>> y = np.arange(-10, 10, 5) 28 | >>> z = np.arange(-10, 10, 5) 29 | >>> x, y, z = np.meshgrid(x, y, z) 30 | >>> grid = pv.StructuredGrid(x, y, z) 31 | >>> pymapdl_reader.quality(grid) 32 | array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 33 | 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.]) 34 | """ 35 | 36 | # lazy load to speed up import 37 | from ansys.mapdl.reader._cellqual import cell_quality, cell_quality_float 38 | 39 | flip = False 40 | if isinstance(grid, pv.StructuredGrid): 41 | grid = grid.cast_to_unstructured_grid() 42 | flip = True 43 | elif not isinstance(grid, pv.UnstructuredGrid): 44 | grid = pv.wrap(grid) 45 | if not isinstance(grid, pv.UnstructuredGrid): 46 | raise TypeError("Input grid should be a pyvista or vtk UnstructuredGrid") 47 | 48 | celltypes = grid.celltypes 49 | points = grid.points 50 | cells, offset = vtk_cell_info(grid) 51 | if points.dtype == np.float64: 52 | qual = cell_quality(cells, offset, celltypes, points) 53 | elif points.dtype == np.float32: 54 | qual = cell_quality_float(cells, offset, celltypes, points) 55 | else: 56 | points = points.astype(np.float64) 57 | qual = cell_quality(cells, offset, celltypes, points) 58 | 59 | # set qual of null cells to 1 60 | qual[grid.celltypes == 0] = 1 61 | if flip: # for structured grids 62 | return -qual 63 | return qual 64 | -------------------------------------------------------------------------------- /ansys/mapdl/reader/cython/_archive.pyx: -------------------------------------------------------------------------------- 1 | # cython: language_level=3 2 | # cython: infer_types=True 3 | # cython: boundscheck=False 4 | # cython: wraparound=False 5 | # cython: cdivision=True 6 | # cython: nonecheck=False 7 | # cython: embedsignature=True 8 | 9 | from libc.math cimport abs 10 | from libc.stdio cimport FILE, fclose, fdopen, fopen, fwrite 11 | 12 | import numpy as np 13 | 14 | cimport numpy as np 15 | 16 | ctypedef unsigned char uint8_t 17 | 18 | cdef extern from 'archive.h' nogil: 19 | int write_nblock(FILE*, const int, const int, const int*, const double*, 20 | const double*, int) 21 | int write_nblock_float(FILE*, const int, const int, const int*, const float*, 22 | const float*, int) 23 | int write_eblock(FILE*, const int, const int*, const int*, const int*, 24 | const int*, const int*, const uint8_t*, const int*, 25 | const int*, const int*, const int*); 26 | 27 | 28 | cdef extern from "stdio.h": 29 | FILE *fdopen(int, const char *) 30 | 31 | 32 | 33 | def py_write_nblock(filename, const int [::1] node_id, int max_node_id, 34 | const double [:, ::1] pos, const double [:, ::1] angles, 35 | mode='w'): 36 | """Write a node block to a file. 37 | 38 | Parameters 39 | ---------- 40 | fid : _io.TextIOWrapper 41 | Opened Python file object. 42 | 43 | node_id : np.ndarray 44 | Array of node ids. 45 | 46 | pos : np.ndarray 47 | Double array of node coordinates 48 | 49 | angles : np.ndarray, optional 50 | 51 | 52 | """ 53 | # attach the stream to the python file 54 | cdef FILE* cfile = fopen(filename.encode(), mode.encode()) 55 | 56 | cdef int n_nodes = pos.shape[0] 57 | 58 | cdef int has_angles = 0 59 | if angles.size == pos.size: 60 | has_angles = 1 61 | else: 62 | angles = np.zeros((1, 1), np.double) 63 | write_nblock(cfile, n_nodes, max_node_id, &node_id[0], &pos[0, 0], 64 | &angles[0, 0], has_angles); 65 | fclose(cfile) 66 | 67 | 68 | def py_write_nblock_float(filename, const int [::1] node_id, int max_node_id, 69 | const float [:, ::1] pos, const float [:, ::1] angles, 70 | mode='w'): 71 | """Write a float32 node block to a file. 72 | 73 | Parameters 74 | ---------- 75 | fid : _io.TextIOWrapper 76 | Opened Python file object. 77 | 78 | node_id : np.ndarray 79 | Array of node ids. 80 | 81 | pos : np.float32 np.ndarray 82 | Double array of node coordinates 83 | 84 | angles : np.ndarray, optional 85 | 86 | """ 87 | # attach the stream to the python file 88 | cdef FILE* cfile = fopen(filename.encode(), mode.encode()) 89 | 90 | cdef int n_nodes = pos.shape[0] 91 | cdef int has_angles = 0 92 | if angles.size == pos.size: 93 | has_angles = 1 94 | else: 95 | angles = np.zeros((1, 1), np.float32) 96 | write_nblock_float(cfile, n_nodes, max_node_id, &node_id[0], &pos[0, 0], 97 | &angles[0, 0], has_angles); 98 | fclose(cfile) 99 | 100 | 101 | def py_write_eblock( 102 | filename, 103 | const int [::1] elem_id, 104 | const int [::1] etype, 105 | const int [::1] mtype, 106 | const int [::1] rcon, 107 | const int [::1] elem_nnodes, 108 | const int [::1] cells, 109 | const int [::1] offset, 110 | const uint8_t [::1] celltypes, 111 | const int [::1] typenum, 112 | const int [::1] nodenum, 113 | mode='w'): 114 | cdef FILE* cfile = fopen(filename.encode(), mode.encode()) 115 | write_eblock( 116 | cfile, 117 | celltypes.size, 118 | &elem_id[0], 119 | &etype[0], 120 | &mtype[0], 121 | &rcon[0], 122 | &elem_nnodes[0], 123 | &celltypes[0], 124 | &offset[0], 125 | &cells[0], 126 | &typenum[0], 127 | &nodenum[0] 128 | ) 129 | fclose(cfile) 130 | 131 | 132 | def cmblock_items_from_array(int [::1] array): 133 | """Given a list of items, convert to a ANSYS formatted CMBLOCK. 134 | 135 | For example ``1, 2, 3, 4, 8`` 136 | 137 | will be converted to 138 | 139 | ``1, -4, 8`` 140 | 141 | Where the -4 indicates all the items between 1 and -4. 142 | """ 143 | 144 | # first, verify items in array are sorted 145 | cdef int i 146 | cdef is_sorted = 1 147 | for i in range(array.size - 1): 148 | if array[i] > array[i + 1]: 149 | is_sorted = 0 150 | break 151 | 152 | if not is_sorted: 153 | array = np.unique(array) 154 | 155 | cdef int [::1] items = np.empty_like(array) 156 | items[0] = array[0] 157 | 158 | cdef int c = 1 159 | cdef int in_list = 0 160 | for i in range(array.size - 1): 161 | # check if part of a range 162 | if array[i + 1] - array[i] == 1: 163 | in_list = 1 164 | elif array[i + 1] - array[i] > 1: 165 | if in_list: 166 | items[c] = -array[i]; c += 1 167 | items[c] = array[i + 1]; c += 1 168 | else: 169 | items[c] = array[i + 1]; c += 1 170 | in_list = 0 171 | 172 | # catch if last item is part of a list 173 | if items[c - 1] != abs(array[array.size - 1]): 174 | items[c] = -array[array.size - 1]; c += 1 175 | 176 | return np.array(items[:c]) 177 | -------------------------------------------------------------------------------- /ansys/mapdl/reader/cython/_parsefull.pyx: -------------------------------------------------------------------------------- 1 | # cython: language_level=3 2 | # cython: infer_types=True 3 | # cython: boundscheck=False 4 | # cython: wraparound=False 5 | # cython: cdivision=True 6 | # cython: nonecheck=False 7 | 8 | import numpy as np 9 | 10 | # cimport numpy as np 11 | 12 | # Definitions from c header 13 | cdef extern from "parsefull.h": 14 | int return_fheader(char*, int*) 15 | 16 | void read_full(int*, int*, int*, int*, int*, double*, int*, int*, double*, 17 | int*, char*, int*, int); 18 | 19 | 20 | def return_header(filename): 21 | """ Just reads in the header """ 22 | # Convert python string to char array 23 | cdef bytes py_bytes = filename.encode() 24 | cdef char* c_filename = py_bytes 25 | 26 | # Read header 27 | cdef int [::1] fheader = np.empty(101, np.int32) 28 | return_fheader(c_filename, &fheader[0]) 29 | 30 | return np.asarray(fheader) 31 | 32 | 33 | def load_km(filename, is_sorted): 34 | """Reads an ANSYS full file and returns indices to construct symmetric, real, 35 | and sparse mass and stiffness matrices 36 | """ 37 | # convert to int 38 | cdef int sort = is_sorted 39 | 40 | # Convert python string to char array 41 | cdef bytes py_bytes = filename.encode() 42 | cdef char* c_filename = py_bytes 43 | 44 | # Read header 45 | cdef int [::1] fheader = np.empty(101, np.int32) 46 | cdef int rst = return_fheader(c_filename, &fheader[0]) 47 | 48 | cdef int neqn = fheader[2]; # Number of equations 49 | cdef int ntermK = fheader[9]; # number of terms in stiffness matrix 50 | cdef int nNodes = fheader[33]; # Number of nodes considered by assembly 51 | cdef int ntermM = fheader[34]; # number of terms in mass matrix 52 | 53 | #### Sanity check #### 54 | #// Check if lumped (item 11) 55 | if fheader[11]: 56 | raise Exception('Unable to read a lumped mass matrix. Terminating') 57 | 58 | # Check if arrays are unsymmetric (item 14) 59 | if fheader[14]: 60 | raise Exception ('Unable to read an unsymmetric mass/stiffness matrix. Terminating') 61 | 62 | # Create numpy memory views so they can be garbage collected later 63 | cdef int[::1] numdat = np.empty(3, np.int32) 64 | # tracks array sizes (nfree, kentry, mentry) 65 | 66 | # node and dof reference arrays 67 | cdef int[::1] sidx = np.empty(nNodes*3, np.int32) # sorting index 68 | cdef int[::1] nref = np.empty(nNodes*3, np.int32) 69 | cdef int[::1] dref = np.empty(nNodes*3, np.int32) 70 | 71 | # size mass and stiffness arrays 72 | cdef int karrsz = 2*ntermK - neqn 73 | cdef int [::1] krows = np.empty(karrsz, np.int32) 74 | cdef int [::1] kcols = np.empty(karrsz, np.int32) 75 | cdef double [::1] kdata = np.empty(karrsz, np.double) 76 | 77 | cdef int marrsz = 2*ntermM - neqn 78 | cdef int [::1] mrows = np.empty(marrsz, np.int32) 79 | cdef int [::1] mcols = np.empty(marrsz, np.int32) 80 | cdef double [::1] mdata = np.empty(marrsz, np.double) 81 | 82 | # Populate these arrays 83 | cdef int nfull 84 | read_full(&numdat[0], &nref[0], &dref[0], &krows[0], &kcols[0], &kdata[0], 85 | &mrows[0], &mcols[0], &mdata[0], &fheader[0], c_filename, 86 | &sidx[0], sort) 87 | 88 | # Grab array sizes 89 | nfree = numdat[0] 90 | kentry = numdat[1] 91 | mentry = numdat[2] 92 | 93 | # Resort degree of freedom references if sorted 94 | cdef int i, sind 95 | cdef int[::1] nref_sort = np.empty(nfree, np.int32) 96 | cdef int[::1] dref_sort = np.empty(nfree, np.int32) 97 | if sort: 98 | for i in range(nfree): 99 | sind = sidx[i] 100 | nref_sort[i] = nref[sind] 101 | dref_sort[i] = dref[sind] 102 | 103 | # Return sorted arrays to python 104 | return (np.asarray(nref_sort), 105 | np.asarray(dref_sort), 106 | np.asarray(krows)[:kentry], 107 | np.asarray(kcols)[:kentry], 108 | np.asarray(kdata)[:kentry], 109 | np.asarray(mrows)[:mentry], 110 | np.asarray(mcols)[:mentry], 111 | np.asarray(mdata)[:mentry]) 112 | else: 113 | # Return unsorted arrays to python 114 | return (np.asarray(nref)[:nfree], 115 | np.asarray(dref)[:nfree], 116 | np.asarray(krows)[:kentry], 117 | np.asarray(kcols)[:kentry], 118 | np.asarray(kdata)[:kentry], 119 | np.asarray(mrows)[:mentry], 120 | np.asarray(mcols)[:mentry], 121 | np.asarray(mdata)[:mentry]) 122 | 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /ansys/mapdl/reader/cython/archive.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #ifdef __linux__ 5 | #include 6 | #endif 7 | 8 | 9 | int write_nblock(FILE*, const int, const int, const int*, const double*, 10 | const double*, int); 11 | int write_nblock_float(FILE*, const int, const int, const int*, const float*, 12 | const float*, int); 13 | int write_eblock(FILE*, const int, const int*, const int*, const int*, 14 | const int*, const int*, const uint8_t*, const int*, 15 | const int*, const int*, const int*); 16 | -------------------------------------------------------------------------------- /ansys/mapdl/reader/cython/binary_reader.h: -------------------------------------------------------------------------------- 1 | #include 2 | /* #include */ 3 | 4 | void read_nodes(const char*, int64_t, int, int *, double *); 5 | void* read_record(const char*, int64_t, int*, int*, int*, int*); 6 | void read_record_stream(std::ifstream*, int64_t, void*, int*, int*, int*); 7 | void* read_record_fid(std::fstream*, int64_t, int*, int*, int*, int*); 8 | std::fstream* open_fstream(const char*); 9 | int overwriteRecord(std::fstream*, int, double*); 10 | int overwriteRecordFloat(std::fstream*, int, float*); 11 | -------------------------------------------------------------------------------- /ansys/mapdl/reader/cython/parsefull.h: -------------------------------------------------------------------------------- 1 | int return_fheader(char*, int*); 2 | 3 | void read_full(int*, int*, int*, int*, int*, double*, int*, int*, double*, 4 | int*, char*, int*, int); 5 | -------------------------------------------------------------------------------- /ansys/mapdl/reader/cython/reader.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifdef __linux__ 4 | #include 5 | #endif 6 | 7 | 8 | int read_nblock(char*, int*, double*, int, int*, int, int64_t*); 9 | int read_eblock(char*, int*, int*, int, int, int64_t*); 10 | int read_nblock_from_nwrite(char*, int*, double*, int); 11 | int write_array_ascii(const char*, const double*, int nvalues); 12 | -------------------------------------------------------------------------------- /ansys/mapdl/reader/cython/vtk_support.h: -------------------------------------------------------------------------------- 1 | #include 2 | int ans_to_vtk(const int, const int*, const int*, const int*, const int, const int*, 3 | int64_t*, int64_t*, uint8_t*, const int); 4 | -------------------------------------------------------------------------------- /ansys/mapdl/reader/errors.py: -------------------------------------------------------------------------------- 1 | """Errors specific to ansys-mapdl-reader""" 2 | 3 | 4 | class VersionError(ValueError): 5 | """Raised when MAPDL is the wrong version""" 6 | 7 | def __init__(self, msg="Invalid MAPDL version"): 8 | ValueError.__init__(self, msg) 9 | 10 | 11 | class NoDistributedFiles(FileNotFoundError): 12 | """Unable to find any distributed result files""" 13 | 14 | def __init__(self, msg="Unable to find any distributed result files."): 15 | FileNotFoundError.__init__(self, msg) 16 | -------------------------------------------------------------------------------- /ansys/mapdl/reader/examples/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates. 2 | # SPDX-License-Identifier: MIT 3 | # 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | from .downloads import * 24 | from .examples import * 25 | -------------------------------------------------------------------------------- /ansys/mapdl/reader/examples/downloads.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates. 2 | # SPDX-License-Identifier: MIT 3 | # 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | """Functions to download sample datasets from the pymapdl data repository""" 24 | 25 | import os 26 | import shutil 27 | import urllib.request 28 | import zipfile 29 | 30 | from ansys.mapdl import reader as pymapdl_reader 31 | 32 | 33 | def get_ext(filename): 34 | """Extract the extension of the filename""" 35 | ext = os.path.splitext(filename)[1].lower() 36 | return ext 37 | 38 | 39 | def delete_downloads(): 40 | """Delete all downloaded examples to free space or update the files""" 41 | shutil.rmtree(pymapdl_reader.EXAMPLES_PATH) 42 | os.makedirs(pymapdl_reader.EXAMPLES_PATH) 43 | return True 44 | 45 | 46 | def _decompress(filename): 47 | zip_ref = zipfile.ZipFile(filename, "r") 48 | zip_ref.extractall(pymapdl_reader.EXAMPLES_PATH) 49 | return zip_ref.close() 50 | 51 | 52 | def _get_file_url(filename): 53 | return f"https://github.com/akaszynski/pyansys-data/raw/master/data/{filename}" 54 | 55 | 56 | def _retrieve_file(url, filename): 57 | if not os.path.exists(pymapdl_reader.EXAMPLES_PATH): 58 | os.makedirs(pymapdl_reader.EXAMPLES_PATH) 59 | 60 | # First check if file has already been downloaded 61 | local_path = os.path.join(pymapdl_reader.EXAMPLES_PATH, os.path.basename(filename)) 62 | local_path_no_zip = local_path.replace(".zip", "") 63 | if os.path.isfile(local_path_no_zip) or os.path.isdir(local_path_no_zip): 64 | return local_path_no_zip, None 65 | 66 | # grab the correct url retriever 67 | urlretrieve = urllib.request.urlretrieve 68 | 69 | # Perform download 70 | saved_file, resp = urlretrieve(url) 71 | shutil.move(saved_file, local_path) 72 | if get_ext(local_path) in [".zip"]: 73 | _decompress(local_path) 74 | local_path = local_path[:-4] 75 | return local_path, resp 76 | 77 | 78 | def download_file(filename): 79 | return _download_file(filename) 80 | 81 | 82 | def _download_file(filename): 83 | url = _get_file_url(filename) 84 | return _retrieve_file(url, filename) 85 | 86 | 87 | def _download_and_read(filename): 88 | saved_file, _ = _download_file(filename) 89 | if saved_file[-3:] == "cdb": 90 | return pymapdl_reader.Archive(saved_file) 91 | else: 92 | return pymapdl_reader.read_binary(saved_file) 93 | 94 | 95 | ############################################################################### 96 | def download_verification_result(index): 97 | """Download a verification manual result file""" 98 | return _download_and_read("vm%d.rst" % index) 99 | 100 | 101 | def download_shaft_modal(): 102 | """Download modal analysis of a rotor shaft""" 103 | return _download_and_read("shaft_modal.rst") 104 | 105 | 106 | def download_sector_modal(): 107 | """Download modal analysis of a cyclic turbine sector""" 108 | return _download_and_read("sector_modal.rst") 109 | 110 | 111 | def download_pontoon(): 112 | """Download modal analysis of a cyclic turbine sector""" 113 | return _download_and_read("pontoon.rst") 114 | 115 | 116 | def _download_solid239_240(): 117 | """SOLID239 and SOLID240 file for unit testing""" 118 | return _download_and_read("solid239_240.rth") 119 | 120 | 121 | def _download_plane238(): 122 | """PLANE result for unit testing""" 123 | return _download_and_read("plane238.rth") 124 | 125 | 126 | def _download_shell181(): 127 | """SHELL181 result for unit testing""" 128 | return _download_and_read("shell181.rst") 129 | 130 | 131 | def download_corner_pipe(): 132 | """Corner pipe result for unit testing and basic demo""" 133 | return _download_and_read("cyc_stress.rst") 134 | 135 | 136 | def download_academic_rotor_result(): 137 | """Cyclic academic rotor result file""" 138 | return _download_and_read("academic_rotor.rst") 139 | 140 | 141 | def download_academic_rotor_archive(): 142 | """Cyclic academic rotor archive file""" 143 | return _download_and_read("academic_rotor.cdb") 144 | 145 | 146 | def download_academic_rotor_4blade_result(): 147 | """Cyclic academic rotor result file""" 148 | return _download_and_read("academic_rotor_4_blade.rst") 149 | -------------------------------------------------------------------------------- /ansys/mapdl/reader/examples/file.full: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/ansys/mapdl/reader/examples/file.full -------------------------------------------------------------------------------- /ansys/mapdl/reader/examples/file.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/ansys/mapdl/reader/examples/file.rst -------------------------------------------------------------------------------- /ansys/mapdl/reader/misc.py: -------------------------------------------------------------------------------- 1 | """Module for miscellaneous functions and methods""" 2 | 3 | import os 4 | import random 5 | import string 6 | import tempfile 7 | 8 | import numpy as np 9 | import pyvista 10 | 11 | try: 12 | # for pyvista >= 0.40 13 | from pyvista.report import GPUInfo 14 | except ImportError: 15 | from pyvista.utilities.errors import GPUInfo 16 | 17 | import scooby 18 | 19 | 20 | def vtk_cell_info(grid, force_int64=True, shift_offset=True): 21 | """Returns version consistent connectivity and cell offset arrays. 22 | 23 | Parameters 24 | ---------- 25 | force_int64 : bool, default: True 26 | Force output arrays to be uint64. 27 | 28 | shift_offset : bool, default: True 29 | Shift the offset by -1. 30 | 31 | Notes 32 | ----- 33 | VTK v9 and greater changed the connectivity and offset arrays: 34 | 35 | Topology: 36 | --------- 37 | Cell 0: Triangle | point ids: {0, 1, 2} 38 | Cell 1: Triangle | point ids: {5, 7, 2} 39 | Cell 2: Quad | point ids: {3, 4, 6, 7} 40 | Cell 4: Line | point ids: {5, 8} 41 | 42 | VTKv9 43 | ===== 44 | Offsets: {0, 3, 6, 10, 12} 45 | Connectivity: {0, 1, 2, 5, 7, 2, 3, 4, 6, 7, 5, 8} 46 | 47 | Prior to VTKv9 48 | ============== 49 | Offsets: {0, 4, 8, 13, 16} 50 | Connectivity: {3, 0, 1, 2, 3, 5, 7, 2, 4, 3, 4, 6, 7, 2, 5, 8} 51 | 52 | """ 53 | cells = grid.cell_connectivity 54 | if shift_offset: 55 | offset = grid.offset - 1 56 | else: 57 | offset = grid.offset 58 | 59 | if force_int64: 60 | if cells.dtype != np.int64: 61 | cells = cells.astype(np.int64) 62 | if offset.dtype != np.int64: 63 | offset = offset.astype(np.int64) 64 | 65 | return cells, offset 66 | 67 | 68 | class Report(scooby.Report): 69 | """Generate an environment and software report. 70 | 71 | Parameters 72 | ---------- 73 | additional : list(ModuleType), list(str) 74 | List of packages or package names to add to output information. 75 | 76 | ncol : int, optional 77 | Number of package-columns in html table; only has effect if 78 | ``mode='HTML'`` or ``mode='html'``. Defaults to 3. 79 | 80 | text_width : int, optional 81 | The text width for non-HTML display modes. 82 | 83 | sort : bool, optional 84 | Alphabetically sort the packages. 85 | 86 | gpu : bool, optional 87 | Gather information about the GPU. Defaults to ``True`` but if 88 | experiencing rendering issues, pass ``False`` to safely 89 | generate a report. 90 | 91 | Examples 92 | -------- 93 | >>> from ansys.mapdl import reader as pymapdl_reader 94 | >>> print(pymapdl_reader.Report()) 95 | ----------------------------------------------------------------- 96 | PyMAPDL-Reader Software and Environment Report 97 | ----------------------------------------------------------------- 98 | Date: Sat Jun 19 14:52:00 2021 MDT 99 | | 100 | OS : Linux 101 | CPU(s) : 16 102 | Machine : x86_64 103 | Architecture : 64bit 104 | RAM : 62.8 GiB 105 | Environment : Python 106 | NVIDIA Corporation : GPU Vendor 107 | NVIDIA Quadro P2000/PCIe/SSE2 : GPU Renderer 108 | 4.5.0 NVIDIA 465.27 : GPU Version 109 | | 110 | Python 3.8.5 (default, May 27 2021, 13:30:53) [GCC 9.3.0] 111 | | 112 | pyvista : 0.31.1 113 | vtk : 9.0.1 114 | numpy : 1.20.3 115 | appdirs : 1.4.4 116 | ansys.mapdl.reader : 0.51.dev0 117 | tqdm : 4.61.1 118 | matplotlib : 3.4.2 119 | ansys.mapdl.core : 0.59.dev0 120 | scipy : 1.6.3 121 | ----------------------------------------------------------------- 122 | 123 | """ 124 | 125 | def __init__(self, additional=None, ncol=3, text_width=79, sort=False, gpu=True): 126 | """Generate a :class:`scooby.Report` instance.""" 127 | # Mandatory packages. 128 | core = [ 129 | "pyvista", 130 | "vtk", 131 | "numpy", 132 | "appdirs", 133 | "ansys.mapdl.reader", 134 | "tqdm", 135 | "matplotlib", 136 | ] 137 | 138 | # Optional packages. 139 | optional = ["matplotlib", "ansys.mapdl.core", "scipy"] 140 | 141 | # Information about the GPU - bare except in case there is a rendering 142 | # bug that the user is trying to report. 143 | if gpu: 144 | try: 145 | extra_meta = [(t[1], t[0]) for t in GPUInfo().get_info()] 146 | except: 147 | extra_meta = ("GPU Details", "error") 148 | else: 149 | extra_meta = ("GPU Details", "None") 150 | 151 | scooby.Report.__init__( 152 | self, 153 | additional=additional, 154 | core=core, 155 | optional=optional, 156 | ncol=ncol, 157 | text_width=text_width, 158 | sort=sort, 159 | extra_meta=extra_meta, 160 | ) 161 | self._text_width = text_width 162 | 163 | def __repr__(self): 164 | add_text = ( 165 | "-" * self.text_width + "\nPyMAPDL-Reader Software and Environment Report" 166 | ) 167 | return add_text + super().__repr__() 168 | 169 | 170 | def is_float(input_string): 171 | """Returns true when a string can be converted to a float""" 172 | try: 173 | float(input_string) 174 | return True 175 | except ValueError: 176 | return False 177 | 178 | 179 | def random_string(stringLength=10): 180 | """Generate a random string of fixed length""" 181 | letters = string.ascii_lowercase 182 | return "".join(random.choice(letters) for i in range(stringLength)) 183 | 184 | 185 | def _configure_pyvista(): 186 | """Configure PyVista's ``rcParams`` for pyansys""" 187 | import pyvista as pv 188 | 189 | # pv.global_theme.interactive = True 190 | pv.global_theme.cmap = "jet" 191 | pv.global_theme.font.family = "courier" 192 | pv.global_theme.title = "PyMAPDL-Reader" 193 | 194 | 195 | def break_apart_surface(surf, force_linear=True): 196 | """Break apart the faces of a vtk PolyData such that the points 197 | for each face are unique and each point is used only by one face. 198 | This leads to duplicate points, but allows multiple scalars per 199 | face. 200 | 201 | Parameters 202 | ---------- 203 | surf : pyvista.PolyData 204 | Surface to break apart. 205 | 206 | force_linear : bool, optional 207 | When ``True``, converts quadratic faces to their linear counterparts. 208 | 209 | Returns 210 | ------- 211 | bsurf : pyvista.PolyData 212 | Surface with unique points for each face. Contains the 213 | original indices in point_data "orig_ind". 214 | 215 | """ 216 | faces = surf.faces 217 | if faces.dtype != np.int64: 218 | faces = faces.astype(np.int64) 219 | 220 | from ansys.mapdl.reader import _binary_reader 221 | 222 | b_points, b_faces, idx = _binary_reader.break_apart_surface( 223 | surf.points, faces, surf.n_faces, force_linear 224 | ) 225 | bsurf = pyvista.PolyData(b_points, b_faces) 226 | bsurf.point_data["orig_ind"] = idx 227 | return bsurf 228 | 229 | 230 | def chunks(l, n): 231 | """Yield successive n-sized chunks from l""" 232 | for i in range(0, len(l), n): 233 | yield l[i : i + n] 234 | 235 | 236 | def unique_rows(a): 237 | """Returns unique rows of a and indices of those rows""" 238 | if not a.flags.c_contiguous: 239 | a = np.ascontiguousarray(a) 240 | 241 | b = a.view(np.dtype((np.void, a.dtype.itemsize * a.shape[1]))) 242 | _, idx, idx2 = np.unique(b, True, True) 243 | 244 | return a[idx], idx, idx2 245 | 246 | 247 | def create_temp_dir(tmpdir=None): 248 | """Create a new unique directory at a given temporary directory""" 249 | if tmpdir is None: 250 | tmpdir = tempfile.gettempdir() 251 | elif not os.path.isdir(tmpdir): 252 | os.makedirs(tmpdir) 253 | 254 | # in the *rare* case of a duplicate path 255 | path = os.path.join(tmpdir, random_string(10)) 256 | while os.path.isdir(path): 257 | path = os.path.join(tempfile.gettempdir(), random_string(10)) 258 | 259 | try: 260 | os.mkdir(path) 261 | except: 262 | raise RuntimeError( 263 | "Unable to create temporary working " 264 | "directory %s\n" % path + "Please specify run_location=" 265 | ) 266 | 267 | return path 268 | 269 | 270 | def no_return(fn): 271 | """Decorator to return nothing from the wrapped function""" 272 | 273 | def wrapper(*args, **kwargs): 274 | fn(*args, **kwargs) 275 | 276 | return wrapper 277 | -------------------------------------------------------------------------------- /ansys/mapdl/reader/plotting.py: -------------------------------------------------------------------------------- 1 | """Plotting helper for MAPDL using pyvista""" 2 | 3 | import numpy as np 4 | import pyvista as pv 5 | 6 | from ansys.mapdl.reader.misc import unique_rows 7 | 8 | 9 | def general_plotter( 10 | title, 11 | meshes, 12 | points, 13 | labels, 14 | cpos=None, 15 | show_bounds=False, 16 | show_axes=True, 17 | background=None, 18 | off_screen=None, 19 | screenshot=False, 20 | window_size=None, 21 | notebook=None, 22 | # add_mesh kwargs: 23 | color="w", 24 | show_edges=None, 25 | edge_color=None, 26 | point_size=5.0, 27 | line_width=None, 28 | opacity=1.0, 29 | flip_scalars=False, 30 | lighting=None, 31 | n_colors=256, 32 | interpolate_before_map=True, 33 | cmap=None, 34 | render_points_as_spheres=False, 35 | render_lines_as_tubes=False, 36 | scalar_bar_args=None, 37 | smooth_shading=False, 38 | # labels kwargs 39 | font_size=None, 40 | font_family=None, 41 | text_color=None, 42 | ): 43 | """General pyansys plotter for APDL geometry and meshes. 44 | 45 | Parameters 46 | ---------- 47 | cpos : list(tuple(floats)), str 48 | The camera position to use. You can either use a saved camera 49 | position or specify one of the following strings: 50 | 51 | - ``"xy"`` 52 | - ``"xz"`` 53 | - ``"yz"`` 54 | - ``"yx"`` 55 | - ``"zx"`` 56 | - ``"zy"`` 57 | - ``"iso"`` 58 | 59 | off_screen : bool, optional 60 | Renders off screen when ``True``. Useful for automated 61 | screenshots. 62 | 63 | window_size : list, optional 64 | Window size in pixels. Defaults to ``[1024, 768]`` 65 | 66 | notebook : bool, optional 67 | When True, the resulting plot is placed inline a jupyter 68 | notebook. Assumes a jupyter console is active. Automatically 69 | enables off_screen. 70 | 71 | show_bounds : bool, optional 72 | Shows mesh bounds when ``True``. 73 | 74 | show_axes : bool, optional 75 | Shows a vtk axes widget. Enabled by default. 76 | 77 | screenshot : str or bool, optional 78 | Saves screenshot to file when enabled. 79 | 80 | color : string or 3 item list, optional, defaults to white 81 | Use to make the entire mesh have a single solid color. Either 82 | a string, RGB list, or hex color string. For example: 83 | ``color='white'``, ``color='w'``, ``color=[1, 1, 1]``, or 84 | ``color='#FFFFFF'``. Color will be overridden if scalars are 85 | specified. 86 | 87 | show_edges : bool, optional 88 | Shows the edges of a mesh. Does not apply to a wireframe 89 | representation. 90 | 91 | edge_color : string or 3 item list, optional, defaults to black 92 | The solid color to give the edges when ``show_edges=True``. 93 | Either a string, RGB list, or hex color string. 94 | 95 | point_size : float, optional 96 | Point size of any nodes in the dataset plotted. Also applicable 97 | when style='points'. Default ``5.0`` 98 | 99 | line_width : float, optional 100 | Thickness of lines. Only valid for wireframe and surface 101 | representations. Default None. 102 | 103 | opacity : float, str, array-like 104 | Opacity of the mesh. If a single float value is given, it will be 105 | the global opacity of the mesh and uniformly applied everywhere - 106 | should be between 0 and 1. A string can also be specified to map 107 | the scalars range to a predefined opacity transfer function 108 | (options include: 'linear', 'linear_r', 'geom', 'geom_r'). 109 | A string could also be used to map a scalars array from the mesh to 110 | the opacity (must have same number of elements as the 111 | ``scalars`` argument). Or you can pass a custom made transfer 112 | function that is an array either ``n_colors`` in length or shorter. 113 | 114 | n_colors : int, optional 115 | Number of colors to use when displaying scalars. Defaults to 256. 116 | The scalar bar will also have this many colors. 117 | 118 | cmap : str, list, optional 119 | Name of the Matplotlib colormap to us when mapping the ``scalars``. 120 | See available Matplotlib colormaps. Only applicable for when 121 | displaying ``scalars``. Requires Matplotlib to be installed. 122 | ``colormap`` is also an accepted alias for this. If ``colorcet`` or 123 | ``cmocean`` are installed, their colormaps can be specified by name. 124 | 125 | You can also specify a list of colors to override an 126 | existing colormap with a custom one. For example, to 127 | create a three color colormap you might specify 128 | ``['green', 'red', 'blue']`` 129 | 130 | render_points_as_spheres : bool, optional 131 | Render points as spheres. 132 | 133 | render_lines_as_tubes : bool, optional 134 | Renders lines as tubes. 135 | 136 | smooth_shading : bool, optional 137 | Smoothly render curved surfaces when plotting. Not helpful 138 | for all meshes. 139 | """ 140 | if notebook: 141 | off_screen = True 142 | 143 | pl = pv.Plotter(off_screen=off_screen, notebook=notebook) 144 | 145 | if background: 146 | pl.set_background(background) 147 | 148 | for point in points: 149 | pl.add_points( 150 | point["points"], 151 | scalars=point.get("scalars", None), 152 | color=color, 153 | show_edges=show_edges, 154 | edge_color=edge_color, 155 | point_size=point_size, 156 | line_width=line_width, 157 | opacity=opacity, 158 | flip_scalars=flip_scalars, 159 | lighting=lighting, 160 | n_colors=n_colors, 161 | interpolate_before_map=interpolate_before_map, 162 | cmap=cmap, 163 | render_points_as_spheres=render_points_as_spheres, 164 | render_lines_as_tubes=render_lines_as_tubes, 165 | ) 166 | 167 | for mesh in meshes: 168 | pl.add_mesh( 169 | mesh["mesh"], 170 | scalars=mesh.get("scalars", None), 171 | scalar_bar_args=scalar_bar_args, 172 | color=mesh.get("color", color), 173 | show_edges=show_edges, 174 | edge_color=edge_color, 175 | smooth_shading=smooth_shading, 176 | point_size=point_size, 177 | line_width=line_width, 178 | opacity=opacity, 179 | flip_scalars=flip_scalars, 180 | lighting=lighting, 181 | n_colors=n_colors, 182 | interpolate_before_map=interpolate_before_map, 183 | cmap=cmap, 184 | render_points_as_spheres=render_points_as_spheres, 185 | render_lines_as_tubes=render_lines_as_tubes, 186 | ) 187 | 188 | for label in labels: 189 | # verify points are not duplicates 190 | points, idx, _ = unique_rows(np.array(label["points"])) 191 | labels = np.array(label["labels"])[idx].tolist() 192 | 193 | pl.add_point_labels( 194 | points, 195 | labels, 196 | show_points=False, 197 | shadow=False, 198 | font_size=font_size, 199 | font_family=font_family, 200 | text_color=text_color, 201 | ) 202 | 203 | if cpos: 204 | pl.camera_position = cpos 205 | 206 | if show_bounds: 207 | pl.show_bounds() 208 | 209 | if show_axes: 210 | pl.show_axes() 211 | 212 | if screenshot: 213 | pl.show(title=title, auto_close=False, window_size=window_size) 214 | pl.screenshot(screenshot) 215 | else: 216 | pl.show() 217 | 218 | return pl.camera_position 219 | -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | SOURCEDIR = source 8 | BUILDDIR = _build 9 | 10 | # Put it first so that "make" without argument is like "make help". 11 | help: 12 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 13 | 14 | .PHONY: help Makefile 15 | 16 | # Catch-all target: route all unknown targets to Sphinx using the new 17 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 18 | %: Makefile 19 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 20 | 21 | 22 | # customized clean due to examples gallery 23 | clean: 24 | rm -rf $(BUILDDIR) 25 | rm -rf source/examples 26 | 27 | # Create PDF 28 | pdf: 29 | @$(SPHINXBUILD) -M latex "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 30 | cd $(BUILDDIR)/latex && latexmk -r latexmkrc -pdf *.tex -interaction=nonstopmode || true 31 | (test -f $(BUILDDIR)/latex/*.pdf && echo pdf exists) || exit 1 32 | -------------------------------------------------------------------------------- /doc/source/_static/pyansys-logo-black-cropped.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/doc/source/_static/pyansys-logo-black-cropped.png -------------------------------------------------------------------------------- /doc/source/api/archive.rst: -------------------------------------------------------------------------------- 1 | .. _ref_archive_api: 2 | 3 | *************************** 4 | Archive Class and Functions 5 | *************************** 6 | .. autoclass:: ansys.mapdl.reader.archive.Archive 7 | :members: 8 | :noindex: 9 | 10 | .. autofunction:: ansys.mapdl.reader.archive.save_as_archive 11 | 12 | .. autofunction:: ansys.mapdl.reader.archive.write_nblock 13 | 14 | .. autofunction:: ansys.mapdl.reader.archive.write_cmblock 15 | -------------------------------------------------------------------------------- /doc/source/api/cyclic_result.rst: -------------------------------------------------------------------------------- 1 | .. _ref_cyc_rst_api: 2 | 3 | ******************* 4 | Cyclic Result Class 5 | ******************* 6 | .. autoclass:: ansys.mapdl.reader.cyclic_reader.CyclicResult 7 | :members: 8 | :noindex: 9 | -------------------------------------------------------------------------------- /doc/source/api/emat.rst: -------------------------------------------------------------------------------- 1 | .. _ref_emat_api: 2 | 3 | ******************** 4 | Element Matrix Class 5 | ******************** 6 | .. autoclass:: ansys.mapdl.reader.emat.EmatFile 7 | :members: 8 | :noindex: 9 | -------------------------------------------------------------------------------- /doc/source/api/full.rst: -------------------------------------------------------------------------------- 1 | .. _ref_full_api: 2 | 3 | *************** 4 | Full File Class 5 | *************** 6 | .. autoclass:: ansys.mapdl.reader.full.FullFile 7 | :members: 8 | :noindex: 9 | -------------------------------------------------------------------------------- /doc/source/api/index.rst: -------------------------------------------------------------------------------- 1 | .. _ref_index_api: 2 | 3 | ============= 4 | API Reference 5 | ============= 6 | This section gives an overview of the API of several public 7 | PyMAPDL-Reader classes, functions, and attributes. 8 | 9 | .. toctree:: 10 | :maxdepth: 1 11 | 12 | archive 13 | cyclic_result 14 | emat 15 | full 16 | mesh_quality 17 | rst 18 | misc 19 | -------------------------------------------------------------------------------- /doc/source/api/mesh_quality.rst: -------------------------------------------------------------------------------- 1 | .. _ref_mesh_quality_api: 2 | 3 | ******************** 4 | Compute Cell Quality 5 | ******************** 6 | .. autofunction:: ansys.mapdl.reader.cell_quality.quality 7 | -------------------------------------------------------------------------------- /doc/source/api/misc.rst: -------------------------------------------------------------------------------- 1 | .. _ref_misc_api: 2 | 3 | ********************* 4 | Miscellaneous Classes 5 | ********************* 6 | .. autoclass:: ansys.mapdl.reader.Report 7 | :members: 8 | :noindex: 9 | -------------------------------------------------------------------------------- /doc/source/api/rst.rst: -------------------------------------------------------------------------------- 1 | .. _ref_rst_api: 2 | 3 | ************ 4 | Result Class 5 | ************ 6 | .. autoclass:: ansys.mapdl.reader.rst.Result 7 | :members: 8 | :noindex: 9 | -------------------------------------------------------------------------------- /doc/source/conf.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | import os 3 | import warnings 4 | 5 | from ansys_sphinx_theme import get_version_match 6 | import pyvista 7 | from sphinx_gallery.sorting import FileNameSortKey 8 | 9 | from ansys.mapdl import reader as pymapdl_reader 10 | 11 | # -- pyvista configuration --------------------------------------------------- 12 | # Manage errors 13 | pyvista.set_error_output_file("errors.txt") 14 | # Ensure that offscreen rendering is used for docs generation 15 | pyvista.OFF_SCREEN = True 16 | # Preferred plotting style for documentation 17 | # pyvista.set_plot_theme('document') 18 | pyvista.global_theme.window_size = (1024, 768) 19 | # Save figures in specified directory 20 | pyvista.FIGURE_PATH = os.path.join(os.path.abspath("./images/"), "auto-generated/") 21 | if not os.path.exists(pyvista.FIGURE_PATH): 22 | os.makedirs(pyvista.FIGURE_PATH) 23 | 24 | pyvista.BUILDING_GALLERY = True 25 | 26 | 27 | # suppress annoying matplotlib bug 28 | warnings.filterwarnings( 29 | "ignore", 30 | category=UserWarning, 31 | message="Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.", 32 | ) 33 | 34 | 35 | # -- General configuration ------------------------------------------------ 36 | # If your documentation needs a minimal Sphinx version, state it here. 37 | # 38 | # needs_sphinx = '1.0' 39 | 40 | # Add any Sphinx extension module names here, as strings. They can be 41 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 42 | # ones. 43 | extensions = [ 44 | "sphinx.ext.intersphinx", 45 | "sphinx.ext.autodoc", 46 | "sphinx.ext.napoleon", 47 | "sphinx.ext.doctest", 48 | "sphinx.ext.autosummary", 49 | "notfound.extension", 50 | "sphinx_copybutton", 51 | "sphinx_gallery.gen_gallery", 52 | "sphinx.ext.extlinks", 53 | "sphinx.ext.coverage", 54 | ] 55 | 56 | # Intersphinx mapping 57 | intersphinx_mapping = { 58 | "python": ("https://docs.python.org/3.11", None), 59 | "scipy": ("https://docs.scipy.org/doc/scipy", None), 60 | "numpy": ("https://numpy.org/doc/stable", None), 61 | "matplotlib": ("https://matplotlib.org/stable", None), 62 | "pandas": ("http://pandas.pydata.org/pandas-docs/stable", None), 63 | "pyvista": ("https://docs.pyvista.org", None), 64 | "grpc": ("https://grpc.github.io/grpc/python", None), 65 | "pypim": ("https://pypim.docs.pyansys.com/version/stable", None), 66 | } 67 | 68 | # Add any paths that contain templates here, relative to this directory. 69 | templates_path = ["_templates"] 70 | 71 | # The suffix(es) of source filenames. 72 | source_suffix = ".rst" 73 | 74 | # The master toctree document. 75 | master_doc = "index" 76 | 77 | # General information about the project. 78 | project = "PyMAPDL Legacy Reader" 79 | copyright = f"(c) {datetime.now().year} ANSYS, Inc. All rights reserved" 80 | author = "ANSYS Inc." 81 | 82 | # The version info for the project you're documenting, acts as replacement for 83 | # |version| and |release|, also used in various other places throughout the 84 | # built documents. 85 | # 86 | # The short X.Y version. 87 | release = version = pymapdl_reader.__version__ 88 | 89 | # The language for content autogenerated by Sphinx. Refer to documentation 90 | # for a list of supported languages. 91 | # 92 | # This is also used if you do content translation via gettext catalogs. 93 | # Usually you set "language" from the command line for these cases. 94 | language = "en" 95 | 96 | # List of patterns, relative to source directory, that match files and 97 | # directories to ignore when looking for source files. 98 | # This patterns also effect to html_static_path and html_extra_path 99 | exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] 100 | 101 | # The name of the Pygments (syntax highlighting) style to use. 102 | pygments_style = "sphinx" 103 | 104 | # If true, `todo` and `todoList` produce output, else they produce nothing. 105 | todo_include_todos = False 106 | 107 | 108 | # Copy button customization --------------------------------------------------- 109 | # exclude traditional Python prompts from the copied code 110 | copybutton_prompt_text = ">>> " 111 | 112 | 113 | # -- Sphinx Gallery Options 114 | 115 | sphinx_gallery_conf = { 116 | "pypandoc": True, # convert rst to md for ipynb 117 | # path to your examples scripts 118 | "examples_dirs": [ 119 | "../../examples/", 120 | ], 121 | # path where to save gallery generated examples 122 | "gallery_dirs": ["examples"], 123 | # Pattern to search for example files 124 | "filename_pattern": r"\.py", 125 | # Remove the "Download all examples" button from the top level gallery 126 | # "download_all_examples": False, 127 | # Sort gallery example by file name instead of number of lines (default) 128 | "within_subsection_order": FileNameSortKey, 129 | # directory where function granular galleries are stored 130 | "backreferences_dir": None, 131 | # Modules for which function level galleries are created. In 132 | "doc_module": "ansys.mapdl.reader", 133 | "image_scrapers": (pymapdl_reader._get_sg_image_scraper(), "matplotlib"), 134 | "thumbnail_size": (350, 350), 135 | "first_notebook_cell": ( 136 | "%matplotlib inline\n" 137 | "from pyvista import set_plot_theme\n" 138 | "set_plot_theme('document')" 139 | ), 140 | } 141 | 142 | 143 | # -- Options for HTML output ------------------------------------------------- 144 | cname = os.getenv("DOCUMENTATION_CNAME", default="nocname.com") 145 | switcher_version = get_version_match(version) 146 | html_short_title = html_title = "PyMAPDL - Legacy Reader" 147 | html_theme = "ansys_sphinx_theme" 148 | html_context = { 149 | "github_user": "ansys", 150 | "github_repo": "pymapdl-reader", 151 | "github_version": "main", 152 | "doc_path": "doc/source", 153 | } 154 | html_theme_options = { 155 | "logo": "pyansys", 156 | "switcher": { 157 | "json_url": f"https://{cname}/versions.json", 158 | "version_match": switcher_version, 159 | }, 160 | "check_switcher": False, 161 | "github_url": "https://github.com/ansys/pymapdl-reader", 162 | "show_prev_next": False, 163 | "show_breadcrumbs": True, 164 | "collapse_navigation": True, 165 | "use_edit_page_button": True, 166 | "additional_breadcrumbs": [ 167 | ("PyAnsys", "https://docs.pyansys.com/"), 168 | ], 169 | } 170 | 171 | # -- Options for HTMLHelp output ------------------------------------------ 172 | 173 | # Output file base name for HTML help builder. 174 | htmlhelp_basename = "pymapdlreaderdoc" 175 | 176 | 177 | # -- Options for LaTeX output --------------------------------------------- 178 | 179 | latex_elements = { 180 | # The paper size ('letterpaper' or 'a4paper'). 181 | # 182 | # 'papersize': 'letterpaper', 183 | # The font size ('10pt', '11pt' or '12pt'). 184 | # 185 | # 'pointsize': '10pt', 186 | # Additional stuff for the LaTeX preamble. 187 | # 188 | # 'preamble': '', 189 | # Latex figure (float) alignment 190 | # 191 | # 'figure_align': 'htbp', 192 | } 193 | 194 | # Grouping the document tree into LaTeX files. List of tuples 195 | # (source start file, target name, title, 196 | # author, documentclass [howto, manual, or own class]). 197 | latex_documents = [ 198 | ( 199 | master_doc, 200 | "pymapdl_reader.tex", 201 | "PyMAPDL Legacy Reader Documentation", 202 | "ANSYS Open Source Developers", 203 | "manual", 204 | ), 205 | ] 206 | 207 | 208 | # -- Options for manual page output --------------------------------------- 209 | 210 | # One entry per manual page. List of tuples 211 | # (source start file, name, description, authors, manual section). 212 | man_pages = [ 213 | (master_doc, "pymapdl_reader", "PyMAPDL Legacy Reader Documentation", [author], 1) 214 | ] 215 | 216 | 217 | # -- Options for Texinfo output ------------------------------------------- 218 | 219 | # Grouping the document tree into Texinfo files. List of tuples 220 | # (source start file, target name, title, author, 221 | # dir menu entry, description, category) 222 | texinfo_documents = [ 223 | ( 224 | master_doc, 225 | "pymapdl-reader", 226 | "PyMAPDL Reader Documentation", 227 | author, 228 | "pymapdl-reader", 229 | "PyMAPDL binary file reader.", 230 | "Miscellaneous", 231 | ), 232 | ] 233 | -------------------------------------------------------------------------------- /doc/source/contributing.rst: -------------------------------------------------------------------------------- 1 | .. _ref_contributing: 2 | 3 | ========== 4 | Contribute 5 | ========== 6 | Overall guidance on contributing to a PyAnsys library appears in the 7 | `Contributing `_ topic 8 | in the *PyAnsys Developer's Guide*. Ensure that you are thoroughly familiar 9 | with it and all `Guidelines and Best Practices `_ 10 | before attempting to contribute to PyMAPDL-Reader. 11 | 12 | The following contribution information is specific to PyMAPDL-Reader. 13 | 14 | Cloning the PyMAPDL Reader Repository 15 | ------------------------------------- 16 | Run this code to clone and install the latest version of PyMAPDL-Reader in development mode: 17 | 18 | .. code:: 19 | 20 | git clone https://github.com/pyansys/pymapdl-reader 21 | cd pymapdl-reader 22 | pip install -e . 23 | 24 | 25 | Posting Issues 26 | -------------- 27 | Use the `PyMAPDL-Reader Issues `_ 28 | page to submit questions, report bugs, and request new features. 29 | 30 | To reach the project support team, email `pyansys.core@ansys.com `_. 31 | 32 | Viewing PyMAPDL-Reader Documentation 33 | ------------------------------------ 34 | Documentation for the latest stable release of PyMAPDL-Reader is hosted at 35 | `PyMAPDL-Reader Documentation `_. 36 | -------------------------------------------------------------------------------- /doc/source/getting_started.rst: -------------------------------------------------------------------------------- 1 | Getting started 2 | --------------- 3 | 4 | Installation is simply:: 5 | 6 | pip install ansys-mapdl-reader 7 | 8 | You can also visit `pymapdl-reader `_ 9 | to download the source or releases from GitHub. 10 | 11 | If you have any installation (or other) issues, please open an issue 12 | at `pymapdl-reader Issues `_. 13 | 14 | The ``ansys-mapdl-reader`` supports 64-Bit Windows, Mac OS, and Linux 15 | for Python 3.10 through Python 3.13. 16 | -------------------------------------------------------------------------------- /doc/source/images/ansys_stress.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/doc/source/images/ansys_stress.png -------------------------------------------------------------------------------- /doc/source/images/beam_mode_shape.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/doc/source/images/beam_mode_shape.gif -------------------------------------------------------------------------------- /doc/source/images/beam_mode_shape_small.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/doc/source/images/beam_mode_shape_small.gif -------------------------------------------------------------------------------- /doc/source/images/beam_stress.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/doc/source/images/beam_stress.png -------------------------------------------------------------------------------- /doc/source/images/beam_stress_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/doc/source/images/beam_stress_small.png -------------------------------------------------------------------------------- /doc/source/images/cellqual.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/doc/source/images/cellqual.png -------------------------------------------------------------------------------- /doc/source/images/hexbeam.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/doc/source/images/hexbeam.png -------------------------------------------------------------------------------- /doc/source/images/hexbeam_disp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/doc/source/images/hexbeam_disp.png -------------------------------------------------------------------------------- /doc/source/images/hexbeam_disp_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/doc/source/images/hexbeam_disp_small.png -------------------------------------------------------------------------------- /doc/source/images/hexbeam_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/doc/source/images/hexbeam_small.png -------------------------------------------------------------------------------- /doc/source/images/paraview.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/doc/source/images/paraview.jpg -------------------------------------------------------------------------------- /doc/source/images/rotor.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/doc/source/images/rotor.jpg -------------------------------------------------------------------------------- /doc/source/images/sector.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/doc/source/images/sector.jpg -------------------------------------------------------------------------------- /doc/source/images/solved_km.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/doc/source/images/solved_km.png -------------------------------------------------------------------------------- /doc/source/images/vplot_cylinder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/doc/source/images/vplot_cylinder.png -------------------------------------------------------------------------------- /doc/source/index.rst: -------------------------------------------------------------------------------- 1 | ====================================================== 2 | PyMAPDL Reader - Legacy Binary and Archive File Reader 3 | ====================================================== 4 | This is the legacy module for reading in binary and ASCII files 5 | generated from MAPDL. 6 | 7 | This Python module allows you to extract data directly from binary 8 | ANSYS v14.5+ files and to display or animate them rapidly using a 9 | straightforward API coupled with C libraries based on header files 10 | provided by ANSYS. 11 | 12 | The ``ansys-mapdl-reader`` module supports the following formats: 13 | - ``*.rst`` - Structural analysis result file 14 | - ``*.rth`` - Thermal analysis result file 15 | - ``*.emat`` - Element matrice data file 16 | - ``*.full`` - Full stiffness-mass matrix file 17 | - ``*.cdb`` or ``*.dat`` - MAPDL ASCII block archive and 18 | Mechanical Workbench input files 19 | 20 | Please see the :ref:`ref_example_gallery` for several demos using 21 | ``ansys-mapdl-reader``. 22 | 23 | .. note:: 24 | 25 | This module will likely change or be depreciated in the future. 26 | 27 | You are encouraged to use the new Data Processing Framework (DPF) 28 | modules at `DPF-Core `_ and 29 | `DPF-Post `_ as they provide a 30 | modern interface to ANSYS result files using a client/server 31 | interface using the same software used within ANSYS Workbench, but 32 | via a Python client. 33 | 34 | 35 | Brief Demo: Direct Access to Binary Files 36 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 37 | Here's a quick example code block to show how easy it is to load and 38 | plots results directly from an ANSYS result file using 39 | ``ansys-mapdl-reader``: 40 | 41 | .. code:: python 42 | 43 | >>> from ansys.mapdl import reader as pymapdl_reader 44 | >>> result = pymapdl_reader.read_binary('rotor.rst') 45 | >>> nnum, stress = result.principal_nodal_stress(0) 46 | >>> print(stress[:3]) 47 | array([[-1.2874937e-06, 1.2874934e-06, 5.6843419e-14, 0.0000000e+00, 48 | 8.1756007e-06, -8.1756007e-06], 49 | [-1.1674185e-04, -1.1674478e-04, -3.0856981e-04, -1.7892545e-06, 50 | -2.5823609e-05, 2.5835518e-05], 51 | [-5.7354209e-05, -5.5398770e-05, -1.4944717e-04, -1.0580692e-06, 52 | -1.7659733e-05, -3.5462126e-06]], dtype=float32) 53 | 54 | Element stress for the first result 55 | 56 | >>> estress, elem, enode = result.element_stress(0) 57 | >>> estress[0] 58 | array([[ 1.0236604e+04, -9.2875127e+03, -4.0922625e+04, -2.3697146e+03, 59 | -1.9239732e+04, 3.0364934e+03] 60 | [ 5.9612605e+04, 2.6905924e+01, -3.6161423e+03, 6.6281304e+03, 61 | 3.1407712e+02, 2.3195926e+04] 62 | [ 3.8178301e+04, 1.7534495e+03, -2.5156013e+02, -6.4841372e+03, 63 | -5.0892783e+03, 5.2503605e+00] 64 | [ 4.9787645e+04, 8.7987168e+03, -2.1928742e+04, -7.3025332e+03, 65 | 1.1294199e+04, 4.3000205e+03]]) 66 | 67 | Get the corresponding ansys element number for the first element. 68 | 69 | >>> elem[0] 70 | 32423 71 | 72 | Get the nodes belonging to for the first element. 73 | 74 | >>> enode[0] 75 | array([ 9012, 7614, 9009, 10920], dtype=int32) 76 | 77 | Plot the nodal displacement of the first result. 78 | 79 | >>> result.plot_nodal_displacement(0) 80 | 81 | .. figure:: ./images/rotor.jpg 82 | :width: 500pt 83 | 84 | 85 | .. toctree:: 86 | :maxdepth: 1 87 | :hidden: 88 | 89 | getting_started 90 | user_guide/index 91 | api/index 92 | examples/index 93 | contributing 94 | 95 | 96 | License and Acknowledgments 97 | --------------------------- 98 | The ``ansys-mapdl-reader`` module is licensed under the MIT license. 99 | -------------------------------------------------------------------------------- /doc/source/user_guide/archive.rst: -------------------------------------------------------------------------------- 1 | Reading and Writing Mapdl Archive Files 2 | ======================================= 3 | 4 | Reading ANSYS Archives 5 | ---------------------- 6 | MAPDL archive ``*.cdb`` and ``*.dat`` files containing elements (both 7 | legacy and modern) can be loaded using Archive and then converted to a 8 | ``vtk`` object: 9 | 10 | .. code:: python 11 | 12 | from ansys.mapdl import reader as pymapdl_reader 13 | from ansys.mapdl.reader import examples 14 | 15 | # Read a sample archive file 16 | archive = pymapdl_reader.Archive(examples.hexarchivefile) 17 | 18 | # Print various raw data from cdb 19 | print(archive.nnum, archive.nodes) 20 | 21 | # access a vtk unstructured grid from the raw data and plot it 22 | grid = archive.grid 23 | archive.plot(color='w', show_edges=True) 24 | 25 | 26 | You can also optionally read in any stored parameters within the 27 | archive file by enabling the ``read_parameters`` parameter. 28 | 29 | .. code:: python 30 | 31 | from ansys.mapdl import reader as pymapdl_reader 32 | archive = pymapdl_reader.Archive('mesh.cdb', read_parameters=True) 33 | 34 | # parameters are stored as a dictionary 35 | archive.parameters 36 | 37 | See the `Archive` class documentation below for more details on the 38 | class methods and properties. 39 | 40 | 41 | Writing ANSYS Archives 42 | ---------------------- 43 | Unstructured grids generated using VTK can be converted to ANSYS APDL 44 | archive files and loaded into any version of ANSYS using 45 | ``pymapdl_reader.save_as_archive``. The following example using the 46 | built-in archive file demonstrates this capability. 47 | 48 | .. code:: python 49 | 50 | import pyvista as pv 51 | from pyvista import examples 52 | from ansys.mapdl import reader as pymapdl_reader 53 | 54 | # load in a vtk unstructured grid 55 | grid = pv.UnstructuredGrid(examples.hexbeamfile) 56 | script_filename = '/tmp/grid.cdb' 57 | pymapdl_reader.save_as_archive(script_filename, grid) 58 | 59 | # optionally read in archive in ANSYS and generate cell shape 60 | # quality report 61 | from ansys.mapdl.core import launch_mapdl 62 | mapdl = launch_mapdl() 63 | mapdl.cdread('db', script_filename) 64 | mapdl.prep7() 65 | mapdl.shpp('SUMM') 66 | 67 | Resulting ANSYS quality report: 68 | 69 | .. code:: 70 | 71 | ------------------------------------------------------------------------------ 72 | <<<<<< SHAPE TESTING SUMMARY >>>>>> 73 | <<<<<< FOR ALL SELECTED ELEMENTS >>>>>> 74 | ------------------------------------------------------------------------------ 75 | -------------------------------------- 76 | | Element count 40 SOLID185 | 77 | -------------------------------------- 78 | 79 | Test Number tested Warning count Error count Warn+Err % 80 | ---- ------------- ------------- ----------- ---------- 81 | Aspect Ratio 40 0 0 0.00 % 82 | Parallel Deviation 40 0 0 0.00 % 83 | Maximum Angle 40 0 0 0.00 % 84 | Jacobian Ratio 40 0 0 0.00 % 85 | Warping Factor 40 0 0 0.00 % 86 | 87 | Any 40 0 0 0.00 % 88 | ------------------------------------------------------------------------------ 89 | 90 | 91 | Converting a MAPDL Archive File to VTK for Paraview 92 | --------------------------------------------------- 93 | MAPDL archive files containing solid elements (both legacy and modern) 94 | can be loaded using Archive and then converted to a VTK object. 95 | 96 | .. code:: python 97 | 98 | from ansys.mapdl import reader as pymapdl_reader 99 | from ansys.mapdl.reader import examples 100 | 101 | # Sample *.cdb 102 | filename = examples.hexarchivefile 103 | 104 | # Read ansys archive file 105 | archive = pymapdl_reader.Archive(filename) 106 | 107 | # Print overview of data read from cdb 108 | print(archive) 109 | 110 | # Create a vtk unstructured grid from the raw data and plot it 111 | grid = archive.parse_vtk(force_linear=True) 112 | grid.plot(color='w', show_edges=True) 113 | 114 | # save this as a vtk xml file 115 | grid.save('hex.vtu') 116 | 117 | .. image:: ../images/hexbeam.png 118 | 119 | 120 | You can then load this vtk file using ``pyvista`` or another program that uses VTK. 121 | 122 | .. code:: python 123 | 124 | # Load this from vtk 125 | import pyvista as pv 126 | grid = pv.read('hex.vtk') 127 | grid.plot() 128 | 129 | 130 | Supported Elements 131 | ~~~~~~~~~~~~~~~~~~ 132 | At the moment, only solid elements are supported by the 133 | ``save_as_archive`` function, to include: 134 | 135 | - ``vtk.VTK_TETRA`` 136 | - ``vtk.VTK_QUADRATIC_TETRA`` 137 | - ``vtk.VTK_PYRAMID`` 138 | - ``vtk.VTK_QUADRATIC_PYRAMID`` 139 | - ``vtk.VTK_WEDGE`` 140 | - ``vtk.VTK_QUADRATIC_WEDGE`` 141 | - ``vtk.VTK_HEXAHEDRON`` 142 | - ``vtk.VTK_QUADRATIC_HEXAHEDRON`` 143 | 144 | Linear element types will be written as SOLID185, quadratic elements 145 | will be written as SOLID186, except for quadratic tetrahedrals, which 146 | will be written as SOLID187. 147 | 148 | 149 | Archive Class 150 | ------------- 151 | .. autoclass:: ansys.mapdl.reader.archive.Archive 152 | :members: 153 | :inherited-members: 154 | -------------------------------------------------------------------------------- /doc/source/user_guide/index.rst: -------------------------------------------------------------------------------- 1 | ========== 2 | User Guide 3 | ========== 4 | This guide provides a general overview of the basics and usage of 5 | ``ansys-mapdl-reader``. 6 | 7 | .. toctree:: 8 | :maxdepth: 2 9 | 10 | loading_results 11 | archive 12 | loading_emat 13 | loading_km 14 | quality 15 | -------------------------------------------------------------------------------- /doc/source/user_guide/loading_emat.rst: -------------------------------------------------------------------------------- 1 | Working with a ANSYS Element Matrix File (.emat) 2 | ================================================ 3 | The ANSYS element matrix file is a FORTRAN formatted binary file 4 | containing the following for each element: 5 | 6 | - Stiffness matrix 7 | - Mass matrix 8 | - Damping matrix 9 | - Stress stiffening matrix 10 | - Complex stiffness matrix 11 | - Element force vectors 12 | 13 | 14 | Example 15 | ------- 16 | Load the element matrix file: 17 | 18 | .. code:: python 19 | 20 | from ansys.mapdl import reader as pymapdl_reader 21 | emat_file = pymapdl_reader.read_binary('file.emat') 22 | 23 | Read a single element from the result file: 24 | 25 | .. code:: python 26 | 27 | dof_ref, element_data = emat_file.read_element(0) 28 | 29 | The dictionary ``element_data`` contains the entries used to construct 30 | stiffness, mass, and damping matrices. If recorded, the dictionary 31 | will also applied force vectors. 32 | 33 | 34 | Applied Force 35 | ~~~~~~~~~~~~~ 36 | Read accumulated applied force for all nodes: 37 | 38 | .. code:: python 39 | 40 | applied_force = emat_file.global_applied_force() 41 | 42 | See ``emat_file.nnum`` for the sorted nodes this applied force corresponds to. 43 | 44 | 45 | DOF Reference 46 | ~~~~~~~~~~~~~ 47 | Each degree of freedom index from ``read_element`` corresponds to a 48 | physical degree of freedom. The table of this correspondence is 49 | below: 50 | 51 | +---------+---------+ 52 | | Index | DOF | 53 | +---------+---------+ 54 | | 1 | UX | 55 | +---------+---------+ 56 | | 2 | UY | 57 | +---------+---------+ 58 | | 3 | UZ | 59 | +---------+---------+ 60 | | 4 | ROTX | 61 | +---------+---------+ 62 | | 5 | ROTY | 63 | +---------+---------+ 64 | | 6 | ROTZ | 65 | +---------+---------+ 66 | | 7 | AX | 67 | +---------+---------+ 68 | | 8 | AY | 69 | +---------+---------+ 70 | | 9 | AZ | 71 | +---------+---------+ 72 | | 10 | VX | 73 | +---------+---------+ 74 | | 11 | VY | 75 | +---------+---------+ 76 | | 12 | VZ | 77 | +---------+---------+ 78 | | 16 | WARP | 79 | +---------+---------+ 80 | | 17 | CONC | 81 | +---------+---------+ 82 | | 18 | HDSP | 83 | +---------+---------+ 84 | | 19 | PRES | 85 | +---------+---------+ 86 | | 20 | TEMP | 87 | +---------+---------+ 88 | | 21 | VOLT | 89 | +---------+---------+ 90 | | 22 | MAG | 91 | +---------+---------+ 92 | | 23 | ENKE | 93 | +---------+---------+ 94 | | 24 | ENDS | 95 | +---------+---------+ 96 | | 25 | EMF | 97 | +---------+---------+ 98 | | 26 | CURR | 99 | +---------+---------+ 100 | | 27 - 32 | Spares | 101 | +---------+---------+ 102 | 103 | 104 | EmatFile Object Methods 105 | ----------------------- 106 | .. autoclass:: ansys.mapdl.reader.emat.EmatFile 107 | :members: 108 | -------------------------------------------------------------------------------- /doc/source/user_guide/loading_km.rst: -------------------------------------------------------------------------------- 1 | Working with a MAPDL Full File (full) 2 | ===================================== 3 | The MAPDL full file is a FORTRAN formatted binary file containing the 4 | mass and stiffness from an Ansys analysis. Using pyansys it can be 5 | loaded into memory as either a sparse or full matrix. 6 | 7 | 8 | Reading a Full File 9 | ------------------- 10 | This example reads in the mass and stiffness matrices associated with 11 | the above example. ``load_km`` sorts degrees of freedom such that the 12 | nodes are ordered from minimum to maximum, and each degree of freedom 13 | (i.e. X, Y, Z), are sorted within each node. The matrices ``k`` and 14 | ``m`` are sparse by default, but if ``scipy`` is not installed, or if 15 | the optional parameter ``as_sparse=False`` then they will be full 16 | numpy arrays. 17 | 18 | By default ``load_km`` outputs the upper triangle of both matrices. 19 | The constrained nodes of the analysis can be identified by accessing 20 | ``fobj.const`` where the constrained degrees of freedom are True and 21 | all others are False. This corresponds to the degrees of reference in 22 | ``dof_ref``. 23 | 24 | By default dof_ref is unsorted. To sort these values, set 25 | ``sort==True``. It is enabled for this example to allow for plotting 26 | of the values later on. 27 | 28 | .. code:: python 29 | 30 | from ansys.mapdl import reader as pymapdl_reader 31 | from ansys.mapdl.reader import examples 32 | 33 | # Create result reader object and read in full file 34 | full = pymapdl_reader.read_binary(examples.fullfile) 35 | dof_ref, k, m = full.load_km(sort=True) 36 | 37 | ANSYS only stores the upper triangular matrix in the full file. To 38 | create the full matrix: 39 | 40 | .. code:: python 41 | 42 | k += sparse.triu(k, 1).T 43 | m += sparse.triu(m, 1).T 44 | 45 | If you have ``scipy`` installed, you can solve solve for the natural 46 | frequencies and mode shapes of a system. 47 | 48 | .. code:: python 49 | 50 | import numpy as np 51 | from scipy.sparse import linalg 52 | 53 | # condition the k matrix 54 | # to avoid getting the "Factor is exactly singular" error 55 | k += sparse.diags(np.random.random(k.shape[0])/1E20, shape=k.shape) 56 | 57 | # Solve 58 | w, v = linalg.eigsh(k, k=20, M=m, sigma=10000) 59 | 60 | # System natural frequencies 61 | f = (np.real(w))**0.5/(2*np.pi) 62 | 63 | .. code:: 64 | 65 | print('First four natural frequencies') 66 | for i in range(4): 67 | print('{:.3f} Hz'.format(f[i])) 68 | 69 | First four natural frequencies 70 | 1283.200 Hz 71 | 1283.200 Hz 72 | 73 | 5781.975 Hz 74 | 6919.399 Hz 75 | 76 | 77 | Plotting a Mode Shape 78 | --------------------- 79 | You can also plot the mode shape of this finite element model. Since 80 | the constrained degrees of freedom have been removed from the 81 | solution, you have to account for these when displaying the 82 | displacement. 83 | 84 | .. code:: python 85 | 86 | import pyvista as pv 87 | 88 | # Get the 4th mode shape 89 | full_mode_shape = v[:, 3] # x, y, z displacement for each node 90 | 91 | # reshape and compute the normalized displacement 92 | disp = full_mode_shape.reshape((-1, 3)) 93 | n = (disp*disp).sum(1)**0.5 94 | n /= n.max() # normalize 95 | 96 | # load an archive file and create a vtk unstructured grid 97 | archive = pymapdl_reader.Archive(examples.hexarchivefile) 98 | grid = archive.parse_vtk() 99 | 100 | # plot the normalized displacement 101 | # grid.plot(scalars=n) 102 | 103 | # Fancy plot the displacement 104 | pl = pv.Plotter() 105 | 106 | # add the nominal mesh 107 | pl.add_mesh(grid, style='wireframe') 108 | 109 | # copy the mesh and displace it 110 | new_grid = grid.copy() 111 | new_grid.points += disp/80 112 | pl.add_mesh(new_grid, scalars=n, stitle='Normalized\nDisplacement', 113 | flipscalars=True) 114 | 115 | pl.add_text('Cantliver Beam 4th Mode Shape at {:.4f}'.format(f[3]), 116 | fontsize=30) 117 | pl.plot() 118 | 119 | .. image:: ../images/solved_km.png 120 | 121 | 122 | This example is built into ``pyansys-mapdl`` and can be run from 123 | ``examples.solve_km()``. 124 | 125 | 126 | FullFile Object Methods 127 | ----------------------- 128 | .. autoclass:: ansys.mapdl.reader.full.FullFile 129 | :members: 130 | -------------------------------------------------------------------------------- /doc/source/user_guide/quality.rst: -------------------------------------------------------------------------------- 1 | Compute Cell Quality 2 | ==================== 3 | Compute the minimum scaled jacoabian of a ``vtk.Unstructured.Grid``, 4 | ``pyvista.UnstructuredGrid``, or ``pyvista.StructuredGrid``. 5 | 6 | Plot Cell Quality 7 | ~~~~~~~~~~~~~~~~~ 8 | This built-in example displays the minimum scaled jacobian of each 9 | element of a tetrahedral beam: 10 | 11 | .. code:: python 12 | 13 | from pyansys import examples 14 | examples.show_cell_qual() 15 | 16 | .. image:: ../images/cellqual.png 17 | 18 | This is the source code for the example: 19 | 20 | .. code:: python 21 | 22 | import pyansys 23 | 24 | # load archive file and parse for subsequent FEM queries 25 | from pyansys import examples 26 | # archive = pyansys.Archive(examples.hexarchivefile) 27 | archive = pyansys.Archive(examples.tetarchivefile) 28 | 29 | # create vtk object 30 | grid = archive.parse_vtk(force_linear=True) 31 | 32 | # get the cell quality 33 | qual = grid.quality 34 | 35 | # plot cell quality 36 | grid.plot(scalars=qual, stitle='Cell Minimum Scaled\nJacobian', rng=[0, 1]) 37 | 38 | 39 | pyansys.quality 40 | --------------- 41 | .. autofunction:: ansys.mapdl.reader.quality 42 | -------------------------------------------------------------------------------- /examples/00-read_binary/README.txt: -------------------------------------------------------------------------------- 1 | Loading and Visualizing Result Files 2 | ------------------------------------ 3 | -------------------------------------------------------------------------------- /examples/00-read_binary/custom_visualization.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates. 2 | # SPDX-License-Identifier: MIT 3 | # 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | """ 24 | .. _ref_custom_visualization: 25 | 26 | Custom Scalar Visualization 27 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 28 | Display custom scalars using an existing mesh. 29 | 30 | """ 31 | 32 | import numpy as np 33 | 34 | from ansys.mapdl.reader import examples 35 | 36 | # Download an example shaft modal analysis result file 37 | shaft = examples.download_shaft_modal() 38 | 39 | ############################################################################### 40 | # Each result file contains both a ``mesh`` property and a ``grid`` 41 | # property. The ``mesh`` property can be through as the MAPDL 42 | # representation of the FEM while the ``grid`` property can be through 43 | # of the Python visualizing property used to plot within Python. 44 | 45 | print("shaft.mesh:\n", shaft.mesh) 46 | print("-" * 79) 47 | print("shaft.grid:\n", shaft.grid) 48 | 49 | ############################################################################### 50 | # Plotting 51 | # ~~~~~~~~ 52 | # 53 | # The grid instance is a :class:`pyvista.UnstructuredGrid` part of the `pyvista 54 | # `_ library. This class allows for advanced 55 | # plotting using VTK in just a few lines of code. For example, you can plot 56 | # the underlying mesh with: 57 | 58 | shaft.grid.plot(color="w", smooth_shading=True) 59 | 60 | ############################################################################### 61 | # Plotting Node Scalars 62 | # ~~~~~~~~~~~~~~~~~~~~~ 63 | # 64 | # If you point-wise or cell-wise scalars (nodes and elements in FEA), 65 | # you can plot these scalars by setting the ``scalars=`` parameter. 66 | # Here, I'm simply using the x location of the nodes to color the 67 | # mesh. 68 | # 69 | # It follows that you can use any set of scalars provided that it 70 | # matches the number of nodes in the unstructured grid or the number 71 | # of cells in the unstructured grid. Here, we're plotting node values. 72 | 73 | x_scalars = shaft.grid.points[:, 0] 74 | shaft.grid.plot(scalars=x_scalars, smooth_shading=True) 75 | 76 | 77 | ############################################################################### 78 | # Plotting With Missing Values 79 | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 80 | # 81 | # If you do not have values for every node (for example, the midside 82 | # nodes), you can leave these values as NAN and the plotter will take 83 | # care of plotting only the real values. 84 | # 85 | # For example, if you have calculated strain scalars that are only 86 | # available at certain nodes, you can still plot those. This example 87 | # just nulls out the first 2000 nodes to be able to visualize the 88 | # missing values. If your are just missing midside values, your plot 89 | # will not show the missing values since `pyvista` only plots the edge 90 | # nodes. 91 | 92 | pontoon = examples.download_pontoon() 93 | nnum, strain = pontoon.nodal_elastic_strain(0) 94 | 95 | scalars = strain[:, 0] 96 | scalars[:2000] = np.nan # here, we simulate unknown values 97 | 98 | pontoon.grid.plot(scalars=scalars, show_edges=True, lighting=False) 99 | -------------------------------------------------------------------------------- /examples/00-read_binary/load_corner_result.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates. 2 | # SPDX-License-Identifier: MIT 3 | # 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | """ 24 | .. _ref_load_cylindrical_result: 25 | 26 | Cylindrical Nodal Stress 27 | ~~~~~~~~~~~~~~~~~~~~~~~~ 28 | Visualize the nodal stress in the radial direction. This is 29 | equivalent to setting the result coordinate system to cylindrical in 30 | MAPDL (e.g. ``RSYS, 1``). 31 | 32 | """ 33 | 34 | ################################################################################ 35 | # Download a small result file containing the corner of a thick pipe 36 | from ansys.mapdl.reader import examples 37 | 38 | rst = examples.download_corner_pipe() 39 | 40 | # obtain the cylindrical_nodal_stress 41 | nnum, stress = rst.cylindrical_nodal_stress(0) 42 | print(stress) 43 | 44 | # contains results for each node in following directions 45 | # R, THETA, Z, RTHETA, THETAZ, and RZ 46 | print(stress.shape) 47 | 48 | ################################################################################ 49 | # plot cylindrical nodal stress in the radial direction 50 | _ = rst.plot_cylindrical_nodal_stress(0, "R", show_edges=True, show_axes=True) 51 | 52 | ################################################################################ 53 | # plot cylindrical nodal stress in the theta direction 54 | _ = rst.plot_cylindrical_nodal_stress( 55 | 0, "THETA", show_edges=True, show_axes=True, add_text=False 56 | ) 57 | 58 | ################################################################################ 59 | # Plot cartesian stress in the "X" direction 60 | _ = rst.plot_nodal_stress(0, "X", show_edges=True, show_axes=True) 61 | -------------------------------------------------------------------------------- /examples/00-read_binary/load_shaft_result.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates. 2 | # SPDX-License-Identifier: MIT 3 | # 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | """ 24 | .. _ref_load_shaft_result: 25 | 26 | Shaft Modal Analysis 27 | ~~~~~~~~~~~~~~~~~~~~ 28 | 29 | Visualize a shaft modal analysis 30 | 31 | """ 32 | 33 | # sphinx_gallery_thumbnail_number = 6 34 | 35 | from ansys.mapdl.reader import examples 36 | 37 | # Download an example shaft modal analysis result file 38 | shaft = examples.download_shaft_modal() 39 | 40 | ############################################################################### 41 | # Mesh is stored within the result object 42 | print(shaft.mesh) 43 | 44 | ############################################################################### 45 | # ...and contains a VTK unstructured grid 46 | print(shaft.mesh._grid) 47 | 48 | ############################################################################### 49 | # Plot the shaft 50 | cpos = shaft.plot() 51 | 52 | # list shaft node components 53 | ############################################################################### 54 | print(shaft.element_components.keys()) 55 | 56 | ############################################################################### 57 | # Plot a node component 58 | # 59 | # This camera angle was saved interactively from ``shaft.plot`` 60 | cpos = [ 61 | (-115.35773008378118, 285.36602704380107, -393.9029392590675), 62 | (126.12852038381345, 0.2179228023931401, 5.236408799851887), 63 | (0.37246222812978824, 0.8468424028124546, 0.37964435122285495), 64 | ] 65 | shaft.plot(element_components=["SHAFT_MESH"], cpos=cpos) 66 | # get cpos from cpos = shaft.plot() 67 | 68 | 69 | ############################################################################### 70 | # Plot a node component as a wireframe: 71 | shaft.plot( 72 | element_components=["SHAFT_MESH"], 73 | cpos=cpos, 74 | style="wireframe", 75 | lighting=False, 76 | color="k", 77 | ) 78 | 79 | 80 | ############################################################################### 81 | # Plot the shaft with edges and with a blue color: 82 | shaft.plot(show_edges=True, color="cyan") 83 | 84 | 85 | ############################################################################### 86 | # Plot the shaft without lighting but with edges and with a blue color: 87 | shaft.plot(lighting=False, show_edges=True, color="cyan") 88 | 89 | 90 | ############################################################################### 91 | # Plot a mode shape without contours using the "bwr" color map: 92 | shaft.plot_nodal_solution( 93 | 9, 94 | element_components=["SHAFT_MESH"], 95 | show_displacement=True, 96 | cmap="bwr", 97 | displacement_factor=0.3, 98 | scalar_bar_args={"title": ""}, 99 | overlay_wireframe=True, 100 | cpos=cpos, 101 | ) 102 | 103 | 104 | ############################################################################### 105 | # Plot a mode shape with contours and the default colormap: 106 | shaft.plot_nodal_solution( 107 | 1, 108 | element_components=["SHAFT_MESH"], 109 | n_colors=10, 110 | show_displacement=True, 111 | displacement_factor=1, 112 | overlay_wireframe=True, 113 | cpos=cpos, 114 | ) 115 | 116 | 117 | ############################################################################### 118 | # Animate a mode of a component the shaft 119 | # 120 | # Set ``loop==True`` to plot continuously. 121 | # Disable ``movie_filename`` and increase ``n_frames`` for a smoother plot 122 | shaft.animate_nodal_solution( 123 | 5, 124 | element_components="SHAFT_MESH", 125 | comp="norm", 126 | displacement_factor=1, 127 | n_colors=12, 128 | show_edges=True, 129 | cpos=cpos, 130 | loop=False, 131 | movie_filename="demo.gif", 132 | n_frames=30, 133 | show_axes=False, 134 | add_text=False, 135 | ) 136 | -------------------------------------------------------------------------------- /examples/00-read_binary/load_thermal_result.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates. 2 | # SPDX-License-Identifier: MIT 3 | # 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | """ 24 | .. _ref_load_thermal_result: 25 | 26 | Thermal Analysis 27 | ~~~~~~~~~~~~~~~~ 28 | 29 | Visualize the result of verification manual test 33. 30 | 31 | """ 32 | 33 | from ansys.mapdl.reader import examples 34 | 35 | ################################################################################ 36 | # Download the result file from verification manual test case 33 37 | vm33 = examples.download_verification_result(33) 38 | 39 | # get nodal thermal strain for result set 1 40 | nnum, tstrain = vm33.nodal_thermal_strain(0) 41 | 42 | # plot nodal thermal strain for result set 11 in the X direction 43 | vm33.plot_nodal_thermal_strain( 44 | 10, "X", show_edges=True, lighting=True, cmap="bwr", show_axes=True 45 | ) 46 | 47 | ################################################################################ 48 | # Plot with contours 49 | 50 | # Disable lighting and set number of colors to 10 to make an MAPDL-like plot 51 | vm33.plot_nodal_thermal_strain( 52 | 10, 53 | "X", 54 | show_edges=True, 55 | n_colors=10, 56 | interpolate_before_map=True, 57 | lighting=False, 58 | show_axes=True, 59 | ) 60 | -------------------------------------------------------------------------------- /examples/00-read_binary/pontoon.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates. 2 | # SPDX-License-Identifier: MIT 3 | # 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | """ 24 | .. _ref_pontoon: 25 | 26 | Shell Static Analysis 27 | ~~~~~~~~~~~~~~~~~~~~~ 28 | 29 | Visualize a shell static analysis 30 | """ 31 | 32 | # download the pontoon example 33 | from ansys.mapdl.reader import examples 34 | 35 | pontoon = examples.download_pontoon() 36 | 37 | ############################################################################### 38 | # Print the pontoon result 39 | print(pontoon) 40 | 41 | ############################################################################### 42 | # Plot the nodal displacement 43 | pontoon.plot_nodal_solution(0, show_displacement=True, displacement_factor=100000) 44 | 45 | 46 | ############################################################################### 47 | # print the available result types 48 | pontoon.available_results 49 | 50 | 51 | ############################################################################### 52 | # Plot the shell elements 53 | pontoon.plot() 54 | 55 | ############################################################################### 56 | # Plot the elastic strain and show exaggerated displacement 57 | pontoon.plot_nodal_elastic_strain( 58 | 0, 59 | "eqv", 60 | show_displacement=True, 61 | displacement_factor=100000, 62 | overlay_wireframe=True, 63 | lighting=False, 64 | add_text=False, 65 | show_edges=True, 66 | ) 67 | # Note: lighting is disabled here as it's too dark 68 | -------------------------------------------------------------------------------- /examples/01-cyclic_results/README.txt: -------------------------------------------------------------------------------- 1 | Cyclic Result Analysis 2 | ---------------------- 3 | The following examples demonstrate how to load results from and 4 | directly analyze MAPDL result files from a cyclic analysis. 5 | -------------------------------------------------------------------------------- /examples/01-cyclic_results/academic_sector_stress_strain.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates. 2 | # SPDX-License-Identifier: MIT 3 | # 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | """ 24 | .. _ref_academic_sector_stress_strain: 25 | 26 | Stress and Strain from a Cyclic Modal Analysis 27 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 28 | 29 | This example shows how to extract strain and stress from a cyclic 30 | modal analysis. 31 | 32 | """ 33 | 34 | # sphinx_gallery_thumbnail_number = 2 35 | from ansys.mapdl.reader import examples 36 | 37 | ############################################################################### 38 | # Download the academic modal analysis file 39 | rotor = examples.download_academic_rotor_result() 40 | print(rotor) 41 | 42 | 43 | ############################################################################### 44 | # Plot nodal displacement for result ``(2, 2)``, which corresponds to 45 | # the load step and sub step in fortran indexing. You could have also 46 | # used the python cumulative index 3. 47 | # rotor._positive_cyclic_dir = True 48 | _ = rotor.plot_nodal_displacement((2, 2), "x", cpos="xy") 49 | 50 | 51 | ############################################################################### 52 | # Extract the nodal elastic strain for the fourth cumulative result. 53 | # Because pymapdl-reader uses zero based indexing, we have to input "3" here. 54 | # 55 | # Depending on the version of ANSYS, MAPDL either does or does not 56 | # write the duplicate sector for a result. If MAPDL does not write a 57 | # duplicate sector, pymapdl-reader will search for a duplicate mode and use 58 | # that as the duplicate sector in order to be able to expand to the 59 | # full rotor. Regardless of if there is or isn't a duplicate sector, 60 | # only the master sector will be output. 61 | # 62 | # .. warning:: 63 | # Cyclic results extracted from pymapdl-reader may disagree with MAPDL 64 | # due to several issues/variations when extracting cyclic results 65 | # within MAPDL using ``PowerGraphics``. By default, MAPDL uses 66 | # ``\EDGE,,,45``, which disables averaging across surface features 67 | # that exceed 45 degrees, but only writes one value when outputting 68 | # with ``PRNSOL``. On the other hand ``pymapdl-reader`` always averages, 69 | # so you will see differences between MAPDL and ``pymapdl-reader`` in 70 | # these cases. 71 | nnum, strain = rotor.nodal_elastic_strain(3, full_rotor=True) 72 | 73 | 74 | ############################################################################### 75 | # Plot the nodal elastic strain in the "Z" direction for result ``(5, 2)``. 76 | # 77 | # ``pymapdl-reader`` can plot the displacements while also plotting the 78 | # stress/strain. Since modal results may or may not be normalized, 79 | # you will have to adjust the ``displacement_factor`` to scale up or 80 | # down the displacement to get a reasonable looking result. Disable 81 | # plotting the displacement by setting ``show_displacement=False``. 82 | # 83 | # Additionally, you can also save screenshots by setting 84 | # ``screenshot`` to a filename with 85 | # ``screenshot='elastic_strain.png'``. If you wish to do this without 86 | # manually closing the plotting screen, set ``off_screen=True``. This 87 | # can help you automate saving screenshots. 88 | 89 | _ = rotor.plot_nodal_elastic_strain( 90 | (5, 2), "Z", show_displacement=True, displacement_factor=0.01 91 | ) 92 | 93 | 94 | ############################################################################### 95 | # Plot the nodal elastic stress in the "Z" direction for this rotor. 96 | # Since this is plotting the other pair of modes for the 5th loadstep, 97 | # the displacement of this response is 90 degrees out of phase of 98 | # result ``(5, 2)`` 99 | # 100 | # Available stress components are ``['Y', 'Z', 'XY', 'YZ', 'XZ']`` 101 | _ = rotor.plot_nodal_stress( 102 | (5, 1), "Z", show_displacement=True, displacement_factor=0.01 103 | ) 104 | 105 | 106 | ############################################################################### 107 | # You can also plot the nodal von mises principal stress. This plot 108 | # shows the principal stress for result ``(5, 2)``. 109 | # 110 | # Available stress components are ``['S1', 'S2', 'S3', 'SINT', 'SEQV']``. 111 | _ = rotor.plot_principal_nodal_stress( 112 | (5, 2), "SEQV", show_displacement=True, displacement_factor=0.01 113 | ) 114 | -------------------------------------------------------------------------------- /examples/01-cyclic_results/sector_model.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates. 2 | # SPDX-License-Identifier: MIT 3 | # 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | """ 24 | .. _ref_sector_model: 25 | 26 | Cyclic Model Visualization 27 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ 28 | Visualize and animate a full cyclic model. This model is based on the 29 | jetcat rotor. 30 | 31 | First, load the rotor. Notice how printing the rotor class reveals 32 | the details of the rotor result file. 33 | """ 34 | 35 | # sphinx_gallery_thumbnail_number = 2 36 | from ansys.mapdl.reader import examples 37 | 38 | rotor = examples.download_sector_modal() 39 | print(rotor) 40 | 41 | ############################################################################### 42 | # Plot the rotor and rotor sectors 43 | # 44 | # Note that additional keyword arguments can be passed to the plotting 45 | # functions of ``pymapdl-reader``. See ``help(pyvista.plot`` for the 46 | # documentation on all the keyword arguments. 47 | rotor.plot_sectors(cpos="xy", smooth_shading=True) 48 | rotor.plot() 49 | 50 | 51 | ############################################################################### 52 | # Plot nodal displacement for result 21. 53 | # 54 | # Note that pymapdl-reader uses 0 based cumulative indexing. You could also 55 | # use the (load step, sub step) ``(4, 3)``. 56 | rotor.plot_nodal_displacement( 57 | 20, show_displacement=True, displacement_factor=0.001, overlay_wireframe=True 58 | ) # same as (2, 4) 59 | 60 | 61 | ############################################################################### 62 | # Animate Mode 21 63 | # ~~~~~~~~~~~~~~~ 64 | # Disable movie_filename and increase n_frames for a smoother plot 65 | rotor.animate_nodal_solution( 66 | 20, 67 | loop=False, 68 | movie_filename="rotor_mode.gif", 69 | background="w", 70 | displacement_factor=0.001, 71 | add_text=False, 72 | n_frames=30, 73 | ) 74 | -------------------------------------------------------------------------------- /examples/README.txt: -------------------------------------------------------------------------------- 1 | .. _ref_example_gallery: 2 | 3 | Examples 4 | ======== 5 | 6 | Here are a series of examples that demonstrate the behavior and usage 7 | of ``ansys-mapdl-reader``. 8 | -------------------------------------------------------------------------------- /ignore_words.txt: -------------------------------------------------------------------------------- 1 | parm 2 | pres 3 | WAN 4 | filname 5 | ans 6 | ect 7 | ist 8 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | build-backend = "setuptools.build_meta" 3 | requires = [ 4 | "cython>=3.0.0", 5 | "numpy>=1.16.0,<3", 6 | "setuptools>=45.0", 7 | "wheel>=0.37.0", 8 | ] 9 | 10 | [tool.pytest.ini_options] 11 | junit_family= "legacy" 12 | filterwarnings = [ 13 | # bogus numpy ABI warning (see numpy/#432) 14 | "ignore:.*numpy.dtype size changed.*:RuntimeWarning", 15 | "ignore:.*numpy.ufunc size changed.*:RuntimeWarning", 16 | "ignore:.*Distutils was imported before Setuptools*", 17 | ] 18 | 19 | [tool.cibuildwheel] 20 | archs = ["auto64"] # 64-bit only 21 | skip = "pp* *musllinux*" # disable PyPy and musl-based wheels 22 | test-requires = "ansys-mapdl-core>=0.60.4 matplotlib pytest scipy" 23 | test-command = "pytest {project}/tests" 24 | 25 | [tool.cibuildwheel.macos] 26 | # https://cibuildwheel.readthedocs.io/en/stable/faq/#apple-silicon 27 | archs = ["x86_64", "universal2"] 28 | test-skip = ["*_arm64", "*_universal2:arm64", "*cp311*"] 29 | -------------------------------------------------------------------------------- /pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | junit_family=legacy 3 | filterwarnings = 4 | ignore::FutureWarning 5 | ignore::PendingDeprecationWarning 6 | ignore::DeprecationWarning 7 | # bogus numpy ABI warning (see numpy/#432) 8 | ignore:.*numpy.dtype size changed.*:RuntimeWarning 9 | ignore:.*numpy.ufunc size changed.*:RuntimeWarning 10 | ignore::UserWarning -------------------------------------------------------------------------------- /requirements/requirements_doc.txt: -------------------------------------------------------------------------------- 1 | Sphinx<9 2 | ansys-sphinx-theme==1.3.2 3 | imageio==2.37.0 4 | nest-asyncio==1.6.0 5 | notfound==1.0.2 6 | pypandoc==1.15 7 | pyvista==0.45.2 8 | sphinx-copybutton==0.5.2 9 | sphinx-gallery==0.19.0 10 | sphinx-notfound-page==1.1.0 11 | trame==3.10.1 12 | vtk==9.4.2 13 | -------------------------------------------------------------------------------- /requirements/requirements_test.txt: -------------------------------------------------------------------------------- 1 | ansys-mapdl-core>=0.60.4 2 | matplotlib>=3.5.3 3 | pytest==8.3.5 4 | pytest-cov==6.1.1 5 | scipy>=1.7.3 6 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | """Installation file for ansys-mapdl-reader""" 2 | 3 | from io import open as io_open 4 | import os 5 | 6 | import numpy as np 7 | from setuptools import Extension, setup 8 | 9 | if os.name == "nt": # windows 10 | extra_compile_args = ["/openmp", "/O2", "/w", "/GS"] 11 | elif os.name == "posix": # linux/mac os 12 | extra_compile_args = ["-O3", "-w"] 13 | 14 | 15 | # Get version from version info 16 | __version__ = None 17 | this_file = os.path.dirname(__file__) 18 | version_file = os.path.join(this_file, "ansys", "mapdl", "reader", "_version.py") 19 | with io_open(version_file, mode="r") as fd: 20 | # execute file from raw string 21 | exec(fd.read()) 22 | 23 | 24 | setup( 25 | name="ansys-mapdl-reader", 26 | packages=["ansys.mapdl.reader", "ansys.mapdl.reader.examples"], 27 | version=__version__, 28 | description="Pythonic interface to files generated by MAPDL", 29 | long_description=open("README.rst").read(), 30 | long_description_content_type="text/x-rst", 31 | author="Ansys, Inc.", 32 | author_email="pyansys.maintainers@ansys.com", 33 | maintainer="PyAnsys developers", 34 | maintainer_email="pyansys.maintainers@ansys.com", 35 | license="MIT", 36 | classifiers=[ 37 | "Development Status :: 4 - Beta", 38 | "Intended Audience :: Science/Research", 39 | "Topic :: Scientific/Engineering :: Information Analysis", 40 | "License :: OSI Approved :: MIT License", 41 | "Operating System :: Microsoft :: Windows", 42 | "Operating System :: POSIX", 43 | "Operating System :: MacOS", 44 | "Programming Language :: Python :: 3.10", 45 | "Programming Language :: Python :: 3.11", 46 | "Programming Language :: Python :: 3.12", 47 | "Programming Language :: Python :: 3.13", 48 | ], 49 | url="https://github.com/pyansys/pymapdl-reader", 50 | # Build cython modules 51 | # cmdclass={"build_ext": build_ext}, 52 | include_dirs=[np.get_include()], 53 | ext_modules=[ 54 | Extension( 55 | "ansys.mapdl.reader._archive", 56 | [ 57 | "ansys/mapdl/reader/cython/_archive.pyx", 58 | "ansys/mapdl/reader/cython/archive.c", 59 | ], 60 | extra_compile_args=extra_compile_args, 61 | language="c", 62 | ), 63 | Extension( 64 | "ansys.mapdl.reader._reader", 65 | [ 66 | "ansys/mapdl/reader/cython/_reader.pyx", 67 | "ansys/mapdl/reader/cython/reader.c", 68 | "ansys/mapdl/reader/cython/vtk_support.c", 69 | ], 70 | extra_compile_args=extra_compile_args, 71 | language="c", 72 | ), 73 | Extension( 74 | "ansys.mapdl.reader._relaxmidside", 75 | ["ansys/mapdl/reader/cython/_relaxmidside.pyx"], 76 | extra_compile_args=extra_compile_args, 77 | language="c", 78 | ), 79 | Extension( 80 | "ansys.mapdl.reader._cellqual", 81 | ["ansys/mapdl/reader/cython/_cellqual.pyx"], 82 | extra_compile_args=extra_compile_args, 83 | language="c", 84 | ), 85 | Extension( 86 | "ansys.mapdl.reader._binary_reader", 87 | [ 88 | "ansys/mapdl/reader/cython/_binary_reader.pyx", 89 | "ansys/mapdl/reader/cython/binary_reader.cpp", 90 | ], 91 | extra_compile_args=extra_compile_args, 92 | language="c++", 93 | ), 94 | ], 95 | python_requires=">=3.10,<4", 96 | keywords="vtk MAPDL ANSYS cdb full rst", 97 | package_data={ 98 | "ansys.mapdl.reader.examples": [ 99 | "TetBeam.cdb", 100 | "HexBeam.cdb", 101 | "file.rst", 102 | "file.full", 103 | "sector.rst", 104 | "sector.cdb", 105 | ] 106 | }, 107 | install_requires=[ 108 | "appdirs>=1.4.0", 109 | "matplotlib>=3.0.0", 110 | "numpy>=1.16.0,<3", 111 | "pyvista>=0.32.0", 112 | "tqdm>=4.45.0", 113 | "vtk>=9.0.0,<10", 114 | ], 115 | ) 116 | -------------------------------------------------------------------------------- /tests/archive/test_data/all_solid_cells.cdb: -------------------------------------------------------------------------------- 1 | /PREP7 2 | ET, 4, 186 3 | /PREP7 4 | NBLOCK,6,SOLID, 14371, 52 5 | (3i8,6e20.13) 6 | 635 0 0 3.7826539829200E+00 1.2788958692644E+00-1.0220880953640E+00 7 | 637 0 0 3.7987359490873E+00 1.2312085780780E+00-1.0001885444969E+00 8 | 638 0 0 3.8138798206653E+00 1.1833200772896E+00-9.7805743587145E-01 9 | 667 0 0 3.7751258193793E+00 1.2956563072306E+00-9.9775569295981E-01 10 | 668 0 0 3.7675976558386E+00 1.3124167451968E+00-9.7342329055565E-01 11 | 844 0 0 3.8071756567432E+00 1.2018089624856E+00-9.5159140433025E-01 12 | 845 0 0 3.8004714928212E+00 1.2202978476816E+00-9.2512537278904E-01 13 | 851 0 0 3.7840345743299E+00 1.2663572964392E+00-9.4927433167235E-01 14 | 919 0 0 3.8682501483615E+00 1.4211343558710E+00-9.2956245308371E-01 15 | 920 0 0 3.8656154427804E+00 1.4283573726940E+00-9.3544082975315E-01 16 | 921 0 0 3.8629807371994E+00 1.4355803895169E+00-9.4131920642259E-01 17 | 934 0 0 3.8698134427618E+00 1.4168612083433E+00-9.3457292477788E-01 18 | 935 0 0 3.8645201728196E+00 1.4314324609914E+00-9.4526873324423E-01 19 | 939 0 0 3.8713767371621E+00 1.4125880608155E+00-9.3958339647206E-01 20 | 940 0 0 3.8687181728010E+00 1.4199362966407E+00-9.4440082826897E-01 21 | 941 0 0 3.8660596084399E+00 1.4272845324660E+00-9.4921826006588E-01 22 | 1070 0 0 3.7847463501820E+00 1.2869612289286E+00-1.0110875234148E+00 23 | 1071 0 0 3.7882161293470E+00 1.2952473975570E+00-1.0006326084202E+00 24 | 1142 0 0 3.7840036708439E+00 1.3089808408341E+00-9.8189659453120E-01 25 | 1147 0 0 3.7736944340897E+00 1.3175655146540E+00-9.6829193559890E-01 26 | 1148 0 0 3.7797912123408E+00 1.3227142841112E+00-9.6316058064216E-01 27 | 4971 0 0 3.8163322819008E+00 1.1913589544053E+00-9.6740419078720E-01 28 | 4985 0 0 3.8046827481496E+00 1.2474593204382E+00-9.7922600135387E-01 29 | 4986 0 0 3.8202228218151E+00 1.1995824283636E+00-9.5733187068101E-01 30 | 5609 0 0 3.9797161316330E+00 2.5147820926190E-01-5.1500799817626E-01 31 | 5629 0 0 3.9831382922541E+00 2.0190980565891E-01-5.0185526897444E-01 32 | 5630 0 0 3.9810868976408E+00 2.3910377061737E-01-5.4962360790281E-01 33 | 5649 0 0 3.9772930845240E+00 2.8865001362748E-01-5.6276585706615E-01 34 | 5692 0 0 3.9816265976187E+00 2.1428739259987E-01-4.6723916677654E-01 35 | 5697 0 0 3.9839413943097E+00 1.8949722823843E-01-5.3648152416530E-01 36 | 5991 0 0 3.7962006776348E+00 1.2764624207283E+00-9.3931008487698E-01 37 | 6006 0 0 3.8126101429289E+00 1.2302105573453E+00-9.1545958911180E-01 38 | 6021 0 0 3.8065408178751E+00 1.2252542025135E+00-9.2029248095042E-01 39 | 6022 0 0 3.8164164823720E+00 1.2148964928545E+00-9.3639572989640E-01 40 | 13148 0 0 3.8972892823450E+00 2.7547119775919E-01-5.6510422311694E-01 41 | 13153 0 0 3.9015993648189E+00 2.0235606714652E-01-4.6987255385930E-01 42 | 13154 0 0 3.9023812010290E+00 1.7705558022279E-01-5.3881795411458E-01 43 | 13155 0 0 3.9019902829240E+00 1.8970582368465E-01-5.0434525398694E-01 44 | 13156 0 0 3.8998352416870E+00 2.2626338899099E-01-5.5196108861576E-01 45 | 13157 0 0 3.8994443235820E+00 2.3891363245285E-01-5.1748838848812E-01 46 | 13674 0 0 3.9372911834345E+00 2.8206060569333E-01-5.6393504009155E-01 47 | 13676 0 0 3.9416129812188E+00 2.0832172987319E-01-4.6855586031792E-01 48 | 13677 0 0 3.9431612976694E+00 1.8327640423061E-01-5.3764973913994E-01 49 | 13983 0 0 3.8619577233846E+00 1.4192189812407E+00-9.2587403626770E-01 50 | 13984 0 0 3.8507167163959E+00 1.4238788373222E+00-9.3661710728291E-01 51 | 13998 0 0 3.8651039358730E+00 1.4201766685559E+00-9.2771824467570E-01 52 | 14000 0 0 3.8624692302920E+00 1.4273996853788E+00-9.3359662134515E-01 53 | 14003 0 0 3.8610467267790E+00 1.4182334490688E+00-9.3810025187748E-01 54 | 14004 0 0 3.8563372198902E+00 1.4215489092814E+00-9.3124557177530E-01 55 | 14038 0 0 3.8568487267976E+00 1.4297296134196E+00-9.3896815685275E-01 56 | 14040 0 0 3.8583881624179E+00 1.4255816848941E+00-9.4291768367439E-01 57 | 14371 0 0 3.8594834323787E+00 1.4225065965966E+00-9.3308978018331E-01 58 | N,R5.3,LOC, -1, 59 | 60 | EBLOCK,19,SOLID, 4644, 4 61 | (19i8) 62 | 1 4 1 1 0 0 0 0 20 0 2170 1071 1148 668 635 4986 6006 845 638 63 | 1142 1147 667 1070 6022 6021 844 4971 4985 5991 851 637 64 | 1 4 1 1 0 0 0 0 20 0 4488 5692 5649 5697 5697 13153 13148 13154 13154 65 | 5609 5630 5697 5629 13157 13156 13154 13155 13676 13674 13677 13677 66 | 1 4 1 1 0 0 0 0 20 0 4643 941 939 919 921 13984 13984 13984 13984 67 | 940 934 920 935 13984 13984 13984 13984 14040 14003 14371 14038 68 | 1 4 1 1 0 0 0 0 20 0 4644 13983 921 919 919 13984 13984 13984 13984 69 | 14000 920 13984 13998 13984 13984 13984 13984 14004 14038 14371 14371 70 | -1 71 | -------------------------------------------------------------------------------- /tests/archive/test_data/workbench_193.cdb: -------------------------------------------------------------------------------- 1 | NBLOCK,6,SOLID, 3, 3 2 | (1i7,2i9,6e21.13) 3 | 219712 0 0 9.8936757830530E-02 -8.0709219224048E-04 8.5376495335856E+00 0.0000000000000E+00 0.0000000000000E+00 0.0000000000000E+00 4 | 219713 0 0 9.6580324356880E-02 2.0090670425012E-02 8.5374495115171E+00 0.0000000000000E+00 0.0000000000000E+00 0.0000000000000E+00 5 | 219714 0 0 9.1924355500557E-02 3.9878161529541E-02 8.5372365249595E+00 0.0000000000000E+00 0.0000000000000E+00 0.0000000000000E+00 6 | N,R5.3,LOC, -1, 7 | 8 | -------------------------------------------------------------------------------- /tests/conftest.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates. 2 | # SPDX-License-Identifier: MIT 3 | # 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | import os 24 | 25 | import pytest 26 | import pyvista 27 | 28 | # Necessary for CI plotting 29 | pyvista.OFF_SCREEN = True 30 | 31 | 32 | @pytest.fixture(scope="session") 33 | def mapdl(request): 34 | """This fixture will only be called if ``ansys.mapdl.core`` is installed.""" 35 | from ansys.mapdl.core import launch_mapdl 36 | from ansys.mapdl.core.launcher import get_start_instance 37 | from ansys.tools.path import get_mapdl_path 38 | 39 | # check if the user wants to permit pytest to start MAPDL 40 | # and don't allow mapdl to exit upon collection unless mapdl is local 41 | cleanup = get_start_instance() 42 | 43 | # check for a valid MAPDL install with gRPC 44 | valid_rver = ["211"] # checks in this order 45 | EXEC_FILE = None 46 | for rver in valid_rver: 47 | if os.path.isfile(get_mapdl_path(rver)): 48 | EXEC_FILE = get_mapdl_path(rver) 49 | break 50 | 51 | return launch_mapdl( 52 | EXEC_FILE, override=True, cleanup_on_exit=cleanup, additional_switches="-smp" 53 | ) 54 | 55 | 56 | @pytest.fixture(scope="function") 57 | def cleared(mapdl): 58 | mapdl.finish() 59 | mapdl.clear("NOSTART") # *MUST* be NOSTART. With START fails after 20 calls... 60 | mapdl.prep7() 61 | yield 62 | -------------------------------------------------------------------------------- /tests/cyclic_reader/academic_rotor/SET1,1_RSYS0_EPEL.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/academic_rotor/SET1,1_RSYS0_EPEL.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/academic_rotor/SET1,1_RSYS0_S,PRIN.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/academic_rotor/SET1,1_RSYS0_S,PRIN.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/academic_rotor/SET1,1_RSYS0_S.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/academic_rotor/SET1,1_RSYS0_S.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/academic_rotor/SET1,2_RSYS0_EPEL.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/academic_rotor/SET1,2_RSYS0_EPEL.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/academic_rotor/SET1,2_RSYS0_S,PRIN.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/academic_rotor/SET1,2_RSYS0_S,PRIN.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/academic_rotor/SET1,2_RSYS0_S.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/academic_rotor/SET1,2_RSYS0_S.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/academic_rotor/SET13,1_RSYS0_EPEL.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/academic_rotor/SET13,1_RSYS0_EPEL.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/academic_rotor/SET13,1_RSYS0_S,PRIN.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/academic_rotor/SET13,1_RSYS0_S,PRIN.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/academic_rotor/SET13,1_RSYS0_S.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/academic_rotor/SET13,1_RSYS0_S.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/academic_rotor/SET13,2_RSYS0_EPEL.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/academic_rotor/SET13,2_RSYS0_EPEL.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/academic_rotor/SET13,2_RSYS0_S,PRIN.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/academic_rotor/SET13,2_RSYS0_S,PRIN.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/academic_rotor/SET13,2_RSYS0_S.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/academic_rotor/SET13,2_RSYS0_S.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/academic_rotor/SET2,1_RSYS0_EPEL.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/academic_rotor/SET2,1_RSYS0_EPEL.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/academic_rotor/SET2,1_RSYS0_S,PRIN.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/academic_rotor/SET2,1_RSYS0_S,PRIN.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/academic_rotor/SET2,1_RSYS0_S.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/academic_rotor/SET2,1_RSYS0_S.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/academic_rotor/SET2,2_RSYS0_EPEL.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/academic_rotor/SET2,2_RSYS0_EPEL.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/academic_rotor/SET2,2_RSYS0_S,PRIN.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/academic_rotor/SET2,2_RSYS0_S,PRIN.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/academic_rotor/SET2,2_RSYS0_S.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/academic_rotor/SET2,2_RSYS0_S.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/academic_rotor/SET5,1_RSYS0_EPEL.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/academic_rotor/SET5,1_RSYS0_EPEL.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/academic_rotor/SET5,1_RSYS0_S,PRIN.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/academic_rotor/SET5,1_RSYS0_S,PRIN.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/academic_rotor/SET5,1_RSYS0_S.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/academic_rotor/SET5,1_RSYS0_S.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/academic_rotor/SET5,2_RSYS0_EPEL.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/academic_rotor/SET5,2_RSYS0_EPEL.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/academic_rotor/SET5,2_RSYS0_S,PRIN.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/academic_rotor/SET5,2_RSYS0_S,PRIN.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/academic_rotor/SET5,2_RSYS0_S.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/academic_rotor/SET5,2_RSYS0_S.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/academic_rotor/academic_rotor.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/academic_rotor/academic_rotor.rst -------------------------------------------------------------------------------- /tests/cyclic_reader/cyclic_v150.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/cyclic_v150.rst -------------------------------------------------------------------------------- /tests/cyclic_reader/cyclic_v182.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/cyclic_v182.rst -------------------------------------------------------------------------------- /tests/cyclic_reader/cyclic_v182_w_comp.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/cyclic_v182_w_comp.rst -------------------------------------------------------------------------------- /tests/cyclic_reader/cyclic_x_v182.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/cyclic_x_v182.rst -------------------------------------------------------------------------------- /tests/cyclic_reader/prnsol_d_cyclic_x_full_v182.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/prnsol_d_cyclic_x_full_v182.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/prnsol_d_cyclic_z_full_v182.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/prnsol_d_cyclic_z_full_v182.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/prnsol_p_cyclic_x_full_v182.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/prnsol_p_cyclic_x_full_v182.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/prnsol_s_cyclic_x_full_v182.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/prnsol_s_cyclic_x_full_v182.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/prnsol_s_cyclic_z_full_v182.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/prnsol_s_cyclic_z_full_v182.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/prnsol_s_cyclic_z_full_v182_set_1_1.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/prnsol_s_cyclic_z_full_v182_set_1_1.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/prnsol_u_cyclic_z_full_v182_set_4_2.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/prnsol_u_cyclic_z_full_v182_set_4_2.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/v182_disp.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/v182_disp.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/v182_presol.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/v182_presol.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/v182_prnsol_prin.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/v182_prnsol_prin.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/v182_prnsol_s.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/v182_prnsol_s.npz -------------------------------------------------------------------------------- /tests/cyclic_reader/v182_x_disp.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/cyclic_reader/v182_x_disp.npz -------------------------------------------------------------------------------- /tests/elements/plane_182_183/plane182_183.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/elements/plane_182_183/plane182_183.rst -------------------------------------------------------------------------------- /tests/elements/plane_182_183/prnsol_s.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/elements/plane_182_183/prnsol_s.npy -------------------------------------------------------------------------------- /tests/elements/plane_182_183/prnsol_s_nnum.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/elements/plane_182_183/prnsol_s_nnum.npy -------------------------------------------------------------------------------- /tests/elements/plane_182_183/prnsol_u.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/elements/plane_182_183/prnsol_u.npy -------------------------------------------------------------------------------- /tests/elements/plane_182_183/prnsol_u_nnum.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/elements/plane_182_183/prnsol_u_nnum.npy -------------------------------------------------------------------------------- /tests/elements/plane_182_183/pymapdl_182_183_42_82.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/elements/plane_182_183/pymapdl_182_183_42_82.rst -------------------------------------------------------------------------------- /tests/elements/plane_182_183/test_archive_182_183.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates. 2 | # SPDX-License-Identifier: MIT 3 | # 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | import os 24 | 25 | import numpy as np 26 | import pytest 27 | 28 | from ansys.mapdl import reader as pymapdl_reader 29 | 30 | testfiles_path = os.path.dirname(os.path.abspath(__file__)) 31 | 32 | 33 | @pytest.fixture(scope="module") 34 | def archive(): 35 | filename = os.path.join(testfiles_path, "archive.cdb") 36 | return pymapdl_reader.Archive(filename) 37 | 38 | 39 | def test_archive_load(archive): 40 | assert archive.nnum.size == 12484 41 | assert len(archive.elem) == 6000 42 | 43 | 44 | def test_parse(archive): 45 | nnode = archive.nnum.size 46 | nelem = len(archive.elem) 47 | assert archive.grid.n_points == nnode 48 | assert archive.grid.n_cells == nelem 49 | assert np.sum(archive.grid.celltypes == 9) == 3000 50 | assert np.sum(archive.grid.celltypes == 23) == 3000 51 | assert np.allclose(archive.nodes, archive.grid.points) 52 | -------------------------------------------------------------------------------- /tests/elements/plane_182_183/test_plane182_183.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates. 2 | # SPDX-License-Identifier: MIT 3 | # 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | """ 24 | Test loading results from plane183 25 | 26 | Need to add ansys results for verification... 27 | 28 | """ 29 | 30 | import os 31 | 32 | import numpy as np 33 | import pytest 34 | 35 | from ansys.mapdl import reader as pymapdl_reader 36 | 37 | testfiles_path = os.path.dirname(os.path.abspath(__file__)) 38 | 39 | 40 | @pytest.fixture(scope="module") 41 | def result(): 42 | filename = os.path.join(testfiles_path, "pymapdl_182_183_42_82.rst") 43 | return pymapdl_reader.read_binary(filename) 44 | 45 | 46 | def test_load(result): 47 | assert np.any(result.grid.cells) 48 | assert np.any(result.grid.points) 49 | 50 | 51 | def test_displacement(result): 52 | nnum, disp = result.nodal_solution(0) 53 | ansys_nnum = np.load(os.path.join(testfiles_path, "prnsol_u_nnum.npy")) 54 | ansys_disp = np.load(os.path.join(testfiles_path, "prnsol_u.npy")) 55 | assert np.allclose(nnum, ansys_nnum) 56 | assert np.allclose(disp, ansys_disp, rtol=1e-4) # rounding in text file 57 | 58 | 59 | def test_stress(result): 60 | ansys_nnum = np.load(os.path.join(testfiles_path, "prnsol_s_nnum.npy")) 61 | ansys_stress = np.load(os.path.join(testfiles_path, "prnsol_s.npy")) 62 | nnum, stress = result.nodal_stress(0) 63 | mask = np.isin(nnum, ansys_nnum) 64 | assert np.allclose(stress[mask], ansys_stress, atol=1e-6) 65 | -------------------------------------------------------------------------------- /tests/elements/shell181/shell181.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/elements/shell181/shell181.rst -------------------------------------------------------------------------------- /tests/elements/shell181/shell181_box.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/elements/shell181/shell181_box.rst -------------------------------------------------------------------------------- /tests/elements/shell181/test_shell181.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates. 2 | # SPDX-License-Identifier: MIT 3 | # 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | """ 24 | Test loading results from shell181 elements 25 | 26 | Reading the stress values from these elements requires more overhead as 27 | the component stresses written to the binary file are relative to the element's 28 | coordinates and not the global coordinates. 29 | 30 | 31 | Element solution results from ANSYS 32 | ############################################################################### 33 | PRINT S ELEMENT SOLUTION PER ELEMENT 34 | 35 | ***** POST1 ELEMENT NODAL STRESS LISTING ***** 36 | 37 | LOAD STEP= 1 SUBSTEP= 1 38 | TIME= 1.0000 LOAD CASE= 0 39 | SHELL RESULTS FOR TOP/BOTTOM ALSO MID WHERE APPROPRIATE 40 | 41 | THE FOLLOWING X,Y,Z VALUES ARE IN GLOBAL COORDINATES 42 | 43 | 44 | ELEMENT= 1 SHELL181 45 | NODE SX SY SZ SXY SYZ SXZ 46 | 2 0.17662E-07 79.410 -11.979 -0.11843E-02 4.8423 -0.72216E-04 47 | 1 0.20287E-07 91.212 27.364 -0.13603E-02 4.8423 -0.72216E-04 48 | 4 0.20287E-07 91.212 27.364 -0.13603E-02 -4.8423 0.72216E-04 49 | 3 0.17662E-07 79.410 -11.979 -0.11843E-02 -4.8423 0.72216E-04 50 | 2 -0.17662E-07 -79.410 11.979 0.11843E-02 -4.8423 0.72216E-04 51 | 1 -0.20287E-07 -91.213 -27.364 0.13603E-02 -4.8423 0.72216E-04 52 | 4 -0.20287E-07 -91.213 -27.364 0.13603E-02 4.8423 -0.72216E-04 53 | 3 -0.17662E-07 -79.410 11.979 0.11843E-02 4.8423 -0.72216E-04 54 | ############################################################################### 55 | 56 | 57 | Nodal Solution results from ANSYS 58 | ############################################################################### 59 | PRINT S NODAL SOLUTION PER NODE 60 | 61 | ***** POST1 NODAL STRESS LISTING ***** 62 | PowerGraphics Is Currently Enabled 63 | 64 | LOAD STEP= 1 SUBSTEP= 1 65 | TIME= 1.0000 LOAD CASE= 0 66 | SHELL NODAL RESULTS ARE AT TOP/BOTTOM FOR MATERIAL 1 67 | 68 | THE FOLLOWING X,Y,Z VALUES ARE IN GLOBAL COORDINATES 69 | 70 | NODE SX SY SZ SXY SYZ SXZ 71 | 1 0.20287E-07 91.212 27.364 -0.13603E-02 4.8423 -0.72216E-04 72 | 1 -0.20287E-07 -91.213 -27.364 0.13603E-02 -4.8423 0.72216E-04 73 | 2 0.17662E-07 79.410 -11.979 -0.11843E-02 4.8423 -0.72216E-04 74 | 2 -0.17662E-07 -79.410 11.979 0.11843E-02 -4.8423 0.72216E-04 75 | 3 0.17662E-07 79.410 -11.979 -0.11843E-02 -4.8423 0.72216E-04 76 | 3 -0.17662E-07 -79.410 11.979 0.11843E-02 4.8423 -0.72216E-04 77 | 4 0.20287E-07 91.212 27.364 -0.13603E-02 -4.8423 0.72216E-04 78 | 4 -0.20287E-07 -91.213 -27.364 0.13603E-02 4.8423 -0.72216E-04 79 | 80 | ***** POST1 NODAL STRESS LISTING ***** 81 | 82 | LOAD STEP= 1 SUBSTEP= 1 83 | TIME= 1.0000 LOAD CASE= 0 84 | SHELL NODAL RESULTS ARE AT TOP/BOTTOM FOR MATERIAL 4 85 | 86 | THE FOLLOWING X,Y,Z VALUES ARE IN GLOBAL COORDINATES 87 | 88 | NODE SX SY SZ SXY SYZ SXZ 89 | 90 | MINIMUM VALUES 91 | NODE 1 1 1 1 1 1 92 | VALUE -0.20287E-07 -91.213 -27.364 -0.13603E-02 -4.8423 -0.72216E-04 93 | 94 | MAXIMUM VALUES 95 | NODE 1 1 1 1 1 1 96 | VALUE 0.20287E-07 91.212 27.364 0.13603E-02 4.8423 0.72216E-04 97 | ############################################################################### 98 | 99 | 100 | """ 101 | 102 | import os 103 | 104 | import numpy as np 105 | import pytest 106 | 107 | from ansys.mapdl import reader as pymapdl_reader 108 | 109 | ANSYS_ELEM = [ 110 | [0.17662e-07, 79.410, -11.979, -0.11843e-02, 4.8423, -0.72216e-04], 111 | [0.20287e-07, 91.212, 27.364, -0.13603e-02, 4.8423, -0.72216e-04], 112 | [0.20287e-07, 91.212, 27.364, -0.13603e-02, -4.8423, 0.72216e-04], 113 | [0.17662e-07, 79.410, -11.979, -0.11843e-02, -4.8423, 0.72216e-04], 114 | ] 115 | 116 | ANSYS_NODE = [ 117 | [0.20287e-07, 91.212, 27.364, -0.13603e-02, 4.8423, -0.72216e-04], 118 | [0.17662e-07, 79.410, -11.979, -0.11843e-02, 4.8423, -0.72216e-04], 119 | [0.17662e-07, 79.410, -11.979, -0.11843e-02, -4.8423, 0.72216e-04], 120 | [0.20287e-07, 91.212, 27.364, -0.13603e-02, -4.8423, 0.72216e-04], 121 | ] 122 | 123 | 124 | @pytest.fixture(scope="module") 125 | def result(): 126 | test_path = os.path.dirname(os.path.abspath(__file__)) 127 | return pymapdl_reader.read_binary(os.path.join(test_path, "shell181.rst")) 128 | 129 | 130 | def test_load(result): 131 | assert np.any(result.grid.cells) 132 | assert np.any(result.grid.points) 133 | 134 | 135 | def test_element_stress(result): 136 | _, element_stress, _ = result.element_stress(0) 137 | element0 = element_stress[0] 138 | 139 | # ansys prints both positive and negative component values 140 | if np.sign(element0[0][0]) != np.sign(ANSYS_ELEM[0][0]): 141 | element0 *= -1 142 | 143 | # wide atol limits considering the 5 sigfig from ASCII tables 144 | assert np.allclose(element0, np.array(ANSYS_ELEM), atol=1e-6) 145 | 146 | 147 | def test_nodal_stress(result): 148 | _, stress = result.nodal_stress(0) 149 | if np.sign(stress[0][0]) != np.sign(ANSYS_NODE[0][0]): 150 | stress *= -1 151 | 152 | # wide atol limits considering the 5 sigfig from ASCII tables 153 | assert np.allclose(stress, np.array(ANSYS_NODE), atol=1e-6) 154 | -------------------------------------------------------------------------------- /tests/elements/shell181/test_shell181_element_coord.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates. 2 | # SPDX-License-Identifier: MIT 3 | # 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | """ 24 | 25 | Attached is the ANSYS rst file. Please consider the following expected outcomes: 26 | element stresses in the element coordinate system: 27 | 28 | ANSYS Version 18.2 29 | Element Type Shell 181 30 | Element# 118223 31 | 32 | Top Surface 33 | Node # Sx Sy Sz Sxy Sxz Syz 34 | 143901 2272.9 968.77 0 -222.11 0 0 35 | 143862 2291 1028.6 0 151.15 0 0 36 | 144000 3304.5 1333.3 0 171.24 0 0 37 | 143931 3286.5 1273.5 0 -202.03 0 0 38 | 39 | Bottom Surface 40 | Node # Sx Sy Sz Sxy Sxz Syz 41 | 143901 -2277.2 -967.94 0 243.1 0 0 42 | 143862 -2295.2 -1028.6 0 -130.16 0 0 43 | 144000 -3313 -1333.3 0 -150.24 0 0 44 | 143931 -3295 -1272.6 0 223.02 0 0 45 | 46 | It should be noted that the average of Top and Bottom surface is what Pyansys 47 | currently provides through result.element_stress(0) command which is in the global 48 | coordinate system. 49 | 50 | """ 51 | 52 | import os 53 | 54 | import numpy as np 55 | 56 | from ansys.mapdl import reader as pymapdl_reader 57 | 58 | # result for element 118223 59 | KNOWN_RESULT_ENODE = [143901, 143862, 144000, 143931] 60 | KNOWN_RESULT_STRESS = np.array( 61 | [ 62 | [2272.9, 968.77, 0, -222.11, 0, 0], 63 | [2291, 1028.6, 0, 151.15, 0, 0], 64 | [3304.5, 1333.3, 0, 171.24, 0, 0], 65 | [3286.5, 1273.5, 0, -202.03, 0, 0], 66 | [-2277.2, -967.94, 0, 243.1, 0, 0], 67 | [-2295.2, -1028.6, 0, -130.16, 0, 0], 68 | [-3313, -1333.3, 0, -150.24, 0, 0], 69 | [-3295, -1272.6, 0, 223.02, 0, 0], 70 | ] 71 | ) 72 | 73 | test_path = os.path.dirname(os.path.abspath(__file__)) 74 | result_file_name = os.path.join(test_path, "shell181_box.rst") 75 | 76 | 77 | def test_shell_stress_element_cs(): 78 | result = pymapdl_reader.read_binary(result_file_name) 79 | enum, stress, enode = result.element_stress(0, in_element_coord_sys=True) 80 | 81 | idx = np.where(enum == 118223)[0][0] 82 | assert np.allclose(KNOWN_RESULT_ENODE, enode[idx][:4]) 83 | assert np.allclose(KNOWN_RESULT_STRESS, stress[idx], rtol=1e-4) 84 | -------------------------------------------------------------------------------- /tests/elements/shell281/MAPDL.inp: -------------------------------------------------------------------------------- 1 | 2 | !List element properties for element #1 3 | elist,1,,,1,0 4 | 5 | LIST ALL SELECTED ELEMENTS IN RANGE 1 TO 1 STEP 1 6 | DO NOT LIST NODES 7 | 8 | ELEM MAT TYP REL ESY SEC 9 | 10 | 1 1 1 1 13 3 11 | 12 | 13 | 14 | 15 | 16 | 17 | !List section properties for section #3 (referenced by element #1) 18 | SLIST,3,,,BRIEF, 19 | 20 | 21 | LIST SECTION ID SETS 3 TO 3 BY 1 22 | Details = 0 23 | 24 | SECTION ID NUMBER: 3 25 | SHELL SECTION TYPE: 26 | SHELL SECTION NAME IS: 27 | SHELL SECTION DATA SUMMARY: 28 | Number of Layers = 3 29 | Total Thickness = 0.003000 30 | 31 | Layer Thickness MatID Ori. Angle Num Intg. Pts 32 | 33 | 1 0.0010 2 0.0000 3 34 | 2 0.0010 2 45.0000 3 35 | 3 0.0010 2 -45.0000 3 36 | 37 | Shell Section is offset to BOTTOM surface of Shell 38 | 39 | Section Solution Controls 40 | User Transverse Shear Stiffness (11)= 0.0000 41 | (22)= 0.0000 42 | (12)= 0.0000 43 | Added Mass Per Unit Area = 0.0000 44 | Hourglass Scale Factor; Membrane = 1.0000 45 | Bending = 1.0000 46 | Drill Stiffness Scale Factor = 1.0000 47 | 48 | 49 | 50 | 51 | 52 | 53 | !List material properties for material number 2 (used in section #3 in element #1) 54 | mplist,2 55 | 56 | 57 | LIST MATERIALS 2 TO 2 BY 1 58 | PROPERTY= ALL 59 | 60 | MATERIAL NUMBER 2 61 | 62 | TEMP EX 63 | 0.4000000E+11 64 | 65 | TEMP EY 66 | 0.1000000E+11 67 | 68 | TEMP EZ 69 | 0.1000000E+11 70 | 71 | TEMP GXY 72 | 0.5000000E+10 73 | 74 | TEMP GYZ 75 | 0.5000000E+10 76 | 77 | TEMP GXZ 78 | 0.5000000E+10 79 | 80 | TEMP PRXY 81 | 0.3000000 82 | 83 | TEMP PRYZ 84 | 0.3000000 85 | 86 | TEMP PRXZ 87 | 0.3000000 88 | 89 | 90 | 91 | 92 | 93 | 94 | !List strength values for material number 2 (used in section #3 in element #1) 95 | tblist,fcli,2 96 | 97 | 98 | LIST DATA TABLE FCLI FOR MATERIAL 2 99 | 100 | FC LIMIT (FCLI) Table For Material 2 101 | Stress Strength Limits 102 | 103 | 1 104 | Temps 0.0000000e+00 105 | XTEN 8.0000000e+08 106 | XCMP -7.0000000e+08 107 | YTEN 4.5000000e+07 108 | YCMP -1.5000000e+08 109 | ZTEN 4.5000000e+01 110 | ZCMP -1.5000000e+08 111 | XY 5.0000000e+07 112 | YZ 5.0000000e+07 113 | XZ 5.0000000e+07 114 | XYCP 0.0000000e+00 115 | YZCP 0.0000000e+00 116 | XZCP 0.0000000e+00 117 | XZIT 3.0000000e-01 118 | XZIC 2.5000000e-01 119 | YZIT 2.0000000e-01 120 | YZIC 2.0000000e-01 121 | GI/GII 0.0000000e+00 122 | ETA_L 0.0000000e+00 123 | ETA_T 0.0000000e+00 124 | ALPHA_0 0.0000000e+00 125 | 126 | 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /tests/elements/shell281/file.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/elements/shell281/file.rst -------------------------------------------------------------------------------- /tests/elements/shell281/test_shell281.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates. 2 | # SPDX-License-Identifier: MIT 3 | # 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | import os 24 | 25 | import pytest 26 | 27 | from ansys.mapdl import reader as pymapdl_reader 28 | 29 | path = os.path.dirname(os.path.abspath(__file__)) 30 | 31 | 32 | @pytest.fixture(scope="module") 33 | def rst(): 34 | rst_file = os.path.join(path, "file.rst") 35 | return pymapdl_reader.read_binary(rst_file) 36 | 37 | 38 | def test_materials(rst): 39 | materials = rst.materials 40 | material = materials[1] 41 | material["EX"] = 40000000000 42 | material["EY"] = 10000000000 43 | material["EZ"] = 10000000000 44 | material["PRXY"] = 0.3 45 | material["PRYZ"] = 0.3 46 | material["PRXZ"] = 0.3 47 | material["GXY"] = 5000000000 48 | material["GYZ"] = 5000000000 49 | material["GXZ"] = 5000000000 50 | 51 | 52 | def test_sections(rst): 53 | sections = rst.section_data 54 | assert isinstance(sections, dict) 55 | # assert isinstance(sections[3], np.ndarray) 56 | 57 | # TODO: add known result types for the section data 58 | -------------------------------------------------------------------------------- /tests/elements/solid186/test_solid186.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates. 2 | # SPDX-License-Identifier: MIT 3 | # 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | import os 24 | 25 | import numpy as np 26 | import pytest 27 | 28 | from ansys.mapdl import reader as pymapdl_reader 29 | from ansys.mapdl.reader import examples 30 | 31 | test_path = os.path.dirname(os.path.abspath(__file__)) 32 | 33 | 34 | @pytest.fixture(scope="module") 35 | def result(): 36 | return pymapdl_reader.read_binary(examples.rstfile) 37 | 38 | 39 | @pytest.fixture(scope="module") 40 | def archive(): 41 | return pymapdl_reader.Archive(examples.hexarchivefile) 42 | 43 | 44 | def test_geometry_elements(result, archive): 45 | r_elem = np.array(result.mesh.elem)[result._sidx_elem] 46 | assert np.allclose(r_elem, archive.elem) 47 | 48 | 49 | def test_geometry_nodes(result, archive): 50 | assert np.allclose(result.mesh.nodes[:, :3], archive.nodes) 51 | 52 | 53 | def test_geometry_nodenum(result, archive): 54 | assert np.allclose(result.mesh.nnum, archive.nnum) 55 | 56 | 57 | def test_results_displacement(result): 58 | textfile = os.path.join(test_path, "prnsol_u.txt") 59 | nnum, r_values = result.nodal_solution(0) 60 | a_values = np.loadtxt(textfile, skiprows=2)[:, 1:4] 61 | assert np.allclose(r_values, a_values) 62 | 63 | 64 | def test_results_stress(result): 65 | _, r_values = result.nodal_stress(0) 66 | textfile = os.path.join(test_path, "prnsol_s.txt") 67 | a_values = np.loadtxt(textfile, skiprows=2)[:, 1:] 68 | 69 | # ignore nan 70 | nanmask = ~np.isnan(r_values).any(1) 71 | assert np.allclose(r_values[nanmask], a_values, atol=1e-1) 72 | 73 | 74 | def test_results_pstress(result): 75 | r_nnum, r_values = result.principal_nodal_stress(0) 76 | textfile = os.path.join(test_path, "prnsol_s_prin.txt") 77 | a_values = np.loadtxt(textfile, skiprows=2)[:, 1:] 78 | 79 | # ignore nan 80 | nanmask = ~np.isnan(r_values).any(1) 81 | assert np.allclose(r_values[nanmask], a_values, atol=100) 82 | -------------------------------------------------------------------------------- /tests/elements/targe170/file.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/elements/targe170/file.rst -------------------------------------------------------------------------------- /tests/elements/targe170/test_targe170.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates. 2 | # SPDX-License-Identifier: MIT 3 | # 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | import os 24 | 25 | import numpy as np 26 | import pytest 27 | 28 | from ansys.mapdl import reader as pymapdl_reader 29 | 30 | path = os.path.dirname(os.path.abspath(__file__)) 31 | 32 | 33 | @pytest.fixture(scope="module") 34 | def rst(): 35 | rst_file = os.path.join(path, "file.rst") 36 | return pymapdl_reader.read_binary(rst_file) 37 | 38 | 39 | def test_tshape(rst): 40 | assert isinstance(rst.mesh.tshape, np.ndarray) 41 | assert 99 in rst.mesh.tshape 42 | assert 7 in rst.mesh.tshape 43 | assert len(rst.mesh.tshape) == 207 44 | 45 | 46 | def test_tshape_keyopt(rst): 47 | assert isinstance(rst.mesh.tshape_key, dict) 48 | assert 99 in rst.mesh.tshape_key.values() 49 | assert 7 in rst.mesh.tshape_key.values() 50 | assert len(rst.mesh.tshape_key) == 7 51 | assert 1 in rst.mesh.tshape_key 52 | assert 2 in rst.mesh.tshape_key 53 | assert 7 in rst.mesh.tshape_key 54 | 55 | assert rst.mesh.tshape_key[1] == 0 56 | assert rst.mesh.tshape_key[2] == 99 57 | assert rst.mesh.tshape_key[3] == 0 58 | assert rst.mesh.tshape_key[4] == 7 59 | assert rst.mesh.tshape_key[7] == 0 60 | 61 | 62 | def test_et_id(rst): 63 | assert isinstance(rst.mesh.et_id, np.ndarray) 64 | assert 1 in rst.mesh.et_id 65 | assert 2 in rst.mesh.et_id 66 | assert len(rst.mesh.et_id) == 207 67 | -------------------------------------------------------------------------------- /tests/elements/test_solid239_240.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates. 2 | # SPDX-License-Identifier: MIT 3 | # 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | import numpy as np 24 | import pytest 25 | 26 | from ansys.mapdl.reader import examples 27 | 28 | try: 29 | result = examples.downloads._download_solid239_240() 30 | except: 31 | result = None 32 | 33 | 34 | @pytest.mark.skipif(result is None, reason="Requires example files") 35 | def test_load(): 36 | assert np.any(result.grid.cells) 37 | assert np.any(result.grid.points) 38 | -------------------------------------------------------------------------------- /tests/test_beam44.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates. 2 | # SPDX-License-Identifier: MIT 3 | # 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | import os 24 | 25 | from ansys.mapdl import reader as pymapdl_reader 26 | 27 | TEST_PATH = os.path.dirname(os.path.abspath(__file__)) 28 | TESTFILES_PATH = os.path.join(TEST_PATH, "testfiles") 29 | BEAM44_RST = os.path.join(TESTFILES_PATH, "beam44.rst") 30 | 31 | 32 | def test_beam44(): 33 | result = pymapdl_reader.read_binary(BEAM44_RST) 34 | assert result.grid.n_cells 35 | assert result.grid.n_points 36 | nnum, disp = result.nodal_solution(0) 37 | assert nnum.size == result.grid.n_points 38 | assert disp.any() 39 | -------------------------------------------------------------------------------- /tests/test_binary_reader_cython.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates. 2 | # SPDX-License-Identifier: MIT 3 | # 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | import numpy as np 24 | import pyvista as pv 25 | import vtk 26 | 27 | from ansys.mapdl.reader import _binary_reader 28 | 29 | # test stress tensors from 30 | # Sx Sy Sz Sxy Syz Sxz 31 | stress = np.array( 32 | [-2.21786547, 99.05487823, -11.42874718, -4.69416809, 23.24783707, 0.4061397] 33 | ) 34 | 35 | # known results when rotating about a vector with angle 20 degrees 36 | # using apsg 37 | stress_rot_x = np.array( 38 | [-2.21786547, 71.18732452, 16.43880463, -4.54998303, 53.31763077, -1.22385347] 39 | ) 40 | 41 | stress_rot_y = np.array( 42 | [-3.03427238, 99.05487823, -10.61234027, 3.54015345, 23.45132099, -2.64919926] 43 | ) 44 | 45 | stress_rot_z = np.array( 46 | [12.64614819, 84.19086457, -11.42874718, -36.1443738, 21.9847289, -7.56958209] 47 | ) 48 | 49 | 50 | def test_tensor_rotation_x(): 51 | transform = vtk.vtkTransform() 52 | transform.RotateX(20) 53 | transform.Update() 54 | rot_matrix = transform.GetMatrix() 55 | # rot_matrix.Invert() # <-- this should not be necessary 56 | trans = pv.array_from_vtkmatrix(rot_matrix) 57 | 58 | s_test = stress.copy().reshape(1, -1) 59 | _binary_reader.tensor_arbitrary(s_test, trans) 60 | assert np.allclose(s_test, stress_rot_x) 61 | 62 | 63 | def test_tensor_rotation_y(): 64 | transform = vtk.vtkTransform() 65 | transform.RotateY(20) 66 | transform.Update() 67 | rot_matrix = transform.GetMatrix() 68 | # rot_matrix.Invert() # <-- this should not be necessary 69 | trans = pv.array_from_vtkmatrix(rot_matrix) 70 | 71 | s_test = stress.copy().reshape(1, -1) 72 | _binary_reader.tensor_arbitrary(s_test, trans) 73 | assert np.allclose(s_test, stress_rot_y) 74 | 75 | 76 | def test_tensor_rotation_z(): 77 | transform = vtk.vtkTransform() 78 | transform.RotateZ(20) 79 | transform.Update() 80 | rot_matrix = transform.GetMatrix() 81 | # rot_matrix.Invert() # <-- this should not be necessary 82 | trans = pv.array_from_vtkmatrix(rot_matrix) 83 | 84 | s_test = stress.copy().reshape(1, -1) 85 | _binary_reader.tensor_arbitrary(s_test, trans) 86 | assert np.allclose(s_test, stress_rot_z) 87 | -------------------------------------------------------------------------------- /tests/test_emat.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates. 2 | # SPDX-License-Identifier: MIT 3 | # 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | import os 24 | import pathlib 25 | 26 | import numpy as np 27 | import pytest 28 | 29 | from ansys.mapdl import reader as pymapdl_reader 30 | from ansys.mapdl.reader.emat import EmatFile 31 | 32 | test_path = os.path.dirname(os.path.abspath(__file__)) 33 | testfiles_path = os.path.join(test_path, "testfiles") 34 | emat_filename = os.path.join(testfiles_path, "file.emat") 35 | 36 | 37 | @pytest.fixture(scope="module") 38 | def emat(): 39 | emat_bin = pymapdl_reader.read_binary(emat_filename) 40 | assert isinstance(emat_bin, EmatFile) 41 | return emat_bin 42 | 43 | 44 | @pytest.fixture(scope="module") 45 | def emat_pathlib(): 46 | emat_bin = EmatFile(pathlib.Path(emat_filename)) 47 | return emat_bin 48 | 49 | 50 | def test_load_element(emat): 51 | dof_idx, element_data = emat.read_element(0) 52 | assert "stress" in element_data 53 | assert "mass" in element_data 54 | 55 | 56 | def test_global_applied_force(emat): 57 | force = emat.global_applied_force() 58 | assert np.allclose(force, 0) 59 | 60 | 61 | def test_eeqv(emat): 62 | assert np.allclose(np.sort(emat.eeqv), emat.enum) 63 | 64 | 65 | def test_neqv(emat): 66 | assert np.allclose(np.sort(emat.neqv), emat.nnum) 67 | 68 | 69 | class TestPathlibFilename: 70 | def test_pathlib_filename_property(self, emat_pathlib): 71 | assert isinstance(emat_pathlib.pathlib_filename, pathlib.Path) 72 | 73 | def test_filename_property_is_string(self, emat_pathlib): 74 | assert isinstance(emat_pathlib.filename, str) 75 | 76 | def test_filename_setter_pathlib(self, emat_pathlib): 77 | with pytest.raises(AttributeError): 78 | emat_pathlib.filename = pathlib.Path("dummy2") 79 | 80 | def test_filename_setter_string(self, emat_pathlib): 81 | with pytest.raises(AttributeError): 82 | emat_pathlib.filename = "dummy2" 83 | -------------------------------------------------------------------------------- /tests/test_full.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates. 2 | # SPDX-License-Identifier: MIT 3 | # 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | import os 24 | import pathlib 25 | 26 | import numpy as np 27 | import pytest 28 | import scipy 29 | 30 | from ansys.mapdl import reader as pymapdl_reader 31 | from ansys.mapdl.reader import examples 32 | from ansys.mapdl.reader.full import FullFile 33 | 34 | test_path = os.path.dirname(os.path.abspath(__file__)) 35 | testfiles_path = os.path.join(test_path, "testfiles") 36 | 37 | 38 | @pytest.fixture() 39 | def sparse_full_pathlib_full_file(): 40 | filename = os.path.join(testfiles_path, "sparse.full") 41 | return FullFile(pathlib.Path(filename)) 42 | 43 | 44 | @pytest.fixture() 45 | def sparse_full(): 46 | filename = os.path.join(testfiles_path, "sparse.full") 47 | return pymapdl_reader.read_binary(filename) 48 | 49 | 50 | def test_fullreader(): 51 | fobj = pymapdl_reader.read_binary(examples.fullfile) 52 | dofref, k, m = fobj.load_km() 53 | assert dofref.size 54 | assert k.size 55 | assert m.size 56 | 57 | 58 | def test_full_sparse(sparse_full): 59 | str_rep = str(sparse_full) 60 | assert "20.1" in str_rep 61 | assert "MAPDL Full File" in str_rep 62 | assert "345" in str_rep 63 | 64 | 65 | def test_full_sparse_k(sparse_full): 66 | assert isinstance(sparse_full.k, scipy.sparse.csc.csc_matrix) 67 | neqn = sparse_full._header["neqn"] 68 | assert sparse_full.k.shape == (neqn, neqn) 69 | 70 | 71 | def test_full_sparse_m(sparse_full): 72 | assert isinstance(sparse_full.m, scipy.sparse.csc.csc_matrix) 73 | neqn = sparse_full._header["neqn"] 74 | assert sparse_full.m.shape == (neqn, neqn) 75 | 76 | 77 | def test_full_sparse_dof_ref(sparse_full): 78 | # tests if sorted ascending 79 | assert (np.diff(sparse_full.dof_ref[:, 0]) >= 0).all() 80 | assert np.allclose(np.unique(sparse_full.dof_ref[:, 1]), [0, 1, 2]) 81 | 82 | 83 | def test_full_sparse_const(sparse_full): 84 | assert not sparse_full.const.any() 85 | 86 | 87 | def test_full_load_km(sparse_full): 88 | dof_ref, k, m = sparse_full.load_km() 89 | assert not (np.diff(dof_ref[:, 0]) >= 0).all() 90 | neqn = sparse_full._header["neqn"] 91 | assert k.shape == (neqn, neqn) 92 | assert m.shape == (neqn, neqn) 93 | 94 | # make sure internal values are not overwritten 95 | assert (np.diff(sparse_full.dof_ref[:, 0]) >= 0).all() 96 | 97 | 98 | def test_load_vector(sparse_full): 99 | assert not sparse_full.load_vector.any() 100 | 101 | 102 | class TestPathlibFilename: 103 | def test_pathlib_filename_property(self, sparse_full_pathlib_full_file): 104 | assert isinstance(sparse_full_pathlib_full_file.pathlib_filename, pathlib.Path) 105 | 106 | def test_filename_property_is_string(self, sparse_full_pathlib_full_file): 107 | assert isinstance(sparse_full_pathlib_full_file.filename, str) 108 | 109 | def test_filename_setter_pathlib(self, sparse_full_pathlib_full_file): 110 | with pytest.raises(AttributeError): 111 | sparse_full_pathlib_full_file.filename = pathlib.Path("dummy2") 112 | 113 | def test_filename_setter_string(self, sparse_full_pathlib_full_file): 114 | with pytest.raises(AttributeError): 115 | sparse_full_pathlib_full_file.filename = "dummy2" 116 | -------------------------------------------------------------------------------- /tests/testfiles/beam44.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/beam44.rst -------------------------------------------------------------------------------- /tests/testfiles/comp_hex_beam.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/comp_hex_beam.rst -------------------------------------------------------------------------------- /tests/testfiles/cyc12.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/cyc12.rst -------------------------------------------------------------------------------- /tests/testfiles/cyc12/RSYS0_ROTOR_PRNSOL_BFE.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/cyc12/RSYS0_ROTOR_PRNSOL_BFE.npz -------------------------------------------------------------------------------- /tests/testfiles/cyc12/RSYS0_ROTOR_PRNSOL_EPEL.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/cyc12/RSYS0_ROTOR_PRNSOL_EPEL.npz -------------------------------------------------------------------------------- /tests/testfiles/cyc12/RSYS0_ROTOR_PRNSOL_EPTH_COMP.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/cyc12/RSYS0_ROTOR_PRNSOL_EPTH_COMP.npz -------------------------------------------------------------------------------- /tests/testfiles/cyclic_reader/cyclic_v150.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/cyclic_reader/cyclic_v150.rst -------------------------------------------------------------------------------- /tests/testfiles/cyclic_reader/cyclic_v182.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/cyclic_reader/cyclic_v182.rst -------------------------------------------------------------------------------- /tests/testfiles/dist_rst/blade_stations/ans_xdisp.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/dist_rst/blade_stations/ans_xdisp.npz -------------------------------------------------------------------------------- /tests/testfiles/dist_rst/blade_stations/beam3_0.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/dist_rst/blade_stations/beam3_0.rst -------------------------------------------------------------------------------- /tests/testfiles/dist_rst/blade_stations/beam3_1.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/dist_rst/blade_stations/beam3_1.rst -------------------------------------------------------------------------------- /tests/testfiles/dist_rst/static/build.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates. 2 | # SPDX-License-Identifier: MIT 3 | # 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | """ 24 | These example files were built with the following script. 25 | """ 26 | 27 | import os 28 | 29 | import numpy as np 30 | import pyansys 31 | 32 | os.environ["I_MPI_SHM_LMT"] = "shm" # necessary on ubuntu and dmp 33 | mapdl = pyansys.launch_mapdl(nproc=4) 34 | 35 | mapdl.finish() 36 | mapdl.clear() 37 | 38 | # cylinder and mesh parameters 39 | # torque = 100 40 | radius = 2 41 | h_tip = 2 42 | height = 20 43 | elemsize = 1.0 44 | # pi = np.arccos(-1) 45 | force = 100 / radius 46 | pressure = force / (h_tip * 2 * np.pi * radius) 47 | 48 | mapdl.prep7() 49 | mapdl.et(1, 186) 50 | mapdl.et(2, 154) 51 | mapdl.r(1) 52 | mapdl.r(2) 53 | 54 | # Aluminum properties (or something) 55 | mapdl.mp("ex", 1, 10e6) 56 | mapdl.mp("nuxy", 1, 0.3) 57 | mapdl.mp("dens", 1, 0.1 / 386.1) 58 | mapdl.mp("dens", 2, 0) 59 | 60 | # Simple cylinder 61 | for i in range(4): 62 | mapdl.cylind(radius, "", "", height, 90 * (i - 1), 90 * i) 63 | 64 | mapdl.nummrg("kp") 65 | 66 | # mesh cylinder 67 | mapdl.lsel("s", "loc", "x", 0) 68 | mapdl.lsel("r", "loc", "y", 0) 69 | mapdl.lsel("r", "loc", "z", 0, height - h_tip) 70 | mapdl.lesize("all", elemsize * 2) 71 | mapdl.mshape(0) 72 | mapdl.mshkey(1) 73 | 74 | mapdl.esize(elemsize) 75 | mapdl.allsel("all") 76 | mapdl.vsweep("ALL") 77 | mapdl.csys(1) 78 | mapdl.asel("s", "loc", "z", "", height - h_tip + 0.0001) 79 | mapdl.asel("r", "loc", "x", radius) 80 | mapdl.local(11, 1) 81 | 82 | mapdl.csys(0) 83 | 84 | # mesh the surface with SURF154 85 | mapdl.aatt(2, 2, 2, 11) 86 | mapdl.amesh("all") 87 | mapdl.prep7() 88 | 89 | # plot elements 90 | # mapdl.eplot() 91 | 92 | # Apply tangential pressure 93 | mapdl.esel("S", "TYPE", "", 2) 94 | mapdl.sfe("all", 2, "pres", "", pressure) 95 | 96 | # Constrain bottom of cylinder/rod 97 | mapdl.asel("s", "loc", "z", 0) 98 | mapdl.nsla("s", 1) 99 | mapdl.d("all", "all") 100 | mapdl.allsel() 101 | 102 | # new solution 103 | mapdl.run("/SOLU") 104 | mapdl.antype("static", "new") 105 | # mapdl.eqslv('pcg', 1e-8) 106 | mapdl.solve() 107 | -------------------------------------------------------------------------------- /tests/testfiles/dist_rst/static/file.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/dist_rst/static/file.rst -------------------------------------------------------------------------------- /tests/testfiles/dist_rst/static/file0.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/dist_rst/static/file0.rst -------------------------------------------------------------------------------- /tests/testfiles/dist_rst/static/file1.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/dist_rst/static/file1.rst -------------------------------------------------------------------------------- /tests/testfiles/dist_rst/static/file2.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/dist_rst/static/file2.rst -------------------------------------------------------------------------------- /tests/testfiles/dist_rst/static/file3.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/dist_rst/static/file3.rst -------------------------------------------------------------------------------- /tests/testfiles/file.emat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/file.emat -------------------------------------------------------------------------------- /tests/testfiles/file.esav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/file.esav -------------------------------------------------------------------------------- /tests/testfiles/file.rth: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/file.rth -------------------------------------------------------------------------------- /tests/testfiles/hex_201.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/hex_201.rst -------------------------------------------------------------------------------- /tests/testfiles/is16.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/is16.npz -------------------------------------------------------------------------------- /tests/testfiles/is16.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/is16.rst -------------------------------------------------------------------------------- /tests/testfiles/link1.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/link1.rst -------------------------------------------------------------------------------- /tests/testfiles/materials/file.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/materials/file.rst -------------------------------------------------------------------------------- /tests/testfiles/materials/stress_lim.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/materials/stress_lim.rst -------------------------------------------------------------------------------- /tests/testfiles/nodal_reaction.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/nodal_reaction.npy -------------------------------------------------------------------------------- /tests/testfiles/para/para0.txt: -------------------------------------------------------------------------------- 1 | /NOPR 2 | *SET,AAS_MAPDL, 1.000000000000 3 | *SET,THISISALONGPARA, 20.00000000000 4 | *SET,_RETURN , 0.000000000000 5 | *SET,_STATUS , 1.000000000000 6 | /GO 7 | -------------------------------------------------------------------------------- /tests/testfiles/para/para2.txt: -------------------------------------------------------------------------------- 1 | /NOPR 2 | *DIM,JOBNAME ,STRING, 8, 1, 1, 3 | *SET,JOBNAME (1, 1, 1),'file ' 4 | *SET,_RETURN , 0.000000000000 5 | *SET,_SAV1 , 200.0000000000 6 | *SET,_SAV2 , 10000.00000000 7 | *SET,_SAV3 , 0.000000000000 8 | *SET,_SAV4 , 5.000000000000 9 | *SET,_STATUS , 1.000000000000 10 | *SET,_UIQR , 0.000000000000 11 | *SET,_Z1 , 0.000000000000 12 | *SET,_ZRD , 0.000000000000 13 | /GO 14 | -------------------------------------------------------------------------------- /tests/testfiles/rst/README.md: -------------------------------------------------------------------------------- 1 | ### Notes 2 | `beam_modal_cantilever.rst` comes from `examples/02-mapdl-examples/mapdl_3d_beam.py` 3 | -------------------------------------------------------------------------------- /tests/testfiles/rst/beam_modal_cantilever.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/rst/beam_modal_cantilever.rst -------------------------------------------------------------------------------- /tests/testfiles/rst/beam_static_bc.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/rst/beam_static_bc.rst -------------------------------------------------------------------------------- /tests/testfiles/rst/cyc_stress.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/rst/cyc_stress.npy -------------------------------------------------------------------------------- /tests/testfiles/rst/cyc_stress.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/rst/cyc_stress.rst -------------------------------------------------------------------------------- /tests/testfiles/shell181_2020R2.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/shell181_2020R2.rst -------------------------------------------------------------------------------- /tests/testfiles/shell181_2021R1.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/shell181_2021R1.rst -------------------------------------------------------------------------------- /tests/testfiles/shell281.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/shell281.rst -------------------------------------------------------------------------------- /tests/testfiles/shell63_beam4.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/shell63_beam4.rst -------------------------------------------------------------------------------- /tests/testfiles/sparse.full: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/sparse.full -------------------------------------------------------------------------------- /tests/testfiles/temp_dependent_results.rth: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/temp_dependent_results.rth -------------------------------------------------------------------------------- /tests/testfiles/temp_v13.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/temp_v13.npz -------------------------------------------------------------------------------- /tests/testfiles/temp_v13.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/temp_v13.rst -------------------------------------------------------------------------------- /tests/testfiles/vm1.dat: -------------------------------------------------------------------------------- 1 | /COM,ANSYS MEDIA REL. 182 (07/10/2017) REF. VERIF. MANUAL: REL. 182 2 | /VERIFY,VM1 3 | /PREP7 4 | /TITLE, VM1, STATICALLY INDETERMINATE REACTION FORCE ANALYSIS 5 | C*** STR. OF MATL., TIMOSHENKO, PART 1, 3RD ED., PAGE 26, PROB.10 6 | ANTYPE,STATIC ! STATIC ANALYSIS 7 | ET,1,LINK180 8 | SECTYPE,1,LINK 9 | SECDATA,1 ! CROSS SECTIONAL AREA (ARBITRARY) = 1 10 | MP,EX,1,30E6 11 | N,1 12 | N,2,,4 13 | N,3,,7 14 | N,4,,10 15 | E,1,2 ! DEFINE ELEMENTS 16 | EGEN,3,1,1 17 | D,1,ALL,,,4,3 ! BOUNDARY CONDITIONS AND LOADING 18 | F,2,FY,-500 19 | F,3,FY,-1000 20 | FINISH 21 | /SOLU 22 | OUTPR,BASIC,1 23 | OUTPR,NLOAD,1 24 | SOLVE 25 | FINISH 26 | /POST1 27 | NSEL,S,LOC,Y,10 28 | FSUM 29 | *GET,REAC_1,FSUM,,ITEM,FY 30 | NSEL,S,LOC,Y,0 31 | FSUM 32 | *GET,REAC_2,FSUM,,ITEM,FY 33 | 34 | *DIM,LABEL,CHAR,2 35 | *DIM,VALUE,,2,3 36 | LABEL(1) = 'R1, lb','R2, lb ' 37 | *VFILL,VALUE(1,1),DATA,900.0,600.0 38 | *VFILL,VALUE(1,2),DATA,ABS(REAC_1),ABS(REAC_2) 39 | *VFILL,VALUE(1,3),DATA,ABS(REAC_1 / 900) ,ABS( REAC_2 / 600) 40 | /OUT,vm1,vrt 41 | /COM 42 | /COM,------------------- VM1 RESULTS COMPARISON --------------------- 43 | /COM, 44 | /COM, | TARGET | Mechanical APDL | RATIO 45 | /COM, 46 | *VWRITE,LABEL(1),VALUE(1,1),VALUE(1,2),VALUE(1,3) 47 | (1X,A8,' ',F10.1,' ',F10.1,' ',1F5.3) 48 | /COM,---------------------------------------------------------------- 49 | /OUT 50 | FINISH 51 | *LIST,vm1,vrt 52 | -------------------------------------------------------------------------------- /tests/testfiles/vm1.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/vm1.rst -------------------------------------------------------------------------------- /tests/testfiles/vm273.dat: -------------------------------------------------------------------------------- 1 | /COM,ANSYS MEDIA REL. 150 (11/8/2013) REF. VERIF. MANUAL: REL. 150 2 | /VERIFY,VM273 3 | /TITLE,VM273, SHAPE MEMORY ALLOY WITH THERMAL EFFECT UNDER UNIAXIAL LOAD 4 | /COM, REF: FERDINANDO AURICHIO, LORENZA PETRINI 5 | /COM, "IMPROVEMENTS AND ALGORITHMICAL CONSIDERATIONS ON A RECENT 6 | /COM, THREE-DIMENSIONAL MODEL DESCRBING STRESS-INDUCED SOLID 7 | /COM, PHASE TRANSFORMATIONS" 8 | /COM, INT. J. NUMER. METH. ENGNG. 55 (2002) 1255-1284 9 | /COM, 10 | /COM, TWO CASES ARE COMPUTED: (1) BODY TEMPERATURE T=285.15K 11 | /COM, (2) BODY TEMPERATURE T=253.15K 12 | /COM, 13 | /COM, CASE ONE: WITH BODY TEMPERATURE T=285.15K 14 | /PREP7 15 | ET,1,SOLID185 !* 3D 8-NODE STRUCTURAL SOLID ELEMENT 16 | 17 | /COM, DEFINING SMA MATERIAL PROPERTIES 18 | MP,EX,1,70E3 !MPA, [AUSTENITE MODULUS] 19 | MP,PRXY,1,0.33 20 | 21 | C1=500 !MPA [HARDENING PARAMETER] 22 | C2=253.15 !K [REF TEMP] 23 | C3=45 !MPA [ELASTIC LIMIT] 24 | C4=7.5 !MPA [TEMPERATURE SCALING PARAMETER] 25 | C5=0.03 ![MAX TRANSFORMATION STRAIN] 26 | C6=70E3 !MPA, [MARTENSITE MODULUS] 27 | C7=0 ! M = 0, SYMMETRICAL BEHAVIOR 28 | 29 | TB,SMA,1,,7,MEFF 30 | TBDATA,1,C1,C2,C3,C4,C5,C6,C7 31 | 32 | BLOCK,0.00,10.00,0.00,10.00,0.00,10.00 33 | ESIZE,10 34 | TYPE,1 35 | MAT,1 36 | VMESH,1 37 | 38 | NSEL,S,LOC,X 39 | D,ALL,UX 40 | NSEL,S,LOC,Y 41 | D,ALL,UY 42 | NSEL,S,LOC,Z 43 | D,ALL,UZ 44 | NSEL,ALL 45 | BFUNIF,TEMP,285.15 46 | FINISH 47 | /SOLU 48 | NROPT,UNSYM 49 | OUTRES,ALL,ALL 50 | NSUBST,50,50,50 51 | TIME,1 52 | NSEL,S,LOC,Y,10 53 | D,ALL,UY,0.35 ! TENSION LOADING 54 | ALLSEL 55 | /OUT,SCRATCH 56 | SOLVE 57 | 58 | TIME,2 59 | NSEL,S,LOC,Y,10 60 | D,ALL,UY,0.00 ! UNLOADING 61 | ALLSEL 62 | SOLVE 63 | 64 | TIME,3 65 | NSEL,S,LOC,Y,10 66 | D,ALL,UY,-0.35 ! COMPRESSION LOADING 67 | ALLSEL 68 | SOLVE 69 | 70 | TIME,4 71 | NSEL,S,LOC,Y,10 72 | D,ALL,UY,0.00 ! UNLOADING 73 | ALLSEL 74 | SOLVE 75 | FINISH 76 | 77 | /POST26 78 | ESOL,2,1,NODE(10,10,0),S,Y !* Y STRESS AT NODE(10,10,0) 79 | ESOL,3,1,NODE(10,10,0),EPEL,Y !* ELASTIC STRAIN AT NODE(10,10,0) 80 | ESOL,4,1,NODE(10,10,0),EPPL,Y !* PLASTIC STRAIN AT NODE(10,10,0) 81 | ADD,5,3,4 !* TOTAL STRAIN AT NODE(10,10,0) 82 | PROD,6,5, , ,STRAIN, , ,100 !* PERCENT TOTAL STRAIN 83 | XVAR,6 84 | /AXLAB,X,Strain[%] 85 | /AXLAB,Y,Stress [MPa] 86 | /YRANGE,-800,800 !* SET Y-RANGE 87 | /XRANGE,-4,4 !* SET X-RANGE 88 | PLVAR,2 !* PLOT TOTAL STRAIN VS Y STRESS 89 | PRVAR,3,4,2 90 | FINISH 91 | /POST1 92 | /OUT, 93 | SET, , , , ,0.16 94 | *GET,S_SAS,NODE,NODE(10,10,0),S,Y 95 | SET, , , , ,0.84 96 | *GET,S_FAS,NODE,NODE(10,10,0),S,Y 97 | SET, , , , ,1.20 98 | *GET,S_SSA,NODE,NODE(10,10,0),S,Y 99 | SET, , , , ,1.90 100 | *GET,S_FSA,NODE,NODE(10,10,0),S,Y 101 | R1 = S_SAS/345 102 | R2 = S_FAS/367 103 | R3 = S_SSA/258 104 | R4 = S_FSA/236 105 | *DIM,LABEL,CHAR,4,2 106 | *DIM,VALUE,,4,3 107 | LABEL(1,1) = 'S','S','S','S' 108 | LABEL(1,2) = '-SAS','-FAS','-SSA','-FSA' 109 | *VFILL,VALUE(1,1),DATA,345,367,258,236 110 | *VFILL,VALUE(1,2),DATA,S_SAS,S_FAS,S_SSA,S_FSA 111 | *VFILL,VALUE(1,3),DATA,R1,R2,R3,R4 112 | SAVE, TABLE_1 113 | FINISH 114 | 115 | /CLEAR,NOSTART ! *CLEAR DATABASE FOR SECOND SOLUTION 116 | /COM, CASE TWO: WITH BODY TEMPERATURE T=253.15K 117 | /PREP7 118 | ET,1,SOLID185 !* 3D 8-NODE STRUCTURAL SOLID ELEMENT 119 | 120 | /COM, DEFINING SMA MATERIAL PROPERTIES 121 | MP,EX,1,70E3 !MPA, [AUSTENITE MODULUS] 122 | MP,PRXY,1,0.33 123 | 124 | C1=500 !MPA [HARDENING PARAMETER] 125 | C2=253.15 !K [REF TEMP] 126 | C3=45 !MPA [ELASTIC LIMIT] 127 | C4=7.5 !MPA 128 | C5=0.03 ! [MAX TRANSFORMATION STRAIN] 129 | C6=70E3 !MPA, [MARTENSITE MODULUS] 130 | C7=0 ! M = 0 131 | 132 | TB,SMA,1,,7,MEFF 133 | TBDATA,1,C1,C2,C3,C4,C5,C6,C7 134 | 135 | BLOCK,0.00,10.00,0.00,10.00,0.00,10.00 136 | ESIZE,10 137 | TYPE,1 138 | MAT,1 139 | VMESH,1 140 | 141 | NSEL,S,LOC,X 142 | D,ALL,UX 143 | NSEL,S,LOC,Y 144 | D,ALL,UY 145 | NSEL,S,LOC,Z 146 | D,ALL,UZ 147 | NSEL,ALL 148 | BFUNIF,TEMP,253.15 149 | FINISH 150 | /SOLU 151 | NROPT,UNSYM 152 | OUTRES,ALL,ALL 153 | NSUBST,50,50,50 154 | 155 | TIME,1 156 | NSEL,S,LOC,Y,10 157 | D,ALL,UY,0.35 ! TENSION LOADING 158 | ALLSEL 159 | /OUT,SCRATCH 160 | SOLVE 161 | 162 | TIME,2 163 | NSEL,S,LOC,Y,10 164 | D,ALL,UY,0.00 ! UNLOADING 165 | ALLSEL 166 | SOLVE 167 | 168 | TIME,3 169 | NSEL,S,LOC,Y,10 170 | D,ALL,UY,-0.35 ! COMPRESSION LOADING 171 | ALLSEL 172 | SOLVE 173 | 174 | TIME,4 175 | NSEL,S,LOC,Y,10 176 | D,ALL,UY,0.00 ! UNLOADING 177 | ALLSEL 178 | SOLVE 179 | FINISH 180 | 181 | /POST26 182 | ESOL,2,1,NODE(10,10,0),S,Y !* Y STRESS AT NODE(10,10,0) 183 | ESOL,3,1,NODE(10,10,0),EPEL,Y !* ELASTIC STRAIN AT NODE(10,10,0) 184 | ESOL,4,1,NODE(10,10,0),EPPL,Y !* PLASTIC STRAIN AT NODE(10,10,0) 185 | ADD,5,3,4 !* TOTAL STRAIN AT NODE(10,10,0) 186 | PROD,6,5, , ,STRAIN, , ,100 !* PERCENT TOTAL STRAIN 187 | XVAR,6 188 | /AXLAB,X,Strain[%] 189 | /AXLAB,Y,Stress [MPa] 190 | /YRANGE,-800,800 !* SET Y-RANGE 191 | /XRANGE,-4,4 !* SET X-RANGE 192 | PLVAR,2 !* PLOT TOTAL STRAIN VS YSTRESS 193 | PRVAR,3,4,2 194 | FINISH 195 | /POST1 196 | /OUT, 197 | SET, , , , ,0.04 198 | *GET,S_SAS,NODE,NODE(10,10,0),S,Y 199 | SET, , , , ,0.72 200 | *GET,S_FAS,NODE,NODE(10,10,0),S,Y 201 | SET, , , , ,1.32 202 | *GET,S_SSA,NODE,NODE(10,10,0),S,Y 203 | R1 = S_SAS/54.6 204 | R2 = S_FAS/74.1 205 | R3 = S_SSA/(-37.1) 206 | *DIM,LABEL,CHAR,3,2 207 | *DIM,VALUE,,3,3 208 | LABEL(1,1) = 'S','S','S' 209 | LABEL(1,2) = '-SAS','-FAS','-SSA' 210 | *VFILL,VALUE(1,1),DATA,54.6,74.1,-37.1 211 | *VFILL,VALUE(1,2),DATA,S_SAS,S_FAS,S_SSA 212 | *VFILL,VALUE(1,3),DATA,R1,R2,R3 213 | SAVE, TABLE_2 214 | RESUME,TABLE_1 215 | FINISH 216 | /COM 217 | /OUT,vm273,vrt 218 | /COM,------------------- VM273 RESULTS COMPARISON -------------- 219 | /COM, 220 | /COM, | TARGET | Mechanical APDL | RATIO 221 | /COM, 222 | /COM,RESULTS WITH BODY TEMPERATURE T=285.15K 223 | *VWRITE,LABEL(1,1),LABEL(1,2),VALUE(1,1),VALUE(1,2),VALUE(1,3) 224 | (1X,A1,A8,' ',F10.3,' ',1F14.3,' ',1F15.3) 225 | /NOPR 226 | RESUME,TABLE_2 227 | /GOPR 228 | /COM,RESULTS WITH BODY TEMPERATURE T=253.15K 229 | *VWRITE,LABEL(1,1),LABEL(1,2),VALUE(1,1),VALUE(1,2),VALUE(1,3) 230 | (1X,A1,A8,' ',F10.3,' ',1F14.3,' ',1F15.3) 231 | 232 | /COM,----------------------------------------------------------- 233 | /OUT 234 | FINISH 235 | *LIST,vm273,vrt 236 | -------------------------------------------------------------------------------- /tests/testfiles/vol_test.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansys/pymapdl-reader/362631aac4703dad8cc203110518c0d3194d6ea5/tests/testfiles/vol_test.rst -------------------------------------------------------------------------------- /tests/unused_test_examples.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates. 2 | # SPDX-License-Identifier: MIT 3 | # 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | import os 24 | import platform 25 | import warnings 26 | 27 | import pytest 28 | from pyvista.plotting import system_supports_plotting 29 | 30 | from ansys.mapdl.reader import examples 31 | 32 | HAS_IMAGEIO = True 33 | try: 34 | import imageio_ffmpeg # noqa: F401 35 | except ImportError: 36 | HAS_IMAGEIO = False 37 | 38 | try: 39 | shaft = examples.download_shaft_modal() 40 | except: 41 | warnings.warn("Unable to execute ``examples.download_shaft_modal``") 42 | shaft = None 43 | 44 | 45 | IS_MAC = platform.system() == "Darwin" 46 | skip_plotting = pytest.mark.skipif( 47 | not system_supports_plotting() or IS_MAC, reason="Requires active X Server" 48 | ) 49 | skip_no_shaft = pytest.mark.skipif(shaft is None, reason="Requires example file") 50 | 51 | 52 | @skip_plotting 53 | def test_show_hex_archive(): 54 | examples.show_hex_archive(off_screen=True) 55 | 56 | 57 | def test_load_result(): 58 | examples.load_result() 59 | 60 | 61 | @skip_plotting 62 | def test_show_displacement(): 63 | examples.show_displacement(off_screen=True) 64 | 65 | 66 | @skip_plotting 67 | def test_show_stress(): 68 | examples.show_stress(off_screen=True) 69 | 70 | 71 | def test_load_km(): 72 | examples.load_km() 73 | 74 | 75 | @skip_plotting 76 | def test_show_cell_qual(): 77 | examples.show_cell_qual(meshtype="tet", off_screen=True) 78 | examples.show_cell_qual(meshtype="hex", off_screen=True) 79 | 80 | 81 | @skip_plotting 82 | @skip_no_shaft 83 | @pytest.mark.skipif(not HAS_IMAGEIO, reason="Requires imageio_ffmpeg") 84 | def test_shaft_animate(tmpdir): 85 | filename = str(tmpdir.mkdir("tmpdir").join("tmp.mp4")) 86 | shaft.animate_nodal_solution( 87 | 5, 88 | element_components="SHAFT_MESH", 89 | comp="norm", 90 | loop=False, 91 | n_frames=10, 92 | show_edges=True, 93 | off_screen=True, 94 | movie_filename=filename, 95 | ) 96 | 97 | 98 | @skip_plotting 99 | @skip_no_shaft 100 | def test_shaft_nodal_solution_ncomp(tmpdir): 101 | filename = str(tmpdir.mkdir("tmpdir").join("tmp.mp4")) 102 | shaft.plot_nodal_solution( 103 | 5, node_components="N_AREA_BC1", sel_type_all=False, off_screen=True 104 | ) 105 | 106 | 107 | @skip_plotting 108 | @skip_no_shaft 109 | def test_shaft_plot_screenshot(tmpdir): 110 | filename = str(tmpdir.mkdir("tmpdir").join("tmp.png")) 111 | shaft.plot_nodal_solution(0, off_screen=True, screenshot=filename) 112 | assert os.path.isfile(filename) 113 | -------------------------------------------------------------------------------- /tests/unused_test_shell281.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates. 2 | # SPDX-License-Identifier: MIT 3 | # 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | """ 24 | In PyAnsys I type 25 | ``` 26 | test_result = pyansys.read_binary('sample.rst') 27 | estress,elem,enode = test_result.element_stress(0) 28 | print(estress[23]) 29 | print(enode[23]) 30 | ``` 31 | And get 32 | ``` 33 | [[nan nan nan nan nan nan] 34 | [nan nan nan nan nan nan] 35 | [nan nan nan nan nan nan] 36 | [nan nan nan nan nan nan]] 37 | [ 1 82 92 8] 38 | ``` 39 | 40 | And in Ansys I get 41 | ``` 42 | ELEMENT= 24 SHELL281 43 | NODE SX SY SZ SXY SYZ SXZ 44 | 1 -50.863 -0.63898E-030 -215.25 -0.18465E-015 0.10251E-013 -47.847 45 | 82 13.635 -0.74815E-030 -178.71 -0.21958E-015 0.11999E-013 17.232 46 | 92 -7.1801 -0.84355E-030 -213.77 -0.56253E-015 0.13214E-013 2.0152 47 | 8 -47.523 -0.96156E-030 -204.12 -0.30574E-014 0.12646E-013 2.4081 48 | 1 107.75 0.13549E-029 454.30 0.45391E-015-0.21674E-013 100.34 49 | 82 -28.816 0.15515E-029 372.47 0.38337E-015-0.24955E-013 -35.077 50 | 92 14.454 0.16547E-029 429.43 0.80716E-015-0.26217E-013 1.2719 51 | 8 94.254 0.19148E-029 409.31 0.59899E-014-0.25281E-013 -3.5690 52 | ``` 53 | 54 | It would also be really useful to be able to read the Nodal Forces and Moment from the Elemental Solution using the: 55 | 56 | element_solution_data(0,'ENF',sort=True) 57 | From PyAnsys for element 24: 58 | ``` 59 | array([ 7.1140683e-01, 2.5775826e-06, 1.8592998e+00, 1.7531972e-03, 60 | -5.4216904e-12, -6.6381943e-04, 7.8414015e-02, 4.7199319e-06, 61 | -1.2074181e+00, -9.0049638e-04, -5.2645028e-12, -3.2152122e-05, 62 | 7.3660083e-02, 2.5742002e-05, -1.1951995e+00, -2.7250897e-04, 63 | 1.0039868e-12, 1.5112829e-04, -1.9362889e-01, 4.7199323e-06, 64 | 1.3849777e+00, 6.4305059e-05, 2.9884493e-12, -2.2116321e-04, 65 | 3.0604819e-02, -4.8676171e-05, -1.0389121e-01, 5.7917450e-16, 66 | -2.7263033e-25, 4.0045388e-17, -8.5023224e-02, 2.9796447e-05, 67 | -5.3827515e+00, -2.2202423e-03, 3.8493188e-11, 7.6806801e-04, 68 | -8.5418850e-01, 2.4989351e-06, -3.3126956e-01, -9.2828198e-04, 69 | 6.3002242e-11, 8.8052053e-05, 2.3875487e-01, -2.1378659e-05, 70 | 4.9762526e+00, 2.5969518e-03, 5.0141464e-11, -1.8303801e-04], 71 | dtype=float32)]) 72 | ``` 73 | And From Ansys: 74 | ``` 75 | ELEM= 24 FX FY FZ 76 | 1 0.71141 0.25776E-005 1.8593 77 | 82 0.78414E-001 0.47199E-005 -1.2074 78 | 92 0.73660E-001 0.25742E-004 -1.1952 79 | 8 -0.19363 0.47199E-005 1.3850 80 | 83 0.30605E-001-0.48676E-004-0.10389 81 | 86 -0.85023E-001 0.29796E-004 -5.3828 82 | 93 -0.85419 0.24989E-005-0.33127 83 | 9 0.23875 -0.21379E-004 4.9763 84 | 85 | ELEM= 24 MX MY MZ 86 | 1 0.17532E-002-0.54217E-011-0.66382E-003 87 | 82 -0.90050E-003-0.52645E-011-0.32152E-004 88 | 92 -0.27251E-003 0.10040E-011 0.15113E-003 89 | 8 0.64305E-004 0.29884E-011-0.22116E-003 90 | 83 0.57917E-015-0.27263E-024 0.40045E-016 91 | 86 -0.22202E-002 0.38493E-010 0.76807E-003 92 | 93 -0.92828E-003 0.63002E-010 0.88052E-004 93 | 9 0.25970E-002 0.50141E-010-0.18304E-003 94 | """ 95 | 96 | import os 97 | 98 | import numpy as np 99 | import pyansys 100 | 101 | # from pyansys.examples import hexarchivefile 102 | # from pyansys.examples import rstfile 103 | # from pyansys.examples import fullfile 104 | 105 | try: 106 | __file__ 107 | test_path = os.path.dirname(os.path.abspath(__file__)) 108 | testfiles_path = os.path.join(test_path, "testfiles") 109 | except: 110 | testfiles_path = "/home/alex/afrl/python/source/pyansys/tests/testfiles" 111 | 112 | 113 | ANSYS_ELEM = [ 114 | [0.17662e-07, 79.410, -11.979, -0.11843e-02, 4.8423, -0.72216e-04], 115 | [0.20287e-07, 91.212, 27.364, -0.13603e-02, 4.8423, -0.72216e-04], 116 | [0.20287e-07, 91.212, 27.364, -0.13603e-02, -4.8423, 0.72216e-04], 117 | [0.17662e-07, 79.410, -11.979, -0.11843e-02, -4.8423, 0.72216e-04], 118 | ] 119 | 120 | ANSYS_NODE = [ 121 | [0.20287e-07, 91.212, 27.364, -0.13603e-02, 4.8423, -0.72216e-04], 122 | [0.17662e-07, 79.410, -11.979, -0.11843e-02, 4.8423, -0.72216e-04], 123 | [0.17662e-07, 79.410, -11.979, -0.11843e-02, -4.8423, 0.72216e-04], 124 | [0.20287e-07, 91.212, 27.364, -0.13603e-02, -4.8423, 0.72216e-04], 125 | ] 126 | 127 | result_file = os.path.join(testfiles_path, "shell281.rst") 128 | test_result = pyansys.read_binary(result_file, valid_element_types=["281"]) 129 | 130 | # estress, elem, enode = test_result.element_stress(0, in_element_coord_sys=False) 131 | estress, elem, enode = test_result.element_stress(0, in_element_coord_sys=True) 132 | print(estress[23][:4]) 133 | 134 | # debug 135 | np.any(np.isclose(-50.863, estress[23])) 136 | np.isclose(-50.863, estress[23]).any(1).nonzero() 137 | # np.isclose(-50.863, table).any(1).nonzero() 138 | 139 | 140 | f.seek(400284 - 8) 141 | table = read_table(f, "f") 142 | # f.seek(400284) 143 | ncomp = 6 144 | nodstr = 4 145 | nl = 7 146 | # nread = nl*3*nodstr*ncomp 147 | # table = read_table(f, 'f', get_nread=False, nread=nread) 148 | print((np.isclose(-50.863, table).nonzero()[0] - 1) / table.size) 149 | 150 | # print(read_table(f, 'i', get_nread=False, nread=1)) 151 | 152 | 153 | # print(table[:10]) 154 | 155 | # # elem, res = test_result.element_solution_data(0, 'ENF', sort=True) 156 | # # print(res[23].reshape(8, -1)) 157 | 158 | 159 | # # fseek(cfile, (ele_table + PTR_ENS_IDX)*4, SEEK_SET) 160 | # # fread(&ptrENS, sizeof(int32_t), 1, cfile) 161 | 162 | # # fseek(cfile, (ele_table + ptrENS)*4, SEEK_SET) 163 | # # fread(&ele_data_arr[c, 0], sizeof(float), nread, cfile) 164 | 165 | # # number of items in this record is NL*3*nodstr*ncomp 166 | # ncomp = 6 167 | # nodstr = 4 168 | --------------------------------------------------------------------------------