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.
MpasMeshConverter.xhas a typo in the law of cosines it uses for the angles of each dual triangle inbuildMeshQualities(), sotriangleAngleQualityis wrong andobtuseTrianglecan be too.What happens
In
mesh_conversion_tools_netcdf_c/mpas_mesh_converter.cpp, the second angle subtractsb_len * c_lenwhere the law of cosines needsb_len * b_len:angle1andangle3are correct. The legacy converter inmesh_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. Onmesh_tools/mesh_conversion_tools/test/mesh.QU.1920km.151026.ncafterMpasMeshConverter.x:triangleAngleQualitymatches 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.obtuseTriangle(and the "Mesh contains: N obtuse triangles" count) uses the samemaxAngle, 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
triangleAngleQualityis 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.