Fix inverted hex cell faces in 3D mesh visualization#62
Merged
lmoresi merged 3 commits intodevelopmentfrom Mar 2, 2026
Merged
Conversation
PETSc DMPlex returns hex vertices with bottom-face winding opposite to VTK convention (CCW vs CW from above). Apply permutation [0,3,2,1,4,5,6,7] to swap vertices 1 and 3 on the bottom face when converting to meshio/VTK format. Closes #40 Underworld development team with AI support from Claude Code
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes incorrect hexahedral cell vertex ordering when converting Underworld3 StructuredQuadBox (3D, non-simplex) meshes to PyVista, preventing inverted faces / normals during visualization (as reported in #40).
Changes:
- Reorders PETSc DMPlex hexahedron vertex indices to match VTK/meshio convention using permutation
[0, 3, 2, 1, 4, 5, 6, 7]. - Applies the reorder in
mesh_to_pv_mesh()fordim == 3andnot isSimplex(), affecting both the meshio and direct VTK construction paths.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+116
to
+118
| if not mesh.dm.isSimplex() and mesh.dim == 3: | ||
| hex_reorder = [0, 3, 2, 1, 4, 5, 6, 7] | ||
| cell_points_list = [pts[hex_reorder] for pts in cell_points_list] |
There was a problem hiding this comment.
Add an automated regression test for this hexahedron reordering. The repository already has optional pyvista tests; consider extending them to build a small 3D StructuredQuadBox (e.g., 2×2×2), convert via mesh_to_pv_mesh(), and assert cell volumes/Jacobians are positive so inverted faces can’t regress.
PETSc DMPlex uses left-handed orientation for tetrahedra; VTK expects right-handed. Swap vertices 1 and 2 ([0,2,1,3]) to correct this. Without correct orientation, face normals point inward which can cause shading artifacts, incorrect surface clipping, and back-face culling issues. Verified: all 3D cell types (hex + tet) now produce positive Jacobian determinant; 2D meshes (quad + triangle) are unaffected. Underworld development team with AI support from Claude Code
Tests that hex and tet cells have positive Jacobian determinant after the PETSc→VTK vertex reordering, and that 2D meshes are unaffected. Underworld development team with AI support from Claude Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
StructuredQuadBox(hexahedral) meshes[0, 3, 2, 1, 4, 5, 6, 7]inmesh_to_pv_mesh()before passing to meshio or direct VTK pathnot isSimplex() and dim == 3); 2D quads, triangles, and tetrahedra are unaffectedCloses #40
Test plan