diff --git a/libs/MeshKernel/include/MeshKernel/CasulliDeRefinement.hpp b/libs/MeshKernel/include/MeshKernel/CasulliDeRefinement.hpp index a885fdfd6..156cc5b14 100644 --- a/libs/MeshKernel/include/MeshKernel/CasulliDeRefinement.hpp +++ b/libs/MeshKernel/include/MeshKernel/CasulliDeRefinement.hpp @@ -43,27 +43,30 @@ namespace meshkernel /// @brief Compute the Casulli de-refinement for the entire mesh. /// /// @param [in, out] mesh Mesh to be de-refined - /* [[nodiscard]] */ std::unique_ptr Compute(Mesh2D& mesh); + /* [[nodiscard]] */ std::unique_ptr Compute(Mesh2D& mesh); - std::vector ElementsToDelete (Mesh2D& mesh, const Polygons& polygon); + /// @brief Compute centres of elements to be deleted. + /// + /// Requires that the element mass centres are computed. + std::vector ElementsToDelete(const Mesh2D& mesh, const Polygons& polygon); /// @brief Compute the Casulli de-refinement for the part of the mesh inside the polygon /// /// @param [in, out] mesh Mesh to be de-refined /// @param [in] polygon Area within which the mesh will be de-refined - /* [[nodiscard]] */ std::unique_ptr Compute(Mesh2D& mesh, const Polygons& polygon); + /* [[nodiscard]] */ std::unique_ptr Compute(Mesh2D& mesh, const Polygons& polygon); private: // WTF enum class ElementMask - { - A = 1, //< front, 'A' cell (used to be node, delete it): 1 - B = 2, //< front, 'B' cell (used to be link, keep it): 2 - C = 3, //< 'C' cell (used to be cell, keep it): 3 - NotA = -1, //< not in front, 'A' cell: -1 - NotB = -2, //< not in front, 'B' cell: -2 - Unassigned = 0 //< 0 - }; + { + A = 1, //< front, 'A' cell (used to be node, delete it): 1 + B = 2, //< front, 'B' cell (used to be link, keep it): 2 + C = 3, //< 'C' cell (used to be cell, keep it): 3 + NotA = -1, //< not in front, 'A' cell: -1 + NotB = -2, //< not in front, 'B' cell: -2 + Unassigned = 0 //< 0 + }; /// @brief Initial size of the edge array static const UInt InitialEdgeArraySize = 100; @@ -174,8 +177,7 @@ namespace meshkernel /// @brief Compute the mesh node types. /// /// Uses the m_nodeTypes has been generated in the mesh. - std::vector ComputeNodeTypes (const Mesh2D& mesh, const Polygons& polygon); - + std::vector ComputeNodeTypes(const Mesh2D& mesh, const Polygons& polygon); }; } // namespace meshkernel diff --git a/libs/MeshKernel/src/CasulliDeRefinement.cpp b/libs/MeshKernel/src/CasulliDeRefinement.cpp index 3100563b3..55eca183d 100644 --- a/libs/MeshKernel/src/CasulliDeRefinement.cpp +++ b/libs/MeshKernel/src/CasulliDeRefinement.cpp @@ -433,14 +433,14 @@ void meshkernel::CasulliDeRefinement::DoDeRefinement(Mesh2D& mesh, const Polygon std::vector directlyConnected; std::vector indirectlyConnected; std::vector> kne(nMax); - std::vector nodeTypes (ComputeNodeTypes (mesh, polygon)); + std::vector nodeTypes(ComputeNodeTypes(mesh, polygon)); directlyConnected.reserve(nMax); indirectlyConnected.reserve(nMax); refinementSuccessful = true; std::vector cellMask(InitialiseElementMask(mesh, nodeTypes, polygon)); - mesh.ComputeCircumcentersMassCentersAndFaceAreas (true); + mesh.ComputeCircumcentersMassCentersAndFaceAreas(true); for (UInt k = 0; k < cellMask.size(); ++k) { @@ -1035,28 +1035,27 @@ bool meshkernel::CasulliDeRefinement::IsElementConvex(const Mesh2D& mesh, const return true; } -std::vector meshkernel::CasulliDeRefinement::ComputeNodeTypes (const Mesh2D& mesh, const Polygons& polygon) +std::vector meshkernel::CasulliDeRefinement::ComputeNodeTypes(const Mesh2D& mesh, const Polygons& polygon) { - std::vector nodeTypes (mesh.GetNumNodes ()); + std::vector nodeTypes(mesh.GetNumNodes()); - for (UInt i = 0; i < mesh.GetNumNodes (); ++i) + for (UInt i = 0; i < mesh.GetNumNodes(); ++i) { - if (polygon.IsPointInAnyPolygon (mesh.Node (i))) + if (polygon.IsPointInAnyPolygon(mesh.Node(i))) { - nodeTypes [i] = mesh.m_nodesTypes [i]; + nodeTypes[i] = mesh.m_nodesTypes[i]; } } return nodeTypes; } -std::vector meshkernel::CasulliDeRefinement::ElementsToDelete (Mesh2D& mesh, const Polygons& polygon) +std::vector meshkernel::CasulliDeRefinement::ElementsToDelete(const Mesh2D& mesh, const Polygons& polygon) { - std::vector nodeTypes (ComputeNodeTypes (mesh, polygon)); + std::vector nodeTypes(ComputeNodeTypes(mesh, polygon)); std::vector cellMask(InitialiseElementMask(mesh, nodeTypes, polygon)); std::vector elementCentres; - elementCentres.reserve (cellMask.size ()); - mesh.ComputeCircumcentersMassCentersAndFaceAreas (true); + elementCentres.reserve(cellMask.size()); for (UInt k = 0; k < cellMask.size(); ++k) { @@ -1066,16 +1065,16 @@ std::vector meshkernel::CasulliDeRefinement::ElementsToDelete for (UInt j = 0; j < mesh.m_numFacesNodes[k]; ++j) { - if (nodeTypes[mesh.m_facesNodes [k][j]] > 0) + if (nodeTypes[mesh.m_facesNodes[k][j]] > 0) { toDelete = true; break; } } - if (toDelete ) + if (toDelete) { - elementCentres.push_back (mesh.m_facesMassCenters [k]); + elementCentres.push_back(mesh.m_facesMassCenters[k]); } } } diff --git a/libs/MeshKernel/tests/src/MeshRefinementTests.cpp b/libs/MeshKernel/tests/src/MeshRefinementTests.cpp index 3874a7ea7..473856a2a 100644 --- a/libs/MeshKernel/tests/src/MeshRefinementTests.cpp +++ b/libs/MeshKernel/tests/src/MeshRefinementTests.cpp @@ -1,3 +1,30 @@ +//---- GPL --------------------------------------------------------------------- +// +// Copyright (C) Stichting Deltares, 2011-2024. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation version 3. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// contact: delft3d.support@deltares.nl +// Stichting Deltares +// P.O. Box 177 +// 2600 MH Delft, The Netherlands +// +// All indications and logos of, and references to, "Delft3D" and "Deltares" +// are registered trademarks of Stichting Deltares, and remain the property of +// Stichting Deltares. All rights reserved. +// +//------------------------------------------------------------------------------ + #include "MeshKernel/BilinearInterpolationOnGriddedSamples.hpp" #include "MeshKernel/CasulliDeRefinement.hpp" #include "MeshKernel/CasulliRefinement.hpp" @@ -2016,6 +2043,8 @@ TEST(MeshRefinement, CasulliTwoPolygonDeRefinement) // Derefine on centre polygon casulliDerefinement.Compute(mesh, centrePolygon); + mesh.ComputeCircumcentersMassCentersAndFaceAreas(true); + // Get the element centres of the elements to be deleted. std::vector toDelete(casulliDerefinement.ElementsToDelete(mesh, lowerPolygon));