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/Utilities/RTreeBase.hpp"
37
38namespace meshkernel
39{
40
45 // Functionality re-implemented from connectcurvilinearquadsddtype.f90
46 class ConnectMeshes final
47 {
48 public:
50 static constexpr double DefaultMaximumSeparationFraction = 0.4;
51
55 static constexpr double minimumParallelDeviation = 0.9;
56
63 [[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> Compute(Mesh2D& mesh, const double separationFraction = DefaultMaximumSeparationFraction);
64
65 private:
67 static constexpr double EdgeLengthTolerance = 1.0e-10;
68
70 static constexpr UInt m_maximumNumberOfIrregularElementsAlongEdge = 5;
71
73 enum class MergeIndicator
74 {
75 Initial,
76 DoMerge,
77 DoNotMerge
78 };
79
81 using BoundedIntegerArray = std::array<UInt, m_maximumNumberOfIrregularElementsAlongEdge>;
82
84 using NodesToMerge = std::pair<UInt, UInt>;
85
87 struct IrregularEdgeInfo
88 {
90 BoundedIntegerArray hangingNodes{constants::missing::uintValue,
91 constants::missing::uintValue,
92 constants::missing::uintValue,
93 constants::missing::uintValue,
94 constants::missing::uintValue};
96 UInt edgeCount = 0;
98 UInt startNode = constants::missing::uintValue;
100 UInt endNode = constants::missing::uintValue;
101 };
102
104 using IrregularEdgeInfoArray = std::vector<IrregularEdgeInfo>;
105
116 static void AreEdgesAdjacent(const Mesh2D& mesh,
117 const double separationFraction,
118 const UInt edge1,
119 const UInt edge2,
120 bool& areAdjacent,
121 UInt& startNode,
122 UInt& endNode,
123 const std::vector<double>& edgeLengths);
124
131 static void GetQuadrilateralElementsOnDomainBoundary(const Mesh2D& mesh,
132 std::vector<UInt>& elementsOnDomainBoundary,
133 std::vector<UInt>& edgesOnDomainBoundary,
134 std::vector<double>& edgeLengths);
135
143 static void GetOrderedDistanceFromPoint(const Mesh2D& mesh,
144 const std::vector<UInt>& nodeIndices,
145 const UInt numberOfNodes,
146 const Point& point,
147 BoundedIntegerArray& nearestNeighbours);
148
154 static std::unique_ptr<meshkernel::UndoAction> MergeNodes(Mesh2D& mesh, const std::vector<NodesToMerge>& nodesToMerge, std::vector<MergeIndicator>& mergeIndicator);
155
162 [[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> FreeOneHangingNode(Mesh2D& mesh,
163 const BoundedIntegerArray& hangingNodes,
164 const UInt startNode,
165 const UInt endNode);
166
175 [[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> FreeTwoHangingNodes(Mesh2D& mesh,
176 const UInt faceId,
177 const UInt edgeId,
178 const BoundedIntegerArray& hangingNodes,
179 const UInt startNode,
180 const UInt endNode);
181
190 [[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> FreeThreeHangingNodes(Mesh2D& mesh,
191 const UInt faceId,
192 const UInt edgeId,
193 const BoundedIntegerArray& hangingNodes,
194 const UInt startNode,
195 const UInt endNode);
196
205 [[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> FreeFourHangingNodes(Mesh2D& mesh,
206 const UInt faceId,
207 const UInt edgeId,
208 const BoundedIntegerArray& hangingNodes,
209 const UInt startNode,
210 const UInt endNode);
211
221 [[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> FreeHangingNodes(Mesh2D& mesh,
222 const UInt numberOfHangingNodes,
223 const std::vector<UInt>& hangingNodesOnEdge,
224 const UInt faceId,
225 const Edge& boundaryEdge,
226 const Point& boundaryNode,
227 const UInt edgeId);
228
236 static void GatherHangingNodeIds(const Mesh2D& mesh,
237 const double separationFraction,
238 const std::vector<UInt>& edgesOnDomainBoundary,
239 const std::vector<double>& edgeLengths,
240 IrregularEdgeInfoArray& irregularEdges);
241
251 static void GatherNodesToMerge(const UInt startNode,
252 const UInt endNode,
253 const Edge& boundaryEdge,
254 std::vector<NodesToMerge>& nodesToMerge,
255 std::vector<MergeIndicator>& mergeIndicator);
256
265 static void GatherHangingNodes(const UInt primaryStartNode,
266 const UInt primaryEndNode,
267 const Edge& irregularEdge,
268 std::vector<UInt>& hangingNodesOnEdge,
269 UInt& numberOfHangingNodes,
270 std::vector<MergeIndicator>& mergeIndicator);
271 };
272
273} // namespace meshkernel
Connects grids across element faces.
Definition ConnectMeshes.hpp:47
static constexpr double minimumParallelDeviation
The cos of the minimum angle between two lines to be considered parallel or almost parallel.
Definition ConnectMeshes.hpp:55
static std::unique_ptr< meshkernel::UndoAction > Compute(Mesh2D &mesh, 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:50
A class derived from Mesh, which describes unstructures 2d meshes.
Definition Mesh2D.hpp:58
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