Skip to content

Fix edge ordering on vertices of obtuse triangles in MpasMeshConverter.x - #779

Merged
xylar merged 3 commits into
MPAS-Dev:masterfrom
xylar:fix-obtuse-vertex-ordering
Nov 17, 2026
Merged

xylar merged 3 commits into
MPAS-Dev:masterfrom
xylar:fix-obtuse-vertex-ordering

Conversation

@xylar

@xylar xylar commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

MpasMeshConverter.x (mesh_conversion_tools_netcdf_c) now orders the edges around each vertex by the direction to the vertex at the other end of each edge, rather than to the edge's location, which lies behind the vertex when its triangle is obtuse. Kites at those vertices now pair each cell with its own edges, and areaTriangle, kiteAreasOnVertex and weightsOnEdge are no longer NaN there. The triangle-area formulas also clamp a slightly negative product at zero, so a degenerate triangle has zero area rather than NaN.

Output is unchanged for meshes without obtuse triangles. The deprecated mesh_conversion_tools copy has the same bug but is left as it is.

Fixes #778


Posted by Claude Code on @xylar's behalf. The testing, analysis and wording above are AI-authored; please check them accordingly.

@xylar

xylar commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator Author

Testing

I built the mpas_tools package with rattler-build (ci/linux_64_python3.14.____cpython.yaml) from master (fbb28c6) and from this branch (6de2f24), with the recipe's tests passing, installed each in its own environment, and ran the packaged MpasMeshConverter.x on the same inputs, comparing every output variable (NaN-aware):

mesh output vs. master misordered vertices (master / branch) NaN (master / branch)
Polaris QU 240 km, 120 km identical 0 / 0 none
Polaris icosahedral 240 km, 120 km identical 0 / 0 none
Polaris u-oi240-lr240 identical 0 / 0 none
Polaris u-oi30-lr10 5 vertex variables differ 1849 / 0 280 areaTriangle / none
planar hex, periodic identical 0 / 0 none
planar hex, non-periodic (culled) identical 0 / 0 none

A package built the same way from cc1a077, which only renames variables, gives output identical to 6de2f24 for all of these meshes.


Posted by Claude Code on @xylar's behalf. The testing, analysis and wording above are AI-authored; please check them accordingly.

xylar and others added 2 commits November 15, 2026 17:03
orderVertexArrays sorted the edges around each vertex by the
direction from the vertex to each edge's location, and builds
cellsOnVertex and the kites in kiteAreasOnVertex from that order.
Where a triangle is obtuse, its circumcenter lies outside it, and the
location of the edge opposite the obtuse angle -- where that edge
crosses the line between its cells -- lies behind the vertex.  That
edge then sorted into the wrong place, so each kite paired a cell with
an edge it doesn't share.  areaTriangle, kiteAreasOnVertex and
weightsOnEdge were wrong at those vertices, and NaN where a mismatched
kite was degenerate enough for round-off to make its area NaN.

Sort by the direction to the vertex at the other end of each edge
instead, falling back to the edge's location on a boundary.  On a
mesh without obtuse triangles the two directions agree and the output
is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Heron's formula and its spherical analog take the square root of a
product that is zero for a degenerate triangle, and round-off can make
it slightly negative, giving NaN.  Clamp the product at zero.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@xylar
xylar marked this pull request as draft November 15, 2026 16:05
@xylar
xylar force-pushed the fix-obtuse-vertex-ordering branch from 403aade to 6de2f24 Compare November 15, 2026 16:30
@xylar
xylar marked this pull request as ready for review November 15, 2026 16:35
They are now usually the vertex at the other end of each edge rather
than the edge's location, so call them dir_point1 and dir_point2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@xylar xylar added the bug label Nov 15, 2026
@xylar
xylar merged commit 9c148ee into MPAS-Dev:master Nov 17, 2026
5 checks passed
@xylar
xylar deleted the fix-obtuse-vertex-ordering branch November 17, 2026 20:31
@xylar xylar mentioned this pull request Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MpasMeshConverter.x misorders vertex edges at obtuse triangles, giving wrong or NaN kite areas

1 participant