Skip to content

Commit

Permalink
Correct computation of smoothness values (#340 | GRIDEDIT-1205)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacarniato authored Jun 12, 2024
1 parent 92580b5 commit 4726aa8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
10 changes: 5 additions & 5 deletions libs/MeshKernel/src/Mesh2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1211,13 +1211,13 @@ std::vector<double> Mesh2D::GetSmoothness()
const auto leftFaceArea = m_faceArea[firstFaceIndex];
const auto rightFaceArea = m_faceArea[secondFaceIndex];

if (leftFaceArea < m_minimumCellArea || rightFaceArea < m_minimumCellArea)
if (leftFaceArea > m_minimumCellArea && rightFaceArea > m_minimumCellArea)
{
val = rightFaceArea / leftFaceArea;
}
if (val < 1.0)
{
val = 1.0 / val;
if (val < 1.0)
{
val = 1.0 / val;
}
}
}
result[e] = val;
Expand Down
32 changes: 32 additions & 0 deletions libs/MeshKernel/tests/src/Mesh2DTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1410,3 +1410,35 @@ TEST(Mesh2D, GetEdgesBoundingBox_WithAnInvalidEdge_ShouldGetOneInvalidEdgeBoundi
ASSERT_NEAR(edgesBoundingBoxes[1].upperRight().x, 1.1111111111111112, tolerance);
ASSERT_NEAR(edgesBoundingBoxes[1].upperRight().y, 1.1111111111111112, tolerance);
}

TEST(Mesh2D, GetSmoothness_OnTriangularMesh_ShouldgetSmoothnessValues)
{
// Setup
const auto mesh = ReadLegacyMesh2DFromFile(TEST_FOLDER + "/data/TestOrthogonalizationMediumTriangularGrid_net.nc");

// Execute
const auto smoothness = mesh->GetSmoothness();

// Assert
const double tolerance = 1e-6;
ASSERT_NEAR(1.0000000000000047, smoothness[0], tolerance);
ASSERT_NEAR(1.5393847629344886, smoothness[10], tolerance);
ASSERT_NEAR(1.1609660187036754, smoothness[20], tolerance);
ASSERT_NEAR(1.4420158602682915, smoothness[30], tolerance);
}

TEST(Mesh2D, GetOrthogonality_OnTriangularMesh_ShouldGetOrthogonalityValues)
{
// Setup
const auto mesh = ReadLegacyMesh2DFromFile(TEST_FOLDER + "/data/TestOrthogonalizationMediumTriangularGrid_net.nc");

// Execute
const auto orthogonality = mesh->GetOrthogonality();

// Assert
const double tolerance = 1e-6;
ASSERT_NEAR(1.0566340037701503e-15, orthogonality[0], tolerance);
ASSERT_NEAR(0.052159566591519289, orthogonality[10], tolerance);
ASSERT_NEAR(1.0342915752434056e-15, orthogonality[20], tolerance);
ASSERT_NEAR(0.045878303256790140, orthogonality[30], tolerance);
}

0 comments on commit 4726aa8

Please sign in to comment.