MeshKernel
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 
35 namespace 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 
97  MeshRefinement(Mesh2D& mesh,
98  std::unique_ptr<MeshInterpolation> interpolant,
99  const MeshRefinementParameters& meshRefinementParameters);
100 
106  MeshRefinement(Mesh2D& mesh,
107  std::unique_ptr<MeshInterpolation> interpolant,
108  const MeshRefinementParameters& meshRefinementParameters,
109  bool useNodalRefinement);
110 
115  MeshRefinement(Mesh2D& mesh,
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  void ComputeRefinementMasksForWaveCourant(UInt face,
155  size_t& numberOfEdgesToRefine,
156  std::vector<UInt>& edgeToRefine);
157 
159  void ComputeRefinementMasksForRidgeDetection(UInt face,
160  size_t& numberOfEdgesToRefine,
161  std::vector<UInt>& edgeToRefine) const;
162 
166  void ComputeRefinementMasksFromSamples(UInt face);
167 
169  void ComputeEdgesRefinementMask();
170 
173  void FindHangingNodes(UInt face);
174 
177  UInt CountHangingNodes() const;
178 
181  UInt CountHangingEdges() const;
182 
186  UInt CountEdgesToRefine(UInt face) const;
187 
188 #if 0
189  [[nodiscard]] UInt DeleteIsolatedHangingnodes();
192 #endif
193 
195  std::unique_ptr<meshkernel::UndoAction> ConnectHangingNodes();
196 
198  void SmoothRefinementMasks();
199 
201  void ComputeIfFaceShouldBeSplit();
202 
204  std::unique_ptr<meshkernel::UndoAction> RefineFacesBySplittingEdges();
205 
210  bool IsEdgeToBeRefinedBasedFaceLocationTypeAndCourantCriteria(UInt edge, FaceLocation faceLocationType) const;
211 
216  bool IsRefineNeededBasedOnCourantCriteria(UInt edge, double depthValues) const;
217 
219  void ComputeFaceLocationTypes();
220 
222  void ComputeEdgeBelowMinSizeAfterRefinement();
223 
224  std::unique_ptr<RTreeBase> m_samplesRTree;
225 
226  std::vector<int> m_faceMask;
227  std::vector<int> m_edgeMask;
228  std::vector<bool> m_isEdgeBelowMinSizeAfterRefinement;
229  std::vector<int> m_nodeMask;
230  std::vector<UInt> m_brotherEdges;
231 
233  std::vector<bool> m_isHangingNodeCache;
234  std::vector<bool> m_isHangingEdgeCache;
235  std::vector<Point> m_polygonNodesCache;
236  std::vector<UInt> m_localNodeIndicesCache;
237  std::vector<UInt> m_globalEdgeIndicesCache;
238  std::vector<UInt> m_refineEdgeCache;
239  std::vector<FaceLocation> m_faceLocationType;
240 
241  RefinementType m_refinementType = RefinementType::WaveCourant;
242  bool m_directionalRefinement = false;
243 
244  Mesh2D& m_mesh;
245  std::unique_ptr<MeshInterpolation> m_interpolant;
246  Polygons m_polygons;
247  MeshRefinementParameters m_meshRefinementParameters;
248  bool m_useNodalRefinement = false;
249  const double m_mergingDistance = 0.001;
250  bool m_isRefinementBasedOnSamples = false;
251  };
252 } // namespace meshkernel
meshkernel::MeshRefinement
A class used to refine a Mesh2D instance.
Definition: MeshRefinement.hpp:74
meshkernel::Mesh2D
A class derived from Mesh, which describes unstructures 2d meshes.
Definition: Mesh2D.hpp:55
meshkernel::MeshRefinement::RefinementType
RefinementType
Enumerator describing the different refinement types.
Definition: MeshRefinement.hpp:86
meshkernel::MeshRefinement::Compute
std::unique_ptr< UndoAction > Compute()
Compute mesh refinement (refinecellsandfaces2).
meshkernel
Contains the logic of the C++ static library.
Definition: AveragingInterpolation.hpp:36
meshkernel::UInt
std::uint32_t UInt
Integer type used when indexing mesh graph entities.
Definition: Definitions.hpp:38
meshkernel::MeshRefinement::MeshRefinement
MeshRefinement(Mesh2D &mesh, std::unique_ptr< MeshInterpolation > interpolant, const MeshRefinementParameters &meshRefinementParameters)
The constructor for refining based on samples.
meshkernel::MeshRefinementParameters
A struct used to describe the mesh refinement parameters in a C-compatible manner.
Definition: Parameters.hpp:186
meshkernel::Polygons
A class containing a list of polygonaly enclosed regions.
Definition: Polygons.hpp:44