Skip to content

Fix law-of-cosines typo in triangleAngleQuality - #763

Open
xylar wants to merge 1 commit into
MPAS-Dev:masterfrom
xylar:fix-triangle-angle-quality
Open

xylar wants to merge 1 commit into
MPAS-Dev:masterfrom
xylar:fix-triangle-angle-quality

Conversation

@xylar

@xylar xylar commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

buildMeshQualities() in MpasMeshConverter.x computed the second angle of each dual triangle with b_len * c_len where the law of cosines needs b_len * b_len. As a result, triangleAngleQuality was wrong wherever the triangle's b and c sides differ, and obtuseTriangle (plus the "Mesh contains: N obtuse triangles" count) could be wrong on meshes with angles near 90°. The same typo is fixed in the legacy converter in mesh_conversion_tools/, although that one isn't built into the conda package.

On mesh.QU.1920km.151026.nc, before the fix triangleAngleQuality was off at 204 of 320 vertices, by up to 0.07, and the three angles of a triangle summed to between 3.037 and 3.227. After the fix, it matches an independent calculation exactly and all angle sums are π. obtuseTriangle is 0 on this mesh either way.

This adds test_conversion_triangle_angle_quality, which recomputes the angles from dcEdge and edgesOnVertex and checks triangleAngleQuality, obtuseTriangle and that the angles sum to π. The test fails without the fix and passes with it.

Closes #761

🤖 Generated with Claude Code

The second angle of each dual triangle in buildMeshQualities() used
b_len * c_len where the law of cosines needs b_len * b_len, so
triangleAngleQuality (and potentially obtuseTriangle) were wrong
wherever the triangle's b and c sides differ.  Fix both the netcdf_c
converter (built into the conda package) and the legacy converter.

Add a test that recomputes the dual-triangle angles from dcEdge and
checks triangleAngleQuality, obtuseTriangle and that the angles sum
to pi.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@xylar

xylar commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator Author

Testing

I built the conda package with rattler-build (from the conda_package/pixi.toml environment, ci/linux_64_python3.14.____cpython.yaml variant), once before the fix and once after, and installed each build into a separate pixi environment for testing.

Before the fix (with the new test added):

  • test_conversion_triangle_angle_quality fails: triangleAngleQuality is off by up to 0.0696.
  • A standalone script that ran MpasMeshConverter.x on mesh.QU.1920km.151026.nc and recomputed the angles from dcEdge and edgesOnVertex showed that the stored triangleAngleQuality matched the formula with the typo exactly. It differed from the correct formula at 204 of 320 vertices, and the angle sums from the typo formula ranged from 3.037 to 3.227.

After the fix:

  • All recipe tests pass during rattler-build (67 passed, 5 skipped), including the new test.
  • The same script shows triangleAngleQuality matches the correct formula exactly at all vertices, with every angle sum equal to π. obtuseTriangle matches too; it's 0 everywhere on this mesh, before and after the fix.

The legacy converter in mesh_conversion_tools/ got the same one-character fix, but it isn't built into the conda package, so it wasn't compiled or tested.


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

@xylar xylar self-assigned this Sep 24, 2026
@xylar

xylar commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator Author

@trhille, could you please take a quick look here as well?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mesh converter uses the wrong law-of-cosines term for triangleAngleQuality

1 participant