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/Polygons.hpp"
36 #include "MeshKernel/UndoActions/UndoAction.hpp"
37 
38 namespace meshkernel
39 {
42  {
43  public:
47  [[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> Compute(Mesh2D& mesh);
48 
53  [[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> Compute(Mesh2D& mesh, const Polygons& polygon);
54 
55  private:
59  enum class NodeMask : char
60  {
61  NewAssignedNode, //< a new node has been added, current node mask value is any value strictly greater than Unassigned.
62  NewGeneralNode, //< a new node has been added, current node mask value is any assigned value
63  Unassigned, //< Uninitialised state for node mask
64  RegisteredNode, //< Node is to be considered as part of the Casulli refinement
65  BoundaryNode, //< Node lies on the boundary
66  CornerNode //< Node lies at corner of element on the boundary.
67  };
68 
70  static constexpr UInt InitialEdgeArraySize = 100;
71 
73  static constexpr UInt MaximumNumberOfNodesInNewlyCreatedElements = 4;
74 
77  using EdgeNodes = std::array<UInt, 4>;
78 
83  static void InitialiseBoundaryNodes(const Mesh2D& mesh, std::vector<NodeMask>& nodeMask);
84 
89  static void InitialiseCornerNodes(const Mesh2D& mesh, std::vector<NodeMask>& nodeMask);
90 
95  static void InitialiseFaceNodes(const Mesh2D& mesh, std::vector<NodeMask>& nodeMask);
96 
101  static std::vector<NodeMask> InitialiseNodeMask(const Mesh2D& mesh, const Polygons& polygon);
102 
108  static void ComputeNewNodes(Mesh2D& mesh, std::vector<EdgeNodes>& newNodes, std::vector<NodeMask>& nodeMask);
109 
115  static void ConnectNodes(Mesh2D& mesh, const std::vector<EdgeNodes>& newNodes, const UInt numEdges);
116 
118  static std::vector<UInt> GetNodesToConnect(const Mesh2D& mesh,
119  const std::vector<NodeMask>& nodeMask,
120  const std::vector<UInt>& newEdges,
121  const std::vector<EdgeNodes>& newNodes,
122  const UInt edgeCount,
123  const UInt nodeIndex);
124 
126  static void ConnectNodes(Mesh2D& mesh,
127  const NodeMask nodeMask,
128  const std::vector<UInt>& nodesToConnect,
129  const UInt edgeCount,
130  const UInt nodeIndex);
131 
138  static void CreateMissingBoundaryEdges(Mesh2D& mesh, const UInt numNodes, const std::vector<EdgeNodes>& newNodes, std::vector<NodeMask>& nodeMask);
139 
145  static void ComputeNewFaceNodes(Mesh2D& mesh, std::vector<EdgeNodes>& newNodes, std::vector<NodeMask>& nodeMask);
146 
153  static void ComputeNewEdgeNodes(Mesh2D& mesh, const UInt numEdges, std::vector<EdgeNodes>& newNodes, std::vector<NodeMask>& nodeMask);
154 
162  static void ConnectEdges(Mesh2D& mesh,
163  const UInt currentNode,
164  const std::vector<EdgeNodes>& newNodes,
165  UInt& edgeCount,
166  std::vector<UInt>& newEdges);
167 
174  static void ConnectFaceNodes(Mesh2D& mesh,
175  const UInt currentFace,
176  const std::vector<EdgeNodes>& newNodes,
177  std::vector<NodeMask>& nodeMask);
178 
187  static void ConnectNewNodes(Mesh2D& mesh, const std::vector<EdgeNodes>& newNodes, const UInt numNodes, const UInt numEdges, const UInt numFaces, std::vector<NodeMask>& nodeMask);
188 
197  static void StoreNewNode(const Mesh2D& mesh, const UInt nodeId, const UInt edge1Index, const UInt edge2Index, const UInt newNodeId, std::vector<EdgeNodes>& newNodes);
198 
206  static void FindPatchIds(const Mesh2D& mesh,
207  const UInt currentNode,
208  std::vector<UInt>& sharedFaces,
209  std::vector<UInt>& connectedNodes,
210  std::vector<std::vector<UInt>>& faceNodeMapping);
211 
217  static void Administrate(Mesh2D& mesh, const UInt numNodes, const std::vector<NodeMask>& nodeMask);
218  };
219 
220 } // namespace meshkernel
meshkernel::CasulliRefinement
Compute the Casulli refinement for a mesh.
Definition: CasulliRefinement.hpp:41
meshkernel::Mesh2D
A class derived from Mesh, which describes unstructures 2d meshes.
Definition: Mesh2D.hpp:55
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:38
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.