@@ -54,6 +54,8 @@ class CAvgGrad_TurbSA final : public CAvgGrad_Scalar<FlowIndices> {
5454 const su2double sigma = 2.0 /3.0 ;
5555 const su2double cb2 = 0.622 ;
5656
57+ const bool use_accurate_jacobians;
58+
5759 /* !
5860 * \brief Adds any extra variables to AD
5961 */
@@ -68,41 +70,39 @@ class CAvgGrad_TurbSA final : public CAvgGrad_Scalar<FlowIndices> {
6870
6971 /* --- Compute mean effective viscosity ---*/
7072
71- /* First Term */
72- su2double nu_i = Laminar_Viscosity_i/Density_i;
73- su2double nu_j = Laminar_Viscosity_j/Density_j;
74- su2double nu_e = 0.5 *(nu_i + nu_j + (1 +cb2)*(ScalarVar_i[0 ] + ScalarVar_j[0 ]));
75- su2double term_1 = nu_e;
73+ /* --- First Term. Normal diffusion, and conservative part of the quadratic diffusion.
74+ * ||grad nu_t||^2 = div(nu_t grad nu_t) - nu_t div grad nu_t ---*/
75+ const su2double nu_i = Laminar_Viscosity_i/Density_i;
76+ const su2double nu_j = Laminar_Viscosity_j/Density_j;
77+ const su2double nu_e = 0.5 * (nu_i + nu_j + (1 + cb2) * (ScalarVar_i[0 ] + ScalarVar_j[0 ]));
78+ const su2double term_1 = nu_e;
7679
77- /* Second Term */
78- su2double nu_tilde_i = ScalarVar_i[0 ];
79- su2double term_2 = cb2 * nu_tilde_i;
80+ /* Second Term (quadratic diffusion, non conservative). */
81+ const su2double nu_tilde_i = ScalarVar_i[0 ];
82+ const su2double term_2 = cb2 * nu_tilde_i;
8083
81- Flux[0 ] = (term_1 - term_2)*Proj_Mean_GradScalarVar[0 ]/sigma;
82- su2double dTerm1_dnut_i = (1 +cb2)*0.5 ;
83- su2double dTerm1_dnut_j = (1 +cb2)*0.5 ;
84+ const su2double diffusion_coefficient = term_1 - term_2;
85+ Flux[0 ] = diffusion_coefficient * Proj_Mean_GradScalarVar[0 ] / sigma;
8486
85- su2double dTerm2_dnut_i = cb2;
86- su2double dTerm2_dnut_j = 0.0 ;
87+ if (implicit) {
88+ /* --- For Jacobians -> Use of TSL approx. to compute derivatives of the gradients ---*/
89+ Jacobian_i[0 ][0 ] = -diffusion_coefficient * proj_vector_ij / sigma;
90+ Jacobian_j[0 ][0 ] = diffusion_coefficient * proj_vector_ij / sigma;
8791
88- su2double dDC_dnut_i = dTerm1_dnut_i - dTerm2_dnut_i;
89- su2double dDC_dnut_j = dTerm1_dnut_j - dTerm2_dnut_j;
92+ if (use_accurate_jacobians) {
93+ /* --- The diffusion coefficient is also a function of nu_t. ---*/
94+ const su2double dTerm1_dnut_i = (1 + cb2) * 0.5 ;
95+ const su2double dTerm1_dnut_j = (1 + cb2) * 0.5 ;
9096
91- su2double dGrad_dnut_i = -proj_vector_ij ;
92- su2double dGrad_dnut_j = proj_vector_ij ;
97+ const su2double dTerm2_dnut_i = cb2 ;
98+ const su2double dTerm2_dnut_j = 0.0 ;
9399
94- /* --- For Jacobians -> Use of TSL approx. to compute derivatives of the gradients ---*/
95- su2double diffusion_coefficient = term_1 - term_2;
96- bool UseExactJacobians = config->GetUse_Accurate_Turb_Jacobians ();
100+ const su2double dDC_dnut_i = dTerm1_dnut_i - dTerm2_dnut_i;
101+ const su2double dDC_dnut_j = dTerm1_dnut_j - dTerm2_dnut_j;
97102
98- if (implicit) {
99- if (UseExactJacobians) {
100- Jacobian_i[0 ][0 ] = (dDC_dnut_i*Proj_Mean_GradScalarVar[0 ] + dGrad_dnut_i*diffusion_coefficient)/sigma; // exact
101- Jacobian_j[0 ][0 ] = (dDC_dnut_j*Proj_Mean_GradScalarVar[0 ] + dGrad_dnut_j*diffusion_coefficient)/sigma; // exact
102- } else {
103- Jacobian_i[0 ][0 ] = diffusion_coefficient*-proj_vector_ij/sigma; // frozen diffusion coefficients
104- Jacobian_j[0 ][0 ] = diffusion_coefficient* proj_vector_ij/sigma; // frozen diffusion coefficients
105- }
103+ Jacobian_i[0 ][0 ] += dDC_dnut_i * Proj_Mean_GradScalarVar[0 ] / sigma;
104+ Jacobian_j[0 ][0 ] += dDC_dnut_j * Proj_Mean_GradScalarVar[0 ] / sigma;
105+ }
106106 }
107107 }
108108
@@ -116,7 +116,8 @@ class CAvgGrad_TurbSA final : public CAvgGrad_Scalar<FlowIndices> {
116116 */
117117 CAvgGrad_TurbSA (unsigned short val_nDim, unsigned short val_nVar,
118118 bool correct_grad, const CConfig* config)
119- : CAvgGrad_Scalar<FlowIndices>(val_nDim, val_nVar, correct_grad, config) {}
119+ : CAvgGrad_Scalar<FlowIndices>(val_nDim, val_nVar, correct_grad, config),
120+ use_accurate_jacobians (config->GetUse_Accurate_Turb_Jacobians ()) {}
120121};
121122
122123/* !
@@ -162,42 +163,40 @@ class CAvgGrad_TurbSA_Neg final : public CAvgGrad_Scalar<FlowIndices> {
162163 const su2double nu_i = Laminar_Viscosity_i/Density_i;
163164 const su2double nu_j = Laminar_Viscosity_j/Density_j;
164165
165- const su2double nu_ij = 0.5 * (nu_i+ nu_j);
166+ const su2double nu_ij = 0.5 * (nu_i + nu_j);
166167 const su2double nu_tilde_i = ScalarVar_i[0 ];
167168 const su2double nu_tilde_j = ScalarVar_j[0 ];
168- const su2double nu_tilde_ij = 0.5 * (nu_tilde_i + nu_tilde_j);
169+ const su2double nu_tilde_ij = 0.5 * (nu_tilde_i + nu_tilde_j);
169170
170- /* Following Diskin's implementation from 10.2514/1.J064629, they propose a new fn function
171- to be evaluated at the cell to maintain positivity in the diffusion coefficient, which is
172- used in both terms. The new fn term averaged across the face reverts to the original fn
173- function. */
171+ /* --- Following Diskin's implementation from 10.2514/1.J064629, they propose a new fn function
172+ * to be evaluated at the cell to maintain positivity in the diffusion coefficient, which is
173+ * used in both terms. The new fn term averaged across the face reverts to the original fn
174+ * function. --- */
174175
175176 /* --- Second Term (LHS) ---*/
176- su2double zeta_i = ((1 + cb2)*nu_tilde_ij - cb2*nu_tilde_i)/nu_ij;
177- su2double fn_i;
178- if (zeta_i >= 0.0 ) {
179- fn_i = 1.0 ;
180- } else {
181- fn_i = (cn1 + pow (zeta_i,3.0 ))/(cn1 - pow (zeta_i,3.0 ));
177+ const su2double zeta_i = ((1 + cb2) * nu_tilde_ij - cb2 * nu_tilde_i) / nu_ij;
178+ su2double fn_i = 1.0 ;
179+ if (zeta_i < 0.0 ) {
180+ fn_i = (cn1 + pow (zeta_i,3 )) / (cn1 - pow (zeta_i,3 ));
182181 }
183182
184- su2double term_1 = (nu_ij + (1 + cb2)* nu_tilde_ij* fn_i);
185- su2double term_2 = cb2* nu_tilde_i* fn_i;
186- Flux[0 ] = (term_1 - term_2)* Proj_Mean_GradScalarVar[0 ]/ sigma;
183+ const su2double term_1 = (nu_ij + (1 + cb2) * nu_tilde_ij * fn_i);
184+ const su2double term_2 = cb2 * nu_tilde_i * fn_i;
185+ Flux[0 ] = (term_1 - term_2) * Proj_Mean_GradScalarVar[0 ] / sigma;
187186
188- /* --- For Jacobians -> Use of TSL approx. to compute derivatives of the gradients
187+ /* --- For Jacobians -> Use of TSL approx. to compute derivatives of the gradients
189188 * Exact Jacobians were tested on multiple cases but resulted in divergence of all
190189 * simulations, hence only frozen diffusion coefficient (approximate) Jacobians are used. ---*/
191190
192- su2double diffusion_coefficient = (term_1 - term_2);
191+ if (implicit) {
192+ const su2double diffusion_coefficient = (term_1 - term_2);
193193
194- su2double dGrad_dnut_i = -proj_vector_ij;
195- su2double dGrad_dnut_j = proj_vector_ij;
194+ const su2double dGrad_dnut_i = -proj_vector_ij;
195+ const su2double dGrad_dnut_j = proj_vector_ij;
196196
197- if (implicit) {
198- Jacobian_i[0 ][0 ] = diffusion_coefficient * dGrad_dnut_i/sigma; // frozen diffusion
199- Jacobian_j[0 ][0 ] = diffusion_coefficient * dGrad_dnut_j/sigma; // frozen diffusion
200- }
197+ Jacobian_i[0 ][0 ] = diffusion_coefficient * dGrad_dnut_i / sigma;
198+ Jacobian_j[0 ][0 ] = diffusion_coefficient * dGrad_dnut_j / sigma;
199+ }
201200 }
202201
203202public:
0 commit comments