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 <vector>
32 
33 #include "MeshKernel/Mesh2D.hpp"
34 #include "MeshKernel/Polygons.hpp"
35 #include "MeshKernel/UndoActions/UndoAction.hpp"
36 
37 namespace meshkernel
38 {
41  {
42  public:
46  [[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> Compute(Mesh2D& mesh);
47 
52  [[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> Compute(Mesh2D& mesh, const Polygons& polygon);
53 
54  private:
58  enum class NodeMask : char
59  {
60  NewAssignedNode, //< a new node has been added, current node mask value is any value strictly greater than Unassigned.
61  NewGeneralNode, //< a new node has been added, current node mask value is any assigned value
62  Unassigned, //< Uninitialised state for node mask
63  RegisteredNode, //< Node is to be considered as part of the Casulli refinement
64  BoundaryNode, //< Node lies on the boundary
65  CornerNode //< Node lies at corner of element on the boundary.
66  };
67 
69  static constexpr UInt InitialEdgeArraySize = 100;
70 
72  static constexpr UInt MaximumNumberOfNodesInNewlyCreatedElements = 4;
73 
76  using EdgeNodes = std::array<UInt, 4>;
77 
82  static void InitialiseBoundaryNodes(const Mesh2D& mesh, std::vector<NodeMask>& nodeMask);
83 
88  static void InitialiseCornerNodes(const Mesh2D& mesh, std::vector<NodeMask>& nodeMask);
89 
94  static void InitialiseFaceNodes(const Mesh2D& mesh, std::vector<NodeMask>& nodeMask);
95 
100  static std::vector<NodeMask> InitialiseNodeMask(const Mesh2D& mesh, const Polygons& polygon);
101 
107  [[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> ComputeNewNodes(Mesh2D& mesh, std::vector<EdgeNodes>& newNodes, std::vector<NodeMask>& nodeMask);
108 
114  [[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> ConnectNodes(Mesh2D& mesh, const std::vector<EdgeNodes>& newNodes, const UInt numEdges);
115 
122  [[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> CreateMissingBoundaryEdges(Mesh2D& mesh, const UInt numNodes, const std::vector<EdgeNodes>& newNodes, std::vector<NodeMask>& nodeMask);
123 
129  [[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> ComputeNewFaceNodes(Mesh2D& mesh, std::vector<EdgeNodes>& newNodes, std::vector<NodeMask>& nodeMask);
130 
137  [[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> ComputeNewEdgeNodes(Mesh2D& mesh, const UInt numEdges, std::vector<EdgeNodes>& newNodes, std::vector<NodeMask>& nodeMask);
138 
146  [[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> ConnectEdges(Mesh2D& mesh,
147  const UInt currentNode,
148  const std::vector<EdgeNodes>& newNodes,
149  UInt& edgeCount,
150  std::vector<UInt>& newEdges);
151 
158  [[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> ConnectFaceNodes(Mesh2D& mesh,
159  const UInt currentFace,
160  const std::vector<EdgeNodes>& newNodes,
161  std::vector<NodeMask>& nodeMask);
162 
171  [[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> ConnectNewNodes(Mesh2D& mesh, const std::vector<EdgeNodes>& newNodes, const UInt numNodes, const UInt numEdges, const UInt numFaces, std::vector<NodeMask>& nodeMask);
172 
181  static void StoreNewNode(const Mesh2D& mesh, const UInt nodeId, const UInt edge1Index, const UInt edge2Index, const UInt newNodeId, std::vector<EdgeNodes>& newNodes);
182 
190  static void FindPatchIds(const Mesh2D& mesh,
191  const UInt currentNode,
192  std::vector<UInt>& sharedFaces,
193  std::vector<UInt>& connectedNodes,
194  std::vector<std::vector<UInt>>& faceNodeMapping);
195 
201  [[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> Administrate(Mesh2D& mesh, const UInt numNodes, const std::vector<NodeMask>& nodeMask);
202  };
203 
204 } // namespace meshkernel
meshkernel::CasulliRefinement
Compute the Casulli refinement for a mesh.
Definition: CasulliRefinement.hpp:40
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.