MeshKernel
Smoother.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/Constants.hpp"
31 
32 namespace meshkernel
33 {
34  class Mesh2D;
35 
39  class Smoother
40  {
41 
42  public:
45  explicit Smoother(const Mesh2D& mesh);
46 
48  void Compute();
49 
54  [[nodiscard]] auto GetWeight(UInt node, int connectedNode) const
55  {
56  return m_weights[node][connectedNode];
57  }
58 
63  [[nodiscard]] auto GetConnectedNodeIndex(UInt node, int connectedNode) const
64  {
65  return m_connectedNodes[node][connectedNode];
66  }
67 
71  [[nodiscard]] auto GetNumConnectedNodes(UInt node) const
72  {
73  return m_numConnectedNodes[node];
74  }
75 
76  private:
79  void Initialize();
80 
82  void ComputeTopologies();
83 
85  void ComputeOperators();
86 
90  bool ComputeCoordinates();
91 
93  void ComputeWeights();
94 
97  void ComputeOperatorsNode(UInt currentNode);
98 
101  void NodeAdministration(UInt currentNode);
102 
105  void ComputeNodeXiEta(UInt currentNode);
106 
113  [[nodiscard]] double OptimalEdgeAngle(UInt numFaceNodes,
114  double theta1 = -1.0,
115  double theta2 = -1.0,
116  bool isBoundaryEdge = false) const;
117 
120  void AllocateNodeOperators(UInt topologyIndex);
121 
124  void SaveNodeTopologyIfNeeded(UInt currentNode);
125 
129  void ComputeJacobian(UInt currentNode, std::vector<double>& J) const;
130 
131  // The mesh to smooth
132  const Mesh2D& m_mesh;
133 
134  // Smoother weights
135  std::vector<std::vector<double>> m_weights;
136 
137  // Smoother operators
138  std::vector<std::vector<std::vector<double>>> m_Gxi;
139  std::vector<std::vector<std::vector<double>>> m_Geta;
140  std::vector<std::vector<double>> m_Divxi;
141  std::vector<std::vector<double>> m_Diveta;
142  std::vector<std::vector<std::vector<double>>> m_Az;
143  std::vector<std::vector<double>> m_Jxi;
144  std::vector<std::vector<double>> m_Jeta;
145  std::vector<std::vector<double>> m_ww2;
146 
147  // Smoother local caches
148  std::vector<UInt> m_sharedFacesCache;
149  std::vector<UInt> m_connectedNodesCache;
150  std::vector<std::vector<UInt>> m_faceNodeMappingCache;
151  std::vector<double> m_xiCache;
152  std::vector<double> m_etaCache;
153  std::vector<UInt> m_boundaryEdgesCache;
154  std::vector<double> m_leftXFaceCenterCache;
155  std::vector<double> m_leftYFaceCenterCache;
156  std::vector<double> m_rightXFaceCenterCache;
157  std::vector<double> m_rightYFaceCenterCache;
158  std::vector<double> m_xisCache;
159  std::vector<double> m_etasCache;
160 
161  // Smoother topologies
162  std::vector<UInt> m_nodeTopologyMapping;
163  std::vector<std::vector<double>> m_topologyXi;
164  std::vector<std::vector<double>> m_topologyEta;
165  std::vector<std::vector<UInt>> m_topologySharedFaces;
166  std::vector<std::vector<std::vector<UInt>>> m_topologyFaceNodeMapping;
167  std::vector<std::vector<UInt>> m_topologyConnectedNodes;
168 
169  std::vector<UInt> m_numConnectedNodes;
170  std::vector<std::vector<UInt>> m_connectedNodes;
171 
172  // Class variables
173  UInt m_maximumNumConnectedNodes = 0;
174  UInt m_maximumNumSharedFaces = 0;
175 
176  static constexpr int m_topologyInitialSize = 10;
177  static constexpr double m_thetaTolerance = 1e-4;
178  };
179 } // namespace meshkernel
meshkernel::Smoother
Orthogonalizion (optimize the aspect ratios) and mesh smoothing (optimize internal face angles or are...
Definition: Smoother.hpp:39
meshkernel::Smoother::GetConnectedNodeIndex
auto GetConnectedNodeIndex(UInt node, int connectedNode) const
Get the index of the connected node as assigned by the smoother administration.
Definition: Smoother.hpp:63
meshkernel::Mesh2D
A class derived from Mesh, which describes unstructures 2d meshes.
Definition: Mesh2D.hpp:55
meshkernel::Smoother::GetNumConnectedNodes
auto GetNumConnectedNodes(UInt node) const
Get number of connected nodes.
Definition: Smoother.hpp:71
meshkernel::Smoother::Compute
void Compute()
Computes the smoother weights.
meshkernel::Smoother::GetWeight
auto GetWeight(UInt node, int connectedNode) const
Gets the weight for a certain node and connected node.
Definition: Smoother.hpp:54
meshkernel::Smoother::Smoother
Smoother(const Mesh2D &mesh)
Mesh2D constructor.
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