Documentation 6b54b78464
Loading...
Searching...
No Matches
CDiscAdjSolver.hpp
Go to the documentation of this file.
1/*!
2 * \file CDiscAdjSolver.hpp
3 * \brief Headers of the CDiscAdjSolver class
4 * \author T. Albring
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 "CSolver.hpp"
31#include "../variables/CDiscAdjVariable.hpp"
32
33/*!
34 * \class CDiscAdjSolver
35 * \ingroup DiscAdj
36 * \brief Main class for defining the discrete adjoint solver.
37 * \author T. Albring
38 */
39class CDiscAdjSolver final : public CSolver {
40protected:
41 static constexpr size_t MAXNDIM = 3; /*!< \brief Max number of space dimensions, used in some static arrays. */
42 static constexpr size_t MAXNVAR = 32; /*!< \brief Max number of variables, for static arrays. */
43
44 static constexpr size_t OMP_MAX_SIZE = 1024; /*!< \brief Max chunk size for light point loops. */
45
46 unsigned long omp_chunk_size; /*!< \brief Chunk size used in light point loops. */
47
48 unsigned short KindDirect_Solver;
50 vector<vector<su2double> > CSensitivity; /*!< \brief Shape sensitivity coefficient for each boundary and vertex. */
51 vector<su2double> Sens_Geo; /*!< \brief Total shape sensitivity for each monitored boundary. */
52 su2double Total_Sens_Mach; /*!< \brief Total mach sensitivity coefficient for all the boundaries. */
53 su2double Total_Sens_AoA; /*!< \brief Total angle of attack sensitivity coefficient for all the boundaries. */
54 su2double Total_Sens_Geo; /*!< \brief Total shape sensitivity coefficient for all the boundaries. */
55 su2double Total_Sens_Press; /*!< \brief Total farfield sensitivity to pressure. */
56 su2double Total_Sens_Temp; /*!< \brief Total farfield sensitivity to temperature. */
57 su2double Total_Sens_BPress; /*!< \brief Total sensitivity to outlet pressure. */
58 su2double Total_Sens_Density; /*!< \brief Total sensitivity to initial density (incompressible). */
59 su2double Total_Sens_ModVel; /*!< \brief Total sensitivity to inlet velocity (incompressible). */
62
63 CDiscAdjVariable* nodes = nullptr; /*!< \brief The highest level in the variable hierarchy this solver can safely use. */
64
65 /*!
66 * \brief Return nodes to allow CSolver::base_nodes to be set.
67 */
68 inline CVariable* GetBaseClassPointerToNodes() override { return nodes; }
69
70public:
71
72 /*!
73 * \brief Constructor of the class.
74 */
75 CDiscAdjSolver() = default;
76
77 /*!
78 * \overload
79 * \param[in] geometry - Geometrical definition of the problem.
80 * \param[in] config - Definition of the particular problem.
81 * \param[in] solver - Initialize the discrete adjoint solver with the corresponding direct solver.
82 * \param[in] Kind_Solver - The kind of direct solver.
83 * \param[in] iMesh - Index of the mesh in multigrid computations.
84 */
85 CDiscAdjSolver(CGeometry *geometry, CConfig *config, CSolver* solver, unsigned short Kind_Solver, unsigned short iMesh);
86
87 /*!
88 * \brief Destructor of the class.
89 */
90 ~CDiscAdjSolver() override;
91
92 /*!
93 * \brief Performs the preprocessing of the adjoint AD-based solver.
94 * Registers all necessary variables on the tape. Called while tape is active.
95 * \param[in] geometry_container - The geometry container holding all grid levels.
96 * \param[in] config_container - The particular config.
97 */
98 void RegisterSolution(CGeometry *geometry, CConfig *config) override;
99
100 /*!
101 * \brief Performs the preprocessing of the adjoint AD-based solver.
102 * Registers all necessary variables that are output variables on the tape.
103 * Called while tape is active.
104 * \param[in] geometry_container - The geometry container holding all grid levels.
105 * \param[in] config_container - The particular config.
106 */
107 void RegisterOutput(CGeometry *geometry, CConfig *config) override;
108
109 /*!
110 * \brief Sets the adjoint values of the output of the flow (+turb.) iteration
111 * before evaluation of the tape.
112 * \param[in] geometry - The geometrical definition of the problem.
113 * \param[in] config - The particular config.
114 */
115 void SetAdjoint_Output(CGeometry *geometry, CConfig *config) override;
116
117 /*!
118 * \brief Sets the adjoint values of the input variables of the flow (+turb.) iteration
119 * after tape has been evaluated.
120 * \param[in] geometry - The geometrical definition of the problem.
121 * \param[in] config - The particular config.
122 * \param[in] CrossTerm - Boolean for CrossTerm.
123 */
124 void ExtractAdjoint_Solution(CGeometry *geometry, CConfig *config, bool CrossTerm) override;
125
126 /*!
127 * \brief Set the surface sensitivity.
128 * \param[in] geometry - Geometrical definition of the problem.
129 * \param[in] config - Definition of the particular problem.
130 */
131 void SetSurface_Sensitivity(CGeometry *geometry, CConfig* config) override;
132
133 /*!
134 * \brief Extract and set the geometrical sensitivity.
135 * \param[in] geometry - Geometrical definition of the problem.
136 * \param[in] config - Definition of the particular problem.
137 */
138 void SetSensitivity(CGeometry *geometry, CConfig *config, CSolver*) override;
139
140 /*!
141 * \brief Provide the total shape sensitivity coefficient.
142 * \return Value of the geometrical sensitivity coefficient
143 * (inviscid + viscous contribution).
144 */
145 inline su2double GetTotal_Sens_Geo() const override { return Total_Sens_Geo; }
146
147 /*!
148 * \brief Set the total Mach number sensitivity coefficient.
149 * \return Value of the Mach sensitivity coefficient
150 * (inviscid + viscous contribution).
151 */
152 inline su2double GetTotal_Sens_Mach() const override { return Total_Sens_Mach; }
153
154 /*!
155 * \brief Set the total angle of attack sensitivity coefficient.
156 * \return Value of the angle of attack sensitivity coefficient
157 * (inviscid + viscous contribution).
158 */
159 inline su2double GetTotal_Sens_AoA() const override { return Total_Sens_AoA; }
160
161 /*!
162 * \brief Set the total farfield pressure sensitivity coefficient.
163 * \return Value of the farfield pressure sensitivity coefficient
164 * (inviscid + viscous contribution).
165 */
166 inline su2double GetTotal_Sens_Press() const override { return Total_Sens_Press; }
167
168 /*!
169 * \brief Set the total farfield temperature sensitivity coefficient.
170 * \return Value of the farfield temperature sensitivity coefficient
171 * (inviscid + viscous contribution).
172 */
173 inline su2double GetTotal_Sens_Temp() const override { return Total_Sens_Temp; }
174
175 /*!
176 * \author H. Kline
177 * \brief Get the total Back pressure number sensitivity coefficient.
178 * \return Value of the Back sensitivity coefficient
179 * (inviscid + viscous contribution).
180 */
181 inline su2double GetTotal_Sens_BPress() const override { return Total_Sens_BPress; }
182
183 /*!
184 * \brief Get the total density sensitivity coefficient.
185 * \return Value of the density sensitivity.
186 */
187 inline su2double GetTotal_Sens_Density() const override { return Total_Sens_Density; }
188
189 /*!
190 * \brief Get the total velocity magnitude sensitivity coefficient.
191 * \return Value of the velocity magnitude sensitivity.
192 */
193 inline su2double GetTotal_Sens_ModVel() const override { return Total_Sens_ModVel; }
194
195 /*!
196 * \brief Get the shape sensitivity coefficient.
197 * \param[in] val_marker - Surface marker where the coefficient is computed.
198 * \param[in] val_vertex - Vertex of the marker <i>val_marker</i> where the coefficient is evaluated.
199 * \return Value of the sensitivity coefficient.
200 */
201 inline su2double GetCSensitivity(unsigned short val_marker,
202 unsigned long val_vertex) const override {
203 return CSensitivity[val_marker][val_vertex];
204 }
205
206 /*!
207 * \brief Prepare the solver for a new recording.
208 * \param[in] kind_recording - Kind of AD recording.
209 */
210 void SetRecording(CGeometry *geometry, CConfig *config) override;
211
212 /*!
213 * \brief A virtual member.
214 * \param[in] geometry - Geometrical definition of the problem.
215 * \param[in] config - Definition of the particular problem.
216 * \param[in] reset - If true reset variables to their initial values.
217 */
218 void RegisterVariables(CGeometry *geometry,
219 CConfig *config,
220 bool reset = false) override;
221
222 /*!
223 * \brief A virtual member.
224 * \param[in] geometry - Geometrical definition of the problem.
225 * \param[in] config - Definition of the particular problem.
226 */
227 void ExtractAdjoint_Variables(CGeometry *geometry, CConfig *config) override;
228
229 /*!
230 * \brief Update the dual-time derivatives.
231 * \param[in] geometry - Geometrical definition of the problem.
232 * \param[in] solver_container - Container vector with all the solutions.
233 * \param[in] config - Definition of the particular problem.
234 * \param[in] iMesh - Index of the mesh in multigrid computations.
235 * \param[in] iRKStep - Current step of the Runge-Kutta iteration.
236 * \param[in] RunTime_EqSystem - System of equations which is going to be solved.
237 * \param[in] Output - boolean to determine whether to print output.
238 */
239 void Preprocessing(CGeometry *geometry,
240 CSolver **solver_container,
241 CConfig *config,
242 unsigned short iMesh,
243 unsigned short iRKStep,
244 unsigned short RunTime_EqSystem,
245 bool Output) override;
246
247 /*!
248 * \brief Load a solution from a restart file.
249 * \param[in] geometry - Geometrical definition of the problem.
250 * \param[in] solver - Container vector with all of the solvers.
251 * \param[in] config - Definition of the particular problem.
252 * \param[in] val_iter - Current external iteration number.
253 * \param[in] val_update_geo - Flag for updating coords and grid velocity.
254 */
255 void LoadRestart(CGeometry **geometry,
256 CSolver ***solver,
257 CConfig *config,
258 int val_iter,
259 bool val_update_geo) override;
260
261 /*!
262 * \brief Depends on the direct solver.
263 */
264 inline bool GetHasHybridParallel() const override {
266 return false;
267 }
268
269};
Headers of the CSolver class which is inherited by all of the other solvers.
Main class for defining the problem; basically this class reads the configuration file,...
Definition CConfig.hpp:64
Main class for defining the discrete adjoint solver.
Definition CDiscAdjSolver.hpp:39
void RegisterSolution(CGeometry *geometry, CConfig *config) override
Performs the preprocessing of the adjoint AD-based solver. Registers all necessary variables on the t...
Definition CDiscAdjSolver.cpp:157
su2double Total_Sens_AoA
Total angle of attack sensitivity coefficient for all the boundaries.
Definition CDiscAdjSolver.hpp:53
CSolver * direct_solver
Definition CDiscAdjSolver.hpp:49
void ExtractAdjoint_Solution(CGeometry *geometry, CConfig *config, bool CrossTerm) override
Sets the adjoint values of the input variables of the flow (+turb.) iteration after tape has been eva...
Definition CDiscAdjSolver.cpp:352
su2double GetTotal_Sens_Geo() const override
Provide the total shape sensitivity coefficient.
Definition CDiscAdjSolver.hpp:145
su2double Alpha
Definition CDiscAdjSolver.hpp:60
vector< su2double > Sens_Geo
Total shape sensitivity for each monitored boundary.
Definition CDiscAdjSolver.hpp:51
void SetSensitivity(CGeometry *geometry, CConfig *config, CSolver *) override
Extract and set the geometrical sensitivity.
Definition CDiscAdjSolver.cpp:540
su2double Total_Sens_BPress
Total sensitivity to outlet pressure.
Definition CDiscAdjSolver.hpp:57
su2double GetCSensitivity(unsigned short val_marker, unsigned long val_vertex) const override
Get the shape sensitivity coefficient.
Definition CDiscAdjSolver.hpp:201
su2double Beta
Definition CDiscAdjSolver.hpp:60
static constexpr size_t MAXNVAR
Max number of variables, for static arrays.
Definition CDiscAdjSolver.hpp:42
su2double GetTotal_Sens_Density() const override
Get the total density sensitivity coefficient.
Definition CDiscAdjSolver.hpp:187
su2double Pressure
Definition CDiscAdjSolver.hpp:60
su2double Total_Sens_ModVel
Total sensitivity to inlet velocity (incompressible).
Definition CDiscAdjSolver.hpp:59
void RegisterVariables(CGeometry *geometry, CConfig *config, bool reset=false) override
A virtual member.
Definition CDiscAdjSolver.cpp:180
su2double GetTotal_Sens_AoA() const override
Set the total angle of attack sensitivity coefficient.
Definition CDiscAdjSolver.hpp:159
CVariable * GetBaseClassPointerToNodes() override
Return nodes to allow CSolver::base_nodes to be set.
Definition CDiscAdjSolver.hpp:68
CDiscAdjSolver()=default
Constructor of the class.
su2double TemperatureRad
Definition CDiscAdjSolver.hpp:61
static constexpr size_t MAXNDIM
Max number of space dimensions, used in some static arrays.
Definition CDiscAdjSolver.hpp:41
void SetAdjoint_Output(CGeometry *geometry, CConfig *config) override
Sets the adjoint values of the output of the flow (+turb.) iteration before evaluation of the tape.
Definition CDiscAdjSolver.cpp:506
unsigned short KindDirect_Solver
Definition CDiscAdjSolver.hpp:48
su2double Total_Sens_Temp_Rad
Definition CDiscAdjSolver.hpp:61
su2double GetTotal_Sens_BPress() const override
Get the total Back pressure number sensitivity coefficient.
Definition CDiscAdjSolver.hpp:181
~CDiscAdjSolver() override
Destructor of the class.
Definition CDiscAdjSolver.cpp:116
su2double Total_Sens_Density
Total sensitivity to initial density (incompressible).
Definition CDiscAdjSolver.hpp:58
su2double GetTotal_Sens_Press() const override
Set the total farfield pressure sensitivity coefficient.
Definition CDiscAdjSolver.hpp:166
void SetRecording(CGeometry *geometry, CConfig *config) override
Prepare the solver for a new recording.
Definition CDiscAdjSolver.cpp:118
su2double GetTotal_Sens_Temp() const override
Set the total farfield temperature sensitivity coefficient.
Definition CDiscAdjSolver.hpp:173
unsigned long omp_chunk_size
Chunk size used in light point loops.
Definition CDiscAdjSolver.hpp:46
static constexpr size_t OMP_MAX_SIZE
Max chunk size for light point loops.
Definition CDiscAdjSolver.hpp:44
void ExtractAdjoint_Variables(CGeometry *geometry, CConfig *config) override
A virtual member.
Definition CDiscAdjSolver.cpp:440
void RegisterOutput(CGeometry *geometry, CConfig *config) override
Performs the preprocessing of the adjoint AD-based solver. Registers all necessary variables that are...
Definition CDiscAdjSolver.cpp:342
su2double Total_Sens_Temp
Total farfield sensitivity to temperature.
Definition CDiscAdjSolver.hpp:56
su2double GetTotal_Sens_ModVel() const override
Get the total velocity magnitude sensitivity coefficient.
Definition CDiscAdjSolver.hpp:193
void Preprocessing(CGeometry *geometry, CSolver **solver_container, CConfig *config, unsigned short iMesh, unsigned short iRKStep, unsigned short RunTime_EqSystem, bool Output) override
Update the dual-time derivatives.
Definition CDiscAdjSolver.cpp:644
CDiscAdjVariable * nodes
The highest level in the variable hierarchy this solver can safely use.
Definition CDiscAdjSolver.hpp:63
su2double Mach
Definition CDiscAdjSolver.hpp:60
vector< vector< su2double > > CSensitivity
Shape sensitivity coefficient for each boundary and vertex.
Definition CDiscAdjSolver.hpp:50
bool GetHasHybridParallel() const override
Depends on the direct solver.
Definition CDiscAdjSolver.hpp:264
void SetSurface_Sensitivity(CGeometry *geometry, CConfig *config) override
Set the surface sensitivity.
Definition CDiscAdjSolver.cpp:582
su2double Temperature
Definition CDiscAdjSolver.hpp:60
su2double Total_Sens_Mach
Total mach sensitivity coefficient for all the boundaries.
Definition CDiscAdjSolver.hpp:52
void LoadRestart(CGeometry **geometry, CSolver ***solver, CConfig *config, int val_iter, bool val_update_geo) override
Load a solution from a restart file.
Definition CDiscAdjSolver.cpp:670
su2double GetTotal_Sens_Mach() const override
Set the total Mach number sensitivity coefficient.
Definition CDiscAdjSolver.hpp:152
su2double Total_Sens_Press
Total farfield sensitivity to pressure.
Definition CDiscAdjSolver.hpp:55
su2double Total_Sens_Geo
Total shape sensitivity coefficient for all the boundaries.
Definition CDiscAdjSolver.hpp:54
su2double ModVel
Definition CDiscAdjSolver.hpp:60
su2double BPressure
Definition CDiscAdjSolver.hpp:60
Main class for defining the variables of the adjoint solver.
Definition CDiscAdjVariable.hpp:38
Parent class for defining the geometry of the problem (complete geometry, multigrid agglomerated geom...
Definition CGeometry.hpp:75
Definition CSolver.hpp:71
virtual bool GetHasHybridParallel() const
Whether the methods of the solver called by multi/single-grid iteration can be executed by multiple t...
Definition CSolver.hpp:4336
Main class for defining the variables.
Definition CVariable.hpp:50
passivedouble su2double
Definition code_config.hpp:181