Skip to content

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

Description

@xylar

MpasMeshConverter.x has a typo in the law of cosines it uses for the angles of each dual triangle in buildMeshQualities(), so triangleAngleQuality is wrong and obtuseTriangle can be too.

What happens

In mesh_conversion_tools_netcdf_c/mpas_mesh_converter.cpp, the second angle subtracts b_len * c_len where the law of cosines needs b_len * b_len:

angle2 = acos( max(-1.0, min(1.0,
    (a_len * a_len + c_len * c_len - b_len * c_len) / (2 * a_len * c_len))));

angle1 and angle3 are correct. The legacy converter in mesh_conversion_tools/mpas_mesh_converter.cpp (line 2317) has the same line, but that version isn't built into the conda package.

The error goes away when b_len == c_len, so it doesn't show up on uniform planar hex meshes. On mesh_tools/mesh_conversion_tools/test/mesh.QU.1920km.151026.nc after MpasMeshConverter.x:

  • The stored triangleAngleQuality matches the formula with the typo, and it differs from the value with the correct formula at 204 of 320 vertices, by up to 0.07.
  • The three angles per triangle add up to between 3.037 and 3.227 instead of π.
  • obtuseTriangle (and the "Mesh contains: N obtuse triangles" count) uses the same maxAngle, so it can be wrong on meshes near 90°. It happens to be 0 either way on this mesh.

What was expected

(a_len * a_len + c_len * c_len - b_len * b_len) / (2 * a_len * c_len)

so that triangleAngleQuality is the ratio of the smallest to the largest angle of each dual triangle.


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

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions