Skip to content

Commit 90ede00

Browse files
author
Angelo Passariello
committed
Add fields to VOLUME_OUTPUT
- Include time-averaged skin friction coefficient and instantaneous energy backscatter ratio into volume output fields. - Fix boundary conditions for the implicit smoothing of the stochastic source term in Langevin equations. - Fix computation of the source term in turbulence model equation. - Fix computation of the subgrid kinetic energy (divide eddy viscosity by flow density). - Diagonalize Jacobian in turbulence equations for numerical robustness.
1 parent 92a016b commit 90ede00

File tree

8 files changed

+186
-153
lines changed

8 files changed

+186
-153
lines changed

Common/include/toolboxes/random_toolbox.hpp

Lines changed: 39 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -91,32 +91,26 @@ inline double GetRandomUniform(std::mt19937 gen, double xmin = 0.0, double xmax
9191
* \return Value of Bessel function.
9292
*/
9393
inline double GetBesselZero(double x) {
94-
double abx = fabs(x);
95-
96-
if (abx < 3.75) {
97-
double t = x / 3.75;
98-
double p = 1.0 +
99-
t*t*(3.5156229 +
100-
t*t*(3.0899424 +
101-
t*t*(1.2067492 +
102-
t*t*(0.2659732 +
103-
t*t*(0.0360768 +
104-
t*t*0.0045813)))));
105-
return log(p);
106-
} else {
107-
double t = 3.75 / abx;
108-
double poly =
109-
0.39894228 +
110-
t*(0.01328592 +
111-
t*(0.00225319 +
112-
t*(-0.00157565 +
113-
t*(0.00916281 +
114-
t*(-0.02057706 +
115-
t*(0.02635537 +
116-
t*(-0.01647633 +
117-
t*0.00392377)))))));
118-
return abx - 0.5*log(abx) + log(poly);
119-
}
94+
double abx = fabs(x);
95+
96+
if (abx < 3.75) {
97+
double t = x / 3.75;
98+
double p =
99+
1.0 +
100+
t * t *
101+
(3.5156229 +
102+
t * t * (3.0899424 + t * t * (1.2067492 + t * t * (0.2659732 + t * t * (0.0360768 + t * t * 0.0045813)))));
103+
return log(p);
104+
} else {
105+
double t = 3.75 / abx;
106+
double poly =
107+
0.39894228 +
108+
t * (0.01328592 +
109+
t * (0.00225319 +
110+
t * (-0.00157565 +
111+
t * (0.00916281 + t * (-0.02057706 + t * (0.02635537 + t * (-0.01647633 + t * 0.00392377)))))));
112+
return abx - 0.5 * log(abx) + log(poly);
113+
}
120114
}
121115

122116
/*!
@@ -127,34 +121,33 @@ inline double GetBesselZero(double x) {
127121
* \return Value of the integral.
128122
*/
129123
inline double GetBesselIntegral(double beta_x, double beta_y, double beta_z) {
124+
const double A = 1.0 + 2.0 * (beta_x + beta_y + beta_z);
125+
const double Bx = 2.0 * beta_x;
126+
const double By = 2.0 * beta_y;
127+
const double Bz = 2.0 * beta_z;
130128

131-
const double A = 1.0 + 2.0*(beta_x + beta_y + beta_z);
132-
const double Bx = 2.0*beta_x;
133-
const double By = 2.0*beta_y;
134-
const double Bz = 2.0*beta_z;
129+
const int N = 4000;
130+
const double t_max = 40.0;
131+
const double dt = t_max / N;
135132

136-
const int N = 4000;
137-
const double t_max = 40.0;
138-
const double dt = t_max / N;
133+
double sum = 0.0;
139134

140-
double sum = 0.0;
135+
for (int i = 1; i < N; i++) {
136+
double t = i * dt;
141137

142-
for (int i = 1; i < N; i++) {
143-
double t = i * dt;
138+
double e = exp(-A * t);
144139

145-
double e = exp(-A*t);
140+
double lx = GetBesselZero(Bx * t);
141+
double ly = GetBesselZero(By * t);
142+
double lz = GetBesselZero(Bz * t);
146143

147-
double lx = GetBesselZero(Bx*t);
148-
double ly = GetBesselZero(By*t);
149-
double lz = GetBesselZero(Bz*t);
144+
double lin = log(t) - A * t + lx + ly + lz;
150145

151-
double lin = log(t) - A*t + lx + ly + lz;
146+
double integrand = exp(lin);
147+
sum += integrand;
148+
}
152149

153-
double integrand = exp(lin);
154-
sum += integrand;
155-
}
156-
157-
return sum * dt;
150+
return sum * dt;
158151
}
159152

160153
/// @}

Common/src/CConfig.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2946,7 +2946,7 @@ void CConfig::SetConfig_Options() {
29462946
addBoolOption("ENFORCE_LES", enforceLES, false);
29472947

29482948
/* DESCRIPTION: Specify if the stochastic source term must be included in the turbulence model equation */
2949-
addBoolOption("STOCH_SOURCE_NU", stochSourceNu, false);
2949+
addBoolOption("STOCH_SOURCE_NU", stochSourceNu, true);
29502950

29512951
/* DESCRIPTION: Filter width for LES (if negative, it is computed based on the local cell size) */
29522952
addDoubleOption("LES_FILTER_WIDTH", LES_FilterWidth, -1.0);

SU2_CFD/include/numerics/CNumerics.hpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -666,23 +666,15 @@ class CNumerics {
666666

667667
/* --- Calculate stochastic tensor --- */
668668

669-
if (lesSensor > 0.999) {
670-
stochReynStress[1][0] = - Cmag * density * turbKE * rndVec[2];
671-
stochReynStress[2][0] = Cmag * density * turbKE * rndVec[1];
672-
stochReynStress[2][1] = - Cmag * density * turbKE * rndVec[0];
673-
for (size_t iDim = 0; iDim < nDim; iDim++) {
674-
for (size_t jDim = 0; jDim <= iDim; jDim++) {
675-
if (iDim==jDim) {
676-
stochReynStress[iDim][jDim] = 0.0;
677-
} else {
678-
stochReynStress[jDim][iDim] = - stochReynStress[iDim][jDim];
679-
}
680-
}
681-
}
682-
} else {
683-
for (size_t iDim = 0; iDim < nDim; iDim++) {
684-
for (size_t jDim = 0; jDim < nDim; jDim++) {
669+
stochReynStress[1][0] = - std::nearbyint(lesSensor) * Cmag * density * turbKE * rndVec[2];
670+
stochReynStress[2][0] = std::nearbyint(lesSensor) * Cmag * density * turbKE * rndVec[1];
671+
stochReynStress[2][1] = - std::nearbyint(lesSensor) * Cmag * density * turbKE * rndVec[0];
672+
for (size_t iDim = 0; iDim < nDim; iDim++) {
673+
for (size_t jDim = 0; jDim <= iDim; jDim++) {
674+
if (iDim==jDim) {
685675
stochReynStress[iDim][jDim] = 0.0;
676+
} else {
677+
stochReynStress[jDim][iDim] = - stochReynStress[iDim][jDim];
686678
}
687679
}
688680
}

SU2_CFD/include/numerics/turbulent/turb_sources.hpp

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,14 @@ class CSourceBase_TurbSA : public CNumerics {
122122
const CSAVariables& var, TIME_MARCHING time_marching) {
123123

124124
const su2double& nue = ScalarVar_i[0];
125-
126125
const auto& density = V_i[idx.Density()];
127126

128-
const su2double nut_small = 1.0e-10;
129-
130-
su2double Ji_2 = pow(var.Ji,2);
131-
su2double Ji_3 = Ji_2 * var.Ji;
127+
const su2double nut_small = 1.0e-12;
132128

133-
const su2double nut = nue * var.fv1;
129+
const su2double nut = max(nue * var.fv1, nut_small);
134130

135-
su2double tLES = ct * pow(lengthScale/DES_const, 2) / max(nut, nut_small);
136-
su2double tRANS = pow(lengthScale, 2) / max(nut, nut_small);
131+
su2double tLES = ct * pow(lengthScale/DES_const, 2) / nut;
132+
su2double tRANS = pow(lengthScale, 2) / nut;
137133
su2double tLR = tLES / tRANS;
138134
su2double tTurb = tLES / (lesMode_i + (1.0-lesMode_i)*tLR);
139135
su2double tRat = timeStep / tTurb;
@@ -146,7 +142,7 @@ class CSourceBase_TurbSA : public CNumerics {
146142
}
147143

148144
su2double scaleFactor = 0.0;
149-
if (lesMode_i > 0.999) scaleFactor = 1.0/tTurb * sqrt(2.0/tRat) * density * corrFac;
145+
if (std::nearbyint(lesMode_i) == 1) scaleFactor = 1.0/tTurb * sqrt(2.0/tRat) * density * corrFac;
150146

151147
ResidSB[0] = Residual;
152148
for (unsigned short iVar = 1; iVar < nVar; iVar++ ) {
@@ -157,22 +153,15 @@ class CSourceBase_TurbSA : public CNumerics {
157153
for (unsigned short iVar = 0; iVar < nVar; iVar++ ) {
158154
for (unsigned short jVar = 0; jVar < nVar; jVar++ ) {
159155
JacobianSB_i[iVar][jVar] = 0.0;
160-
if (iVar == jVar) JacobianSB_i[iVar][jVar] = -1.0/tTurb * density * Volume;
161156
}
162157
}
163-
JacobianSB_i[0][0] = Jacobian_i[0];
164-
165-
su2double dnut_dnue = var.fv1 + 3.0 * var.cv1_3 * Ji_3 / pow(Ji_3 + var.cv1_3, 2);
166-
su2double dtTurb_dnut = - ct * pow(lengthScale,2) / (max(nut, nut_small)*max(nut, nut_small));
167158

168159
for (unsigned short iVar = 1; iVar < nVar; iVar++ ) {
169-
JacobianSB_i[iVar][0] = - 1.0/tTurb * scaleFactor * stochSource[iVar-1]
170-
+ 1.0/(tTurb*tTurb) * ScalarVar_i[iVar]
171-
+ density * corrFac * stochSource[iVar-1] /
172-
(tTurb * sqrt(2.0*tTurb*timeStep));
173-
JacobianSB_i[iVar][0] *= dtTurb_dnut * dnut_dnue * Volume;
160+
JacobianSB_i[iVar][iVar] = -1.0/tTurb * density * Volume;
174161
}
175162

163+
JacobianSB_i[0][0] = Jacobian_i[0];
164+
176165
}
177166

178167
/*!
@@ -182,23 +171,21 @@ class CSourceBase_TurbSA : public CNumerics {
182171
inline void AddStochSource(const CSAVariables& var, const MatrixType& velGrad, const su2double Cmag) {
183172

184173
su2double dist2 = dist_i * dist_i;
185-
const su2double eps = 1.0e-10;
174+
const su2double eps = 1.0e-12;
186175
su2double xi3 = pow(var.Ji, 3);
187176

188177
su2double factor = dist2 / (2.0 * var.fv1 * ScalarVar_i[0] + eps);
189178
factor /= (3.0 * xi3 * var.cv1_3 / pow(xi3 + var.cv1_3, 2) + var.fv1 + eps);
190179

191-
const auto& density = V_i[idx.Density()];
192-
193180
su2double tke = pow(var.fv1*ScalarVar_i[0]/dist_i, 2);
194181

195-
su2double R12 = Cmag * density * tke * ScalarVar_i[2];
196-
su2double R13 = - Cmag * density * tke * ScalarVar_i[1];
197-
su2double R23 = Cmag * density * tke * ScalarVar_i[0];
182+
su2double R12 = (nDim==3 ? Cmag * tke * ScalarVar_i[3] : 0.0);
183+
su2double R13 = - Cmag * tke * ScalarVar_i[2];
184+
su2double R23 = Cmag * tke * ScalarVar_i[1];
198185

199-
su2double RGradU = R12 * (velGrad[0][1] - velGrad[1][0]) +
200-
R13 * (velGrad[0][2] - velGrad[2][0]) +
201-
R23 * (velGrad[1][2] - velGrad[2][1]);
186+
su2double RGradU = R12 * (velGrad[0][1] - velGrad[1][0]) +
187+
(nDim==3 ? R13 * (velGrad[0][2] - velGrad[2][0]) +
188+
R23 * (velGrad[1][2] - velGrad[2][1]) : 0.0);
202189

203190
su2double source_k = - RGradU;
204191
su2double source_nu = factor * source_k;
@@ -379,7 +366,7 @@ class CSourceBase_TurbSA : public CNumerics {
379366
/*--- Compute residual for Langevin equations (Stochastic Backscatter Model). ---*/
380367

381368
if (backscatter) {
382-
if (lesMode_i > 0.999 && config->GetStochSourceNu())
369+
if (std::nearbyint(lesMode_i) == 1 && config->GetStochSourceNu())
383370
AddStochSource(var, PrimVar_Grad_i + idx.Velocity(), config->GetSBS_Cmag());
384371
const su2double DES_const = config->GetConst_DES();
385372
const su2double ctau = config->GetSBS_Ctau();

SU2_CFD/include/solvers/CFVMFlowSolverBase.inl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,11 @@ void CFVMFlowSolverBase<V, R>::Viscous_Residual_impl(unsigned long iEdge, CGeome
475475
numerics->SetStochVar(turbNodes->GetSolution(iPoint, 1 + iDim),
476476
turbNodes->GetSolution(jPoint, 1 + iDim), iDim);
477477
}
478-
su2double eddy_visc_i, eddy_visc_j, DES_length_i,
478+
su2double rho, eddy_visc_i, eddy_visc_j, DES_length_i,
479479
DES_length_j, tke_i, tke_j, lesMode_i, lesMode_j;
480-
eddy_visc_i = turbNodes->GetmuT(iPoint);
481-
eddy_visc_j = turbNodes->GetmuT(jPoint);
480+
rho = nodes->GetDensity(iPoint);
481+
eddy_visc_i = turbNodes->GetmuT(iPoint) / rho;
482+
eddy_visc_j = turbNodes->GetmuT(jPoint) / rho;
482483
DES_length_i = turbNodes->GetDES_LengthScale(iPoint);
483484
DES_length_j = turbNodes->GetDES_LengthScale(jPoint);
484485
lesMode_i = turbNodes->GetLES_Mode(iPoint);

0 commit comments

Comments
 (0)