Loading [MathJax]/extensions/tex2jax.js
MeshKernel
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages Concepts
MeshRefinement.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 <MeshKernel/AveragingInterpolation.hpp>
31#include <MeshKernel/Parameters.hpp>
32#include <MeshKernel/Polygons.hpp>
33#include <MeshKernel/Utilities/RTreeBase.hpp>
34
35namespace meshkernel
36{
37 // Forward declarations
38 class Mesh2D;
39
75 {
77 enum class FaceLocation
78 {
79 Land = 1,
80 Water = 2,
81 LandWater = 3
82 };
83
84 public:
86 enum class RefinementType
87 {
88 WaveCourant = 1,
89 RefinementLevels = 2,
90 RidgeDetection = 3
91 };
92
98 std::unique_ptr<MeshInterpolation> interpolant,
99 const MeshRefinementParameters& meshRefinementParameters);
100
107 std::unique_ptr<MeshInterpolation> interpolant,
108 const MeshRefinementParameters& meshRefinementParameters,
109 bool useNodalRefinement);
110
116 const Polygons& polygon,
117 const MeshRefinementParameters& meshRefinementParameters);
118
132 [[nodiscard]] std::unique_ptr<UndoAction> Compute();
133
134 private:
136 void FindBrotherEdges();
137
140 void ComputeNodeMaskAtPolygonPerimeter();
141
143 void ComputeRefinementMasksFromSamples();
144
146 void ComputeRefinementMaskFromEdgeSize();
147
149 void ComputeRefinementMasksForRefinementLevels(UInt face,
150 size_t& numberOfEdgesToRefine,
151 std::vector<UInt>& edgeToRefine) const;
152
154 bool DetermineRequiredRefinement(const UInt face,
155 const UInt edge) const;
156
158 void ResetNumberOfEdgesToRefineForFace(const UInt face,
159 const std::vector<UInt>& edgeToRefine,
160 size_t& numberOfEdgesToRefine) const;
161
163 void DetermineEdgesToRefine(const UInt face,
164 std::vector<UInt>& edgeToRefine,
165 size_t& numberOfEdgesToRefine) const;
166
168 void ComputeRefinementMasksForWaveCourant(UInt face,
169 size_t& numberOfEdgesToRefine,
170 std::vector<UInt>& edgeToRefine);
171
173 void ComputeRefinementMasksForRidgeDetection(UInt face,
174 size_t& numberOfEdgesToRefine,
175 std::vector<UInt>& edgeToRefine) const;
176
180 void ComputeRefinementMasksFromSamples(UInt face);
181
183 void ComputeEdgesRefinementMask();
184
187 void FindHangingNodes(UInt face);
188
191 UInt CountHangingNodes() const;
192
195 UInt CountHangingEdges() const;
196
200 UInt CountEdgesToRefine(UInt face) const;
201
203 void UpdateFaceMask(const int level);
204
205#if 0
208 [[nodiscard]] UInt DeleteIsolatedHangingnodes();
209#endif
210
212 void ConnectOneHangingNodeForQuadrilateral(const UInt numNonHangingNodes,
213 const std::vector<UInt>& edgeEndNodeCache,
214 std::vector<UInt>& hangingNodeCache,
215 CompoundUndoAction& hangingNodeAction);
216
218 void ConnectTwoHangingNodesForQuadrilateral(const UInt numNonHangingNodes,
219 const std::vector<UInt>& edgeEndNodeCache,
220 std::vector<UInt>& hangingNodeCache,
221 CompoundUndoAction& hangingNodeAction);
222
224 void ConnectOneHangingNodeForTriangle(const UInt numNonHangingNodes,
225 const std::vector<UInt>& edgeEndNodeCache,
226 std::vector<UInt>& hangingNodeCache,
227 CompoundUndoAction& hangingNodeAction);
228
230 void ConnectTwoHangingNodesForTriangle(const UInt numNonHangingNodes,
231 std::vector<UInt>& hangingNodeCache,
232 CompoundUndoAction& hangingNodeAction);
233
235 std::unique_ptr<meshkernel::UndoAction> ConnectHangingNodes();
236
238 void FindEdgesToSplit(const UInt faceId,
239 const UInt numEdges,
240 std::vector<bool>& splitEdge) const;
241
243 void UpdateFaceRefinementMask(std::vector<bool>& splitEdge);
244
246 void UpdateEdgeRefinementMask();
247
249 void SmoothRefinementMasks();
250
252 bool IsSplittingIsRequiredForFace(const UInt faceId) const;
253
256 UInt UpdateEdgeMaskForNonHangingEdge(const UInt faceId,
257 const UInt numFaceNodes,
258 const UInt iter,
259 const UInt maxiter);
260
262 void ComputeIfFaceShouldBeSplit();
263
265 Point ComputeMidPoint(const Point& firstNode, const Point& secondNode) const;
266
268 int DetermineNodeMaskValue(const int firstNodeMask, const int secondNodeMask) const;
269
271 bool DetermineIfParentIsCrossed(const UInt faceId, const UInt numEdges) const;
272
274 bool FindNonHangingNodeEdges(const UInt faceId,
275 const UInt numEdges,
276 std::vector<UInt>& notHangingFaceNodes,
277 std::vector<UInt>& nonHangingEdges,
278 UInt& numBrotherEdges) const;
279
281 void ComputeSplittingNode(const UInt faceId,
282 std::vector<Point>& facePolygonWithoutHangingNodes,
283 std::vector<UInt>& localEdgesNumFaces,
284 Point& splittingNode) const;
285
287 void FindFacePolygonWithoutHangingNodes(const UInt faceId,
288 const std::vector<UInt>& nonHangingEdges,
289 std::vector<Point>& facePolygonWithoutHangingNodes,
290 std::vector<UInt>& localEdgesNumFaces) const;
291
293 void SplitEdges(const bool isParentCrossed,
294 const std::vector<UInt>& localEdgesNumFaces,
295 const std::vector<UInt>& notHangingFaceNodes,
296 const Point& splittingNode,
297 CompoundUndoAction& refineFacesAction);
298
300 std::unique_ptr<meshkernel::UndoAction> RefineFacesBySplittingEdges();
301
306 bool IsEdgeToBeRefinedBasedFaceLocationTypeAndCourantCriteria(UInt edge, FaceLocation faceLocationType) const;
307
312 bool IsRefineNeededBasedOnCourantCriteria(UInt edge, double depthValues) const;
313
315 void ComputeFaceLocationTypes();
316
318 void ComputeEdgeBelowMinSizeAfterRefinement();
319
320 std::unique_ptr<RTreeBase> m_samplesRTree;
321
322 std::vector<int> m_faceMask;
323 std::vector<int> m_edgeMask;
324 std::vector<bool> m_isEdgeBelowMinSizeAfterRefinement;
325 std::vector<int> m_nodeMask;
326 std::vector<UInt> m_brotherEdges;
327
329 std::vector<bool> m_isHangingNodeCache;
330 std::vector<bool> m_isHangingEdgeCache;
331 std::vector<Point> m_polygonNodesCache;
332 std::vector<UInt> m_localNodeIndicesCache;
333 std::vector<UInt> m_globalEdgeIndicesCache;
334 std::vector<UInt> m_refineEdgeCache;
335 std::vector<FaceLocation> m_faceLocationType;
336 std::vector<double> m_edgeLengths;
337
338 RefinementType m_refinementType = RefinementType::WaveCourant;
339 bool m_directionalRefinement = false;
340
341 Mesh2D& m_mesh;
342 std::unique_ptr<MeshInterpolation> m_interpolant;
343 Polygons m_polygons;
344 MeshRefinementParameters m_meshRefinementParameters;
345 bool m_useNodalRefinement = false;
346 const double m_mergingDistance = 0.001;
347 bool m_isRefinementBasedOnSamples = false;
348 };
349} // namespace meshkernel
A class derived from Mesh, which describes unstructures 2d meshes.
Definition Mesh2D.hpp:58
A class used to refine a Mesh2D instance.
Definition MeshRefinement.hpp:75
RefinementType
Enumerator describing the different refinement types.
Definition MeshRefinement.hpp:87
MeshRefinement(Mesh2D &mesh, std::unique_ptr< MeshInterpolation > interpolant, const MeshRefinementParameters &meshRefinementParameters)
The constructor for refining based on samples.
std::unique_ptr< UndoAction > Compute()
Compute mesh refinement (refinecellsandfaces2).
MeshRefinement(Mesh2D &mesh, const Polygons &polygon, const MeshRefinementParameters &meshRefinementParameters)
The constructor for refining based on polygons.
MeshRefinement(Mesh2D &mesh, std::unique_ptr< MeshInterpolation > interpolant, const MeshRefinementParameters &meshRefinementParameters, bool useNodalRefinement)
The constructor for refining based on samples.
A struct describing a point in a two-dimensional space.
Definition Point.hpp:41
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::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