Skip to content

Commit

Permalink
GRIDEDIT-778 Corrected parameter mode for function
Browse files Browse the repository at this point in the history
  • Loading branch information
BillSenior committed May 8, 2024
1 parent d987a0d commit ad888c5
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 27 deletions.
28 changes: 15 additions & 13 deletions libs/MeshKernel/include/MeshKernel/CasulliDeRefinement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<meshkernel::UndoAction> Compute(Mesh2D& mesh);
/* [[nodiscard]] */ std::unique_ptr<meshkernel::UndoAction> Compute(Mesh2D& mesh);

std::vector<Point> ElementsToDelete (Mesh2D& mesh, const Polygons& polygon);
/// @brief Compute centres of elements to be deleted.
///
/// Requires that the element mass centres are computed.
std::vector<Point> 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<meshkernel::UndoAction> Compute(Mesh2D& mesh, const Polygons& polygon);
/* [[nodiscard]] */ std::unique_ptr<meshkernel::UndoAction> 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;
Expand Down Expand Up @@ -174,8 +177,7 @@ namespace meshkernel
/// @brief Compute the mesh node types.
///
/// Uses the m_nodeTypes has been generated in the mesh.
std::vector<int> ComputeNodeTypes (const Mesh2D& mesh, const Polygons& polygon);

std::vector<int> ComputeNodeTypes(const Mesh2D& mesh, const Polygons& polygon);
};

} // namespace meshkernel
27 changes: 13 additions & 14 deletions libs/MeshKernel/src/CasulliDeRefinement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,14 +433,14 @@ void meshkernel::CasulliDeRefinement::DoDeRefinement(Mesh2D& mesh, const Polygon
std::vector<UInt> directlyConnected;
std::vector<UInt> indirectlyConnected;
std::vector<std::array<int, 2>> kne(nMax);
std::vector<int> nodeTypes (ComputeNodeTypes (mesh, polygon));
std::vector<int> nodeTypes(ComputeNodeTypes(mesh, polygon));
directlyConnected.reserve(nMax);
indirectlyConnected.reserve(nMax);

refinementSuccessful = true;

std::vector<ElementMask> cellMask(InitialiseElementMask(mesh, nodeTypes, polygon));
mesh.ComputeCircumcentersMassCentersAndFaceAreas (true);
mesh.ComputeCircumcentersMassCentersAndFaceAreas(true);

for (UInt k = 0; k < cellMask.size(); ++k)
{
Expand Down Expand Up @@ -1035,28 +1035,27 @@ bool meshkernel::CasulliDeRefinement::IsElementConvex(const Mesh2D& mesh, const
return true;
}

std::vector<int> meshkernel::CasulliDeRefinement::ComputeNodeTypes (const Mesh2D& mesh, const Polygons& polygon)
std::vector<int> meshkernel::CasulliDeRefinement::ComputeNodeTypes(const Mesh2D& mesh, const Polygons& polygon)
{
std::vector<int> nodeTypes (mesh.GetNumNodes ());
std::vector<int> 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::Point> meshkernel::CasulliDeRefinement::ElementsToDelete (Mesh2D& mesh, const Polygons& polygon)
std::vector<meshkernel::Point> meshkernel::CasulliDeRefinement::ElementsToDelete(const Mesh2D& mesh, const Polygons& polygon)
{
std::vector<int> nodeTypes (ComputeNodeTypes (mesh, polygon));
std::vector<int> nodeTypes(ComputeNodeTypes(mesh, polygon));
std::vector<ElementMask> cellMask(InitialiseElementMask(mesh, nodeTypes, polygon));
std::vector<Point> elementCentres;
elementCentres.reserve (cellMask.size ());
mesh.ComputeCircumcentersMassCentersAndFaceAreas (true);
elementCentres.reserve(cellMask.size());

for (UInt k = 0; k < cellMask.size(); ++k)
{
Expand All @@ -1066,16 +1065,16 @@ std::vector<meshkernel::Point> 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]);
}
}
}
Expand Down
29 changes: 29 additions & 0 deletions libs/MeshKernel/tests/src/MeshRefinementTests.cpp
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
//
// contact: [email protected]
// 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"
Expand Down Expand Up @@ -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<meshkernel::Point> toDelete(casulliDerefinement.ElementsToDelete(mesh, lowerPolygon));

Expand Down

0 comments on commit ad888c5

Please sign in to comment.