Loading [MathJax]/extensions/tex2jax.js
MeshKernel
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages Concepts
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/SampleInterpolator.hpp"
38#include "MeshKernel/UndoActions/UndoAction.hpp"
39
40namespace meshkernel
41{
44 {
45 public:
49 [[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> Compute(Mesh2D& mesh);
50
55 [[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> Compute(Mesh2D& mesh, const Polygons& polygon);
56
64 [[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> Compute(Mesh2D& mesh,
65 const Polygons& polygon,
66 const std::vector<double>& depthValues,
67 const MeshRefinementParameters& refinementParameters,
68 const double minimumDepthRefinement);
69
78 [[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> Compute(Mesh2D& mesh,
79 const Polygons& polygon,
80 const SampleInterpolator& interpolator,
81 const int propertyId,
82 const MeshRefinementParameters& refinementParameters,
83 const double minimumDepthRefinement);
84
85 private:
89 enum class NodeMask : char
90 {
91 NewAssignedNode, //< a new node has been added, current node mask value is any value strictly greater than Unassigned.
92 NewGeneralNode, //< a new node has been added, current node mask value is any assigned value
93 Unassigned, //< Uninitialised state for node mask
94 RegisteredNode, //< Node is to be considered as part of the Casulli refinement
95 BoundaryNode, //< Node lies on the boundary
96 CornerNode //< Node lies at corner of element on the boundary.
97 };
98
100 static constexpr UInt InitialEdgeArraySize = 100;
101
103 static constexpr UInt MaximumNumberOfNodesInNewlyCreatedElements = 4;
104
107 using EdgeNodes = std::array<UInt, 4>;
108
113 static void InitialiseBoundaryNodes(const Mesh2D& mesh, std::vector<NodeMask>& nodeMask);
114
119 static void InitialiseCornerNodes(const Mesh2D& mesh, std::vector<NodeMask>& nodeMask);
120
125 static void InitialiseFaceNodes(const Mesh2D& mesh, std::vector<NodeMask>& nodeMask);
126
128 static void RegisterNodesInsidePolygon(const Mesh2D& mesh,
129 const Polygons& polygon,
130 std::vector<NodeMask>& nodeMask);
131
136 static std::vector<NodeMask> InitialiseNodeMask(const Mesh2D& mesh, const Polygons& polygon);
137
141 static std::vector<NodeMask> InitialiseDepthBasedNodeMask(const Mesh2D& mesh,
142 const Polygons& polygon,
143 const std::vector<double>& depthValues,
144 const MeshRefinementParameters& refinementParameters,
145 const double minimumDepthRefinement,
146 bool& refinementRequested);
147
149 static void RefineNodeMaskBasedOnDepths(const Mesh2D& mesh,
150 const std::vector<double>& depthValues,
151 const MeshRefinementParameters& refinementParameters,
152 const double minimumDepthRefinement,
153 std::vector<NodeMask>& nodeMask,
154 bool& refinementRequested);
155
161 static void ComputeNewNodes(Mesh2D& mesh, std::vector<EdgeNodes>& newNodes, std::vector<NodeMask>& nodeMask);
162
168 static void ConnectNodes(Mesh2D& mesh, const std::vector<EdgeNodes>& newNodes, const UInt numEdges);
169
171 static std::vector<UInt> GetNodesToConnect(const Mesh2D& mesh,
172 const std::vector<NodeMask>& nodeMask,
173 const std::vector<UInt>& newEdges,
174 const std::vector<EdgeNodes>& newNodes,
175 const UInt edgeCount,
176 const UInt nodeIndex);
177
179 static void ConnectNodes(Mesh2D& mesh,
180 const NodeMask nodeMask,
181 const std::vector<UInt>& nodesToConnect,
182 const UInt edgeCount,
183 const UInt nodeIndex);
184
191 static void CreateMissingBoundaryEdges(Mesh2D& mesh, const UInt numNodes, const std::vector<EdgeNodes>& newNodes, std::vector<NodeMask>& nodeMask);
192
198 static void ComputeNewFaceNodes(Mesh2D& mesh, std::vector<EdgeNodes>& newNodes, std::vector<NodeMask>& nodeMask);
199
206 static void ComputeNewEdgeNodes(Mesh2D& mesh, const UInt numEdges, std::vector<EdgeNodes>& newNodes, std::vector<NodeMask>& nodeMask);
207
215 static void ConnectEdges(Mesh2D& mesh,
216 const UInt currentNode,
217 const std::vector<EdgeNodes>& newNodes,
218 UInt& edgeCount,
219 std::vector<UInt>& newEdges);
220
227 static void ConnectFaceNodes(Mesh2D& mesh,
228 const UInt currentFace,
229 const std::vector<EdgeNodes>& newNodes,
230 std::vector<NodeMask>& nodeMask);
231
240 static void ConnectNewNodes(Mesh2D& mesh, const std::vector<EdgeNodes>& newNodes, const UInt numNodes, const UInt numEdges, const UInt numFaces, std::vector<NodeMask>& nodeMask);
241
250 static void StoreNewNode(const Mesh2D& mesh, const UInt nodeId, const UInt edge1Index, const UInt edge2Index, const UInt newNodeId, std::vector<EdgeNodes>& newNodes);
251
259 static void FindPatchIds(const Mesh2D& mesh,
260 const UInt currentNode,
261 std::vector<UInt>& sharedFaces,
262 std::vector<UInt>& connectedNodes,
263 std::vector<std::vector<UInt>>& faceNodeMapping);
264
270 static void Administrate(Mesh2D& mesh, const UInt numNodes, const std::vector<NodeMask>& nodeMask);
271 };
272
273} // namespace meshkernel
Compute the Casulli refinement for a mesh.
Definition CasulliRefinement.hpp:44
static std::unique_ptr< meshkernel::UndoAction > Compute(Mesh2D &mesh, const Polygons &polygon)
Compute the Casulli refinement for the part of the mesh inside the polygon.
static std::unique_ptr< meshkernel::UndoAction > Compute(Mesh2D &mesh, const Polygons &polygon, const SampleInterpolator &interpolator, const int propertyId, const MeshRefinementParameters &refinementParameters, const double minimumDepthRefinement)
Compute the Casulli refinement for the part of the mesh inside the polygon.
static std::unique_ptr< meshkernel::UndoAction > Compute(Mesh2D &mesh)
Compute the Casulli refinement for the entire mesh.
static std::unique_ptr< meshkernel::UndoAction > Compute(Mesh2D &mesh, const Polygons &polygon, const std::vector< double > &depthValues, const MeshRefinementParameters &refinementParameters, const double minimumDepthRefinement)
Compute the Casulli refinement for the part of the mesh inside the polygon.
A class derived from Mesh, which describes unstructures 2d meshes.
Definition Mesh2D.hpp:58
A class containing a list of polygonaly enclosed regions.
Definition Polygons.hpp:45
Interface for sample interpolation.
Definition SampleInterpolator.hpp:53
Contains the logic of the C++ static library.
Definition AveragingInterpolation.hpp:37
std::uint32_t UInt
Integer type used when indexing mesh graph entities.
Definition Definitions.hpp:39
A struct used to describe the mesh refinement parameters in a C-compatible manner.
Definition Parameters.hpp:187