From f92e2455001d2af141a01598601c4c2f0a22adee Mon Sep 17 00:00:00 2001 From: Luca Carniato Date: Thu, 4 Apr 2024 16:14:32 +0200 Subject: [PATCH] Correct delete node incosistent behavior (#321 | GRIDEDIT-969_delete_node_incosistent_behavior) --- .../src/CurvilinearGrid/CurvilinearGrid.cpp | 47 +++++++------------ .../src/CurvilinearGridRectangularTests.cpp | 30 ++++++++++++ 2 files changed, 46 insertions(+), 31 deletions(-) diff --git a/libs/MeshKernel/src/CurvilinearGrid/CurvilinearGrid.cpp b/libs/MeshKernel/src/CurvilinearGrid/CurvilinearGrid.cpp index 56d3a569d..1329cabc5 100644 --- a/libs/MeshKernel/src/CurvilinearGrid/CurvilinearGrid.cpp +++ b/libs/MeshKernel/src/CurvilinearGrid/CurvilinearGrid.cpp @@ -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); } diff --git a/libs/MeshKernel/tests/src/CurvilinearGridRectangularTests.cpp b/libs/MeshKernel/tests/src/CurvilinearGridRectangularTests.cpp index 309d53eca..c89fd620d 100644 --- a/libs/MeshKernel/tests/src/CurvilinearGridRectangularTests.cpp +++ b/libs/MeshKernel/tests/src/CurvilinearGridRectangularTests.cpp @@ -614,3 +614,33 @@ TEST(CurvilinearGridUniform, ConvertCurvilinearToNodesAndEdges_ReturnsSerialized << "[" << edges[i].first << "," << edges[i].second << "]"; } } + +class CurvilinearGridUniformTests : public ::testing::TestWithParam> +{ +public: + [[nodiscard]] static std::vector> GetData() + { + return { + std::make_tuple(Point{10.0, 30.0}, 14), + std::make_tuple(Point{0.0, 30.0}, 15), + std::make_tuple(Point{30.0, 30.0}, 15), + std::make_tuple(Point{10.0, 10.0}, 12), + std::make_tuple(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()));