Keep on-boundary 3D points inside the domain (fix corner/edge/face NaN masking) - #5704
Closed
aabills wants to merge 2 commits into
Closed
Keep on-boundary 3D points inside the domain (fix corner/edge/face NaN masking)#5704aabills wants to merge 2 commits into
aabills wants to merge 2 commits into
Conversation
UnstructuredSubMesh.contains_points_3d classified query points lying exactly on a face, edge, or corner of the domain as outside, because their winding number is a partial value (2*pi on a face, pi on an edge, pi/2 at a corner) that fails the strict > 2*pi interior test. Points sampled on the domain boundary when interpolating or plotting a 3D unstructured field were therefore masked to NaN. Use a small positive threshold so on-boundary points count as inside while true exterior (winding ~ 0) stays outside. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5704 +/- ##
=======================================
Coverage 98.11% 98.11%
=======================================
Files 340 340
Lines 32744 32744
=======================================
Hits 32128 32128
Misses 616 616 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
Author
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.
Description
UnstructuredSubMesh.contains_points_3ddecides whether 3D query points lie inside the mesh domain, using the generalized winding number (sum of signed solid angles over the boundary triangles), and returnswinding > 2 * np.pi.A point sitting exactly on the boundary surface gets a partial solid angle that lands at or below the halfway threshold, so it is misclassified as outside:
> 2π?contains_points_3dis called (viaProcessedVariable._get_boundary_mask→_interpolate_spatial, and viaget_3d_slices) to blank out-of-domain points to NaN when interpolating or plotting a 3D unstructured field. So any query point that lands exactly on a domain face/edge/corner — which happens routinely when a regular plotting/sampling grid touches the domain boundary — is masked to NaN. The solution itself is unaffected; this is post-processing/plotting only.Verified empirically on a unit cube: winding is exactly π/2 at a corner, π on an edge, 2π on a face, 4π in the interior, and 0 outside — matching the geometry.
Fix
Lower the threshold below the smallest on-surface value (π/2 at a corner), so interior and on-boundary points count as inside while true exterior (winding ≈ 0) stays outside:
Testing
test_contains_points_3d_boundary_points_are_insideasserts a corner, edge midpoint, face centre, and interior point are all inside, and an exterior point is not. It fails before the change (corner/edge/face classified outside) and passes after — verified by reverting the source line alone.uv run --group dev pytest packages/pybamm/tests/unit/test_meshes— 163 passed.uv run pre-commit run --all-filesclean.🤖 Generated with Claude Code