MeshKernel
OrthogonalizationAndSmoothing.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/LandBoundaries.hpp>
31 #include <MeshKernel/Parameters.hpp>
32 #include <MeshKernel/UndoActions/UndoAction.hpp>
33 
34 namespace meshkernel
35 {
36  // Forward declare everything to reduce compile time dependency
37  class Point;
38  class Mesh2D;
39  class Smoother;
40  class Orthogonalizer;
41  class Polygons;
42  enum class Projection;
43 
82  {
83 
84  public:
94  std::unique_ptr<Smoother> smoother,
95  std::unique_ptr<Orthogonalizer> orthogonalizer,
96  std::unique_ptr<Polygons> polygon,
97  std::unique_ptr<LandBoundaries> landBoundaries,
98  LandBoundaries::ProjectToLandBoundaryOption projectToLandBoundaryOption,
99  const OrthogonalizationParameters& orthogonalizationParameters);
100 
102  [[nodiscard]] std::unique_ptr<UndoAction> Initialize();
103 
105  void Compute();
106 
108  void PrepareOuterIteration();
109 
111  void Solve();
112 
114  void FinalizeOuterIteration();
115 
116  private:
118  void FindNeighbouringBoundaryNodes(const UInt nodeId,
119  const UInt nearestPointIndex,
120  UInt& leftNode,
121  UInt& rightNode) const;
122 
124  void SnapMeshToOriginalMeshBoundary();
125 
127  void ComputeLinearSystemTerms();
128 
134  void ComputeLocalIncrements(UInt nodeIndex,
135  double& dx0,
136  double& dy0,
137  std::array<double, 2>& weightsSum);
138 
141  void UpdateNodeCoordinates(UInt nodeIndex);
142 
144  void AllocateLinearSystem();
145 
147  void ComputeCoordinates() const;
148 
149  Mesh2D& m_mesh;
150  std::unique_ptr<Smoother> m_smoother;
151  std::unique_ptr<Orthogonalizer> m_orthogonalizer;
152  std::unique_ptr<Polygons> m_polygons;
153  std::unique_ptr<LandBoundaries> m_landBoundaries;
154  LandBoundaries::ProjectToLandBoundaryOption m_projectToLandBoundaryOption;
155  OrthogonalizationParameters m_orthogonalizationParameters;
156 
157  std::vector<UInt> m_localCoordinatesIndices;
158  std::vector<Point> m_localCoordinates;
159  std::vector<Point> m_orthogonalCoordinates;
160  std::vector<Point> m_originalNodes;
161 
162  // Linear system terms
163  std::vector<UInt> m_compressedEndNodeIndex;
164  std::vector<UInt> m_compressedStartNodeIndex;
165  std::vector<double> m_compressedWeightX;
166  std::vector<double> m_compressedWeightY;
167  std::vector<double> m_compressedRhs;
168  std::vector<UInt> m_compressedNodesNodes;
169 
170  // run-time parameters
171  double m_mumax = 0.0;
172  double m_mu = 0.0;
173  };
174 } // namespace meshkernel
meshkernel::Projection
Projection
Enumerator describing the supported projections.
Definition: Definitions.hpp:41
meshkernel::Mesh2D
A class derived from Mesh, which describes unstructures 2d meshes.
Definition: Mesh2D.hpp:55
meshkernel::LandBoundaries::ProjectToLandBoundaryOption
ProjectToLandBoundaryOption
Enumerator describing the options how to project to the land boundary.
Definition: LandBoundaries.hpp:54
meshkernel::OrthogonalizationAndSmoothing::Initialize
std::unique_ptr< UndoAction > Initialize()
Initializes the object.
meshkernel::OrthogonalizationAndSmoothing::PrepareOuterIteration
void PrepareOuterIteration()
Prepares the outer iteration, calculates orthogonalizer and smoother coefficients and assable the lin...
meshkernel::OrthogonalizationAndSmoothing::Compute
void Compute()
Executes the entire algorithm.
meshkernel::OrthogonalizationAndSmoothing
Orthogonalizion (optimize the aspect ratios) and mesh smoothing (optimize internal face angles or are...
Definition: OrthogonalizationAndSmoothing.hpp:81
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::OrthogonalizationAndSmoothing::Solve
void Solve()
Performs an inner iteration, update the mesh node positions.
meshkernel::OrthogonalizationAndSmoothing::OrthogonalizationAndSmoothing
OrthogonalizationAndSmoothing(Mesh2D &mesh, std::unique_ptr< Smoother > smoother, std::unique_ptr< Orthogonalizer > orthogonalizer, std::unique_ptr< Polygons > polygon, std::unique_ptr< LandBoundaries > landBoundaries, LandBoundaries::ProjectToLandBoundaryOption projectToLandBoundaryOption, const OrthogonalizationParameters &orthogonalizationParameters)
meshkernel::OrthogonalizationAndSmoothing::FinalizeOuterIteration
void FinalizeOuterIteration()
Finalize the outer iteration, computes new mu and face areas, masscenters, circumcenters.
meshkernel::OrthogonalizationParameters
A struct used to describe the orthogonalization parameters in a C-compatible manner.
Definition: Parameters.hpp:237