MeshKernel
CasulliRefinement.hpp
1 //---- GPL ---------------------------------------------------------------------
2 //
3 // Copyright (C) Stichting Deltares, 2011-2021.
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation version 3.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // contact: delft3d.support@deltares.nl
18 // Stichting Deltares
19 // P.O. Box 177
20 // 2600 MH Delft, The Netherlands
21 //
22 // All indications and logos of, and references to, "Delft3D" and "Deltares"
23 // are registered trademarks of Stichting Deltares, and remain the property of
24 // Stichting Deltares. All rights reserved.
25 //
26 //------------------------------------------------------------------------------
27 
28 #pragma once
29 
30 #include <array>
31 #include <memory>
32 #include <vector>
33 
34 #include "MeshKernel/Mesh2D.hpp"
35 #include "MeshKernel/Parameters.hpp"
36 #include "MeshKernel/Polygons.hpp"
37 #include "MeshKernel/UndoActions/UndoAction.hpp"
38 
39 namespace meshkernel
40 {
43  {
44  public:
48  [[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> Compute(Mesh2D& mesh);
49 
54  [[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> Compute(Mesh2D& mesh, const Polygons& polygon);
55 
56  private:
60  enum class NodeMask : char
61  {
62  NewAssignedNode, //< a new node has been added, current node mask value is any value strictly greater than Unassigned.
63  NewGeneralNode, //< a new node has been added, current node mask value is any assigned value
64  Unassigned, //< Uninitialised state for node mask
65  RegisteredNode, //< Node is to be considered as part of the Casulli refinement
66  BoundaryNode, //< Node lies on the boundary
67  CornerNode //< Node lies at corner of element on the boundary.
68  };
69 
71  static constexpr UInt InitialEdgeArraySize = 100;
72 
74  static constexpr UInt MaximumNumberOfNodesInNewlyCreatedElements = 4;
75 
78  using EdgeNodes = std::array<UInt, 4>;
79 
84  static void InitialiseBoundaryNodes(const Mesh2D& mesh, std::vector<NodeMask>& nodeMask);
85 
90  static void InitialiseCornerNodes(const Mesh2D& mesh, std::vector<NodeMask>& nodeMask);
91 
96  static void InitialiseFaceNodes(const Mesh2D& mesh, std::vector<NodeMask>& nodeMask);
97 
99  static void RegisterNodesInsidePolygon(const Mesh2D& mesh,
100  const Polygons& polygon,
101  std::vector<NodeMask>& nodeMask);
102 
107  static std::vector<NodeMask> InitialiseNodeMask(const Mesh2D& mesh, const Polygons& polygon);
108 
114  static void ComputeNewNodes(Mesh2D& mesh, std::vector<EdgeNodes>& newNodes, std::vector<NodeMask>& nodeMask);
115 
121  static void ConnectNodes(Mesh2D& mesh, const std::vector<EdgeNodes>& newNodes, const UInt numEdges);
122 
124  static std::vector<UInt> GetNodesToConnect(const Mesh2D& mesh,
125  const std::vector<NodeMask>& nodeMask,
126  const std::vector<UInt>& newEdges,
127  const std::vector<EdgeNodes>& newNodes,
128  const UInt edgeCount,
129  const UInt nodeIndex);
130 
132  static void ConnectNodes(Mesh2D& mesh,
133  const NodeMask nodeMask,
134  const std::vector<UInt>& nodesToConnect,
135  const UInt edgeCount,
136  const UInt nodeIndex);
137 
144  static void CreateMissingBoundaryEdges(Mesh2D& mesh, const UInt numNodes, const std::vector<EdgeNodes>& newNodes, std::vector<NodeMask>& nodeMask);
145 
151  static void ComputeNewFaceNodes(Mesh2D& mesh, std::vector<EdgeNodes>& newNodes, std::vector<NodeMask>& nodeMask);
152 
159  static void ComputeNewEdgeNodes(Mesh2D& mesh, const UInt numEdges, std::vector<EdgeNodes>& newNodes, std::vector<NodeMask>& nodeMask);
160 
168  static void ConnectEdges(Mesh2D& mesh,
169  const UInt currentNode,
170  const std::vector<EdgeNodes>& newNodes,
171  UInt& edgeCount,
172  std::vector<UInt>& newEdges);
173 
180  static void ConnectFaceNodes(Mesh2D& mesh,
181  const UInt currentFace,
182  const std::vector<EdgeNodes>& newNodes,
183  std::vector<NodeMask>& nodeMask);
184 
193  static void ConnectNewNodes(Mesh2D& mesh, const std::vector<EdgeNodes>& newNodes, const UInt numNodes, const UInt numEdges, const UInt numFaces, std::vector<NodeMask>& nodeMask);
194 
203  static void StoreNewNode(const Mesh2D& mesh, const UInt nodeId, const UInt edge1Index, const UInt edge2Index, const UInt newNodeId, std::vector<EdgeNodes>& newNodes);
204 
212  static void FindPatchIds(const Mesh2D& mesh,
213  const UInt currentNode,
214  std::vector<UInt>& sharedFaces,
215  std::vector<UInt>& connectedNodes,
216  std::vector<std::vector<UInt>>& faceNodeMapping);
217 
223  static void Administrate(Mesh2D& mesh, const UInt numNodes, const std::vector<NodeMask>& nodeMask);
224  };
225 
226 } // namespace meshkernel
meshkernel::CasulliRefinement
Compute the Casulli refinement for a mesh.
Definition: CasulliRefinement.hpp:42
meshkernel::Mesh2D
A class derived from Mesh, which describes unstructures 2d meshes.
Definition: Mesh2D.hpp:56
meshkernel
Contains the logic of the C++ static library.
Definition: AveragingInterpolation.hpp:36
meshkernel::UInt
std::uint32_t UInt
Integer type used when indexing mesh graph entities.
Definition: Definitions.hpp:39
meshkernel::Polygons
A class containing a list of polygonaly enclosed regions.
Definition: Polygons.hpp:44
meshkernel::CasulliRefinement::Compute
static std::unique_ptr< meshkernel::UndoAction > Compute(Mesh2D &mesh)
Compute the Casulli refinement for the entire mesh.