Skip to content

fix(loop-common): tetra boundary points, rotated local frames, bounded lookup memory - #415

Open
lachlangrose wants to merge 7 commits into
masterfrom
fix/supports-boundary-rotation
Open

lachlangrose wants to merge 7 commits into
masterfrom
fix/supports-boundary-rotation

Conversation

@lachlangrose

Copy link
Copy Markdown
Member

Fixes three support problems found in a repo audit.

  • Points on the tetra mesh boundary evaluated to NaN. TetMesh and P2TetMesh used a strict </> inside test, so corners and max-face points were "outside". Example: on a 4³ mesh with a linear field, (0,0,0), (4,4,4) and (4,1.5,1.5) gave NaN, where StructuredGrid gives the right values. Both now use the inherited inclusive inside(). Points on the max face map to the last cell. Points even 1e-12 outside are still outside.
  • A rotated local frame built a support with zero width. The support factory projected only two corners into the local frame. With a 45° rotation, the x width was 8.9e-16. It now uses bounding_box.local_enclosure(). Unrotated boxes give bit-identical results.
  • TetMesh point lookup used about 2.7 KB per point (about 2.7 GB for 1M points). It now runs in blocks of 10k points: peak memory for 300k points went from 788 MB to 89 MB, and the results are identical.

packages/loop_common/tests/data/structured_support_reference.npz is regenerated. Exactly 18 entries changed, all {TetMesh,P2TetMesh}/*/inside and position_to_cell_index: the intended boundary change. No evaluation or geometry entry changed.

Behaviour change for rotated boxes: the support covers the whole rotated extent with the same nsteps, so cells are larger and are no longer cubes. Before, the support was degenerate.

Tests: 95 passed in the touched loop_common test files. The review also ran test_world_location_consumers and test_frame_persistence: 241 passed. It checked boundary points against StructuredGrid on 30k points (max difference 1e-14), rotated frames with 3 support types, and chunked against unchunked lookup. Not run locally: the full loop_interpolation and LoopStructural suites; please rely on CI. Not changed: P2TetMesh lookup still uses one full block.

🤖 Generated with Claude Code

lachlangrose and others added 7 commits November 25, 2026 16:18
TetMesh and P2TetMesh used a strict test for the mesh extent, so a point
on a boundary face gave NaN. Remove their own inside() so they use the
grid test, which includes the boundary. position_to_cell_index already
puts a point on the maximum face in the last cell.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
create_support_from_bbox projected only the origin and maximum corners
into the local frame. With a rotation this gave a flat support. Use
BoundingBox.local_enclosure, which projects all corners, and remove the
old comment that said no rotation is used.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
get_element_for_location built (n, 5, 4, 3) arrays for all points at
once, about 2.7 KB a point. Process the points in blocks of 1e4, the
same block size as the unstructured tetra lookup. The results do not
change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
P2TetMesh nsteps counts cells, so use nsteps=[4, 4, 4] to put the test
points on the boundary. Remove an inside() call in the TetMesh block
lookup whose result was not used.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…points

TetMesh and P2TetMesh now count points on the mesh boundary as inside.
Only the inside and position_to_cell_index arrays of the two tetra
meshes change (18 keys: unit, aniso and small cases).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…boundary

TetMesh and P2TetMesh now keep points on the mesh boundary inside, so the
P1 and DFI golden fields have finite values on the lower faces (631
values and 1893 gradient components that were NaN). Values that were
finite before are unchanged. The strict xfail for finding F2 now passes,
so the marker is removed. Golden files of the other engines are kept:
they differ only by machine rounding, far below the test tolerance.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A support built in a rotated local frame now covers the whole rotated
box, but it reused the cell counts of the world box. The local box is
longer than the world box on the rotated axes, so the cells became
larger and stretched (for 30 degrees: 2.05 x 1.75 x 1.4 instead of
about 1.4 on each axis). The PLI gradient error then grew 10 times and
two diagnostics frame tests failed.

Scale the cell count on each axis by the ratio of the local length to
the world length, so each axis keeps the world cell size. An unrotated
box has a ratio of 1 and keeps the same mesh.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lachlangrose

Copy link
Copy Markdown
Member Author

CI fix notes:

  • Golden files: P1 and DFI golden fields were updated (fbe1b7e). Boundary points are now finite, the strict xfail for finding F2 now passes, and other engines' files are unchanged.
  • Rotated-frame accuracy: the r30 PLI gradient test failed because a rotated support reused the world nsteps on a local box about 1.4x longer, so cells were coarser and stretched. Master passed only by accident: its two-corner box left a tiny x step, which gave about 5x more elements than asked for. Master itself fails the same tolerance at nelements 2000. 5f5b060 now scales the cell count per axis so each local cell keeps the world cell size. Unrotated supports are unchanged. A 30° box gets about 2x the cells, so rotated models solve a bit slower.

🤖 Generated with Claude Code

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant