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 SnapMeshToOriginalMeshBoundary();
119 
121  void ComputeLinearSystemTerms();
122 
128  void ComputeLocalIncrements(UInt nodeIndex,
129  double& dx0,
130  double& dy0,
131  std::array<double, 2>& weightsSum);
132 
135  void UpdateNodeCoordinates(UInt nodeIndex);
136 
138  void AllocateLinearSystem();
139 
141  void ComputeCoordinates() const;
142 
143  Mesh2D& m_mesh;
144  std::unique_ptr<Smoother> m_smoother;
145  std::unique_ptr<Orthogonalizer> m_orthogonalizer;
146  std::unique_ptr<Polygons> m_polygons;
147  std::unique_ptr<LandBoundaries> m_landBoundaries;
148  LandBoundaries::ProjectToLandBoundaryOption m_projectToLandBoundaryOption;
149  OrthogonalizationParameters m_orthogonalizationParameters;
150 
151  std::vector<UInt> m_localCoordinatesIndices;
152  std::vector<Point> m_localCoordinates;
153  std::vector<Point> m_orthogonalCoordinates;
154  std::vector<Point> m_originalNodes;
155 
156  // Linear system terms
157  std::vector<UInt> m_compressedEndNodeIndex;
158  std::vector<UInt> m_compressedStartNodeIndex;
159  std::vector<double> m_compressedWeightX;
160  std::vector<double> m_compressedWeightY;
161  std::vector<double> m_compressedRhs;
162  std::vector<UInt> m_compressedNodesNodes;
163 
164  // run-time parameters
165  double m_mumax = 0.0;
166  double m_mu = 0.0;
167  };
168 } // 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