Loading [MathJax]/extensions/tex2jax.js
MeshKernel
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages Concepts
ConnectMeshes.hpp
1//---- GPL ---------------------------------------------------------------------
2//
3// Copyright (C) Stichting Deltares, 2011-2023.
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#include <array>
30#include <utility>
31#include <vector>
32
33#include "MeshKernel/Definitions.hpp"
34#include "MeshKernel/Mesh2D.hpp"
35#include "MeshKernel/Point.hpp"
36#include "MeshKernel/Polygons.hpp"
37#include "MeshKernel/Utilities/RTreeBase.hpp"
38
39namespace meshkernel
40{
41
46 // Functionality re-implemented from connectcurvilinearquadsddtype.f90
47 class ConnectMeshes final
48 {
49 public:
51 static constexpr double DefaultMaximumSeparationFraction = 0.4;
52
56 static constexpr double minimumParallelDeviation = 0.9;
57
64 [[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> Compute(Mesh2D& mesh, const double separationFraction = DefaultMaximumSeparationFraction);
65
73 [[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> Compute(Mesh2D& mesh, const Polygons& polygon, const double separationFraction = DefaultMaximumSeparationFraction);
74
75 private:
77 static constexpr double EdgeLengthTolerance = 1.0e-10;
78
80 static constexpr UInt m_maximumNumberOfIrregularElementsAlongEdge = 5;
81
83 enum class MergeIndicator
84 {
85 Initial,
86 DoMerge,
87 DoNotMerge
88 };
89
91 using BoundedIntegerArray = std::array<UInt, m_maximumNumberOfIrregularElementsAlongEdge>;
92
94 using NodesToMerge = std::pair<UInt, UInt>;
95
97 struct IrregularEdgeInfo
98 {
100 BoundedIntegerArray hangingNodes{constants::missing::uintValue,
101 constants::missing::uintValue,
102 constants::missing::uintValue,
103 constants::missing::uintValue,
104 constants::missing::uintValue};
106 UInt edgeCount = 0;
108 UInt startNode = constants::missing::uintValue;
110 UInt endNode = constants::missing::uintValue;
111 };
112
114 using IrregularEdgeInfoArray = std::vector<IrregularEdgeInfo>;
115
126 static void AreEdgesAdjacent(const Mesh2D& mesh,
127 const double separationFraction,
128 const UInt edge1,
129 const UInt edge2,
130 bool& areAdjacent,
131 UInt& startNode,
132 UInt& endNode,
133 const std::vector<double>& edgeLengths);
134
142 static void GetQuadrilateralElementsOnDomainBoundary(const Mesh2D& mesh,
143 const std::vector<Boolean>& nodeInsidePolygon,
144 std::vector<UInt>& elementsOnDomainBoundary,
145 std::vector<UInt>& edgesOnDomainBoundary,
146 std::vector<double>& edgeLengths);
147
155 static void GetOrderedDistanceFromPoint(const Mesh2D& mesh,
156 const std::vector<UInt>& nodeIndices,
157 const UInt numberOfNodes,
158 const Point& point,
159 BoundedIntegerArray& nearestNeighbours);
160
166 static std::unique_ptr<meshkernel::UndoAction> MergeNodes(Mesh2D& mesh, const std::vector<NodesToMerge>& nodesToMerge, std::vector<MergeIndicator>& mergeIndicator);
167
174 [[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> FreeOneHangingNode(Mesh2D& mesh,
175 const BoundedIntegerArray& hangingNodes,
176 const UInt startNode,
177 const UInt endNode);
178
187 [[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> FreeTwoHangingNodes(Mesh2D& mesh,
188 const UInt faceId,
189 const UInt edgeId,
190 const BoundedIntegerArray& hangingNodes,
191 const UInt startNode,
192 const UInt endNode);
193
202 [[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> FreeThreeHangingNodes(Mesh2D& mesh,
203 const UInt faceId,
204 const UInt edgeId,
205 const BoundedIntegerArray& hangingNodes,
206 const UInt startNode,
207 const UInt endNode);
208
217 [[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> FreeFourHangingNodes(Mesh2D& mesh,
218 const UInt faceId,
219 const UInt edgeId,
220 const BoundedIntegerArray& hangingNodes,
221 const UInt startNode,
222 const UInt endNode);
223
233 [[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> FreeHangingNodes(Mesh2D& mesh,
234 const UInt numberOfHangingNodes,
235 const std::vector<UInt>& hangingNodesOnEdge,
236 const UInt faceId,
237 const Edge& boundaryEdge,
238 const Point& boundaryNode,
239 const UInt edgeId);
240
248 static void GatherHangingNodeIds(const Mesh2D& mesh,
249 const double separationFraction,
250 const std::vector<UInt>& edgesOnDomainBoundary,
251 const std::vector<double>& edgeLengths,
252 IrregularEdgeInfoArray& irregularEdges);
253
263 static void GatherNodesToMerge(const UInt startNode,
264 const UInt endNode,
265 const Edge& boundaryEdge,
266 std::vector<NodesToMerge>& nodesToMerge,
267 std::vector<MergeIndicator>& mergeIndicator);
268
277 static void GatherHangingNodes(const UInt primaryStartNode,
278 const UInt primaryEndNode,
279 const Edge& irregularEdge,
280 std::vector<UInt>& hangingNodesOnEdge,
281 UInt& numberOfHangingNodes,
282 std::vector<MergeIndicator>& mergeIndicator);
283 };
284
285} // namespace meshkernel
Connects grids across element faces.
Definition ConnectMeshes.hpp:48
static constexpr double minimumParallelDeviation
The cos of the minimum angle between two lines to be considered parallel or almost parallel.
Definition ConnectMeshes.hpp:56
static std::unique_ptr< meshkernel::UndoAction > Compute(Mesh2D &mesh, const double separationFraction=DefaultMaximumSeparationFraction)
Connect grids.
static std::unique_ptr< meshkernel::UndoAction > Compute(Mesh2D &mesh, const Polygons &polygon, const double separationFraction=DefaultMaximumSeparationFraction)
Connect grids.
static constexpr double DefaultMaximumSeparationFraction
The default and maximum value of the fraction of the edge length used to determine if edges are adjac...
Definition ConnectMeshes.hpp:51
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
Contains the logic of the C++ static library.
Definition AveragingInterpolation.hpp:37
std::pair< UInt, UInt > Edge
Describes an edge with two indices.
Definition Entities.hpp:50
std::uint32_t UInt
Integer type used when indexing mesh graph entities.
Definition Definitions.hpp:39