Skip to content

Commit 9a4f21e

Browse files
authored
Merge pull request #1127 from su2code/feature_ReynoldsStressInCNumerics
Introduce a function to compute stress tensor
2 parents 94e1231 + 8879c13 commit 9a4f21e

17 files changed

Lines changed: 152 additions & 308 deletions

SU2_CFD/include/numerics/CNumerics.hpp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,86 @@ class CNumerics {
459459
TurbPsi_Grad_j = val_turbpsivar_grad_j;
460460
}
461461

462+
/*!
463+
* \brief Compute the mean rate of strain matrix.
464+
* \details The parameter primvargrad can be e.g. PrimVar_Grad_i or Mean_GradPrimVar.
465+
* \param[in] nDim - 2 or 3
466+
* \param[out] rateofstrain - Rate of strain matrix
467+
* \param[in] velgrad - A velocity gradient matrix.
468+
* \tparam TWOINDICES_1 - any type that supports the [][] interface
469+
* \tparam TWOINDICES_2 - any type that supports the [][] interface
470+
*/
471+
template<class TWOINDICES_1, class TWOINDICES_2>
472+
inline static void ComputeMeanRateOfStrainMatrix(unsigned short nDim, TWOINDICES_1& rateofstrain, const TWOINDICES_2& velgrad){
473+
474+
/* --- Calculate the rate of strain tensor, using mean velocity gradients --- */
475+
476+
if (nDim == 3){
477+
rateofstrain[0][0] = velgrad[0][0];
478+
rateofstrain[1][1] = velgrad[1][1];
479+
rateofstrain[2][2] = velgrad[2][2];
480+
rateofstrain[0][1] = 0.5 * (velgrad[0][1] + velgrad[1][0]);
481+
rateofstrain[0][2] = 0.5 * (velgrad[0][2] + velgrad[2][0]);
482+
rateofstrain[1][2] = 0.5 * (velgrad[1][2] + velgrad[2][1]);
483+
rateofstrain[1][0] = rateofstrain[0][1];
484+
rateofstrain[2][1] = rateofstrain[1][2];
485+
rateofstrain[2][0] = rateofstrain[0][2];
486+
}
487+
else { // nDim==2
488+
rateofstrain[0][0] = velgrad[0][0];
489+
rateofstrain[1][1] = velgrad[1][1];
490+
rateofstrain[2][2] = 0.0;
491+
rateofstrain[0][1] = 0.5 * (velgrad[0][1] + velgrad[1][0]);
492+
rateofstrain[0][2] = 0.0;
493+
rateofstrain[1][2] = 0.0;
494+
rateofstrain[1][0] = rateofstrain[0][1];
495+
rateofstrain[2][1] = rateofstrain[1][2];
496+
rateofstrain[2][0] = rateofstrain[0][2];
497+
}
498+
}
499+
500+
/*!
501+
* \brief Compute the stress tensor from the velocity gradients.
502+
* \details To obtain the Reynolds stress tensor +(u_i' u_j')~, divide the result
503+
* of this function by (-rho). The argument density is only used if turb_ke is not 0.
504+
* To select the velocity gradient components from a primitive variable gradient PrimVar_Grad_i,
505+
* write PrimVar_Grad_i+1.
506+
* If <code>nDim==2</code>, we use the same formula but only only access the entries [0][0]..[1][1] of
507+
* stress and velgrad. If <code>reynolds3x3</code> is true, the other non-diagonal entries of stress
508+
* set to zero, and <code>stress[2][2]</code> to some value.
509+
* \param[in] nDim - Dimension of the flow problem, 2 or 3
510+
* \param[out] stress - Stress tensor
511+
* \param[in] velgrad - A velocity gradient matrix.
512+
* \param[in] viscosity - Viscosity
513+
* \param[in] density - Density
514+
* \param[in] turb_ke - Turbulent kinetic energy, for the turbulent stress tensor
515+
* \param[in] reynolds3x3 - If true, write to the third row and column of stress even if nDim==2.
516+
* \tparam TWOINDICES_1 - any type that supports the [][] interface
517+
* \tparam TWOINDICES_2 - any type that supports the [][] interface
518+
*/
519+
template<class TWOINDICES_1, class TWOINDICES_2>
520+
inline static void ComputeStressTensor(unsigned short nDim, TWOINDICES_1& stress, const TWOINDICES_2& velgrad,
521+
su2double viscosity, su2double density=0.0, su2double turb_ke=0.0, bool reynolds3x3=false){
522+
su2double divVel = 0;
523+
for (unsigned short iDim = 0; iDim < nDim; iDim++){
524+
divVel += velgrad[iDim][iDim];
525+
}
526+
su2double pTerm = 2./3. * (divVel * viscosity + density * turb_ke);
527+
528+
for (unsigned short iDim = 0; iDim < nDim; iDim++){
529+
for (unsigned short jDim = 0; jDim < nDim; jDim++){
530+
stress[iDim][jDim] = viscosity * (velgrad[iDim][jDim]+velgrad[jDim][iDim]);
531+
}
532+
stress[iDim][iDim] -= pTerm;
533+
}
534+
535+
if(reynolds3x3 && nDim==2){ // fill the third row and column of Reynolds stress matrix
536+
stress[0][2] = stress[1][2] = stress[2][0] = stress[2][1] = 0.0;
537+
stress[2][2] = -pTerm;
538+
}
539+
540+
}
541+
462542
/*!
463543
* \brief Set the value of the first blending function.
464544
* \param[in] val_F1_i - Value of the first Menter blending function at point i.

SU2_CFD/include/numerics/flow/flow_diffusion.hpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,6 @@ class CAvgGrad_Base : public CNumerics {
190190
*/
191191
void SetPerturbedRSM(su2double turb_ke, const CConfig* config);
192192

193-
/*!
194-
* \brief Get the mean rate of strain matrix based on velocity gradients
195-
* \param[in] S_ij
196-
*/
197-
void GetMeanRateOfStrainMatrix(su2double **S_ij) const;
198-
199193
public:
200194

201195
/*!

SU2_CFD/include/numerics/turbulent/turb_sources.hpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,6 @@ class CSourcePieceWise_TurbSST final : public CNumerics {
339339
*/
340340
void SetPerturbedStrainMag(su2double turb_ke);
341341

342-
/*!
343-
* \brief Get the mean rate of strain matrix based on velocity gradients
344-
* \param[in] S_ij
345-
*/
346-
void GetMeanRateOfStrainMatrix(su2double **S_ij);
347-
348342
public:
349343
/*!
350344
* \brief Constructor of the class.

SU2_CFD/include/solvers/CFVMFlowSolverBase.inl

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,12 +2030,11 @@ void CFVMFlowSolverBase<V, FlowRegime>::Friction_Forces(const CGeometry* geometr
20302030
unsigned long iVertex, iPoint, iPointNormal;
20312031
unsigned short iMarker, iMarker_Monitoring, iDim, jDim;
20322032
unsigned short T_INDEX = 0, TVE_INDEX = 0, VEL_INDEX = 0;
2033-
su2double Viscosity = 0.0, div_vel, WallDist[3] = {0.0}, Area, TauNormal, RefTemp, RefVel2 = 0.0,
2033+
su2double Viscosity = 0.0, WallDist[3] = {0.0}, Area, TauNormal, RefTemp, RefVel2 = 0.0,
20342034
RefDensity = 0.0, GradTemperature, Density = 0.0, WallDistMod, FrictionVel, Mach2Vel, Mach_Motion,
20352035
UnitNormal[3] = {0.0}, TauElem[3] = {0.0}, TauTangent[3] = {0.0}, Tau[3][3] = {{0.0}}, Cp,
20362036
thermal_conductivity, thermal_conductivity_tr, thermal_conductivity_ve = 0.0,
2037-
MaxNorm = 8.0, Grad_Vel[3][3] = {{0.0}}, Grad_Temp[3] = {0.0}, AxiFactor,
2038-
delta[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}};
2037+
MaxNorm = 8.0, Grad_Vel[3][3] = {{0.0}}, Grad_Temp[3] = {0.0}, AxiFactor;
20392038
const su2double *Coord = nullptr, *Coord_Normal = nullptr, *Normal = nullptr;
20402039
su2double **Grad_PrimVar = nullptr, dTn, dTven;
20412040

@@ -2190,16 +2189,7 @@ void CFVMFlowSolverBase<V, FlowRegime>::Friction_Forces(const CGeometry* geometr
21902189
}
21912190

21922191
/*--- Evaluate Tau ---*/
2193-
2194-
div_vel = 0.0;
2195-
for (iDim = 0; iDim < nDim; iDim++) div_vel += Grad_Vel[iDim][iDim];
2196-
2197-
for (iDim = 0; iDim < nDim; iDim++) {
2198-
for (jDim = 0; jDim < nDim; jDim++) {
2199-
Tau[iDim][jDim] = Viscosity * (Grad_Vel[jDim][iDim] + Grad_Vel[iDim][jDim]) -
2200-
TWO3 * Viscosity * div_vel * delta[iDim][jDim];
2201-
}
2202-
}
2192+
CNumerics::ComputeStressTensor(nDim, Tau, Grad_Vel, Viscosity);
22032193

22042194
/*--- If necessary evaluate the QCR contribution to Tau ---*/
22052195

SU2_CFD/src/interfaces/fsi/CFlowTractionInterface.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -188,22 +188,15 @@ void CFlowTractionInterface::GetDonor_Variable(CSolver *flow_solution, CGeometry
188188

189189
su2double Viscosity = flow_nodes->GetLaminarViscosity(Point_Flow);
190190

191-
const su2double* const* GradVel = &flow_nodes->GetGradient_Primitive(Point_Flow)[1];
192-
193-
// Divergence of the velocity
194-
su2double DivVel = 0.0;
195-
for (auto iVar = 0u; iVar < nVar; iVar++) DivVel += GradVel[iVar][iVar];
196-
191+
su2double tau[3][3];
192+
CNumerics::ComputeStressTensor(nVar, tau, flow_nodes->GetGradient_Primitive(Point_Flow)+1,Viscosity);
197193
for (auto iVar = 0u; iVar < nVar; iVar++) {
198194
for (auto jVar = 0u; jVar < nVar; jVar++) {
199-
// Viscous stress
200-
su2double delta_ij = (iVar == jVar);
201-
su2double tau_ij = Viscosity*(GradVel[jVar][iVar] + GradVel[iVar][jVar] - TWO3*DivVel*delta_ij);
202-
203195
// Viscous component in the tn vector --> Units of force (non-dimensional).
204-
Donor_Variable[iVar] += tau_ij * Normal_Flow[jVar];
196+
Donor_Variable[iVar] += tau[iVar][jVar] * Normal_Flow[jVar];
205197
}
206198
}
199+
207200
}
208201

209202
// Redimensionalize and take into account ramp transfer of the loads

SU2_CFD/src/numerics/NEMO/CNEMONumerics.cpp

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ void CNEMONumerics::GetViscousProjFlux(su2double *val_primvar,
237237
// rather than the standard V = [r1, ... , rn, T, Tve, ... ]
238238

239239
unsigned short iSpecies, iVar, iDim, jDim;
240-
su2double *Ds, *V, **GV, mu, ktr, kve, div_vel;
240+
su2double *Ds, *V, **GV, mu, ktr, kve;
241241
su2double rho, T, Tve, RuSI, Ru;
242242
auto& Ms = fluidmodel->GetSpeciesMolarMass();
243243

@@ -279,12 +279,7 @@ void CNEMONumerics::GetViscousProjFlux(su2double *val_primvar,
279279
//Cpve = V[RHOCVVE_INDEX]+Ru/Mass;
280280
//kve += Cpve*(val_eddy_viscosity/Prandtl_Turb);
281281

282-
/*--- Calculate the velocity divergence ---*/
283-
div_vel = 0.0;
284-
for (iDim = 0 ; iDim < nDim; iDim++)
285-
div_vel += GV[VEL_INDEX+iDim][iDim];
286-
287-
282+
288283
/*--- Pre-compute mixture quantities ---*/
289284
for (iDim = 0; iDim < nDim; iDim++) {
290285
Vector[iDim] = 0.0;
@@ -294,16 +289,7 @@ void CNEMONumerics::GetViscousProjFlux(su2double *val_primvar,
294289
}
295290

296291
/*--- Compute the viscous stress tensor ---*/
297-
for (iDim = 0; iDim < nDim; iDim++)
298-
for (jDim = 0; jDim < nDim; jDim++)
299-
tau[iDim][jDim] = 0.0;
300-
for (iDim = 0 ; iDim < nDim; iDim++) {
301-
for (jDim = 0 ; jDim < nDim; jDim++) {
302-
tau[iDim][jDim] += mu * (val_gradprimvar[VEL_INDEX+jDim][iDim] +
303-
val_gradprimvar[VEL_INDEX+iDim][jDim]);
304-
}
305-
tau[iDim][iDim] -= TWO3*mu*div_vel;
306-
}
292+
ComputeStressTensor(nDim,tau,val_gradprimvar+VEL_INDEX, mu);
307293

308294
/*--- Populate entries in the viscous flux vector ---*/
309295
for (iDim = 0; iDim < nDim; iDim++) {

SU2_CFD/src/numerics/flow/flow_diffusion.cpp

Lines changed: 16 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -123,28 +123,22 @@ void CAvgGrad_Base::SetStressTensor(const su2double *val_primvar,
123123
const su2double val_laminar_viscosity,
124124
const su2double val_eddy_viscosity) {
125125

126-
unsigned short iDim, jDim;
127126
const su2double Density = val_primvar[nDim+2];
128-
const su2double total_viscosity = val_laminar_viscosity + val_eddy_viscosity;
129-
130-
su2double div_vel = 0.0;
131-
for (iDim = 0 ; iDim < nDim; iDim++)
132-
div_vel += val_gradprimvar[iDim+1][iDim];
133127

134-
/* --- If UQ methodology is used, calculate tau using the perturbed reynolds stress tensor --- */
128+
/* --- If UQ methodology is used, use the perturbed Reynolds stress tensor
129+
* for the turbulent part of tau. Otherwise both the laminar and turbulent
130+
* parts of tau can be computed with the total viscosity. --- */
135131

136132
if (using_uq){
137-
for (iDim = 0 ; iDim < nDim; iDim++)
138-
for (jDim = 0 ; jDim < nDim; jDim++)
139-
tau[iDim][jDim] = val_laminar_viscosity*( val_gradprimvar[jDim+1][iDim] + val_gradprimvar[iDim+1][jDim] )
140-
- TWO3*val_laminar_viscosity*div_vel*delta[iDim][jDim] - Density * MeanPerturbedRSM[iDim][jDim];
141-
133+
ComputeStressTensor(nDim, tau, val_gradprimvar+1, val_laminar_viscosity); // laminar part
134+
// add turbulent part which was perturbed
135+
for (unsigned short iDim = 0 ; iDim < nDim; iDim++)
136+
for (unsigned short jDim = 0 ; jDim < nDim; jDim++)
137+
tau[iDim][jDim] += (-Density) * MeanPerturbedRSM[iDim][jDim];
142138
} else {
143-
144-
for (iDim = 0 ; iDim < nDim; iDim++)
145-
for (jDim = 0 ; jDim < nDim; jDim++)
146-
tau[iDim][jDim] = total_viscosity*( val_gradprimvar[jDim+1][iDim] + val_gradprimvar[iDim+1][jDim] )
147-
- TWO3*total_viscosity*div_vel*delta[iDim][jDim];
139+
// compute both parts in one step
140+
const su2double total_viscosity = val_laminar_viscosity + val_eddy_viscosity;
141+
ComputeStressTensor(nDim, tau, val_gradprimvar+1, total_viscosity, Density, 0.0); // TODO why ignore turb_ke?
148142
}
149143
}
150144

@@ -217,67 +211,14 @@ void CAvgGrad_Base::AddTauWall(const su2double *val_normal,
217211
tau[iDim][jDim] = tau[iDim][jDim]*(val_tau_wall/WallShearStress);
218212
}
219213

220-
void CAvgGrad_Base::GetMeanRateOfStrainMatrix(su2double **S_ij) const
221-
{
222-
/* --- Calculate the rate of strain tensor, using mean velocity gradients --- */
223-
224-
if (nDim == 3){
225-
S_ij[0][0] = Mean_GradPrimVar[1][0];
226-
S_ij[1][1] = Mean_GradPrimVar[2][1];
227-
S_ij[2][2] = Mean_GradPrimVar[3][2];
228-
S_ij[0][1] = 0.5 * (Mean_GradPrimVar[1][1] + Mean_GradPrimVar[2][0]);
229-
S_ij[0][2] = 0.5 * (Mean_GradPrimVar[1][2] + Mean_GradPrimVar[3][0]);
230-
S_ij[1][2] = 0.5 * (Mean_GradPrimVar[2][2] + Mean_GradPrimVar[3][1]);
231-
S_ij[1][0] = S_ij[0][1];
232-
S_ij[2][1] = S_ij[1][2];
233-
S_ij[2][0] = S_ij[0][2];
234-
}
235-
else {
236-
S_ij[0][0] = Mean_GradPrimVar[1][0];
237-
S_ij[1][1] = Mean_GradPrimVar[2][1];
238-
S_ij[2][2] = 0.0;
239-
S_ij[0][1] = 0.5 * (Mean_GradPrimVar[1][1] + Mean_GradPrimVar[2][0]);
240-
S_ij[0][2] = 0.0;
241-
S_ij[1][2] = 0.0;
242-
S_ij[1][0] = S_ij[0][1];
243-
S_ij[2][1] = S_ij[1][2];
244-
S_ij[2][0] = S_ij[0][2];
245-
246-
}
247-
}
248-
249214
void CAvgGrad_Base::SetReynoldsStressMatrix(su2double turb_ke){
250-
251-
unsigned short iDim, jDim;
252-
su2double **S_ij = new su2double* [3];
253-
su2double muT = Mean_Eddy_Viscosity;
254-
su2double divVel = 0;
255-
su2double density;
256-
su2double TWO3 = 2.0/3.0;
257-
density = Mean_PrimVar[nDim+2];
258-
259-
for (iDim = 0; iDim < 3; iDim++){
260-
S_ij[iDim] = new su2double [3];
261-
}
262-
263-
GetMeanRateOfStrainMatrix(S_ij);
264-
265-
/* --- Using rate of strain matrix, calculate Reynolds stress tensor --- */
266-
267-
for (iDim = 0; iDim < 3; iDim++){
268-
divVel += S_ij[iDim][iDim];
269-
}
270-
271-
for (iDim = 0; iDim < 3; iDim++){
272-
for (jDim = 0; jDim < 3; jDim++){
273-
MeanReynoldsStress[iDim][jDim] = TWO3 * turb_ke * delta3[iDim][jDim]
274-
- muT / density * (2 * S_ij[iDim][jDim] - TWO3 * divVel * delta3[iDim][jDim]);
215+
su2double meandensity = Mean_PrimVar[nDim+2];
216+
ComputeStressTensor(nDim, MeanReynoldsStress, Mean_GradPrimVar+1, Mean_Eddy_Viscosity, meandensity, turb_ke, true);
217+
for(unsigned short iDim=0; iDim<3; iDim++){
218+
for(unsigned short jDim=0; jDim<3; jDim++){
219+
MeanReynoldsStress[iDim][jDim] /= (-meandensity);
275220
}
276221
}
277-
278-
for (iDim = 0; iDim < 3; iDim++)
279-
delete [] S_ij[iDim];
280-
delete [] S_ij;
281222
}
282223

283224
void CAvgGrad_Base::SetPerturbedRSM(su2double turb_ke, const CConfig* config){

SU2_CFD/src/numerics/flow/flow_sources.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ CSourceIncAxisymmetric_Flow::CSourceIncAxisymmetric_Flow(unsigned short val_nDim
136136
CNumerics::ResidualType<> CSourceIncAxisymmetric_Flow::ComputeResidual(const CConfig* config) {
137137

138138
su2double yinv, Velocity_i[3];
139-
unsigned short iDim, jDim, iVar, jVar;
139+
unsigned short iDim, iVar, jVar;
140140

141141
if (Coord_i[1] > EPS) {
142142

@@ -197,21 +197,12 @@ CNumerics::ResidualType<> CSourceIncAxisymmetric_Flow::ComputeResidual(const CCo
197197
Eddy_Viscosity_i = V_i[nDim+5];
198198
Thermal_Conductivity_i = V_i[nDim+6];
199199

200-
su2double total_viscosity, div_vel;
200+
su2double total_viscosity;
201201

202202
total_viscosity = (Laminar_Viscosity_i + Eddy_Viscosity_i);
203203

204204
/*--- The full stress tensor is needed for variable density ---*/
205-
206-
div_vel = 0.0;
207-
for (iDim = 0 ; iDim < nDim; iDim++)
208-
div_vel += PrimVar_Grad_i[iDim+1][iDim];
209-
210-
for (iDim = 0 ; iDim < nDim; iDim++)
211-
for (jDim = 0 ; jDim < nDim; jDim++)
212-
tau[iDim][jDim] = (total_viscosity*(PrimVar_Grad_i[jDim+1][iDim] +
213-
PrimVar_Grad_i[iDim+1][jDim] )
214-
-TWO3*total_viscosity*div_vel*delta[iDim][jDim]);
205+
ComputeStressTensor(nDim, tau, PrimVar_Grad_i+1, total_viscosity);
215206

216207
/*--- Viscous terms. ---*/
217208

0 commit comments

Comments
 (0)