Skip to content

Polyhedra with no kernel: located by winding number, interpolated by mean value coordinates (#334) - #512

Open
berkgeveci wants to merge 1 commit into
Kitware:mainfrom
berkgeveci:vis/polyhedra-no-kernel
Open

berkgeveci wants to merge 1 commit into
Kitware:mainfrom
berkgeveci:vis/polyhedra-no-kernel

Conversation

@berkgeveci

Copy link
Copy Markdown
Collaborator

Closes #334.

A polyhedron with no kernel (tangled, inside out, or with a face whose own fan folds over), where no point inside sees all of its faces, was skipped with a warning. A point inside it was found in a neighbour or nowhere, and a particle reaching it stopped. On AhmedML's volume 12 of 21.5M cells are like this: wall cells 2–3 mm across at the nose's corners.

What

  • Inside test (_PolyhedralLocation.winding_number, locate_by_winding): the solid angles of the cell's face triangles (each face fanned from its face point, as its neighbour fans it, so the cells' surfaces meet) over 4π, by Van Oosterom and Strackee's formula. A point is held where the faces wind round it once, either way, so an inside-out cell holds its points too. A point outside, within the locator's slack of a face triangle, is near, as in other cells. A cell with no volume winds round nothing.

  • Interpolant (mvc_value): mean value coordinates over the same triangles (Ju, Schaefer and Warren, 2005, in the robust form vtkMeanValueCoordinatesInterpolator uses, with its angle tolerance), exact for a linear field.

  • The location: its sub-tetrahedron is views.NO_KERNEL_TET, which is positive and past any fan's, so callers testing t >= 0 need no change; its pc is the point less the cell point. Readers:

    • the locator's search from the cells;
    • by_id's _PolyhedralMesh (locate_held, tet_value_of), which probe and advection use. The MVC branch is compiled out where MOVED is 0, which is most meshes.
    • probe's evaluation from the cells.

    Advection's shortcut (_well_inside) does not stop at such a cell, since it may overlap its neighbours.

  • The warning is gone: these cells are handled now. Polygon and polyline views get a locate_by_winding that is plain locate_from, since the locator's kernel is shared with them.

  • Not done: gradients in such cells. Nothing reads a polyhedral location's gradient yet.

Tests

  • test_polyhedra.py:
    • the C-shaped prism, from the cells and from the points: probes held in the C and not in its notch, a linear field exact, and a particle running up its spine to the far end. It used to stop.
    • an inside-out cube holds its points.
    • mean value coordinates exact in f64 (1e-12) at 2000 random points and on faces, for a scalar and a vector field.
  • test_mixed_cells.py: the C-shaped prism beside a hexahedron.
  • AhmedML (CPU, VTK master build): the 10 polyhedra with no kernel each hold their centre and points a third of the way to each corner (80 points), none found in a neighbour, and every interpolated UMean is within the cell's own point range.

Results (CPU, M1 Max):

  • the touched files: 523 passed;
  • the new tests under TACK_DEBUG=1: 18 passed;
  • the quick tier: 4687 passed;
  • ruff, SPDX, the changelog check and mkdocs build --strict are clean.

GPUs not run yet.

This will be merged after the 0.8 release.

🤖 Generated with Claude Code

…mean value coordinates (Kitware#334)

A polyhedron no point inside sees whole (tangled, inside out, a face whose fan
folds) was skipped with a warning: a point inside it was found in a neighbour or
nowhere, and a particle reaching it stopped. It now holds a point where its face
triangles' solid angles wind round it once (either way), and point data there is
the mean value coordinates' sum (Ju, Schaefer and Warren, robust form as VTK's
interpolator), exact for a linear field. The location's sub-tetrahedron is
views.NO_KERNEL_TET, its pc the point less the cell point; the locator's search
from the cells, by_id (probe, advection) and probe's evaluation from the cells
read it. On AhmedML's volume the 10 such polyhedra hold their centres and points
toward each corner, none found in a neighbour, UMean within each cell's range.
@berkgeveci berkgeveci added this to the 0.9 milestone Dec 5, 2026
if abs(self.winding_number(c, x)) > 0.5:
t = NO_KERNEL_TET
inside = 1
else:

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.

A cell with no volume still gets -2 from the locator, and this branch makes it hold points within the slack. Mean value coordinates are undefined there. A flat cube (z = 0) beside a cube, u = 2x + 3y + 1: at (0.5, 0.5, 1e-4), probe gives 2.0 on the CPU and -12 on CUDA, against 3.5, with valid 1. Main left these cells out. Leave cells with no volume out again, or take a near point's value from its nearest face triangle's barycentric weights.

_for_cells(_not_star_shaped, data, True, *self._moved(), bad)
if int(bad.numpy().sum()):
self.moved_cell_points = _moved_cell_points(data, bad)
bad.fill(0)

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.

"One with no volume winds round nothing, so holds nothing": true inside, but it holds near points (comment 1).

solid angles of its face triangles), and point data there is interpolated by
mean value coordinates, which are exact for a linear field, as VTK's
`vtkPolyhedron` interpolates. Probes, `CellLocator.find`, `advect` and
streamlines take it. On AhmedML's volume 12 of 21.5M cells are such (#334).

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.

The design doc says 10 of the 12 are read as polyhedra; the changelog says all 12 are handled.

@@ -327,7 +329,8 @@ def tet_face(self, c, t):
edge by edge, as ``side_point_id`` walks them."""
k = 0

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.

What needs the k < last guard? With NO_KERNEL_TET it stops at the last face with j still past its points, so a caller that forgets to check t reads out of range instead of failing. Comment 1 is why it matters: a gradient reader added later would hit it.

@jlee-kitware

Copy link
Copy Markdown
Collaborator

Winding number plus mean value coordinates is the right pair here, and the readers that see NO_KERNEL_TET all handle it. I ran the new tests on CUDA (GB10) too; they pass. One problem inline with cells of no volume, and two nits.

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.

Locating in polyhedra with no kernel

2 participants