ansys / pymapdl-reader

Legacy binary interface to MAPDL binary files.
https://reader.docs.pyansys.com
MIT License
47 stars 23 forks source link

save_as_vtk fails for RST file (ansys.mapdl.reader) #240

Open MichaelZimmermannMNE opened 1 year ago

MichaelZimmermannMNE commented 1 year ago

Before submitting the issue

Description of the bug

I have a rst file (size approx 2 GB) for which I would like to export the results to VTK/VTU file format. The rst file contains 4 static loadcases which where solved with Ansys MAPDL 18.x.

I can read the RST file and plot results. Yet, result.save_as_vtk() leads to an exception in PyVista as follows: ValueError: data length of (151876) != required length (161175)

The demo files provided by PyAnsys work well and export the data to VTK/VTU format as expected.

Steps To Reproduce

Code as follows:

rName = "c:\\_workspaces\\221206-Rev00.rst"
rOut = "c:\\_tmp\\result.vtu"
rst = reader.read_binary(rName)
rst.plot_nodal_displacement(0)
rst.plot_principal_nodal_stress(0,'SEQV')
rst.save_as_vtk(rOut)

leads to the following error:

 File "C:\\scratch.py", line 13, in <module>
    rst.save_as_vtk(rOut)
  File "C:\...\venv\lib\site-packages\ansys\mapdl\reader\rst.py", line 3363, in save_as_vtk
    grid.point_data['Nodal Solution {:d}'.format(i)] = val
  File "C:\...\venv\lib\site-packages\pyvista\core\datasetattributes.py", line 227, in __setitem__
    self.set_array(value, name=key)
  File "C:\...\venv\lib\site-packages\pyvista\core\datasetattributes.py", line 613, in set_array
    vtk_arr = self._prepare_array(data, name, deep_copy)
  File "C:\...\venv\lib\site-packages\pyvista\core\datasetattributes.py", line 769, in _prepare_array
    raise ValueError(f'data length of ({data.shape[0]}) != required length ({array_len})')
ValueError: data length of (151876) != required length (161175)

Which Operating System are you using?

Windows

Which Python version are you using?

3.9

PyMAPDL Report

Show the Report! ```text PyMAPDL Software and Environment Report Packages Requirements ********************* Core packages ------------- ansys.mapdl.core : 0.63.4 numpy : 1.24.1 appdirs : 1.4.4 scipy : 1.10.0 grpc : Package not found ansys.api.mapdl.v0 : Package not found ansys.mapdl.reader : 0.52.6 google.protobuf : Package not found Optional packages ----------------- matplotlib : 3.6.2 pyvista : 0.37.0 pyiges : 0.2.1 tqdm : 4.64.1 ```

Installed packages

Show the installed packages! ```text acoustics==0.2.6 adodbapi==2.6.1.3 affine==2.3.0 aiofiles==0.8.0 aiohttp==3.8.1 aiosignal==1.2.0 aiosqlite==0.17.0 alabaster==0.7.12 alembic==1.7.5 algopy==0.5.7 altair==4.2.0 altair-data-server==0.4.1 altair-transform==0.2.0 altair-widgets==0.2.2 altgraph==0.17.2 amply==0.1.4 aniso8601==7.0.0 ansiwrap==0.8.4 ansys-api-mapdl==0.5.1 ansys-api-platform-instancemanagement==1.0.0b3 ansys-corba==0.1.0 ansys-mapdl-core==0.63.4 ansys-mapdl-reader==0.52.6 ansys-platform-instancemanagement==1.0.2 anyio==3.5.0 apgl==0.8.1 appdirs==1.4.4 argon2-cffi==21.3.0 argon2-cffi-bindings==21.2.0 arrow==1.2.1 asciitree==0.3.3 asgi-csrf==0.9 asgiref==3.4.1 asn1crypto==1.4.0 asteval==0.9.26 astor==0.8.1 astroid==2.9.3 astroML==1.0.1 astropy==4.3.1 async-generator==1.10 async-timeout==4.0.2 atomicwrites==1.4.0 attrs==21.4.0 audioread==2.1.9 autopep8==1.6.0 Babel==2.9.1 backcall==0.2.0 backports-abc==0.5 baresql==0.7.6 base58==2.1.1 bcrypt==3.2.0 beautifulsoup4==4.10.0 binaryornot==0.4.4 black==21.12b0 bleach==4.1.0 blinker==1.4 blis==0.7.5 blosc==1.10.6 bokeh==2.4.2 botorch==0.4.0 Bottleneck==1.3.2 bqplot==0.12.32 branca==0.4.2 brewer2mpl==1.4.1 Brotli==1.0.9 cachelib==0.5.0 cachetools==5.0.0 Cartopy==0.20.2 catalogue==2.0.6 certifi==2022.12.7 cffi==1.15.0 cftime==1.5.1.1 chardet==4.0.0 charset-normalizer==2.1.1 click==7.1.2 click-default-group==1.2.2 click-plugins==1.1.1 cligj==0.7.2 cloudpickle==2.0.0 clr-loader==0.1.7 clrmagic==0.0.1a2 colorama==0.4.6 colorcet==3.0.0 colorlog==6.6.0 configobj==5.0.6 contourpy==1.0.6 cookiecutter==1.7.3 coverage==6.2 cramjam==2.5.0 cryptography==35.0.0 csvs-to-sqlite==1.3 cvxopt==1.2.7 cvxpy==1.1.18 cx-Freeze==6.9 cx-Logging==3.0 cycler==0.11.0 cymem==2.0.6 Cython==0.29.26 cytoolz==0.11.0 dash==2.0.0 dash-core-components==2.0.0 dash-html-components==2.0.0 dash-table==5.0.0 dask==2022.1.0 dask-glm==0.2.0 dask-image==2021.12.0 dask-labextension==5.2.0 dask-ml==2021.11.30 dask-searchcv==0.2.0 databases==0.4.1 datasette==0.60 datasette-graphql==1.5 datashader==0.13.0 datashape==0.5.2 dateparser==1.1.0 db.py==0.5.4b1 debugpy==1.5.1 decorator==4.4.2 defusedxml==0.7.1 Deprecated==1.2.13 deprecation==2.1.0 descartes==1.1.0 diff-match-patch==20200713 distlib==0.3.4 distributed==2022.1.0 docopt==0.6.2 docrepr==0.1.1 docutils==0.17.1 easydev==0.12.0 ecos==2.0.10 emcee==3.1.1 entrypoints==0.3 enum34==1.1.10 et-xmlfile==1.1.0 fast-histogram==0.10 fastai==2.5.3 fastapi==0.71.0 fastcore==1.3.27 fastdownload==0.0.5 fasteners==0.17.2 fastparquet==0.7.2 fastprogress==1.0.0 feather-format==0.4.1 filelock==3.4.2 Fiona==1.8.20 flake8==4.0.1 Flask==2.0.2 flask-accepts==0.18.4 Flask-Compress==1.10.1 Flask-Mail==0.9.1 flask-restx==0.5.1 Flask-Session==0.4.0 Flask-SQLAlchemy==2.5.1 flaskerize==0.14.0 flatbuffers==2.0 flit==3.6.0 flit_core==3.6.0 folium==0.12.1 fonttools==4.38.0 FormEncode==2.0.1 formlayout==1.2.1a1 frozenlist==1.2.0 fs==2.4.14 fsspec==2022.1.0 future==0.18.2 fuzzywuzzy==0.18.0 GDAL==3.4.1 geographiclib==1.52 geomdl==5.3.1 geopandas==0.10.2 geopy==2.2.0 geoviews==1.9.3 gitdb==4.0.9 GitPython==3.1.26 gmpy2==2.1.2 googleapis-common-protos==1.57.1 gpytorch==1.5.1 graphene==2.1.9 graphql-core==2.3.1 graphql-relay==2.0.1 great-expectations==0.13.41 greenlet==1.1.2 grpcio==1.51.1 guidata==2.0.3 guiqwt==4.0.1 h11==0.12.0 h2==4.1.0 h5py==3.6.0 HeapDict==1.0.1 holoviews==1.14.7 hpack==4.0.0 html5lib==1.1 httpcore==0.14.5 httpie==2.6.0 httpx==0.21.3 hupper==1.10.3 husl==4.0.3 hvplot==0.7.3 hypercorn==0.13.2 hyperframe==6.0.1 hypothesis==6.35.0 idlex==1.22 idna==3.4 imageio==2.23.0 imageio-ffmpeg==0.4.2 imagesize==1.3.0 imbalanced-learn==0.9.0 importlib-metadata==6.0.0 inflection==0.5.1 iniconfig==1.1.1 intake==0.6.4 intervaltree==3.0.2 ipycanvas==0.10.2 ipykernel==6.7.0 ipyleaflet==0.14.0 ipympl==0.8.6 ipython==7.31.0 ipython-genutils==0.2.0 ipython-sql==0.4.1b1 ipywidgets==7.6.5 isort==5.10.1 itsdangerous==2.0.1 janus==1.0.0 jedi==0.18.1 jellyfish==0.9.0 Jinja2==3.0.3 jinja2-time==0.2.0 joblib==1.1.0 json5==0.9.6 jsonpatch==1.32 jsonpointer==2.2 jsonschema==4.4.0 julia==0.5.7 jupyter==1.0.0 jupyter-bokeh==3.0.4 jupyter-client==7.1.1 jupyter-console==6.4.0 jupyter-core==4.9.1 jupyter-lsp==1.5.1 jupyter-packaging==0.11.1 jupyter-server==1.13.4 jupyter-server-mathjax==0.2.3 jupyter-server-proxy==3.2.0 jupyter-sphinx==0.3.2 jupyterlab==3.2.8 jupyterlab-git==0.34.2 jupyterlab-launcher==0.13.1 jupyterlab-lsp==3.10.0 jupyterlab-pygments==0.1.2 jupyterlab-server==2.10.3 jupyterlab-widgets==1.0.2 keyring==23.5.0 kiwisolver==1.4.4 langcodes==3.3.0 lazy-object-proxy==1.7.1 llvmlite==0.38.0 lmfit==1.0.3 locket==0.2.1 loky==3.0.0 lxml==4.7.1 lz4==3.1.10 Mako==1.1.6 Markdown==3.3.6 MarkupSafe==2.0.1 marshmallow==3.12.1 matplotlib==3.6.2 matplotlib-inline==0.1.3 maturin==0.12.6 mccabe==0.6.1 mercantile==1.2.1 mergedeep==1.3.4 metakernel==0.28.2 mistune==0.8.4 mizani==0.7.3 mkl-service==2.4.0 mlxtend==0.18.0 moviepy==1.0.3 mpl-scatter-density==0.7 mpld3==0.5.7 mpldatacursor==0.7.1 mpmath==1.2.1 msgpack==1.0.3 msvc-runtime==14.29.30133 multidict==5.2.0 multipledispatch==0.6.0 munch==2.5.0 murmurhash==1.0.6 mypy==0.931 mypy-extensions==0.4.3 mysql-connector-python==8.0.26 nbclassic==0.3.5 nbclient==0.5.10 nbconvert==6.4.0 nbconvert_reportlab==0.2 nbdime==3.1.1 nbformat==5.1.3 nbval==0.9.6 nest-asyncio==1.5.4 netCDF4==1.5.8 networkx==2.6.4a0 NLopt==2.7.0 nltk==3.6.7 notebook==6.4.7 numba==0.55.0 numcodecs==0.9.1 numdifftools==0.9.40 numexpr==2.8.1 numpy==1.24.1 numpydoc==1.1.0 oct2py==5.4.2 octave-kernel==0.34.0 onnxruntime==1.10.0 openpyxl==3.0.9 orjson==3.6.5 osqp==0.6.2.post4 outcome==1.1.0 packaging==22.0 palettable==3.3.0 pandas==1.4.0 pandas-datareader==0.10.0 pandocfilters==1.5.0 panel==0.12.6 papermill==2.3.3 param==1.12.0 parambokeh==0.2.3 paramiko==2.8.0 paramnb==2.0.4 parso==0.8.3 partd==1.2.0 pathspec==0.9.0 pathy==0.6.1 patsy==0.5.2 pdfrw==0.4.post2 pdvega==0.2.1.dev0 pefile==2021.9.3 pep8==1.7.1 pexpect==4.8.0 pg8000==1.23.0 pickleshare==0.7.5 Pillow==9.4.0 PIMS==0.5 Pint==0.18 pipdeptree==2.2.1 pkginfo==1.8.2 platformdirs==2.4.1 plotly==5.5.0 plotnine==0.8.0 pluggy==1.0.0 ply==3.11 pockets==0.9.1 pooch==1.6.0 portpicker==1.4.0 poyo==0.5.0 ppci==0.5.8 preshed==3.0.6 prettytable==3.0.0 priority==2.0.0 proglog==0.1.9 prometheus-client==0.12.0 promise==2.3 prompt-toolkit==3.0.24 protobuf==3.20.3 protoc-gen-swagger==0.1.0 psutil==5.9.0 ptpython==3.0.20 ptyprocess==0.7.0 PuLP==2.3 py==1.11.0 py-lru-cache==0.1.4 pyaml==20.4.0 pyarrow==6.0.1 PyAudio==0.2.11 pybars3==0.9.7 pybind11==2.9.0 pycodestyle==2.8.0 pycosat==0.6.3 pycparser==2.21 pyct==0.4.8 pydantic==1.8.2 pydeck==0.7.1 pydocstyle==6.1.1 pyepsg==0.4.0 pyerfa==2.0.0.1 pyflakes==2.4.0 pyflux==0.4.17 pygame==2.1.2 pygbm==0.1.0 Pygments==2.11.2 pyhdf==0.10.3 pyiges==0.2.1 pyinstaller==4.8 pyinstaller-hooks-contrib==2021.5 pylint==2.12.2 pyls-spyder==0.4.0 pymc==2.3.8 PyMeta3==0.5.1 pymongo==4.0.1 PyNaCl==1.5.0 pynndescent==0.5.5 pyodbc==4.0.32 PyOpenGL==3.1.5 pypandoc==1.5 pyparsing==3.0.9 pyproj==3.3.0 PyQt5==5.15.1 PyQt5-sip==12.8.1 PyQt5-stubs==5.15.6.0 pyqt5-tools==5.15.1.1.7.5.post3 pyqtgraph==0.12.3 PyQtWebEngine==5.15.1 pyrsistent==0.18.1 pyserial==3.5 pyshp==2.1.3 PySocks==1.7.1 PySoundFile==0.9.0.post1 pystache==0.5.4 pytest==6.2.5 python-baseconv==1.2.2 python-dateutil==2.8.2 python-dotenv==0.19.2 python-hdf4==0.10.0+dummy python-Levenshtein==0.12.2 python-lsp-black==1.0.1 python-lsp-jsonrpc==1.0.0 python-lsp-server==1.3.3 python-multipart==0.0.5 python-picard==0.7 python-slugify==5.0.2 python-snappy==0.6.0 pythonnet==3.0.0a1 PythonQwt==0.10.1 pytz==2021.3 pytz-deprecation-shim==0.1.0.post0 pyvista==0.37.0 pyviz-comms==2.1.0 PyWavelets==1.2.0 pywin32==303 pywin32-ctypes==0.2.0 pywinpty==1.1.6 pywinusb==0.4.2 PyYAML==6.0 pyzmq==22.3.0 pyzo==4.12.0 pyzstd==0.15.1 QDarkStyle==3.0.2 qdldl==0.1.5.post0 qpsolvers==1.8.0 qstylizer==0.2.1 QtAwesome==1.1.1 qtconsole==5.2.2 QtPy==2.0.0 quadprog==0.1.8 quantecon==0.5.2 quart==0.16.2 rasterio==1.2.10 readme-renderer==32.0 redis==4.1.0 regex==2022.1.18 reportlab==3.6.5 requests==2.28.1 requests-toolbelt==0.9.1 rfc3986==1.5.0 rise==5.7.1 rope==0.22.0 rpy2==3.4.0.dev0 Rtree==0.9.7 ruamel.yaml==0.17.20 ruamel.yaml.clib==0.2.6 Rx==1.6.1 scikit-fuzzy==0.4.1 scikit-image==0.19.1 scikit-learn==1.0.2 scikit-optimize==0.9.0 scilab2py==0.6.2 scipy==1.10.0 scooby==0.7.0 scramp==1.4.1 scs==3.1.0 seaborn==0.11.2 Send2Trash==1.8.0 shap==0.39.0 Shapely==1.8.0 simpervisor==0.4 simplegeneric==0.8.1 simplejson==3.17.6 simpy==4.0.1 six==1.16.0 sklearn-contrib-lightning==0.6.1 slicer==0.0.7 slicerator==1.0.0 smart-open==5.2.1 smmap==5.0.0 snakeviz==2.1.0 sniffio==1.2.0 snowballstemmer==2.2.0 snuggs==1.4.7 sortedcontainers==2.4.0 sounddevice==0.4.4 soupsieve==2.3.1 spacy==3.2.1 spacy-legacy==3.0.8 spacy-loggers==1.0.1 Sphinx==4.4.0 sphinx-epytext==0.0.4 sphinx-readable-theme==1.3.0 sphinx-rtd-theme==1.0.0 sphinxcontrib-applehelp==1.0.2 sphinxcontrib-devhelp==1.0.2 sphinxcontrib-htmlhelp==2.0.0 sphinxcontrib-jsmath==1.0.1 sphinxcontrib-napoleon==0.7 sphinxcontrib-qthelp==1.0.3 sphinxcontrib-serializinghtml==1.1.5 spyder==5.2.2 spyder-kernels==2.2.1 SQLAlchemy==1.4.28 sqlite-bro==0.12.1 sqlite-fts4==1.0.1 sqlite-utils==3.22 sqlparse==0.4.2 srsly==2.4.2 starlette==0.17.1 statsmodels==0.13.1 streamlit==1.1.0 streamz==0.6.3 supersmoother==0.4 swifter==1.0.9 sympy==1.9 tables==3.7.0 tabulate==0.8.9 tblib==1.7.0 tenacity==8.0.1 termcolor==1.1.0 terminado==0.12.1 testfixtures==7.0.0 testpath==0.5.0 text-unidecode==1.3 textdistance==4.2.2 textwrap3==0.9.2 thinc==8.0.13 threadpoolctl==3.0.0 three-merge==0.1.1 thrift==0.15.0 tifffile==2021.11.2 tinycss2==1.1.1 toml==0.10.2 tomli==1.2.2 tomli_w==1.0.0 tomlkit==0.8.0 toolz==0.11.2 torch==1.10.1 torchaudio==0.10.1 torchvision==0.11.2 tornado==6.1 tqdm==4.64.1 traitlets==5.1.1 traittypes==0.2.1 transforms3d==0.3.1 trio==0.19.0 trio-asyncio==0.12.0 twine==3.7.1 twitter==1.19.2 typer==0.4.0 typing_extensions==4.0.1 tzdata==2021.5 tzlocal==4.1 ujson==5.1.0 umap-learn==0.5.1 uncertainties==3.1.6 urllib3==1.26.13 uvicorn==0.17.0 validators==0.18.2 vega==3.5.0 vega-datasets==0.9.0 virtualenv==20.13.0 ViTables==3.0.2 voila==0.3.0 vtk==9.2.5 wasabi==0.9.0 wasmer==1.1.0 wasmer_compiler_cranelift==1.1.0 wasmer_compiler_singlepass==1.1.0 watchdog==2.1.5 wavefile==1.5 wcwidth==0.2.5 webencodings==0.5.1 websocket-client==1.2.3 websockets==10.1 Werkzeug==2.0.2 widgetsnbextension==3.5.2 winpython==4.6.20220116 winrt==1.0.21033.1 wordcloud==1.8.1 wrapt==1.13.3 wslink==1.6.4 wsproto==1.0.0 xarray==0.20.2 XlsxWriter==3.0.2 xlwings==0.24.7 xmltodict==0.13.0 yapf==0.32.0 yarl==1.7.2 zarr==2.10.2 zict==2.0.0 zipp==3.11.0 zstandard==0.16.0 ```

Logger output file

No response

MichaelZimmermannMNE commented 1 year ago

I just had a closer look at the model.

The model is a shell & beam model where the orientation of the beams is defined via orieantation nodes. In total there are 161176 nodes, yet only 151877 nodes are active nodes (aka no orientation nodes). The remaining nodes are inactive nodes (orientation nodes) which can be selected via NSLE,S,INACTIVE. For these inactive (orientation) nodes there are no nodal results.

Any idea how to make the export working?

germa89 commented 1 year ago

Interesting.... can you share the model? So I can have a better look at the issue?

MichaelZimmermannMNE commented 1 year ago

Can I send you the link to the model privately`If so please let me know how. Thx.

MichaelZimmermannMNE commented 1 year ago

I just created a reduced test case which contains 10955 nodes and some elements In this model 949 nodes are inactive nodes (orientation nodes) and 10077 nodes are active nodes which contribute to the DOF count. The result set contains one load set only.

Running this model with the code from above gives an error as follows:

ValueError: data length of (10077) != required length (10955)

Is there an option to unselect the orientation nodes before writing to vtk?

You can find the result file here: https://drive.google.com/file/d/1Bswpcw4mCXhdrNhktYOATRlqM3-9SRp4/view?usp=sharing

mikerife commented 1 year ago

Hi @MichaelZimmermannMNE & @germa89 I've been contemplating/thinking about beam elements in PyMAPDL with respect to grid (PyVista) a lot lately.

MichaelZ - the PyMAPDL Reader is a stand-alone tool. Meaning that it is not interacting with an MAPDL instance like PyMAPDL does. So it cannot respect the nsel,u,inactive command. And as far as I can tell PyVista does not have an "beam" object type like most FEA programs do. I.E. a line defined by its end points, some 3rd point defining an orientation, and a cross-section definition. The line in PyVista is a true 2 point line. VTK is just huge...I tried to slog my way through the documentation and I don't think it has a FEA style beam object either.

Now the PyMAPDL mesh.grid method can save the vtk data but it kind of outsmarts itself. In the function it selects all the nodes defining the elements (APDL command). So even though generally speaking we can work with sub-sets of elements and nodes with the mesh method, issuing that nsel,u,inactive prior to creating the vtk object would be undone by the internal logic.

Since I'm self-learning Python and working with PyMAPDL quite a bit (not a developer though!) I was sketching out an idea of how to write out a solid element representation of a FEA beam. But the results are making my brain sweat. The cross section corner nodes results can be written to the result file. The order is an internal solution order and not the as defined by the cross section mesh order. So not trivial (to me) to get the mapping of node numbers right.

Sorry I don't really have a good answer for you.

Mike

germa89 commented 1 year ago

This is not very straight forward to solve if there is no vtk element for a quadratic beam element.

I have seen there is a polyline object:

Screenshot 2023-04-13 at 11 15 18

We might be able to adapt it to our needs with minimal changes.


I have also seen this: https://wiki.freecad.org/FEM_Mesh#Beam,_3_node_line,_seg3_(quadratic)

Leaving it here for (maybe) future references.