Skip to content

Preserve face order across an Exodus round trip - #1913

Merged
cmdupuis3 merged 5 commits into
mainfrom
cmd/exodus_elem_num_map
Dec 4, 2026
Merged

cmdupuis3 merged 5 commits into
mainfrom
cmd/exodus_elem_num_map

Conversation

@cmdupuis3

@cmdupuis3 cmdupuis3 commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1910

Overview

Overview

Exodus element blocks are homogeneous, so _encode_exodus regroups a mixed mesh by face size. Nothing recorded that permutation, so the mesh reloaded reordered -- intact, but with any face-centered data now describing the wrong faces, and no error to say so.

Carry each face's original position through the regrouping and write it to elem_num_map, then undo the permutation on read. Exodus defines elem_num_map as a user-facing element ID rather than a position, so the reader only honors it on files this writer produced, identified via qa_records, and only when the IDs form a genuine permutation.

This restores the exact-order assertions in test_mixed_exodus and test_grid_ugrid_exodus_roundtrip. #1752 (8d36335, "Fix Exodus encode treating every face as full width") had relaxed them to compare faces as an unordered set via a _face_rows helper, because the round trip permuted faces. That helper is removed here.

Also in this PR (small scope expansion): the hand-built mixed mesh in test_encode_exodus_mixed_blocks was not a valid mesh. Node 4 sat at (20, 0), on the same line as nodes 0 and 1, and the triangle [0, 3, 4] overlapped the quad, so edges crossed each other. Node 4 moves to (20, -10) and the triangles become [0, 4, 1] and [1, 4, 2], so the three faces now tile without overlapping and share edges. The new round-trip test uses the same mesh.

PR Checklist

General

  • An issue is created and linked
  • Added appropriate labels (if your uxarray repo permissions allow it)
  • Filled out Overview and Expected Usage (if applicable) sections

Testing & Benchmarking

  • There is adequate test coverage of changes from this PR (add new tests if needed)
  • If this PR could affect performance, ran ASV benchmarks and confirmed they show expected behavior (add a new benchmark if necessary)

Documentation and Examples

  • Docstrings updated with any function changes, and included in all new functions
  • User (public) functions added to docs/api.rst; internal (private) function names start with an underscore (_)

AI Disclosure

AI Usage: Claude Opus 5.5

  • I have tested and take responsibility for all AI-generated content in my PR.

Exodus element blocks are homogeneous, so `_encode_exodus` regroups a mixed
mesh by face size. Nothing recorded that permutation, so the mesh reloaded
reordered -- intact, but with any face-centered data now describing the
wrong faces, and no error to say so.

Carry each face's original position through the regrouping and write it to
`elem_num_map`, then undo the permutation on read. Exodus defines
`elem_num_map` as a user-facing element ID rather than a position, so the
reader only honors it on files this writer produced, identified via
`qa_records`, and only when the IDs form a genuine permutation.

This restores the exact-order assertions in `test_mixed_exodus` and
`test_grid_ugrid_exodus_roundtrip` that the previous commit had to relax.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cmdupuis3 cmdupuis3 self-assigned this Nov 20, 2026
@cmdupuis3 cmdupuis3 added bug Something isn't working accuracy Related to mathematical accuracy of operations, such as numerical precision or rounding errors labels Nov 20, 2026
@cmdupuis3
cmdupuis3 marked this pull request as ready for review December 2, 2026 22:07
@cmdupuis3
cmdupuis3 requested a review from Sevans711 December 2, 2026 22:07

@Sevans711 Sevans711 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks reasonable here, and the new tests do catch the old bug when run against main. Happy to approve this one!

Minor non-blocking comments:

  1. Could you update the PR description to mention the cleanup to the uxgrid example in test_encode_exodus_mixed_blocks? I don't think it's required for this PR which makes it a minor expansion of scope, but it is definitely good to include, as plotting the old uxgrid example shows some edges intersect with each other.
  2. Could you clarify, in the PR description ("This restores the exact-order assertions in test_mixed_exodus and test_grid_ugrid_exodus_roundtrip that the previous commit had to relax."), which commit is "the previous commit"?

@cmdupuis3
cmdupuis3 requested a review from dylannelson December 3, 2026 17:10
@cmdupuis3

Copy link
Copy Markdown
Collaborator Author

pre-commit.ci autofix

@rajeeja
rajeeja self-requested a review December 4, 2026 16:31
@cmdupuis3
cmdupuis3 removed the request for review from dylannelson December 4, 2026 17:27
@cmdupuis3
cmdupuis3 merged commit 554f77a into main Dec 4, 2026
29 of 30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accuracy Related to mathematical accuracy of operations, such as numerical precision or rounding errors bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exodus encode reorders faces without writing an element map

3 participants