Description
Before submitting the issue
- I have checked for Compatibility issues
- I have searched among the existing issues
- I am using a Python virtual environment
Description of the bug
Hello,
pyvista_op = dpf.operators.mesh.mesh_to_pyvista() seems to be writing wrong order of nodes while exporing cell information for pyvista.
As per documentation https://vtk.org/doc/nightly/html/classvtkWedge.html#details, 012 should point outwards but in case of dpf results, it points inwards, leading to a negative volume element.
This was detected when data was uploaded on SimAI, and warning was thrown. Sample script and result file is also provided.
Steps To Reproduce
from ansys.dpf import core as dpf
import pyvista as pv
import numpy as np
import vtk
rst_path = r"file.rst"
model = dpf.Model(rst_path)
mesh = model.metadata.meshed_region
pyvista_op = dpf.operators.mesh.mesh_to_pyvista()
pyvista_op.inputs.mesh.connect(mesh)
# Extract nodes, cells, and cell types from the PyVista operator
nodes = pyvista_op.outputs.nodes().data
cells = pyvista_op.outputs.cells()
cell_types = pyvista_op.outputs.cell_types()
mesh = pv.UnstructuredGrid(cells, cell_types, nodes)
volumes = mesh.compute_cell_sizes().cell_data["Volume"]
negative_volume_indices = np.where(volumes < 0)[0]
print(f"Found {len(negative_volume_indices)} negative volume cells.")
#### Temporary fix, swaping 1 <-> 2, 4 <-> 5.
fixed_mesh = mesh.copy()
cell_array = vtk.vtkCellArray()
cell_type_ids = []
for cell_id in range(fixed_mesh.n_cells):
cell = fixed_mesh.get_cell(cell_id)
cell_type_ids.append(cell.type)
if cell_id in negative_volume_indices:
# Swaping order as per bug https://discourse.vtk.org/t/bug-in-documentation-figure-on-wedge-node-ordering/9946
temp1 = cell.GetPointIds().GetId(1)
cell.GetPointIds().SetId(1, cell.GetPointIds().GetId(2))
cell.GetPointIds().SetId(2, temp1)
temp1 = cell.GetPointIds().GetId(4)
cell.GetPointIds().SetId(4, cell.GetPointIds().GetId(5))
cell.GetPointIds().SetId(5, temp1)
cell_array.InsertNextCell(cell)
fixed_mesh.SetCells(cell_type_ids, cell_array)
# Save the repaired mesh
fixed_mesh.save("fixed_mesh.vtu")
Which Operating System causes the issue?
Windows
Which DPF/Ansys version are you using?
Ansys 2024 R2
Which Python version causes the issue?
3.10
Installed packages
aiohappyeyeballs==2.4.3
aiohttp==3.11.7
aiosignal==1.3.1
ansys-api-dbu==0.3.6
ansys-api-geometry==0.4.16
ansys-api-mechanical==0.1.2
ansys-api-platform-instancemanagement==1.1.0
ansys-dpf-core==0.13.2
ansys-geometry-core==0.7.6
ansys-mechanical-core==0.11.10
ansys-mechanical-env==0.1.8
ansys-mechanical-stubs==0.1.4
ansys-platform-instancemanagement==1.1.2
ansys-pythonnet==3.1.0rc4
ansys-tools-path==0.7.0
ansys-tools-visualization-interface==0.5.0
anyio==4.6.2.post1
appdirs==1.4.4
argon2-cffi==23.1.0
argon2-cffi-bindings==21.2.0
arrow==1.3.0
asttokens==2.4.1
async-timeout==5.0.1
attrs==24.2.0
beartype==0.19.0
beautifulsoup4==4.12.3
bleach==6.2.0
cachetools==5.5.0
certifi==2024.8.30
cffi==1.17.1
charset-normalizer==3.4.0
click==8.1.7
clr-loader==0.2.6
colorama==0.4.6
comm==0.2.2
contourpy==1.3.1
cycler==0.12.1
decorator==5.1.1
defusedxml==0.7.1
docker==7.1.0
exceptiongroup==1.2.2
executing==2.1.0
fastjsonschema==2.20.0
flexcache==0.3
flexparser==0.4
fonttools==4.55.0
fqdn==1.5.1
frozenlist==1.5.0
google-api-core==2.23.0
google-api-python-client==2.154.0
google-auth==2.36.0
google-auth-httplib2==0.2.0
googleapis-common-protos==1.66.0
grpcio==1.67.1
grpcio-health-checking==1.67.1
httplib2==0.22.0
idna==3.10
imageio==2.28.0
imageio-ffmpeg==0.5.1
importlib_metadata==8.5.0
ipython==8.29.0
ipywidgets==8.1.5
isoduration==20.11.0
jedi==0.19.2
Jinja2==3.1.4
jsonpointer==3.0.0
jsonschema==4.23.0
jsonschema-specifications==2024.10.1
jupyter-events==0.10.0
jupyter_client==8.6.3
jupyter_core==5.7.2
jupyter_server==2.14.2
jupyter_server_proxy==4.4.0
jupyter_server_terminals==0.5.3
jupyterlab_pygments==0.3.0
jupyterlab_widgets==3.0.13
kiwisolver==1.4.7
MarkupSafe==3.0.2
matplotlib==3.9.2
matplotlib-inline==0.1.7
mistune==3.0.2
more-itertools==10.5.0
msgpack==1.1.0
multidict==6.1.0
nbclient==0.10.0
nbconvert==7.16.4
nbformat==5.10.4
nest-asyncio==1.6.0
numpy==1.26.4
overrides==7.7.0
packaging==24.2
pandocfilters==1.5.1
parso==0.8.4
pillow==11.0.0
Pint==0.24.4
platformdirs==4.3.6
pooch==1.8.2
prometheus_client==0.21.0
prompt_toolkit==3.0.48
propcache==0.2.0
proto-plus==1.25.0
protobuf==5.28.3
psutil==6.1.0
pure_eval==0.2.3
pyasn1==0.6.1
pyasn1_modules==0.4.1
pycparser==2.22
Pygments==2.18.0
PyMuPDF==1.25.1
pyparsing==3.2.0
python-dateutil==2.9.0.post0
python-json-logger==2.0.7
pyvista==0.44.1
pywin32==308
pywinpty==2.0.14
PyYAML==6.0.2
pyzmq==26.2.0
referencing==0.35.1
requests==2.32.3
rfc3339-validator==0.1.4
rfc3986-validator==0.1.1
rpds-py==0.21.0
rsa==4.9
scipy==1.14.1
scooby==0.10.0
semver==3.0.2
Send2Trash==1.8.3
simpervisor==1.0.0
six==1.16.0
sniffio==1.3.1
soupsieve==2.6
stack-data==0.6.3
terminado==0.18.1
tinycss2==1.4.0
tornado==6.4.2
tqdm==4.67.0
traitlets==5.14.3
trame==3.7.0
trame-client==3.5.0
trame-server==3.2.3
trame-vtk==2.8.12
trame-vuetify==2.7.2
types-python-dateutil==2.9.0.20241003
typing_extensions==4.12.2
uri-template==1.3.0
uritemplate==4.1.1
urllib3==2.2.3
usd-core==24.11
vtk==9.3.1
wcwidth==0.2.13
webcolors==24.11.1
webencodings==0.5.1
websocket-client==1.8.0
websockets==13.1
widgetsnbextension==4.0.13
wslink==2.2.1
yarl==1.18.0
zipp==3.21.0