Skip to content

Commit b0e6db1

Browse files
committed
all features supported with vectorized centered schemes
1 parent 264d2e0 commit b0e6db1

6 files changed

Lines changed: 246 additions & 74 deletions

File tree

SU2_CFD/include/numerics_simd/CNumericsSIMD.cpp

Lines changed: 79 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,43 +32,98 @@
3232
#include "flow/convection/centered.hpp"
3333
#include "flow/diffusion/viscous_fluxes.hpp"
3434

35+
namespace {
36+
3537
/*!
36-
* \brief Generic factory implementation.
38+
* \brief Upwind factory implementation for ideal gas.
3739
*/
3840
template<class ViscousDecorator>
41+
CNumericsSIMD* createUpwindIdealNumerics(const CConfig& config, int iMesh, const CVariable* turbVars) {
42+
CNumericsSIMD* obj = nullptr;
43+
switch (config.GetKind_Upwind_Flow()) {
44+
case ROE:
45+
obj = new CRoeScheme<ViscousDecorator>(config, iMesh, turbVars);
46+
break;
47+
}
48+
return obj;
49+
}
50+
51+
/*!
52+
* \brief Upwind factory implementation for real gas.
53+
*/
54+
template<class ViscousDecorator>
55+
CNumericsSIMD* createUpwindGeneralNumerics(const CConfig& config, int iMesh, const CVariable* turbVars) {
56+
return nullptr;
57+
}
58+
59+
/*!
60+
* \brief Centered factory implementation.
61+
*/
62+
template<class ViscousDecorator>
63+
CNumericsSIMD* createCenteredNumerics(const CConfig& config, int iMesh, const CVariable* turbVars) {
64+
CNumericsSIMD* obj = nullptr;
65+
switch ((iMesh==MESH_0)? config.GetKind_Centered_Flow() : LAX) {
66+
case NO_CENTERED:
67+
break;
68+
case LAX:
69+
obj = new CLaxScheme<ViscousDecorator>(config, iMesh, turbVars);
70+
break;
71+
case JST:
72+
obj = new CJSTScheme<ViscousDecorator>(config, iMesh, turbVars);
73+
break;
74+
case JST_KE:
75+
obj = new CJSTkeScheme<ViscousDecorator>(config, iMesh, turbVars);
76+
break;
77+
case JST_MAT:
78+
obj = new CJSTmatScheme<ViscousDecorator>(config, iMesh, turbVars);
79+
break;
80+
}
81+
return obj;
82+
}
83+
84+
/*!
85+
* \brief Generic factory implementation.
86+
*/
87+
template<int nDim>
3988
CNumericsSIMD* createNumerics(const CConfig& config, int iMesh, const CVariable* turbVars) {
4089
CNumericsSIMD* obj = nullptr;
90+
const bool ideal_gas = (config.GetKind_FluidModel() == STANDARD_AIR) ||
91+
(config.GetKind_FluidModel() == IDEAL_GAS);
92+
4193
switch (config.GetKind_ConvNumScheme_Flow()) {
4294
case SPACE_UPWIND:
43-
switch (config.GetKind_Upwind_Flow()) {
44-
case ROE:
45-
obj = new CRoeScheme<ViscousDecorator>(config, iMesh, turbVars);
46-
break;
95+
if (config.GetViscous()) {
96+
if (ideal_gas)
97+
obj = createUpwindIdealNumerics<CCompressibleViscousFlux<nDim> >(config, iMesh, turbVars);
98+
else
99+
obj = createUpwindGeneralNumerics<CGeneralCompressibleViscousFlux<nDim> >(config, iMesh, turbVars);
100+
}
101+
else {
102+
if (ideal_gas)
103+
obj = createUpwindIdealNumerics<CNoViscousFlux<nDim> >(config, iMesh, turbVars);
104+
else
105+
obj = createUpwindGeneralNumerics<CNoViscousFlux<nDim> >(config, iMesh, turbVars);
47106
}
48107
break;
49108

50109
case SPACE_CENTERED:
51-
switch ((iMesh==MESH_0)? config.GetKind_Centered_Flow() : LAX) {
52-
case NO_CENTERED:
53-
break;
54-
case LAX:
55-
obj = new CLaxScheme<ViscousDecorator>(config, iMesh, turbVars);
56-
break;
57-
case JST:
58-
obj = new CJSTScheme<ViscousDecorator>(config, iMesh, turbVars);
59-
break;
60-
case JST_KE:
61-
obj = new CJSTkeScheme<ViscousDecorator>(config, iMesh, turbVars);
62-
break;
63-
case JST_MAT:
64-
obj = new CJSTmatScheme<ViscousDecorator>(config, iMesh, turbVars);
65-
break;
110+
if (config.GetViscous()) {
111+
if (ideal_gas)
112+
obj = createCenteredNumerics<CCompressibleViscousFlux<nDim> >(config, iMesh, turbVars);
113+
else
114+
obj = createCenteredNumerics<CGeneralCompressibleViscousFlux<nDim> >(config, iMesh, turbVars);
115+
}
116+
else {
117+
obj = createCenteredNumerics<CNoViscousFlux<nDim> >(config, iMesh, turbVars);
66118
}
67119
break;
68120
}
121+
69122
return obj;
70123
}
71124

125+
} // namespace
126+
72127
/*!
73128
* \brief This function instantiates both 2D and 3D versions of the implementation in
74129
* createNumerics, which in turn instantiates the class templates of the different
@@ -78,13 +133,8 @@ CNumericsSIMD* CNumericsSIMD::CreateNumerics(const CConfig& config, int nDim, in
78133
if ((Double::Size < 4) && (SU2_MPI::GetRank() == MASTER_NODE)) {
79134
cout << "WARNING: SU2 was not compiled for an AVX-capable architecture." << endl;
80135
}
81-
CNumericsSIMD* obj = nullptr;
82-
if (config.GetViscous()) {
83-
if (nDim == 2) obj = createNumerics<CCompressibleViscousFlux<2> >(config, iMesh, turbVars);
84-
if (nDim == 3) obj = createNumerics<CCompressibleViscousFlux<3> >(config, iMesh, turbVars);
85-
} else {
86-
if (nDim == 2) obj = createNumerics<CNoViscousFlux<2> >(config, iMesh, turbVars);
87-
if (nDim == 3) obj = createNumerics<CNoViscousFlux<3> >(config, iMesh, turbVars);
88-
}
89-
return obj;
136+
if (nDim == 2) return createNumerics<2>(config, iMesh, turbVars);
137+
if (nDim == 3) return createNumerics<3>(config, iMesh, turbVars);
138+
139+
return nullptr;
90140
}

SU2_CFD/include/numerics_simd/flow/diffusion/viscous_fluxes.hpp

Lines changed: 135 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,13 @@ class CNoViscousFlux : public CNumericsSIMD {
6262
};
6363

6464
/*!
65-
* \class CCompressibleViscousFlux
66-
* \brief Decorator class to add viscous fluxes (compressible flow, ideal gas).
65+
* \class CCompressibleViscousFluxBase
66+
* \brief Decorator class to add viscous fluxes (compressible flow).
6767
*/
68-
template<size_t NDIM>
69-
class CCompressibleViscousFlux : public CNumericsSIMD {
68+
template<size_t NDIM, class Derived>
69+
class CCompressibleViscousFluxBase : public CNumericsSIMD {
7070
protected:
7171
static constexpr size_t nDim = NDIM;
72-
static constexpr size_t nPrimVar = nDim+7;
7372
static constexpr size_t nPrimVarGrad = nDim+1;
7473

7574
const su2double gamma;
@@ -91,8 +90,8 @@ class CCompressibleViscousFlux : public CNumericsSIMD {
9190
* \brief Constructor, initialize constants and booleans.
9291
*/
9392
template<class... Ts>
94-
CCompressibleViscousFlux(const CConfig& config, int iMesh,
95-
const CVariable* turbVars_ = nullptr, Ts&...) :
93+
CCompressibleViscousFluxBase(const CConfig& config, int iMesh,
94+
const CVariable* turbVars_ = nullptr, Ts&...) :
9695
gamma(config.GetGamma()),
9796
gasConst(config.GetGas_ConstantND()),
9897
prandtlLam(config.GetPrandtl_Lam()),
@@ -128,7 +127,11 @@ class CCompressibleViscousFlux : public CNumericsSIMD {
128127
MatrixDbl<nVar>& jac_i,
129128
MatrixDbl<nVar>& jac_j) const {
130129

131-
static_assert(PrimVarType::nVar <= nPrimVar,"");
130+
static_assert(PrimVarType::nVar <= Derived::nPrimVar,"");
131+
132+
/*--- Pointer on which to call the "compile-time virtual" methods. ---*/
133+
134+
const auto derived = static_cast<const Derived*>(this);
132135

133136
const auto& solution = static_cast<const CNSVariable&>(solution_);
134137
const auto& gradient = solution.GetGradient_Primitive();
@@ -155,7 +158,7 @@ class CCompressibleViscousFlux : public CNumericsSIMD {
155158
uq_eigval_comp, uq_permute, uq_delta_b, uq_urlx);
156159
}
157160

158-
Double cond = cp * (avgV.laminarVisc()/prandtlLam + avgV.eddyVisc()/prandtlTurb);
161+
Double cond = derived->thermalConductivity(avgV);
159162
VectorDbl<nDim> heatFlux;
160163
for (size_t iDim = 0; iDim < nDim; ++iDim) {
161164
heatFlux(iDim) = cond * avgGrad(0,iDim);
@@ -175,23 +178,9 @@ class CCompressibleViscousFlux : public CNumericsSIMD {
175178

176179
Double dist_ij = sqrt(dist2_ij);
177180
auto dtau = stressTensorJacobian<nVar>(avgV, unitNormal, dist_ij);
178-
Double contraction = 0.0;
179-
for (size_t iDim = 0; iDim < nDim; ++iDim) {
180-
contraction += dtau(iDim,0) * avgV.velocity(iDim);
181-
}
182181

183182
/*--- Energy flux Jacobian. ---*/
184-
VectorDbl<nVar> dEdU;
185-
Double vel2 = 0.5 * squaredNorm<nDim>(avgV.velocity());
186-
Double phi = (gamma-1) / avgV.density();
187-
Double RdTdrho = phi*vel2 - avgV.pressure() / pow(avgV.density(),2);
188-
Double condOnRd = cond / (gasConst * dist_ij);
189-
190-
dEdU(0) = area * (condOnRd * RdTdrho - contraction);
191-
for (size_t iDim = 0; iDim < nDim; ++iDim) {
192-
dEdU(iDim+1) = area * (condOnRd*phi*avgV.velocity(iDim) + dtau(iDim,0));
193-
}
194-
dEdU(nDim+1) = area * condOnRd * phi;
183+
auto dEdU = derived->energyJacobian(avgV, dtau, cond, area, dist_ij, iPoint, jPoint, solution);
195184

196185
/*--- Update momentum and energy terms ("symmetric" part). ---*/
197186
for (size_t iDim = 0; iDim < nDim; ++iDim) {
@@ -252,3 +241,125 @@ class CCompressibleViscousFlux : public CNumericsSIMD {
252241
viscousTerms(iEdge, iPoint, jPoint, avgV, V, solution_, vector_ij, geometry, args...);
253242
}
254243
};
244+
245+
/*!
246+
* \class CCompressibleViscousFlux
247+
* \brief Decorator class to add viscous fluxes (compressible flow, ideal gas).
248+
*/
249+
template<size_t NDIM>
250+
class CCompressibleViscousFlux : public CCompressibleViscousFluxBase<NDIM, CCompressibleViscousFlux<NDIM> > {
251+
public:
252+
static constexpr size_t nPrimVar = NDIM+7;
253+
using Base = CCompressibleViscousFluxBase<NDIM, CCompressibleViscousFlux<NDIM> >;
254+
using Base::gamma;
255+
using Base::gasConst;
256+
using Base::prandtlLam;
257+
using Base::prandtlTurb;
258+
using Base::cp;
259+
260+
/*!
261+
* \brief Constructor, initialize constants and booleans.
262+
*/
263+
template<class... Ts>
264+
CCompressibleViscousFlux(Ts&... args) : Base(args...) {}
265+
266+
/*!
267+
* \brief Compute the thermal conductivity.
268+
*/
269+
template<class PrimitiveType>
270+
FORCEINLINE Double thermalConductivity(const PrimitiveType& V) const {
271+
return cp * (V.laminarVisc()/prandtlLam + V.eddyVisc()/prandtlTurb);
272+
}
273+
274+
/*!
275+
* \brief Compute Jacobian of the energy flux, except the part due to the work of viscous forces.
276+
*/
277+
template<size_t nVar, size_t nDim, class PrimitiveType, class... Ts>
278+
FORCEINLINE VectorDbl<nVar> energyJacobian(const PrimitiveType& V,
279+
const MatrixDbl<nDim,nVar>& dtau,
280+
Double thermalCond,
281+
Double area,
282+
Double dist_ij,
283+
Ts&... args) const {
284+
Double vel2 = 0.5 * squaredNorm<nDim>(V.velocity());
285+
Double phi = (gamma-1) / V.density();
286+
Double RdTdrho = phi*vel2 - V.pressure() / pow(V.density(),2);
287+
Double condOnRd = thermalCond / (gasConst * dist_ij);
288+
Double contraction = 0.0;
289+
for (size_t iDim = 0; iDim < nDim; ++iDim) {
290+
contraction += dtau(iDim,0) * V.velocity(iDim);
291+
}
292+
VectorDbl<nVar> dEdU;
293+
dEdU(0) = area * (condOnRd * RdTdrho - contraction);
294+
for (size_t iDim = 0; iDim < nDim; ++iDim) {
295+
dEdU(iDim+1) = area * (dtau(iDim,0) - condOnRd*phi*V.velocity(iDim));
296+
}
297+
dEdU(nDim+1) = area * condOnRd * phi;
298+
299+
return dEdU;
300+
}
301+
};
302+
303+
/*!
304+
* \class CGeneralCompressibleViscousFlux
305+
* \brief Decorator class to add viscous fluxes (compressible flow, real gas).
306+
*/
307+
template<size_t NDIM>
308+
class CGeneralCompressibleViscousFlux : public CCompressibleViscousFluxBase<NDIM, CGeneralCompressibleViscousFlux<NDIM> > {
309+
public:
310+
static constexpr size_t nPrimVar = NDIM+9;
311+
static constexpr size_t nSecVar = 4;
312+
using Base = CCompressibleViscousFluxBase<NDIM, CGeneralCompressibleViscousFlux<NDIM> >;
313+
using Base::prandtlTurb;
314+
315+
/*!
316+
* \brief Constructor, initialize constants and booleans.
317+
*/
318+
template<class... Ts>
319+
CGeneralCompressibleViscousFlux(Ts&... args) : Base(args...) {}
320+
321+
/*!
322+
* \brief Compute the thermal conductivity.
323+
*/
324+
template<class PrimitiveType>
325+
FORCEINLINE Double thermalConductivity(const PrimitiveType& V) const {
326+
return V.thermalCond() + V.cp()*V.eddyVisc()/prandtlTurb;
327+
}
328+
329+
/*!
330+
* \brief Compute Jacobian of the energy flux, except the part due to the work of viscous forces.
331+
*/
332+
template<size_t nVar, size_t nDim, class PrimitiveType, class VariableType>
333+
FORCEINLINE VectorDbl<nVar> energyJacobian(const PrimitiveType& V,
334+
const MatrixDbl<nDim,nVar>& dtau,
335+
Double thermalCond,
336+
Double area,
337+
Double dist_ij,
338+
Int iPoint,
339+
Int jPoint,
340+
const VariableType& solution) const {
341+
Double vel2 = squaredNorm<nDim>(V.velocity());
342+
Double contraction = 0.0;
343+
for (size_t iDim = 0; iDim < nDim; ++iDim) {
344+
contraction += dtau(iDim,0) * V.velocity(iDim);
345+
}
346+
347+
auto secVar_i = gatherVariables<nSecVar>(iPoint, solution.GetSecondary());
348+
auto secVar_j = gatherVariables<nSecVar>(jPoint, solution.GetSecondary());
349+
350+
Double dTdrho_e = 0.5 * (secVar_i(2) + secVar_j(2));
351+
Double dTde_rho = 0.5 * (secVar_i(3) + secVar_j(3)) / V.density();
352+
353+
Double condOnDist = thermalCond / dist_ij;
354+
Double dTdrho = dTdrho_e + dTde_rho*(vel2-V.enthalpy()+V.pressure()/V.density());
355+
356+
VectorDbl<nVar> dEdU;
357+
dEdU(0) = area * (condOnDist * dTdrho - contraction);
358+
for (size_t iDim = 0; iDim < nDim; ++iDim) {
359+
dEdU(iDim+1) = area * (dtau(iDim,0) - condOnDist*dTde_rho*V.velocity(iDim));
360+
}
361+
dEdU(nDim+1) = area * condOnDist * dTde_rho;
362+
363+
return dEdU;
364+
}
365+
};

SU2_CFD/include/numerics_simd/flow/variables.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,17 @@ struct CCompressiblePrimitives {
5050
FORCEINLINE const Double& velocity(size_t iDim) const { return all(iDim+1); }
5151
FORCEINLINE const Double* velocity() const { return &velocity(0); }
5252

53-
/*--- Un-reconstructed variables (not allocated by default). ---*/
53+
/*--- Un-reconstructed variables. ---*/
5454
FORCEINLINE Double& speedSound() { return all(nDim+4); }
5555
FORCEINLINE Double& laminarVisc() { return all(nDim+5); }
5656
FORCEINLINE Double& eddyVisc() { return all(nDim+6); }
57+
FORCEINLINE Double& thermalCond() { return all(nDim+7); }
58+
FORCEINLINE Double& cp() { return all(nDim+8); }
5759
FORCEINLINE const Double& speedSound() const { return all(nDim+4); }
5860
FORCEINLINE const Double& laminarVisc() const { return all(nDim+5); }
5961
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); }
6064
};
6165

6266
/*!

0 commit comments

Comments
 (0)