Loading [MathJax]/extensions/tex2jax.js
MeshKernel
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages Concepts
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 <vector>
31
32#include "MeshKernel/Constants.hpp"
33#include "MeshKernel/Definitions.hpp"
34
35namespace meshkernel
36{
37 class Mesh2D;
38
43 {
44
45 public:
49 explicit Smoother(const Mesh2D& mesh, const std::vector<MeshNodeType>& nodeType);
50
52 void Compute();
53
55 [[nodiscard]] auto GetWeight(UInt node, int connectedNode) const
56 {
57 return m_weights[node][connectedNode];
58 }
59
64 [[nodiscard]] auto GetConnectedNodeIndex(UInt node, int connectedNode) const
65 {
66 return m_connectedNodes[node][connectedNode];
67 }
68
72 [[nodiscard]] auto GetNumConnectedNodes(UInt node) const
73 {
74 return m_numConnectedNodes[node];
75 }
76
77 private:
79 struct InternalAngleData
80 {
81 UInt numSquaredTriangles = 0;
82 UInt numTriangles = 0;
83 double phiSquaredTriangles = 0.0;
84 double phiQuads = 0.0;
85 double phiTriangles = 0.0;
86 double phiTot = 0.0;
87 };
88
90 void ComputeInternalAngle(const UInt currentNode,
91 const UInt numSharedFaces,
92 const std::vector<double>& thetaSquare,
93 const std::vector<bool>& isSquareFace,
94 InternalAngleData& internalAngleData,
95 UInt& numNonStencilQuad);
96
98 void UpdateThetaForInteriorFaces(const UInt numSharedFaces, std::vector<double>& thetaSquare);
99
101 void UpdateXiEtaForSharedFace(const UInt currentNode,
102 const UInt currentFace,
103 const UInt numFaceNodes,
104 const double dPhi,
105 const double phi0);
106
108 void ComputeOptimalAngleForSharedFaces(const UInt currentNode,
109 const UInt numSharedFaces,
110 const MeshNodeType nodeType,
111 const std::vector<double>& thetaSquare,
112 const std::vector<bool>& isSquareFace,
113 const double mu,
114 const double muSquaredTriangles,
115 const double muTriangles);
116
119 void Initialize();
120
122 void ComputeTopologies();
123
125 void ComputeOperators();
126
128 void ComputeWeights();
129
131 std::tuple<double, double> ComputeOperatorsForBoundaryNode(const UInt f, const UInt faceLeftIndex, const UInt currentTopology);
132
134 std::tuple<double, double, double, double> ComputeOperatorsForInteriorNode(const UInt f,
135 const UInt edgeIndex,
136 const UInt faceLeftIndex,
137 const UInt faceRightIndex,
138 const UInt currentTopology);
139
141 void ComputeNodeEdgeDerivative(const UInt f,
142 const UInt edgeIndex,
143 const UInt currentTopology,
144 const UInt faceLeftIndex,
145 const UInt faceRightIndex,
146 const double facxiL,
147 const double facetaL,
148 const double facxiR,
149 const double facetaR);
150
154 void ComputeOperatorsNode(UInt currentNode, const MeshNodeType nodeType);
155
158 void NodeAdministration(UInt currentNode);
159
162 void ComputeNodeXiEta(UInt currentNode);
163
170 [[nodiscard]] double OptimalEdgeAngle(UInt numFaceNodes,
171 double theta1 = -1.0,
172 double theta2 = -1.0,
173 bool isBoundaryEdge = false) const;
174
177 void AllocateNodeOperators(UInt topologyIndex);
178
181 void SaveNodeTopologyIfNeeded(UInt currentNode);
182
186 void ComputeJacobian(UInt currentNode, std::vector<double>& J) const;
187
189 void ComputeCellCircumcentreCoefficients(const UInt currentNode, const UInt currentTopology, const MeshNodeType nodeType);
190
192 void ComputeNodeToNodeGradients(const UInt currentNode, const UInt currentTopology);
193
195 void ComputeLaplacianSmootherWeights(const UInt currentNode, const UInt currentTopology);
196
197 // The mesh to smooth
198 const Mesh2D& m_mesh;
199
200 const std::vector<MeshNodeType>& m_nodeType;
201
202 // Smoother weights
203 std::vector<std::vector<double>> m_weights;
204
205 // Smoother operators
206 std::vector<std::vector<std::vector<double>>> m_Gxi;
207 std::vector<std::vector<std::vector<double>>> m_Geta;
208 std::vector<std::vector<double>> m_Divxi;
209 std::vector<std::vector<double>> m_Diveta;
210 std::vector<std::vector<std::vector<double>>> m_Az;
211 std::vector<std::vector<double>> m_Jxi;
212 std::vector<std::vector<double>> m_Jeta;
213 std::vector<std::vector<double>> m_ww2;
214
215 // Smoother local caches
216 std::vector<UInt> m_sharedFacesCache;
217 std::vector<UInt> m_connectedNodesCache;
218 std::vector<std::vector<UInt>> m_faceNodeMappingCache;
219 std::vector<double> m_xiCache;
220 std::vector<double> m_etaCache;
221 std::vector<double> m_leftXFaceCenterCache;
222 std::vector<double> m_leftYFaceCenterCache;
223 std::vector<double> m_rightXFaceCenterCache;
224 std::vector<double> m_rightYFaceCenterCache;
225 std::vector<double> m_xisCache;
226 std::vector<double> m_etasCache;
227
228 // Smoother topologies
229 std::vector<UInt> m_nodeTopologyMapping;
230 std::vector<std::vector<double>> m_topologyXi;
231 std::vector<std::vector<double>> m_topologyEta;
232 std::vector<std::vector<UInt>> m_topologySharedFaces;
233 std::vector<std::vector<std::vector<UInt>>> m_topologyFaceNodeMapping;
234 std::vector<std::vector<UInt>> m_topologyConnectedNodes;
235
236 std::vector<UInt> m_numConnectedNodes;
237 std::vector<std::vector<UInt>> m_connectedNodes;
238
239 // Class variables
240 UInt m_maximumNumConnectedNodes = 0;
241 UInt m_maximumNumSharedFaces = 0;
242
243 static constexpr int m_topologyInitialSize = 10;
244 static constexpr double m_thetaTolerance = 1e-4;
245 };
246} // namespace meshkernel
A class derived from Mesh, which describes unstructures 2d meshes.
Definition Mesh2D.hpp:58
Orthogonalizion (optimize the aspect ratios) and mesh smoothing (optimize internal face angles or are...
Definition Smoother.hpp:43
auto GetConnectedNodeIndex(UInt node, int connectedNode) const
Get the index of the connected node as assigned by the smoother administration.
Definition Smoother.hpp:64
auto GetWeight(UInt node, int connectedNode) const
Gets the weight for a certain node and connected node.
Definition Smoother.hpp:55
void Compute()
Computes the smoother weights.
auto GetNumConnectedNodes(UInt node) const
Get number of connected nodes.
Definition Smoother.hpp:72
Smoother(const Mesh2D &mesh, const std::vector< MeshNodeType > &nodeType)
Mesh2D constructor.
Contains the logic of the C++ static library.
Definition AveragingInterpolation.hpp:37
MeshNodeType
Possible unstructured node types.
Definition Definitions.hpp:148
std::uint32_t UInt
Integer type used when indexing mesh graph entities.
Definition Definitions.hpp:39