Skip to content

Commit

Permalink
Correct delete node incosistent behavior (#321 | GRIDEDIT-969_delete_…
Browse files Browse the repository at this point in the history
…node_incosistent_behavior)
  • Loading branch information
lucacarniato authored Apr 4, 2024
1 parent 19e08d5 commit f92e245
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 31 deletions.
47 changes: 16 additions & 31 deletions libs/MeshKernel/src/CurvilinearGrid/CurvilinearGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,49 +335,34 @@ void CurvilinearGrid::RemoveInvalidNodes(bool invalidNodesToRemove)
// Compute the face mask
ComputeGridFacesMask();

invalidNodesToRemove = false;
// Flag nodes not connected to valid faces
for (UInt n = 1; n < NumN() - 1; ++n)
std::vector validNodeMask(NumN(), std::vector(NumM(), false));
for (UInt n = 0; n < NumN() - 1; ++n)
{
for (UInt m = 1; m < NumM() - 1; ++m)
for (UInt m = 0; m < NumM() - 1; ++m)
{
if (m_gridNodes(n, m).IsValid() &&
!m_gridFacesMask(n, m) &&
!m_gridFacesMask(n, m - 1) &&
!m_gridFacesMask(n - 1, m - 1) &&
!m_gridFacesMask(n - 1, m))
if (m_gridFacesMask(n, m))
{
m_gridNodes(n, m) = {constants::missing::doubleValue, constants::missing::doubleValue};
invalidNodesToRemove = true;
validNodeMask[n][m] = true;
validNodeMask[n][m + 1] = true;
validNodeMask[n + 1][m] = true;
validNodeMask[n + 1][m + 1] = true;
}
}
}

for (UInt m = 1; m < NumM() - 1; ++m)
{
if (m_gridNodes(0, m).IsValid() &&
!m_gridFacesMask(0, m - 1) &&
!m_gridFacesMask(0, m))
{
m_gridNodes(0, m) = {constants::missing::doubleValue, constants::missing::doubleValue};
}
}

for (UInt n = 1; n < NumN() - 1; ++n)
invalidNodesToRemove = false;
for (UInt n = 0; n < NumN(); ++n)
{
if (m_gridNodes(n, 0).IsValid() &&
!m_gridFacesMask(n - 1, 0) &&
!m_gridFacesMask(n, 0))
for (UInt m = 0; m < NumM(); ++m)
{
m_gridNodes(n, 0) = {constants::missing::doubleValue, constants::missing::doubleValue};
if (!validNodeMask[n][m] && m_gridNodes(n, m).IsValid())
{
m_gridNodes(n, m) = {constants::missing::doubleValue, constants::missing::doubleValue};
invalidNodesToRemove = true;
}
}
}

if (m_gridNodes(0, 0).IsValid() && !m_gridFacesMask(0, 0))
{
m_gridNodes(0, 0) = {constants::missing::doubleValue, constants::missing::doubleValue};
}

RemoveInvalidNodes(invalidNodesToRemove);
}

Expand Down
30 changes: 30 additions & 0 deletions libs/MeshKernel/tests/src/CurvilinearGridRectangularTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,3 +614,33 @@ TEST(CurvilinearGridUniform, ConvertCurvilinearToNodesAndEdges_ReturnsSerialized
<< "[" << edges[i].first << "," << edges[i].second << "]";
}
}

class CurvilinearGridUniformTests : public ::testing::TestWithParam<std::tuple<meshkernel::Point, int>>
{
public:
[[nodiscard]] static std::vector<std::tuple<Point, int>> GetData()
{
return {
std::make_tuple<Point, int>(Point{10.0, 30.0}, 14),
std::make_tuple<Point, int>(Point{0.0, 30.0}, 15),
std::make_tuple<Point, int>(Point{30.0, 30.0}, 15),
std::make_tuple<Point, int>(Point{10.0, 10.0}, 12),
std::make_tuple<Point, int>(Point{20.0, 10.0}, 12)};
}
};

TEST_P(CurvilinearGridUniformTests, parameters)
{
// Get the test parameters
auto const& [point, expectedNumNodes] = GetParam();

// Prepare
const auto curvilinearGrid = MakeCurvilinearGrid(0.0, 0.0, 10.0, 10.0, 4, 4);

// Execute
curvilinearGrid->DeleteNode(point);

auto const numValidNodes = CurvilinearGridCountValidNodes(*curvilinearGrid);
ASSERT_EQ(numValidNodes, expectedNumNodes);
}
INSTANTIATE_TEST_SUITE_P(curvilinearGridDeletionTests, CurvilinearGridUniformTests, ::testing::ValuesIn(CurvilinearGridUniformTests::GetData()));

0 comments on commit f92e245

Please sign in to comment.