-
Notifications
You must be signed in to change notification settings - Fork 987
Expand file tree
/
Copy pathCEulerVariable.hpp
More file actions
351 lines (305 loc) · 13 KB
/
Copy pathCEulerVariable.hpp
File metadata and controls
351 lines (305 loc) · 13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
/*!
* \file CEulerVariable.hpp
* \brief Class for defining the variables of the compressible Euler solver.
* \author F. Palacios, T. Economon
* \version 8.1.0 "Harrier"
*
* SU2 Project Website: https://su2code.github.io
*
* The SU2 Project is maintained by the SU2 Foundation
* (http://su2foundation.org)
*
* Copyright 2012-2024, SU2 Contributors (cf. AUTHORS.md)
*
* SU2 is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* SU2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with SU2. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <limits>
#include "CFlowVariable.hpp"
/*!
* \class CEulerVariable
* \brief Class for defining the variables of the compressible Euler solver.
* \note Primitive variables (T, vx, vy, vz, P, rho, h, c)
* \note Gradients and limiters (T, vx, vy, vz, P, rho)
* \ingroup Euler_Equations
* \author F. Palacios, T. Economon
*/
class CEulerVariable : public CFlowVariable {
public:
static constexpr size_t MAXNVAR = 12;
template <class IndexType>
struct CIndices {
const IndexType nDim;
CIndices(IndexType ndim, IndexType) : nDim(ndim) {}
inline IndexType NDim() const { return nDim; }
inline IndexType NSpecies() const { return 0; }
inline IndexType Temperature() const { return 0; }
inline IndexType Velocity() const { return 1; }
inline IndexType Pressure() const { return nDim+1; }
inline IndexType Density() const { return nDim+2; }
inline IndexType Enthalpy() const { return nDim+3; }
inline IndexType SoundSpeed() const { return nDim+4; }
inline IndexType LaminarViscosity() const { return nDim+5; }
inline IndexType EddyViscosity() const { return nDim+6; }
inline IndexType ThermalConductivity() const { return nDim+7; }
inline IndexType CpTotal() const { return nDim+8; }
/*--- For compatible interface with NEMO. ---*/
inline IndexType SpeciesDensities() const { return std::numeric_limits<IndexType>::max(); }
inline IndexType Temperature_ve() const { return std::numeric_limits<IndexType>::max(); }
};
protected:
const CIndices<unsigned long> indices;
/*!< \brief Secondary variables (dPdrho_e, dPde_rho, dTdrho_e, dTde_rho, dmudrho_T, dmudT_rho, dktdrho_T, dktdT_rho)
* in compressible (Euler: 2, NS: 8) flows. */
MatrixType Secondary;
MatrixType WindGust; /*! < \brief Wind gust value */
bool DataDrivenFluid = false; /*!< \brief Usage of data-driven fluid model. DatasetExtrapolation and FluidEntropy will not be sized if disabled. */
su2vector<unsigned short> DatasetExtrapolation; /*!< \brief Stores instances of dataset bounds violation when using data-driven fluid models. */
su2vector<unsigned long> NIterNewtonsolver; /*!< \brief Stores number of Newton solver iterations when using data-driven fluid models. */
VectorType FluidEntropy; /*!< \brief Stores the fluid entropy value as computed by the data-driven fluid model. */
public:
/*!
* \brief Constructor of the class.
* \param[in] density - Value of the flow density (initialization value).
* \param[in] velocity - Value of the flow velocity (initialization value).
* \param[in] energy - Value of the flow energy (initialization value).
* \param[in] npoint - Number of points/nodes/vertices in the domain.
* \param[in] ndim - Number of dimensions of the problem.
* \param[in] nvar - Number of variables of the problem.
* \param[in] config - Definition of the particular problem.
*/
CEulerVariable(su2double density, const su2double *velocity, su2double energy,
unsigned long npoint, unsigned long ndim, unsigned long nvar, const CConfig *config);
/*!
* \brief A virtual member.
*/
inline void SetdPdrho_e(unsigned long iPoint, su2double dPdrho_e) final { Secondary(iPoint,0) = dPdrho_e;}
/*!
* \brief A virtual member.
*/
inline void SetdPde_rho(unsigned long iPoint, su2double dPde_rho) final { Secondary(iPoint,1) = dPde_rho;}
/*!
* \brief Set the value of the pressure.
*/
inline bool SetPressure(unsigned long iPoint, su2double pressure) final {
Primitive(iPoint,nDim+1) = pressure;
return pressure <= 0.0;
}
/*!
* \brief Set the value of the speed of the sound.
* \param[in] soundspeed2 - Value of soundspeed^2.
*/
bool SetSoundSpeed(unsigned long iPoint, su2double soundspeed2) final {
if (soundspeed2 < 0.0) return true;
Primitive(iPoint,nDim+4) = sqrt(soundspeed2);
return false;
}
/*!
* \brief Set the value of the enthalpy.
*/
inline void SetEnthalpy(unsigned long iPoint) final {
Primitive(iPoint, indices.Enthalpy()) =
(Solution(iPoint,nVar-1) + Primitive(iPoint, indices.Pressure())) / Solution(iPoint,0);
}
/*!
* \brief Set all the primitive variables for compressible flows.
*/
bool SetPrimVar(unsigned long iPoint, CFluidModel *FluidModel) final;
/*!
* \brief A virtual member.
*/
void SetSecondaryVar(unsigned long iPoint, CFluidModel *FluidModel) override;
/*!
* \brief Get all the secondary variables.
*/
inline const MatrixType& GetSecondary() const {return Secondary; }
/*!
* \brief Get the secondary variables.
* \param[in] iVar - Index of the variable.
* \return Value of the secondary variable for the index <i>iVar</i>.
*/
inline su2double GetSecondary(unsigned long iPoint, unsigned long iVar) const final { return Secondary(iPoint,iVar); }
/*!
* \brief Set the value of the secondary variables.
* \param[in] iVar - Index of the variable.
* \param[in] iVar - Index of the variable.
* \return Set the value of the secondary variable for the index <i>iVar</i>.
*/
inline void SetSecondary(unsigned long iPoint, unsigned long iVar, su2double val_secondary) final {
Secondary(iPoint,iVar) = val_secondary;
}
/*!
* \brief Set the value of the secondary variables.
* \param[in] val_prim - Primitive variables.
* \return Set the value of the secondary variable for the index <i>iVar</i>.
*/
inline void SetSecondary(unsigned long iPoint, const su2double *val_secondary) final {
for (unsigned long iVar = 0; iVar < nSecondaryVar; iVar++)
Secondary(iPoint,iVar) = val_secondary[iVar];
}
/*!
* \brief Get the secondary variables of the problem.
* \return Pointer to the secondary variable vector.
*/
inline su2double *GetSecondary(unsigned long iPoint) final { return Secondary[iPoint]; }
/*!
* \brief Set the value of the density for the incompressible flows.
*/
inline bool SetDensity(unsigned long iPoint) final {
Primitive(iPoint, indices.Density()) = Solution(iPoint,0);
return Primitive(iPoint, indices.Density()) <= 0.0;
}
inline void Set_Density_time_n(unsigned long iPoint, su2double val) {
Density_time_n[iPoint] = val;
}
inline void Set_Density_unsteady(unsigned long iPoint, su2double val) {
Density_unsteady[iPoint] = val;
}
/*!
* \brief Set the value of the temperature.
* \param[in] temperature - how agitated the particles are :)
*/
inline bool SetTemperature(unsigned long iPoint, su2double temperature) final {
Primitive(iPoint, indices.Temperature()) = temperature;
return temperature <= 0.0;
}
/*!
* \brief Get the flow pressure.
* \return Value of the flow pressure.
*/
inline su2double GetPressure(unsigned long iPoint) const final { return Primitive(iPoint, indices.Pressure()); }
/*!
* \brief Get the speed of the sound.
* \return Value of speed of the sound.
*/
inline su2double GetSoundSpeed(unsigned long iPoint) const final { return Primitive(iPoint, indices.SoundSpeed()); }
/*!
* \brief Get the enthalpy of the flow.
* \return Value of the enthalpy of the flow.
*/
inline su2double GetEnthalpy(unsigned long iPoint) const final { return Primitive(iPoint, indices.Enthalpy()); }
/*!
* \brief Get the density of the flow.
* \return Value of the density of the flow.
*/
inline su2double GetDensity(unsigned long iPoint) const final { return Solution(iPoint,0); }
/*!
* \brief Get the energy of the flow.
* \return Value of the energy of the flow.
*/
inline su2double GetEnergy(unsigned long iPoint) const final { return Solution(iPoint,nVar-1)/Solution(iPoint,0); }
/*!
* \brief Get the temperature of the flow.
* \return Value of the temperature of the flow.
*/
inline su2double GetTemperature(unsigned long iPoint) const final { return Primitive(iPoint,indices.Temperature()); }
/*!
* \brief Get the velocity of the flow.
* \param[in] iDim - Index of the dimension.
* \return Value of the velocity for the dimension <i>iDim</i>.
*/
inline su2double GetVelocity(unsigned long iPoint, unsigned long iDim) const final {
return Primitive(iPoint, iDim+indices.Velocity());
}
/*!
* \brief Get the velocity gradient.
* \return Value of the velocity gradient.
*/
inline CMatrixView<const su2double> GetVelocityGradient(unsigned long iPoint) const final {
return Gradient_Primitive(iPoint, indices.Velocity());
}
/*!
* \brief Get the projected velocity in a unitary vector direction (compressible solver).
* \param[in] val_vector - Direction of projection.
* \return Value of the projected velocity.
*/
inline su2double GetProjVel(unsigned long iPoint, const su2double *val_vector) const final {
su2double ProjVel = 0.0;
for (unsigned long iDim = 0; iDim < nDim; iDim++)
ProjVel += Primitive(iPoint, iDim+indices.Velocity())*val_vector[iDim];
return ProjVel;
}
/*!
* \brief Set the velocity vector from the solution.
* \param[in] val_velocity - Pointer to the velocity.
*/
inline void SetVelocity(unsigned long iPoint) final {
Velocity2(iPoint) = 0.0;
for (unsigned long iDim = 0; iDim < nDim; iDim++) {
Primitive(iPoint,iDim+indices.Velocity()) = Solution(iPoint,iDim+1) / Solution(iPoint,0);
Velocity2(iPoint) += pow(Primitive(iPoint,iDim+indices.Velocity()),2);
}
}
/*!
* \brief Set the velocity vector from the old solution.
* \param[in] val_velocity - Pointer to the velocity.
*/
inline void SetVelocity_Old(unsigned long iPoint, const su2double *val_velocity) final {
for (unsigned long iDim = 0; iDim < nDim; iDim++)
Solution_Old(iPoint,iDim+1) = val_velocity[iDim]*Solution(iPoint,0);
}
/*!
* \brief Set the momentum part of the truncation error to zero.
* \param[in] iPoint - Point index.
*/
inline void SetVel_ResTruncError_Zero(unsigned long iPoint) final {
for (unsigned long iDim = 0; iDim < nDim; iDim++) Res_TruncError(iPoint,iDim+1) = 0.0;
}
/*!
* \brief Specify a vector to set the velocity components of the solution. Multiplied by density for compressible cases.
* \param[in] iPoint - Point index.
* \param[in] val_vector - Pointer to the vector.
*/
inline void SetVelSolutionVector(unsigned long iPoint, const su2double *val_vector) final {
for (unsigned long iDim = 0; iDim < nDim; iDim++) Solution(iPoint, iDim+1) = GetDensity(iPoint) * val_vector[iDim];
}
/*!
* \brief Set fluid entropy
* \param[in] iPoint - Node index
* \param[in] entropy - fluid entropy value.
*/
inline void SetEntropy(unsigned long iPoint, su2double entropy) final { FluidEntropy[iPoint] = entropy; };
/*!
* \brief Get fluid entropy
* \param[in] iPoint - Node index
* \return Entropy - Fluid entropy value
*/
inline su2double GetEntropy(unsigned long iPoint) const final { return FluidEntropy[iPoint]; }
/*!
* \brief Set dataset extrapolation instance
* \param[in] iPoint - Node index
* \param[in] extrapolation - Extrapolation instance (0 = within dataset, 1 = outside dataset)
*/
inline void SetDataExtrapolation(unsigned long iPoint, unsigned short extrapolation) final {
DatasetExtrapolation[iPoint] = extrapolation;
};
/*!
* \brief Get dataset extrapolation instance
* \param[in] iPoint - Node index
* \return extrapolation - Extrapolation instance (0 = within dataset, 1 = outside dataset)
*/
inline unsigned short GetDataExtrapolation(unsigned long iPoint) const final { return DatasetExtrapolation[iPoint]; }
/*!
* \brief Set the number of iterations required by a Newton solver used by the fluid model.
* \param[in] iPoint - Node index
* \param[in] nIter - Number of iterations evaluated by the Newton solver
*/
inline void SetNewtonSolverIterations(unsigned long iPoint, unsigned long nIter) final { NIterNewtonsolver[iPoint] = nIter; }
/*!
* \brief Get the number of iterations required by a Newton solver used by the fluid model.
* \param[in] iPoint - Node index
* \return Number of iterations evaluated by the Newton solver
*/
inline unsigned long GetNewtonSolverIterations(unsigned long iPoint) const final { return NIterNewtonsolver[iPoint]; }
};