Skip to content

Commit e9421f5

Browse files
committed
cleanup sst a bit
1 parent b3d97e5 commit e9421f5

3 files changed

Lines changed: 41 additions & 71 deletions

File tree

SU2_CFD/include/numerics/CNumerics.hpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ class CNumerics {
182182

183183
su2double MeanPerturbedRSM[3][3];/*!< \brief Perturbed Reynolds stress tensor */
184184
bool using_uq; /*!< \brief Flag for UQ methodology */
185-
su2double PerturbedStrainMag; /*!< \brief Strain magnitude calculated using perturbed stress tensor */
186185
unsigned short Eig_Val_Comp; /*!< \brief Component towards which perturbation is perfromed */
187186
su2double uq_delta_b; /*!< \brief Magnitude of perturbation */
188187
su2double uq_urlx; /*!< \brief Under-relaxation factor for numerical stability */
@@ -689,17 +688,15 @@ class CNumerics {
689688

690689
/*!
691690
* \brief Set the value of the second blending function.
692-
* \param[in] val_F1_i - Value of the second Menter blending function at point i.
693-
* \param[in] val_F1_j - Value of the second Menter blending function at point j.
691+
* \param[in] val_F2_i - Value of the second Menter blending function at point i.
694692
*/
695-
virtual void SetF2blending(su2double val_F1_i, su2double val_F1_j) {/* empty */};
693+
virtual void SetF2blending(su2double val_F2_i) {/* empty */};
696694

697695
/*!
698696
* \brief Set the value of the cross diffusion for the SST model.
699697
* \param[in] val_CDkw_i - Value of the cross diffusion at point i.
700-
* \param[in] val_CDkw_j - Value of the cross diffusion at point j.
701698
*/
702-
virtual void SetCrossDiff(su2double val_CDkw_i, su2double val_CDkw_j) {/* empty */};
699+
virtual void SetCrossDiff(su2double val_CDkw_i) {/* empty */};
703700

704701
/*!
705702
* \brief Set the gradient of the auxiliary variables.

SU2_CFD/include/numerics/turbulent/turb_sources.hpp

Lines changed: 36 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -549,12 +549,9 @@ class CSourcePieceWise_TurbSST final : public CNumerics {
549549
private:
550550
const FlowIndices idx; /*!< \brief Object to manage the access to the flow primitives. */
551551

552-
su2double F1_i, F1_j, F2_i, F2_j;
552+
su2double F1_i, F2_i, CDkw_i;
553553

554554
su2double alfa_1, alfa_2, beta_1, beta_2, sigma_k_1, sigma_k_2, sigma_w_1, sigma_w_2, beta_star, a1;
555-
556-
su2double CDkw_i, CDkw_j;
557-
558555
su2double kAmb, omegaAmb;
559556

560557
su2double Residual[2];
@@ -565,22 +562,22 @@ class CSourcePieceWise_TurbSST final : public CNumerics {
565562
const bool axisymmetric = false;
566563

567564
/*!
568-
* \brief A virtual member. Get strain magnitude based on perturbed reynolds stress matrix
569-
* \param[in] turb_ke: turbulent kinetic energy of the node
565+
* \brief Get strain magnitude based on perturbed reynolds stress matrix.
566+
* \param[in] turb_ke: turbulent kinetic energy of the node.
570567
*/
571-
inline void SetPerturbedStrainMag(su2double turb_ke) {
568+
inline su2double PerturbedStrainMag(su2double turb_ke) const {
572569
/*--- Compute norm of perturbed strain rate tensor. ---*/
573570

574-
PerturbedStrainMag = 0;
571+
su2double perturbedStrainMag = 0;
575572
for (unsigned short iDim = 0; iDim < nDim; iDim++) {
576573
for (unsigned short jDim = 0; jDim < nDim; jDim++) {
577574
su2double StrainRate_ij = MeanPerturbedRSM[iDim][jDim] - TWO3 * turb_ke * delta[iDim][jDim];
578575
StrainRate_ij = -StrainRate_ij * Density_i / (2 * Eddy_Viscosity_i);
579576

580-
PerturbedStrainMag += pow(StrainRate_ij, 2.0);
577+
perturbedStrainMag += pow(StrainRate_ij, 2.0);
581578
}
582579
}
583-
PerturbedStrainMag = sqrt(2.0 * PerturbedStrainMag);
580+
return sqrt(2.0 * perturbedStrainMag);
584581
}
585582

586583
/*!
@@ -589,29 +586,25 @@ class CSourcePieceWise_TurbSST final : public CNumerics {
589586
inline void ResidualAxisymmetric(su2double alfa_blended, su2double zeta) {
590587
if (Coord_i[1] < EPS) return;
591588

592-
su2double yinv, rhov, k, w;
593-
su2double sigma_k_i, sigma_w_i;
594-
su2double pk_axi, pw_axi, cdk_axi, cdw_axi;
595-
596589
AD::SetPreaccIn(Coord_i[1]);
597590

598-
yinv = 1.0 / Coord_i[1];
599-
rhov = Density_i * V_i[2];
600-
k = ScalarVar_i[0];
601-
w = ScalarVar_i[1];
591+
const su2double yinv = 1.0 / Coord_i[1];
592+
const su2double rhov = Density_i * V_i[2];
593+
const su2double& k = ScalarVar_i[0];
594+
const su2double& w = ScalarVar_i[1];
602595

603596
/*--- Compute blended constants ---*/
604-
sigma_k_i = F1_i * sigma_k_1 + (1.0 - F1_i) * sigma_k_2;
605-
sigma_w_i = F1_i * sigma_w_1 + (1.0 - F1_i) * sigma_w_2;
597+
const su2double sigma_k_i = F1_i * sigma_k_1 + (1.0 - F1_i) * sigma_k_2;
598+
const su2double sigma_w_i = F1_i * sigma_w_1 + (1.0 - F1_i) * sigma_w_2;
606599

607600
/*--- Production ---*/
608-
pk_axi = max(
601+
const su2double pk_axi = max(
609602
0.0, 2.0 / 3.0 * rhov * k * ((2.0 * yinv * V_i[2] - PrimVar_Grad_i[2][1] - PrimVar_Grad_i[1][0]) / zeta - 1.0));
610-
pw_axi = alfa_blended * zeta / k * pk_axi;
603+
const su2double pw_axi = alfa_blended * zeta / k * pk_axi;
611604

612605
/*--- Convection-Diffusion ---*/
613-
cdk_axi = rhov * k - (Laminar_Viscosity_i + sigma_k_i * Eddy_Viscosity_i) * ScalarVar_Grad_i[0][1];
614-
cdw_axi = rhov * w - (Laminar_Viscosity_i + sigma_w_i * Eddy_Viscosity_i) * ScalarVar_Grad_i[1][1];
606+
const su2double cdk_axi = rhov * k - (Laminar_Viscosity_i + sigma_k_i * Eddy_Viscosity_i) * ScalarVar_Grad_i[0][1];
607+
const su2double cdw_axi = rhov * w - (Laminar_Viscosity_i + sigma_w_i * Eddy_Viscosity_i) * ScalarVar_Grad_i[1][1];
615608

616609
/*--- Add terms to the residuals ---*/
617610
Residual[0] += yinv * Volume * (pk_axi - cdk_axi);
@@ -657,31 +650,26 @@ class CSourcePieceWise_TurbSST final : public CNumerics {
657650
/*!
658651
* \brief Set the value of the first blending function.
659652
* \param[in] val_F1_i - Value of the first blending function at point i.
660-
* \param[in] val_F1_j - Value of the first blending function at point j.
653+
* \param[in] Not used.
661654
*/
662-
inline void SetF1blending(su2double val_F1_i, su2double val_F1_j) override {
655+
inline void SetF1blending(su2double val_F1_i, su2double) override {
663656
F1_i = val_F1_i;
664-
F1_j = val_F1_j;
665657
}
666658

667659
/*!
668660
* \brief Set the value of the second blending function.
669661
* \param[in] val_F2_i - Value of the second blending function at point i.
670-
* \param[in] val_F2_j - Value of the second blending function at point j.
671662
*/
672-
inline void SetF2blending(su2double val_F2_i, su2double val_F2_j) override {
663+
inline void SetF2blending(su2double val_F2_i) override {
673664
F2_i = val_F2_i;
674-
F2_j = val_F2_j;
675665
}
676666

677667
/*!
678668
* \brief Set the value of the cross diffusion for the SST model.
679669
* \param[in] val_CDkw_i - Value of the cross diffusion at point i.
680-
* \param[in] val_CDkw_j - Value of the cross diffusion at point j.
681670
*/
682-
inline void SetCrossDiff(su2double val_CDkw_i, su2double val_CDkw_j) override {
671+
inline void SetCrossDiff(su2double val_CDkw_i) override {
683672
CDkw_i = val_CDkw_i;
684-
CDkw_j = val_CDkw_j;
685673
}
686674

687675
/*!
@@ -701,12 +689,6 @@ class CSourcePieceWise_TurbSST final : public CNumerics {
701689
AD::SetPreaccIn(CDkw_i);
702690
AD::SetPreaccIn(PrimVar_Grad_i, nDim + idx.Velocity(), nDim);
703691
AD::SetPreaccIn(Vorticity_i, 3);
704-
705-
unsigned short iDim;
706-
su2double alfa_blended, beta_blended;
707-
su2double diverg, pk, pw, zeta;
708-
const su2double VorticityMag = GeometryToolbox::Norm(3, Vorticity_i);
709-
710692
AD::SetPreaccIn(V_i[idx.Density()], V_i[idx.LaminarViscosity()], V_i[idx.EddyViscosity()]);
711693

712694
Density_i = V_i[idx.Density()];
@@ -720,42 +702,34 @@ class CSourcePieceWise_TurbSST final : public CNumerics {
720702
Jacobian_i[1][0] = 0.0;
721703
Jacobian_i[1][1] = 0.0;
722704

723-
/*--- Computation of blended constants for the source terms---*/
705+
/*--- Computation of blended constants for the source terms ---*/
724706

725-
alfa_blended = F1_i * alfa_1 + (1.0 - F1_i) * alfa_2;
726-
beta_blended = F1_i * beta_1 + (1.0 - F1_i) * beta_2;
707+
const su2double alfa_blended = F1_i * alfa_1 + (1.0 - F1_i) * alfa_2;
708+
const su2double beta_blended = F1_i * beta_1 + (1.0 - F1_i) * beta_2;
727709

728710
if (dist_i > 1e-10) {
729711
/*--- Production ---*/
730712

731-
diverg = 0.0;
732-
for (iDim = 0; iDim < nDim; iDim++) diverg += PrimVar_Grad_i[iDim + idx.Velocity()][iDim];
713+
su2double diverg = 0.0;
714+
for (unsigned short iDim = 0; iDim < nDim; iDim++)
715+
diverg += PrimVar_Grad_i[iDim + idx.Velocity()][iDim];
716+
717+
/*--- If using UQ methodolgy, calculate production using perturbed Reynolds stress matrix ---*/
733718

734-
/* if using UQ methodolgy, calculate production using perturbed Reynolds stress matrix */
719+
su2double StrainMag = StrainMag_i;
735720

736721
if (using_uq) {
737722
ComputePerturbedRSM(nDim, Eig_Val_Comp, uq_permute, uq_delta_b, uq_urlx, PrimVar_Grad_i + idx.Velocity(),
738723
Density_i, Eddy_Viscosity_i, ScalarVar_i[0], MeanPerturbedRSM);
739-
SetPerturbedStrainMag(ScalarVar_i[0]);
740-
pk = Eddy_Viscosity_i * PerturbedStrainMag * PerturbedStrainMag -
741-
2.0 / 3.0 * Density_i * ScalarVar_i[0] * diverg;
742-
} else {
743-
pk = Eddy_Viscosity_i * StrainMag_i * StrainMag_i - 2.0 / 3.0 * Density_i * ScalarVar_i[0] * diverg;
724+
StrainMag = PerturbedStrainMag(ScalarVar_i[0]);
744725
}
745726

746-
pk = min(pk, 20.0 * beta_star * Density_i * ScalarVar_i[1] * ScalarVar_i[0]);
747-
pk = max(pk, 0.0);
727+
su2double pk = Eddy_Viscosity_i * pow(StrainMag, 2) - 2.0 / 3.0 * Density_i * ScalarVar_i[0] * diverg;
728+
pk = max(0.0, min(pk, 20.0 * beta_star * Density_i * ScalarVar_i[1] * ScalarVar_i[0]));
748729

749-
zeta = max(ScalarVar_i[1], VorticityMag * F2_i / a1);
750-
751-
/* if using UQ methodolgy, calculate production using perturbed Reynolds stress matrix */
752-
753-
if (using_uq) {
754-
pw = PerturbedStrainMag * PerturbedStrainMag - 2.0 / 3.0 * zeta * diverg;
755-
} else {
756-
pw = StrainMag_i * StrainMag_i - 2.0 / 3.0 * zeta * diverg;
757-
}
758-
pw = alfa_blended * Density_i * max(pw, 0.0);
730+
const su2double VorticityMag = GeometryToolbox::Norm(3, Vorticity_i);
731+
const su2double zeta = max(ScalarVar_i[1], VorticityMag * F2_i / a1);
732+
su2double pw = alfa_blended * Density_i * max(pow(StrainMag, 2) - 2.0 / 3.0 * zeta * diverg, 0.0);
759733

760734
/*--- Sustaining terms, if desired. Note that if the production terms are
761735
larger equal than the sustaining terms, the original formulation is
@@ -767,7 +741,6 @@ class CSourcePieceWise_TurbSST final : public CNumerics {
767741
if (sustaining_terms) {
768742
const su2double sust_k = beta_star * Density_i * kAmb * omegaAmb;
769743
const su2double sust_w = beta_blended * Density_i * omegaAmb * omegaAmb;
770-
771744
pk = max(pk, sust_k);
772745
pw = max(pw, sust_w);
773746
}

SU2_CFD/src/solvers/CTurbSSTSolver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ void CTurbSSTSolver::Source_Residual(CGeometry *geometry, CSolver **solver_conta
300300

301301
/*--- Menter's second blending function ---*/
302302

303-
numerics->SetF2blending(nodes->GetF2blending(iPoint),0.0);
303+
numerics->SetF2blending(nodes->GetF2blending(iPoint));
304304

305305
/*--- Set vorticity and strain rate magnitude ---*/
306306

@@ -310,7 +310,7 @@ void CTurbSSTSolver::Source_Residual(CGeometry *geometry, CSolver **solver_conta
310310

311311
/*--- Cross diffusion ---*/
312312

313-
numerics->SetCrossDiff(nodes->GetCrossDiff(iPoint),0.0);
313+
numerics->SetCrossDiff(nodes->GetCrossDiff(iPoint));
314314

315315
if (axisymmetric){
316316
/*--- Set y coordinate ---*/

0 commit comments

Comments
 (0)