Documentation 6b54b78464
Loading...
Searching...
No Matches
CGradientSmoothingSolver.hpp
Go to the documentation of this file.
1/*!
2 * \file CGradientSmoothingSolver.hpp
3 * \brief SOlver class for Sobolev smoothing of sensitivities.
4 * \author T. Dick
5 * \version 8.5.0 "Harrier"
6 *
7 * SU2 Project Website: https://su2code.github.io
8 *
9 * The SU2 Project is maintained by the SU2 Foundation
10 * (http://su2foundation.org)
11 *
12 * Copyright 2012-2026, SU2 Contributors (cf. AUTHORS.md)
13 *
14 * SU2 is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
18 *
19 * SU2 is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with SU2. If not, see <http://www.gnu.org/licenses/>.
26 */
27
28#pragma once
29
30#include "../../../Common/include/linear_algebra/CMatrixVectorProduct.hpp"
31#include "../../../Common/include/toolboxes/CSquareMatrixCM.hpp"
32#include "../variables/CSobolevSmoothingVariable.hpp"
33#include "CFEASolverBase.hpp"
34
35/*!
36 * \brief Main class for defining a Sobolev-based gradient smoothing.
37 * \author T. Dick.
38 * \ingroup GradSmooth
39 */
41 private:
42 unsigned int curDim; /*!< \brief If we separate dimensions this tells us in what dimension we currently are. */
43
44 CSysVector<su2double> activeCoord; /*!< \brief Auxiliar vector to keep the indeces of geometry->vertex->Coord */
45
46 CSysVector<su2mixedfloat> helperVecIn; /*!< \brief Helper vectors for projection and matrix vector product (must be su2mixedfloat) */
47 CSysVector<su2mixedfloat> helperVecOut; /*!< \brief Helper vectors for projection and matrix vector product (must be su2mixedfloat) */
48 CSysVector<su2mixedfloat> helperVecAux; /*!< \brief Helper vectors for matrix vector product if working on surface (smaller dim) */
49
50 std::vector<su2double> deltaP; /*!< \brief The smoothed gradient with respect to the design variables. */
51
52 CSquareMatrixCM hessian; /*!< \brief The approximated Hessian with respect to the design variables. */
53
54 std::vector<bool> visited; /*! <\brief Stores already visited points for surface applications with multiple markers. */
55
56 /*!
57 * \brief The highest level in the variable hierarchy all derived solvers can safely use,
58 * CVariable is the common denominator between the FEA and Mesh deformationd variables.
59 */
60 CSobolevSmoothingVariable* nodes = nullptr;
61
62 /*!
63 * \brief Return nodes to allow CSolver::base_nodes to be set.
64 */
65 inline CVariable* GetBaseClassPointerToNodes() override { return nodes; }
66
67 public:
68 /*!
69 * \brief Constructor of the class.
70 */
72 CConfig *config);
73
74 /*!
75 * \brief Destructor of the class.
76 */
78
79 /*!
80 * \brief Main routine for applying the solver on the volume sensitivities
81 */
82 void ApplyGradientSmoothingVolume(CGeometry* geometry, CNumerics* numerics, const CConfig* config) override;
83
84 /*!
85 * \brief Main routine to apply the method only on the surface for mesh sensitivities
86 * Projects and smoothes only in the normal direction!
87 */
88 void ApplyGradientSmoothingSurface(CGeometry* geometry, CNumerics* numerics, const CConfig* config) override;
89
90 /*!
91 * \brief All steps required for smoothing the whole system on DV level in an iterative way
92 */
94 CNumerics *numerics,
95 CSurfaceMovement *surface_movement,
96 CVolumetricMovement *grid_movement,
97 CConfig *config,
98 su2double** Gradient) override;
99
100 private:
101
102 /*!
103 * \brief Assemble the stiffness matrix
104 */
105 void Compute_StiffMatrix(CGeometry* geometry, CNumerics* numerics, const CConfig* config);
106
107 /*!
108 * \brief Compute the stiffness matrix of the surface mesh
109 */
110 void Compute_Surface_StiffMatrix(CGeometry* geometry, CNumerics* numerics, const CConfig* config,
111 unsigned long val_marker, unsigned int nSurfDim = 1);
112
113 /*!
114 * \brief Calculate the RHS of the PDE
115 */
116 void Compute_Residual(CGeometry* geometry, const CConfig* config);
117
118 /*!
119 * \brief Compute the RHS of the PDE on the surface mesh
120 */
121 void Compute_Surface_Residual(CGeometry* geometry, const CConfig* config, unsigned long val_marker);
122
123 /*!
124 * \brief Set the boundary conditions
125 */
126 void Impose_BC(const CGeometry* geometry, const CConfig* config);
127
128 /*!
129 * \brief Set Dirichlet boundary conditions
130 */
131 void BC_Dirichlet(const CGeometry* geometry, const CConfig* config, unsigned int val_marker);
132
133 /*!
134 * \brief Set Dirichlet boundary conditions for the surface solver
135 */
136 void BC_Surface_Dirichlet(const CGeometry* geometry, const CConfig* config, unsigned int val_marker);
137
138 /*!
139 * \brief Call the linear systems solver
140 */
141 void Solve_Linear_System(CGeometry* geometry, const CConfig* config);
142
143 /*!
144 * \brief Get the matrix vector product with the StiffnessMatrix
145 * \note This always applies the stiffness matrix for all dimensions independent of each other!
146 */
147 template <typename scalar_type>
148 CSysMatrixVectorProduct<scalar_type> GetStiffnessMatrixVectorProduct(CGeometry* geometry, CNumerics* numerics,
149 const CConfig* config);
150
151 /*!
152 * \brief calculate the original DV gradient similar to SU2_DOT_AD
153 */
154 void CalculateOriginalGradient(CGeometry *geometry,
155 CVolumetricMovement* grid_movement,
156 CConfig *config,
157 su2double **Gradient);
158
159 /*!
160 * \brief Return the original gradient for application in OneShot.
161 */
162 void RecordTapeAndCalculateOriginalGradient(CGeometry *geometry,
163 CSurfaceMovement *surface_movement,
164 CVolumetricMovement *grid_movement,
165 CConfig *config,
166 su2double** Gradient) override;
167
168 /*!
169 * \brief write the DV gradient into a file
170 */
171 void OutputDVGradient(const CConfig* config, string out_file = "delta_p.txt");
172
173 /*!
174 * \brief Record a tape containing the parameter Jacobian.
175 * \param geometry - Geometrical definition of the problem.
176 * \param surface_movement - Surface movement of the problem.
177 * \param registeredCoord - Indexes of the affected coordinates.
178 * \param config - Definition of the particular problem.
179 */
180 void RecordParameterizationJacobian(CGeometry *geometry,
181 CSurfaceMovement *surface_movement,
182 CSysVector<su2double> &registeredCoord,
183 CConfig *config);
184
185 /*!
186 * \brief Forward evaluate parameterization Jacobian.
187 */
188 void ProjectDVtoMesh(CGeometry *geometry,
189 std::vector<su2double>& seeding,
191 CSysVector<su2double>& registeredCoord,
192 CConfig *config);
193
194 /*!
195 * \brief Reverse evaluate parameterization Jacobian.
196 */
197 void ProjectMeshToDV(CGeometry *geometry,
198 CSysVector<su2mixedfloat>& sensitivity,
199 std::vector<su2double>& output,
200 CSysVector<su2double> &registeredCoord,
201 CConfig *config);
202
203 /*!
204 * \brief Write the content of sensitivity in the nodes to the sensitivity in the geometry
205 * \param[in] geometry - Geometrical definition of the problem.
206 */
207 void WriteSensToGeometry(CGeometry* geometry) const override;
208
209 /*!
210 * \brief Read the sensitivity for the geometry into the nodes
211 * \param[in] geometry - Geometrical definition of the problem.
212 */
213 void ReadSensFromGeometry(const CGeometry *geometry) override;
214
215 /*!
216 * \brief Write the solution of the linear solver into the sensitivities of the nodes
217 */
218 void WriteSensitivity(CGeometry* geometry, const CConfig* config);
219
220 /*!
221 * \brief Get the value of the reference coordinate to set on the element structure.
222 * \param[in] geometry - Geometrical definition of the problem.
223 * \param[in] indexNode - Index of the node.
224 * \param[in] iDim - Dimension required.
225 */
226 inline su2double Get_ValCoord(CGeometry *geometry,
227 unsigned long indexNode,
228 unsigned int iDim) {
229 return geometry->nodes->GetCoord(indexNode, iDim);
230 }
231
232 /*!
233 * \brief Extra entries to eliminate in the linear system
234 */
235 void Set_VertexEliminationSchedule(CGeometry* geometry, const CConfig* config);
236
237 /*!
238 * \brief Complete the calculation of the surface stiffness matrix
239 * \param[in] geometry - Geometrical definition of the problem.
240 */
241 void Complete_Surface_StiffMatrix(const CGeometry* geometry);
242
243 /*!
244 * \brief Get the element container index and number of nodes of a given VTK type.
245 * \param[in] VTK_Type - Type of element.
246 * \param[out] EL_KIND - Element container index.
247 * \param[out] nNodes - Number of nodes.
248 */
249 static void GetElemKindAndNumNodes(unsigned short VTK_Type, int& EL_KIND, unsigned int& nNodes) {
250 /*--- if we need higher order quadrature rules overide some of the element kinds ---*/
251 switch (VTK_Type) {
252 case LINE: nNodes = 2; EL_KIND = EL_LINE; break;
253 case TRIANGLE: nNodes = 3; EL_KIND = EL_TRIA2; break;
254 case QUADRILATERAL: nNodes = 4; EL_KIND = EL_QUAD; break;
255 case TETRAHEDRON: nNodes = 4; EL_KIND = EL_TETRA2; break;
256 case PYRAMID: nNodes = 5; EL_KIND = EL_PYRAM2; break;
257 case PRISM: nNodes = 6; EL_KIND = EL_PRISM; break;
258 case HEXAHEDRON: nNodes = 8; EL_KIND = EL_HEXA; break;
259 default: assert(false); nNodes = 0; EL_KIND = -(1<<30); break;
260 }
261 }
262
263 /*!
264 * \brief Set the current working dimension, if the separate dimension option is set.
265 * \param[in] iDim - the dimension we are currently working in.
266 */
267 inline void SetCurrentDim(unsigned int iDim) {
268 curDim=iDim;
269 }
270
271 /*!
272 * \brief Return the current working dimension.
273 */
274 inline unsigned int GetCurrentDim() const {
275 return curDim;
276 }
277
278};
Main class for defining the problem; basically this class reads the configuration file,...
Definition CConfig.hpp:64
Base class for FEM elasticity solvers.
Definition CFEASolverBase.hpp:41
Parent class for defining the geometry of the problem (complete geometry, multigrid agglomerated geom...
Definition CGeometry.hpp:75
CPoint * nodes
Node vector (dual grid information).
Definition CGeometry.hpp:253
Main class for defining a Sobolev-based gradient smoothing.
Definition CGradientSmoothingSolver.hpp:40
void ApplyGradientSmoothingSurface(CGeometry *geometry, CNumerics *numerics, const CConfig *config) override
Main routine to apply the method only on the surface for mesh sensitivities Projects and smoothes onl...
Definition CGradientSmoothingSolver.cpp:219
void ApplyGradientSmoothingVolume(CGeometry *geometry, CNumerics *numerics, const CConfig *config) override
Main routine for applying the solver on the volume sensitivities.
Definition CGradientSmoothingSolver.cpp:176
void ApplyGradientSmoothingDV(CGeometry *geometry, CNumerics *numerics, CSurfaceMovement *surface_movement, CVolumetricMovement *grid_movement, CConfig *config, su2double **Gradient) override
All steps required for smoothing the whole system on DV level in an iterative way.
Definition CGradientSmoothingSolver.cpp:251
~CGradientSmoothingSolver(void)
Destructor of the class.
Definition CGradientSmoothingSolver.cpp:169
Class for defining the numerical methods.
Definition CNumerics.hpp:48
su2double GetCoord(unsigned long iPoint, unsigned long iDim) const
Get the coordinates dor the control volume.
Definition CPoint.hpp:158
Definition CSobolevSmoothingVariable.hpp:33
Class to store a dense general square matrix that uses the Column Major order storage format....
Definition CSquareMatrixCM.hpp:39
Class for moving the surface numerical grid.
Definition CSurfaceMovement.hpp:38
Specialization of matrix-vector product that uses CSysMatrix class.
Definition CMatrixVectorProduct.hpp:70
Class for holding and manipulating vectors needed by linear solvers.
Definition CSysVector.hpp:195
Main class for defining the variables.
Definition CVariable.hpp:50
Class for moving the volumetric numerical grid.
Definition CVolumetricMovement.hpp:37
passivedouble su2double
Definition code_config.hpp:181
const int EL_QUAD
Elements of four nodes (2D).
Definition option_structure.hpp:617
@ TRIANGLE
VTK nomenclature for defining a triangle element.
Definition option_structure.hpp:134
@ PYRAMID
VTK nomenclature for defining a pyramid element.
Definition option_structure.hpp:139
@ PRISM
VTK nomenclature for defining a prism element.
Definition option_structure.hpp:138
@ QUADRILATERAL
VTK nomenclature for defining a quadrilateral element.
Definition option_structure.hpp:135
@ HEXAHEDRON
VTK nomenclature for defining a hexahedron element.
Definition option_structure.hpp:137
@ LINE
VTK nomenclature for defining a line element.
Definition option_structure.hpp:133
@ TETRAHEDRON
VTK nomenclature for defining a tetrahedron element.
Definition option_structure.hpp:136
const int EL_TRIA2
Elements of three nodes (2D), with second order gauss quadrature.
Definition option_structure.hpp:618
const int EL_TETRA2
Elements of four nodes, with second order gauss quadrature (3D).
Definition option_structure.hpp:624
const int EL_LINE
Types of finite elements (in 1D or 2D or 3D)
Definition option_structure.hpp:614
const int EL_PYRAM2
Elements of five nodes, with third order gauss quadrature (3D).
Definition option_structure.hpp:625
const int EL_HEXA
Elements of eight nodes (3D).
Definition option_structure.hpp:621
const int EL_PRISM
Elements of six nodes (3D).
Definition option_structure.hpp:623