MeshKernel
Loading...
Searching...
No Matches
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
99 const Polygons& polygon,
100 std::unique_ptr<MeshInterpolation> interpolant,
101 const MeshRefinementParameters& meshRefinementParameters);
102
110 const Polygons& polygon,
111 std::unique_ptr<MeshInterpolation> interpolant,
112 const MeshRefinementParameters& meshRefinementParameters,
113 bool useNodalRefinement);
114
120 const Polygons& polygon,
121 const MeshRefinementParameters& meshRefinementParameters);
122
136 [[nodiscard]] std::unique_ptr<UndoAction> Compute();
137
138 private:
140 void FindBrotherEdges();
141
144 void ComputeNodeMaskAtPolygonPerimeter();
145
147 void ComputeRefinementMasksFromSamples();
148
150 void ComputeRefinementMaskFromEdgeSize();
151
153 void ComputeRefinementMasksForRefinementLevels(UInt face,
154 size_t& numberOfEdgesToRefine,
155 std::vector<UInt>& edgeToRefine) const;
156
158 bool DetermineRequiredRefinement(const UInt face,
159 const UInt edge) const;
160
162 void ResetNumberOfEdgesToRefineForFace(const UInt face,
163 const std::vector<UInt>& edgeToRefine,
164 size_t& numberOfEdgesToRefine) const;
165
167 void DetermineEdgesToRefine(const UInt face,
168 std::vector<UInt>& edgeToRefine,
169 size_t& numberOfEdgesToRefine) const;
170
172 void ComputeRefinementMasksForWaveCourant(UInt face,
173 size_t& numberOfEdgesToRefine,
174 std::vector<UInt>& edgeToRefine);
175
177 void ComputeRefinementMasksForRidgeDetection(UInt face,
178 size_t& numberOfEdgesToRefine,
179 std::vector<UInt>& edgeToRefine) const;
180
184 void ComputeRefinementMasksFromSamples(UInt face);
185
187 void ComputeEdgesRefinementMask();
188
191 void FindHangingNodes(UInt face);
192
195 UInt CountHangingNodes() const;
196
199 UInt CountHangingEdges() const;
200
204 UInt CountEdgesToRefine(UInt face) const;
205
207 void UpdateFaceMask(const int level);
208
209#if 0
212 [[nodiscard]] UInt DeleteIsolatedHangingnodes();
213#endif
214
216 void ConnectOneHangingNodeForQuadrilateral(const UInt numNonHangingNodes,
217 const std::vector<UInt>& edgeEndNodeCache,
218 std::vector<UInt>& hangingNodeCache,
219 CompoundUndoAction& hangingNodeAction);
220
222 void ConnectTwoHangingNodesForQuadrilateral(const UInt numNonHangingNodes,
223 const std::vector<UInt>& edgeEndNodeCache,
224 std::vector<UInt>& hangingNodeCache,
225 CompoundUndoAction& hangingNodeAction);
226
228 void ConnectOneHangingNodeForTriangle(const UInt numNonHangingNodes,
229 const std::vector<UInt>& edgeEndNodeCache,
230 std::vector<UInt>& hangingNodeCache,
231 CompoundUndoAction& hangingNodeAction);
232
234 void ConnectTwoHangingNodesForTriangle(const UInt numNonHangingNodes,
235 std::vector<UInt>& hangingNodeCache,
236 CompoundUndoAction& hangingNodeAction);
237
239 std::unique_ptr<meshkernel::UndoAction> ConnectHangingNodes();
240
242 void FindEdgesToSplit(const UInt faceId,
243 const UInt numEdges,
244 std::vector<bool>& splitEdge) const;
245
247 void UpdateFaceRefinementMask(std::vector<bool>& splitEdge);
248
250 void UpdateEdgeRefinementMask();
251
253 void SmoothRefinementMasks();
254
256 bool IsSplittingIsRequiredForFace(const UInt faceId) const;
257
260 UInt UpdateEdgeMaskForNonHangingEdge(const UInt faceId,
261 const UInt numFaceNodes,
262 const UInt iter,
263 const UInt maxiter);
264
266 void ComputeIfFaceShouldBeSplit();
267
269 Point ComputeMidPoint(const Point& firstNode, const Point& secondNode) const;
270
272 int DetermineNodeMaskValue(const int firstNodeMask, const int secondNodeMask) const;
273
275 bool DetermineIfParentIsCrossed(const UInt faceId, const UInt numEdges) const;
276
278 bool FindNonHangingNodeEdges(const UInt faceId,
279 const UInt numEdges,
280 std::vector<UInt>& notHangingFaceNodes,
281 std::vector<UInt>& nonHangingEdges,
282 UInt& numBrotherEdges) const;
283
285 void ComputeSplittingNode(const UInt faceId,
286 std::vector<Point>& facePolygonWithoutHangingNodes,
287 std::vector<UInt>& localEdgesNumFaces,
288 Point& splittingNode) const;
289
291 void FindFacePolygonWithoutHangingNodes(const UInt faceId,
292 const std::vector<UInt>& nonHangingEdges,
293 std::vector<Point>& facePolygonWithoutHangingNodes,
294 std::vector<UInt>& localEdgesNumFaces) const;
295
297 void SplitEdges(const bool isParentCrossed,
298 const std::vector<UInt>& localEdgesNumFaces,
299 const std::vector<UInt>& notHangingFaceNodes,
300 const Point& splittingNode,
301 CompoundUndoAction& refineFacesAction);
302
304 std::unique_ptr<meshkernel::UndoAction> RefineFacesBySplittingEdges();
305
310 bool IsEdgeToBeRefinedBasedFaceLocationTypeAndCourantCriteria(UInt edge, FaceLocation faceLocationType) const;
311
316 bool IsRefineNeededBasedOnCourantCriteria(UInt edge, double depthValues) const;
317
319 void ComputeFaceLocationTypes();
320
322 void ComputeEdgeBelowMinSizeAfterRefinement();
323
324 std::unique_ptr<RTreeBase> m_samplesRTree;
325
326 std::vector<int> m_faceMask;
327 std::vector<int> m_edgeMask;
328 std::vector<bool> m_isEdgeBelowMinSizeAfterRefinement;
329 std::vector<int> m_nodeMask;
330 std::vector<UInt> m_brotherEdges;
331
333 std::vector<bool> m_isHangingNodeCache;
334 std::vector<bool> m_isHangingEdgeCache;
335 std::vector<Point> m_polygonNodesCache;
336 std::vector<UInt> m_localNodeIndicesCache;
337 std::vector<UInt> m_globalEdgeIndicesCache;
338 std::vector<UInt> m_refineEdgeCache;
339 std::vector<FaceLocation> m_faceLocationType;
340 std::vector<double> m_edgeLengths;
341
342 RefinementType m_refinementType = RefinementType::WaveCourant;
343 bool m_directionalRefinement = false;
344
345 Mesh2D& m_mesh;
346 std::unique_ptr<MeshInterpolation> m_interpolant;
347 Polygons m_polygons;
348 MeshRefinementParameters m_meshRefinementParameters;
349 bool m_useNodalRefinement = false;
350 const double m_mergingDistance = 0.001;
351 bool m_isRefinementBasedOnSamples = false;
352 };
353} // 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
MeshRefinement(Mesh2D &mesh, const Polygons &polygon, std::unique_ptr< MeshInterpolation > interpolant, const MeshRefinementParameters &meshRefinementParameters)
The constructor for refining based on samples.
RefinementType
Enumerator describing the different refinement types.
Definition MeshRefinement.hpp:87
std::unique_ptr< UndoAction > Compute()
Compute mesh refinement (refinecellsandfaces2).
MeshRefinement(Mesh2D &mesh, const Polygons &polygon, std::unique_ptr< MeshInterpolation > interpolant, const MeshRefinementParameters &meshRefinementParameters, bool useNodalRefinement)
The constructor for refining based on samples.
MeshRefinement(Mesh2D &mesh, const Polygons &polygon, const MeshRefinementParameters &meshRefinementParameters)
The constructor for refining based on polygons.
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