Documentation 6b54b78464
Loading...
Searching...
No Matches
CFlowVariable.hpp
Go to the documentation of this file.
1/*!
2 * \file CFlowVariable.hpp
3 * \brief Class for defining the common variables of flow solvers.
4 * \version 8.5.0 "Harrier"
5 *
6 * SU2 Project Website: https://su2code.github.io
7 *
8 * The SU2 Project is maintained by the SU2 Foundation
9 * (http://su2foundation.org)
10 *
11 * Copyright 2012-2026, SU2 Contributors (cf. AUTHORS.md)
12 *
13 * SU2 is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2.1 of the License, or (at your option) any later version.
17 *
18 * SU2 is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
22 *
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with SU2. If not, see <http://www.gnu.org/licenses/>.
25 */
26
27#pragma once
28
29#include <algorithm>
30#include <cstdint>
31
32#include "CVariable.hpp"
33
34/*!
35 * \class CFlowVariable
36 * \brief Class for defining the common variables of flow solvers.
37 */
38class CFlowVariable : public CVariable {
39 protected:
40 /*--- Primitive variable definition. ---*/
41 MatrixType Primitive; /*!< \brief Primitive variables. */
42 CVectorOfMatrix Gradient_Primitive; /*!< \brief Gradient of the primitive variables. */
43 CVectorOfMatrix& Gradient_Reconstruction; /*!< \brief Reference to the gradient of the primitive variables for MUSCL
44 reconstruction for the convective term */
46 Gradient_Aux; /*!< \brief Auxiliary structure to store a second gradient for reconstruction, if required. */
47 MatrixType Limiter_Primitive; /*!< \brief Limiter of the primitive variables. */
48 VectorType Velocity2; /*!< \brief Squared norm of velocity. */
49
50 MatrixType Solution_New; /*!< \brief New solution container for Classical RK4. */
51 MatrixType HB_Source; /*!< \brief harmonic balance source term. */
52
53 /*--- NS Variables declared here to make it easier to re-use code between compressible and incompressible solvers.
54 * ---*/
55 MatrixType Vorticity; /*!< \brief Vorticity of the flow field. */
56 VectorType StrainMag; /*!< \brief Magnitude of rate of strain tensor. */
57
58 /*!
59 * \brief Constructor of the class.
60 * \note This class is not meant to be instantiated directly, it is only a building block.
61 * \param[in] npoint - Number of points/nodes/vertices in the domain.
62 * \param[in] ndim - Number of dimensions.
63 * \param[in] nvar - Number of variables.
64 * \param[in] nprimvar - Number of primitive variables.
65 * \param[in] nprimvargrad - Number of primitive variables for which to compute gradients.
66 * \param[in] config - Definition of the particular problem.
67 */
68 CFlowVariable(unsigned long npoint, unsigned long ndim, unsigned long nvar, unsigned long nprimvar,
69 unsigned long nprimvargrad, const CConfig* config);
70
71 public:
72 mutable su2vector<int8_t> NonPhysicalEdgeCounter; /*!< \brief Non-physical reconstruction counter for each edge. */
73 /*!
74 * \brief Updates the non-physical counter of an edge.
75 * \param[in] iEdge - Edge index.
76 * \param[in] isNonPhys - Should be 1 (true) if a non-physical reconstruction was occurred.
77 * \return Whether the reconstruction should be limited to first order, based on the counter.
78 */
79 template <class T>
80 inline T UpdateNonPhysicalEdgeCounter(unsigned long iEdge, const T& isNonPhys) const {
81 if (isNonPhys != 0) {
82 /*--- Force 1st order for this edge for at least 20 iterations. ---*/
83 NonPhysicalEdgeCounter[iEdge] = 21;
84 }
85 NonPhysicalEdgeCounter[iEdge] = std::max<int8_t>(0, NonPhysicalEdgeCounter[iEdge] - 1);
86 return static_cast<T>(NonPhysicalEdgeCounter[iEdge] > 0);
87 }
88
89 /*!
90 * \brief Get a primitive variable.
91 * \param[in] iPoint - Point index.
92 * \param[in] iVar - Index of the variable.
93 * \return Value of the primitive variable for the index <i>iVar</i>.
94 */
95 inline su2double GetPrimitive(unsigned long iPoint, unsigned long iVar) const final {
96 return Primitive(iPoint, iVar);
97 }
98
99 /*!
100 * \brief Get all the primitive variables of the problem.
101 * \param[in] iPoint - Point index.
102 * \return Pointer to the primitive variable vector.
103 */
104 inline su2double* GetPrimitive(unsigned long iPoint) final { return Primitive[iPoint]; }
105
106 /*!
107 * \brief Get the primitive variables for all points.
108 * \return Reference to primitives.
109 */
110 inline const MatrixType& GetPrimitive() const final { return Primitive; }
111
112 /*!
113 * \brief Set the value of the primitive variables.
114 * \param[in] iPoint - Point index.
115 * \param[in] iVar - Index of the variable.
116 * \param[in] val_prim - Value of the variable.
117 * \return Set the value of the primitive variable for the index <i>iVar</i>.
118 */
119 inline void SetPrimitive(unsigned long iPoint, unsigned long iVar, su2double val_prim) final {
120 Primitive(iPoint, iVar) = val_prim;
121 }
122
123 /*!
124 * \brief Set the value of the primitive variables.
125 * \param[in] iPoint - Point index.
126 * \param[in] val_prim - Values of primitive variables.
127 * \return Set the value of the primitive variable for the index <i>iVar</i>.
128 */
129 inline void SetPrimitive(unsigned long iPoint, const su2double* val_prim) final {
130 for (unsigned long iVar = 0; iVar < nPrimVar; iVar++) Primitive(iPoint, iVar) = val_prim[iVar];
131 }
132
133 /*!
134 * \brief Get the squared norm of the velocity.
135 * \param[in] iPoint - Point index.
136 * \return Squared norm of the velocity vector.
137 */
138 inline su2double GetVelocity2(unsigned long iPoint) const final { return Velocity2(iPoint); }
139
140 /*!
141 * \brief Get the value of the primitive variables gradient.
142 * \param[in] iPoint - Point index.
143 * \param[in] iVar - Index of the variable.
144 * \param[in] iDim - Index of the dimension.
145 * \return Value of the primitive variables gradient.
146 */
147 inline su2double GetGradient_Primitive(unsigned long iPoint, unsigned long iVar, unsigned long iDim) const final {
148 return Gradient_Primitive(iPoint, iVar, iDim);
149 }
150
151 /*!
152 * \brief Get the value of the primitive variables gradient.
153 * \param[in] iPoint - Point index.
154 * \param[in] iVarStart - Offset from which to start reading.
155 * \return Value of the primitive variables gradient.
156 */
157 inline CMatrixView<su2double> GetGradient_Primitive(unsigned long iPoint, unsigned long iVarStart = 0) final {
158 return Gradient_Primitive(iPoint, iVarStart);
159 }
160
161 /*!
162 * \brief Get the primitive variable gradients for all points.
163 * \return Reference to primitive variable gradient.
164 */
166 inline const CVectorOfMatrix& GetGradient_Primitive() const final { return Gradient_Primitive; }
167
168 /*!
169 * \brief Get the array of the reconstruction variables gradient at a node.
170 * \param[in] iPoint - Point index.
171 * \return Array of the reconstruction variables gradient at a node.
172 */
173 inline CMatrixView<su2double> GetGradient_Reconstruction(unsigned long iPoint) final {
174 return Gradient_Reconstruction[iPoint];
175 }
176
177 /*!
178 * \brief Get the reconstruction gradient for primitive variable at all points.
179 * \return Reference to variable reconstruction gradient.
180 */
183
184 /*!
185 * \brief Get the value of the primitive variables gradient.
186 * \param[in] iPoint - Point index.
187 * \param[in] iVar - Index of the variable.
188 * \return Value of the primitive variables gradient.
189 */
190 inline su2double GetLimiter_Primitive(unsigned long iPoint, unsigned long iVar) const final {
191 return Limiter_Primitive(iPoint, iVar);
192 }
193
194 /*!
195 * \brief Get the value of the primitive variables gradient.
196 * \param[in] iPoint - Point index.
197 * \return Value of the primitive variables gradient.
198 */
199 inline su2double* GetLimiter_Primitive(unsigned long iPoint) final { return Limiter_Primitive[iPoint]; }
200
201 /*!
202 * \brief Get the primitive variables limiter.
203 * \return Primitive variables limiter for the entire domain.
204 */
206 inline const MatrixType& GetLimiter_Primitive() const final { return Limiter_Primitive; }
207
208 /*!
209 * \brief Number of primitive variables that have a gradient/limiter column, from the start of
210 * the primitive row. Some convective schemes (see EulerNPrimVarGrad) size this smaller
211 * than the full primitive count.
212 */
213 inline unsigned long GetnPrimVarGrad() const { return nPrimVarGrad; }
214
215 /*!
216 * \brief Get the new solution of the problem (Classical RK4).
217 * \param[in] iPoint - Point index.
218 * \param[in] iVar - Index of the variable.
219 * \return Pointer to the old solution vector.
220 */
221 inline su2double GetSolution_New(unsigned long iPoint, unsigned long iVar) const final {
222 return Solution_New(iPoint, iVar);
223 }
224
225 /*!
226 * \brief Add a value to the new solution container for Classical RK4.
227 * \param[in] iPoint - Point index.
228 * \param[in] iVar - Index of the variable.
229 * \param[in] val_solution - Value that we want to add to the new solution.
230 */
231 inline void AddSolution_New(unsigned long iPoint, unsigned long iVar, su2double val_solution) final {
232 Solution_New(iPoint, iVar) += val_solution;
233 }
234
235 /*!
236 * \brief Set the new solution container for Classical RK4.
237 */
238 void SetSolution_New() final;
239
240 /*!
241 * \brief Get the harmonic balance source term.
242 * \param[in] iPoint - Point index.
243 * \param[in] iVar - Index of the variable.
244 * \return Value of the harmonic balance source term for the index <i>iVar</i>.
245 */
246 inline su2double GetHarmonicBalance_Source(unsigned long iPoint, unsigned long iVar) const final {
247 return HB_Source(iPoint, iVar);
248 }
249
250 /*!
251 * \brief Set the harmonic balance source term.
252 * \param[in] iPoint - Point index.
253 * \param[in] iVar - Index of the variable.
254 * \param[in] val_solution - Value of the harmonic balance source term. for the index <i>iVar</i>.
255 */
256 inline void SetHarmonicBalance_Source(unsigned long iPoint, unsigned long iVar, su2double val_source) final {
257 HB_Source(iPoint, iVar) = val_source;
258 }
259
260 /*!
261 * \brief Get the values of the vorticity (3 values also in 2D).
262 * \param[in] iPoint - Point index.
263 * \return Vorticity array.
264 */
265 inline su2double* GetVorticity(unsigned long iPoint) final { return Vorticity[iPoint]; }
266 inline const su2double* GetVorticity(unsigned long iPoint) const final { return Vorticity[iPoint]; }
267
268 /*!
269 * \brief Get the magnitude of rate of strain.
270 * \param[in] iPoint - Point index.
271 * \return Value of magnitude.
272 */
273 inline su2double GetStrainMag(unsigned long iPoint) const final { return StrainMag(iPoint); }
274
275 /*!
276 * \brief Get the entire vector of the rate of strain magnitude.
277 * \return Vector of magnitudes.
278 */
280
281 /*!
282 * \brief Get the density at time level n for dual-time stepping.
283 * \param[in] iPoint - Point index.
284 * \return Density at time level n.
285 */
286 virtual su2double GetDensity_time_n(unsigned long iPoint) const = 0;
287
288 /*!
289 * \brief Get the density at time level n-1 for dual-time stepping.
290 * \param[in] iPoint - Point index.
291 * \return Density at time level n-1.
292 */
293 virtual su2double GetDensity_time_n1(unsigned long iPoint) const = 0;
294};
Declaration and inlines of the parent class for defining problem variables, function definitions in f...
Main class for defining the problem; basically this class reads the configuration file,...
Definition CConfig.hpp:64
Class for defining the common variables of flow solvers.
Definition CFlowVariable.hpp:38
su2double GetVelocity2(unsigned long iPoint) const final
Get the squared norm of the velocity.
Definition CFlowVariable.hpp:138
void AddSolution_New(unsigned long iPoint, unsigned long iVar, su2double val_solution) final
Add a value to the new solution container for Classical RK4.
Definition CFlowVariable.hpp:231
MatrixType Solution_New
New solution container for Classical RK4.
Definition CFlowVariable.hpp:50
su2double GetHarmonicBalance_Source(unsigned long iPoint, unsigned long iVar) const final
Get the harmonic balance source term.
Definition CFlowVariable.hpp:246
virtual su2double GetDensity_time_n(unsigned long iPoint) const =0
Get the density at time level n for dual-time stepping.
const MatrixType & GetLimiter_Primitive() const final
Definition CFlowVariable.hpp:206
const CVectorOfMatrix & GetGradient_Primitive() const final
Definition CFlowVariable.hpp:166
unsigned long GetnPrimVarGrad() const
Number of primitive variables that have a gradient/limiter column, from the start of the primitive ro...
Definition CFlowVariable.hpp:213
su2double GetGradient_Primitive(unsigned long iPoint, unsigned long iVar, unsigned long iDim) const final
Get the value of the primitive variables gradient.
Definition CFlowVariable.hpp:147
CVectorOfMatrix & Gradient_Reconstruction
Reference to the gradient of the primitive variables for MUSCL reconstruction for the convective term...
Definition CFlowVariable.hpp:43
void SetHarmonicBalance_Source(unsigned long iPoint, unsigned long iVar, su2double val_source) final
Set the harmonic balance source term.
Definition CFlowVariable.hpp:256
virtual su2double GetDensity_time_n1(unsigned long iPoint) const =0
Get the density at time level n-1 for dual-time stepping.
su2activevector & GetStrainMag()
Get the entire vector of the rate of strain magnitude.
Definition CFlowVariable.hpp:279
const CVectorOfMatrix & GetGradient_Reconstruction() const final
Definition CFlowVariable.hpp:182
const su2double * GetVorticity(unsigned long iPoint) const final
Definition CFlowVariable.hpp:266
MatrixType Vorticity
Vorticity of the flow field.
Definition CFlowVariable.hpp:55
const MatrixType & GetPrimitive() const final
Get the primitive variables for all points.
Definition CFlowVariable.hpp:110
void SetSolution_New() final
Set the new solution container for Classical RK4.
Definition CFlowVariable.cpp:102
MatrixType & GetLimiter_Primitive() final
Get the primitive variables limiter.
Definition CFlowVariable.hpp:205
void SetPrimitive(unsigned long iPoint, const su2double *val_prim) final
Set the value of the primitive variables.
Definition CFlowVariable.hpp:129
CMatrixView< su2double > GetGradient_Primitive(unsigned long iPoint, unsigned long iVarStart=0) final
Get the value of the primitive variables gradient.
Definition CFlowVariable.hpp:157
su2double GetPrimitive(unsigned long iPoint, unsigned long iVar) const final
Get a primitive variable.
Definition CFlowVariable.hpp:95
MatrixType HB_Source
harmonic balance source term.
Definition CFlowVariable.hpp:51
su2double * GetVorticity(unsigned long iPoint) final
Get the values of the vorticity (3 values also in 2D).
Definition CFlowVariable.hpp:265
CMatrixView< su2double > GetGradient_Reconstruction(unsigned long iPoint) final
Get the array of the reconstruction variables gradient at a node.
Definition CFlowVariable.hpp:173
CVectorOfMatrix & GetGradient_Reconstruction() final
Get the reconstruction gradient for primitive variable at all points.
Definition CFlowVariable.hpp:181
CVectorOfMatrix Gradient_Aux
Auxiliary structure to store a second gradient for reconstruction, if required.
Definition CFlowVariable.hpp:46
su2vector< int8_t > NonPhysicalEdgeCounter
Non-physical reconstruction counter for each edge.
Definition CFlowVariable.hpp:72
su2double * GetLimiter_Primitive(unsigned long iPoint) final
Get the value of the primitive variables gradient.
Definition CFlowVariable.hpp:199
su2double GetSolution_New(unsigned long iPoint, unsigned long iVar) const final
Get the new solution of the problem (Classical RK4).
Definition CFlowVariable.hpp:221
void SetPrimitive(unsigned long iPoint, unsigned long iVar, su2double val_prim) final
Set the value of the primitive variables.
Definition CFlowVariable.hpp:119
su2double GetStrainMag(unsigned long iPoint) const final
Get the magnitude of rate of strain.
Definition CFlowVariable.hpp:273
MatrixType Limiter_Primitive
Limiter of the primitive variables.
Definition CFlowVariable.hpp:47
T UpdateNonPhysicalEdgeCounter(unsigned long iEdge, const T &isNonPhys) const
Updates the non-physical counter of an edge.
Definition CFlowVariable.hpp:80
CVectorOfMatrix Gradient_Primitive
Gradient of the primitive variables.
Definition CFlowVariable.hpp:42
su2double * GetPrimitive(unsigned long iPoint) final
Get all the primitive variables of the problem.
Definition CFlowVariable.hpp:104
su2double GetLimiter_Primitive(unsigned long iPoint, unsigned long iVar) const final
Get the value of the primitive variables gradient.
Definition CFlowVariable.hpp:190
MatrixType Primitive
Primitive variables.
Definition CFlowVariable.hpp:41
CVectorOfMatrix & GetGradient_Primitive() final
Get the primitive variable gradients for all points.
Definition CFlowVariable.hpp:165
VectorType StrainMag
Magnitude of rate of strain tensor.
Definition CFlowVariable.hpp:56
VectorType Velocity2
Squared norm of velocity.
Definition CFlowVariable.hpp:48
Class to represent a matrix (without owning the data, this just wraps a pointer).
Definition container_decorators.hpp:40
Main class for defining the variables.
Definition CVariable.hpp:50
unsigned long nPrimVar
Number of primitive variables.
Definition CVariable.hpp:109
unsigned long nPrimVarGrad
Number of primitives for which a gradient is computed.
Definition CVariable.hpp:110
passivedouble su2double
Definition code_config.hpp:181