Documentation 6b54b78464
Loading...
Searching...
No Matches
variables.hpp
Go to the documentation of this file.
1/*!
2 * \file variables.hpp
3 * \brief Collection of types to store physical variables.
4 * \author P. Gomes
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 "../CNumericsSIMD.hpp"
31#include "../util.hpp"
32
33/*!
34 * \brief Type to store compressible primitive variables and access them by name.
35 */
36template<size_t nDim_, size_t nVar_>
38 static constexpr size_t nDim = nDim_;
39 static constexpr size_t nVar = nVar_;
43 FORCEINLINE Double& density() { return all(nDim+2); }
45 FORCEINLINE Double& velocity(size_t iDim) { return all(iDim+1); }
46 FORCEINLINE const Double& temperature() const { return all(0); }
47 FORCEINLINE const Double& pressure() const { return all(nDim+1); }
48 FORCEINLINE const Double& density() const { return all(nDim+2); }
49 FORCEINLINE const Double& enthalpy() const { return all(nDim+3); }
50 FORCEINLINE const Double& velocity(size_t iDim) const { return all(iDim+1); }
51 FORCEINLINE const Double* velocity() const { return &velocity(0); }
52
53 /*--- Un-reconstructed variables. ---*/
58 FORCEINLINE Double& cp() { return all(nDim+8); }
59 FORCEINLINE const Double& speedSound() const { return all(nDim+4); }
60 FORCEINLINE const Double& laminarVisc() const { return all(nDim+5); }
61 FORCEINLINE const Double& eddyVisc() const { return all(nDim+6); }
62 FORCEINLINE const Double& thermalCond() const { return all(nDim+7); }
63 FORCEINLINE const Double& cp() const { return all(nDim+8); }
64};
65
66/*!
67 * \brief Type to store compressible conservative (i.e. solution) variables.
68 */
69template<size_t nDim_>
71 static constexpr size_t nDim = nDim_;
72 static constexpr size_t nVar = nDim+2;
74
75 FORCEINLINE Double& density() { return all(0); }
77 FORCEINLINE Double& momentum(size_t iDim) { return all(iDim+1); }
78 FORCEINLINE const Double& density() const { return all(0); }
79 FORCEINLINE const Double& rhoEnergy() const { return all(nDim+1); }
80 FORCEINLINE const Double& momentum(size_t iDim) const { return all(iDim+1); }
81
82 FORCEINLINE Double energy() const { return rhoEnergy() / density(); }
83 FORCEINLINE const Double* momentum() const { return &momentum(0); }
84};
85
86/*!
87 * \brief Primitive to conservative conversion.
88 */
89template<size_t nDim, size_t N>
92 U.density() = V.density();
93 for (size_t iDim = 0; iDim < nDim; ++iDim) {
94 U.momentum(iDim) = V.density() * V.velocity(iDim);
95 }
96 U.rhoEnergy() = V.density() * V.enthalpy() - V.pressure();
97 return U;
98}
99
100/*!
101 * \brief Roe-averaged variables.
102 */
103template<size_t nDim>
111
112/*!
113 * \brief Compute Roe-averaged variables from pair of primitive variables.
114 */
115template<size_t nDim, class PrimVarType>
117 const CPair<PrimVarType>& V,
118 const VectorDbl<nDim>& normal) {
119 CRoeVariables<nDim> roeAvg;
120 Double R = sqrt(V.j.density() / V.i.density());
121 Double D = 1 / (R+1);
122 roeAvg.density = R * V.i.density();
123 for (size_t iDim = 0; iDim < nDim; ++iDim) {
124 roeAvg.velocity(iDim) = (R*V.j.velocity(iDim) + V.i.velocity(iDim)) * D;
125 }
126 roeAvg.enthalpy = (R*V.j.enthalpy() + V.i.enthalpy()) * D;
127 roeAvg.speedSound = sqrt((gamma-1) * (roeAvg.enthalpy - 0.5*squaredNorm(roeAvg.velocity)));
128 roeAvg.projVel = dot(roeAvg.velocity, normal);
129 return roeAvg;
130}
A templated matrix/vector-like object.
Definition C2DContainer.hpp:374
#define FORCEINLINE
Definition code_config.hpp:44
FORCEINLINE ARRAY_T sqrt(const ARRAY_T &x)
Definition special_vectorization.hpp:116
auto squaredNorm(ForwardIterator iterator) -> typename std::decay< decltype(*iterator)>::type
Squared norm.
Definition util.hpp:231
auto dot(ForwardIterator iterator, const T *ptr) -> typename std::decay< decltype(*ptr)>::type
Dot product.
Definition util.hpp:203
@ V
Menter k-w SST model with vorticity production terms.
Type to store compressible conservative (i.e. solution) variables.
Definition variables.hpp:70
VectorDbl< nVar > all
Definition variables.hpp:73
const Double & rhoEnergy() const
Definition variables.hpp:79
const Double & momentum(size_t iDim) const
Definition variables.hpp:80
static constexpr size_t nDim
Definition variables.hpp:71
Double & density()
Definition variables.hpp:75
const Double * momentum() const
Definition variables.hpp:83
Double & rhoEnergy()
Definition variables.hpp:76
static constexpr size_t nVar
Definition variables.hpp:72
Double energy() const
Definition variables.hpp:82
const Double & density() const
Definition variables.hpp:78
Double & momentum(size_t iDim)
Definition variables.hpp:77
Type to store compressible primitive variables and access them by name.
Definition variables.hpp:37
static constexpr size_t nVar
Definition variables.hpp:39
const Double & eddyVisc() const
Definition variables.hpp:61
const Double & velocity(size_t iDim) const
Definition variables.hpp:50
VectorDbl< nVar > all
Definition variables.hpp:40
const Double & laminarVisc() const
Definition variables.hpp:60
Double & thermalCond()
Definition variables.hpp:57
const Double & pressure() const
Definition variables.hpp:47
Double & cp()
Definition variables.hpp:58
const Double & temperature() const
Definition variables.hpp:46
Double & enthalpy()
Definition variables.hpp:44
Double & density()
Definition variables.hpp:43
const Double & enthalpy() const
Definition variables.hpp:49
Double & pressure()
Definition variables.hpp:42
Double & temperature()
Definition variables.hpp:41
const Double & density() const
Definition variables.hpp:48
static constexpr size_t nDim
Definition variables.hpp:38
const Double & speedSound() const
Definition variables.hpp:59
const Double & thermalCond() const
Definition variables.hpp:62
Double & speedSound()
Definition variables.hpp:54
Double & laminarVisc()
Definition variables.hpp:55
Double & eddyVisc()
Definition variables.hpp:56
const Double * velocity() const
Definition variables.hpp:51
const Double & cp() const
Definition variables.hpp:63
Double & velocity(size_t iDim)
Definition variables.hpp:45
Simple pair type for i/j variables.
Definition util.hpp:130
Roe-averaged variables.
Definition variables.hpp:104
Double speedSound
Definition variables.hpp:108
Double enthalpy
Definition variables.hpp:107
Double projVel
Definition variables.hpp:109
Double density
Definition variables.hpp:105
VectorDbl< nDim > velocity
Definition variables.hpp:106
CRoeVariables< nDim > roeAveragedVariables(const Double &gamma, const CPair< PrimVarType > &V, const VectorDbl< nDim > &normal)
Compute Roe-averaged variables from pair of primitive variables.
Definition variables.hpp:116
CCompressibleConservatives< nDim > compressibleConservatives(const CCompressiblePrimitives< nDim, N > &V)
Primitive to conservative conversion.
Definition variables.hpp:90