Skip to content

Commit 02878dd

Browse files
committed
cleanup
1 parent 7d38d8c commit 02878dd

File tree

2 files changed

+84
-52
lines changed

2 files changed

+84
-52
lines changed

SU2_CFD/include/numerics/turbulent/turb_diffusion.hpp

Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ class CAvgGrad_TurbSST final : public CAvgGrad_Scalar<FlowIndices> {
240240
const su2double sigma_k2;
241241
const su2double sigma_om1;
242242
const su2double sigma_om2;
243+
const bool use_accurate_jacobians;
243244

244245
su2double F1_i, F1_j; /*!< \brief Menter's first blending function */
245246

@@ -262,46 +263,75 @@ class CAvgGrad_TurbSST final : public CAvgGrad_Scalar<FlowIndices> {
262263
const su2double sigma_kine_j = F1_j*sigma_k1 + (1.0 - F1_j)*sigma_k2;
263264
const su2double sigma_omega_i = F1_i*sigma_om1 + (1.0 - F1_i)*sigma_om2;
264265
const su2double sigma_omega_j = F1_j*sigma_om1 + (1.0 - F1_j)*sigma_om2;
265-
const su2double lambda_i = 2 * (1 - F1_i) * Density_i * sigma_omega_i / ScalarVar_i[1];
266-
const su2double lambda_j = 2 * (1 - F1_j) * Density_j * sigma_omega_j / ScalarVar_j[1];
267-
const su2double lambda_ij = 0.5 * (lambda_i + lambda_j);
268266

269267
/*--- Compute mean effective dynamic viscosity ---*/
270268
const su2double diff_i_kine = Laminar_Viscosity_i + sigma_kine_i*Eddy_Viscosity_i;
271269
const su2double diff_j_kine = Laminar_Viscosity_j + sigma_kine_j*Eddy_Viscosity_j;
272-
const su2double diff_i_omega = Laminar_Viscosity_i + sigma_omega_i*Eddy_Viscosity_i + lambda_i * ScalarVar_i[0];
273-
const su2double diff_j_omega = Laminar_Viscosity_j + sigma_omega_j*Eddy_Viscosity_j + lambda_j * ScalarVar_j[0];
274-
275-
//non-conservative term:
276-
const su2double diff_omega_t1 = 0.5 * (diff_i_omega + diff_j_omega);
277-
const su2double diff_omega_t2 = -ScalarVar_i[0] * lambda_ij;
270+
const su2double diff_i_omega = Laminar_Viscosity_i + sigma_omega_i*Eddy_Viscosity_i;
271+
const su2double diff_j_omega = Laminar_Viscosity_j + sigma_omega_j*Eddy_Viscosity_j;
278272

279273
const su2double diff_kine = 0.5*(diff_i_kine + diff_j_kine);
280-
const su2double diff_omega = diff_omega_t1 + diff_omega_t2;
274+
const su2double diff_omega_T1 = 0.5*(diff_i_omega + diff_j_omega);
275+
276+
/*--- We aim to treat the cross-diffusion as a diffusion treat rather than a source term.
277+
* Re-writing the cross-diffusion contribution as λ ∇k ∇ω, where λ = (2 (1- F1) ρ σ_ω2)/ ω
278+
* and expanding using the product rule gives: ∇(λk∇ω) - k ∇(λ∇ω).
279+
* Discretising using FVM, gives a diffusion coefficient of: (λk)_ij - k_i λ_ij. ---*/
280+
281+
const su2double lambda_i = 2 * (1 - F1_i) * Density_i * sigma_omega_i / ScalarVar_i[1];
282+
const su2double lambda_j = 2 * (1 - F1_j) * Density_j * sigma_omega_j / ScalarVar_j[1];
283+
const su2double lambda_ij = 0.5 * (lambda_i + lambda_j);
284+
const su2double k_ij = 0.5 * (ScalarVar_i[0] + ScalarVar_j[0]);
285+
286+
const su2double diff_omega_T2 = lambda_ij * k_ij;
281287

282-
/*Store coefficients to be output*/
288+
/*--- clipping k_c: if clipped to this, 0 diffusion is possible which greatly affects
289+
* convergence and accuracy. clipping to k_ij is better if needed, testing showed clipping
290+
* is not required. REMOVE LATER if more testing shows it is redundant ---*/
291+
const su2double mu_ij = 0.5 * (Laminar_Viscosity_i + Laminar_Viscosity_j);
292+
const su2double mut_ij = 0.5 * (Eddy_Viscosity_i + Eddy_Viscosity_j);
293+
const su2double Coi = 2 * sigma_omega_i * (1 - F1_i);
294+
const su2double Coj = 2 * sigma_omega_j * (1 - F1_j);
295+
const su2double Coij = 0.5 * (Coi + Coj);
296+
const su2double k_clip = (diff_omega_T1 + Coij*mu_ij)/(Coij * mut_ij/k_ij); //
297+
298+
const su2double diff_omega_T3 = -ScalarVar_i[0] * lambda_ij;
299+
300+
const su2double diff_omega = diff_omega_T1 + diff_omega_T2 + diff_omega_T3;
301+
302+
/* Store some variables for debugging, REMOVE LATER.*/
283303
CNumerics::DiffCoeff_kw[0] = diff_kine;
284304
CNumerics::DiffCoeff_kw[1] = diff_omega;
285-
305+
CNumerics::DiffCoeff_kw[2] = diff_omega_T1;
306+
CNumerics::DiffCoeff_kw[3] = diff_omega_T2;
307+
CNumerics::DiffCoeff_kw[4] = diff_omega_T3;
308+
CNumerics::DiffCoeff_kw[5] = k_clip;
309+
286310
Flux[0] = diff_kine*Proj_Mean_GradScalarVar[0];
287-
Flux[1] = diff_omega*Proj_Mean_GradScalarVar[1];
311+
Flux[1] = (diff_omega_T1 + diff_omega_T2 + diff_omega_T3)*Proj_Mean_GradScalarVar[1];
288312

289313
/*--- For Jacobians -> Use of TSL (Thin Shear Layer) approx. to compute derivatives of the gradients ---*/
290-
314+
//Using Frozen Coefficient Jacobians, for stability during debugging.
291315
if (implicit) {
292316
const su2double proj_on_rho_i = proj_vector_ij/Density_i;
293-
const su2double dlambda_domega_i = - (2 * (1 - F1_i) * Density_i * (sigma_omega_i))/pow(ScalarVar_i[1], 2);
294-
Jacobian_i[0][0] = -diff_kine*proj_on_rho_i;
317+
const su2double proj_on_rho_j = proj_vector_ij/Density_j;
318+
Jacobian_i[0][0] = -diff_kine*proj_on_rho_i; Jacobian_i[0][1] = 0.0;
319+
Jacobian_i[1][0] = 0.0; Jacobian_i[1][1] = -diff_omega*proj_on_rho_i;
320+
321+
Jacobian_j[0][0] = diff_kine*proj_on_rho_j; Jacobian_j[0][1] = 0.0;
322+
Jacobian_j[1][0] = 0.0; Jacobian_j[1][1] = diff_omega*proj_on_rho_j;
323+
324+
if (use_accurate_jacobians) {
325+
Jacobian_i[0][0] = -diff_kine*proj_on_rho_i;
295326
Jacobian_i[0][1] = 0.0;
296-
Jacobian_i[1][0] = -0.5 * lambda_j * Proj_Mean_GradScalarVar[1];
297-
Jacobian_i[1][1] = (diff_omega_t1 + diff_omega_t2) * -proj_on_rho_i;
327+
Jacobian_i[1][0] = -lambda_ij/2 * Proj_Mean_GradScalarVar[1];
328+
Jacobian_i[1][1] = (-k_ij+ScalarVar_i[0]) * (lambda_i/(2*ScalarVar_i[1]*ScalarVar_i[1])) * Proj_Mean_GradScalarVar[1] + diff_omega*-proj_on_rho_i ;
298329

299-
const su2double proj_on_rho_j = proj_vector_ij/Density_j;
300-
const su2double dlambda_domega_j = - (2 * (1 - F1_j) * Density_j * (sigma_omega_j))/pow(ScalarVar_j[1], 2);
301330
Jacobian_j[0][0] = diff_kine*proj_on_rho_j;
302331
Jacobian_j[0][1] = 0.0;
303-
Jacobian_j[1][0] = 0.5 * lambda_j * Proj_Mean_GradScalarVar[1];
304-
Jacobian_j[1][1] = 0.5 * (ScalarVar_j[0] - ScalarVar_i[0]) * dlambda_domega_j * Proj_Mean_GradScalarVar[1] + (diff_omega_t1 + diff_omega_t2) * proj_on_rho_j;
332+
Jacobian_j[1][0] = lambda_ij/2 * Proj_Mean_GradScalarVar[1];
333+
Jacobian_j[1][1] = (-k_ij+ScalarVar_i[0]) * (lambda_j/(2*ScalarVar_j[1]*ScalarVar_j[1])) * Proj_Mean_GradScalarVar[1] + diff_omega*proj_on_rho_j;
334+
}
305335
}
306336
}
307337

@@ -320,7 +350,8 @@ class CAvgGrad_TurbSST final : public CAvgGrad_Scalar<FlowIndices> {
320350
sigma_k1(constants[0]),
321351
sigma_k2(constants[1]),
322352
sigma_om1(constants[2]),
323-
sigma_om2(constants[3]) {
353+
sigma_om2(constants[3]),
354+
use_accurate_jacobians(config->GetUse_Accurate_Turb_Jacobians()) {
324355
}
325356

326357
/*!

SU2_CFD/src/solvers/CTurbSSTSolver.cpp

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ CTurbSSTSolver::CTurbSSTSolver(CGeometry *geometry, CConfig *config, unsigned sh
7777

7878
if (ReducerStrategy) {
7979
EdgeFluxes.Initialize(geometry->GetnEdge(), geometry->GetnEdge(), nVar, nullptr);
80-
EdgeFluxes_Diff.Initialize(geometry->GetnEdge(), geometry->GetnEdge(), nVar, nullptr);
80+
EdgeFluxesDiff.Initialize(geometry->GetnEdge(), geometry->GetnEdge(), nVar, nullptr);
8181
}
8282

8383
/*--- Initialize the BGS residuals in multizone problems. ---*/
@@ -325,26 +325,27 @@ void CTurbSSTSolver::Viscous_Residual(const unsigned long iEdge, const CGeometry
325325
/*--- Compute fluxes and jacobians i->j ---*/
326326
const su2double* normal = geometry->edges->GetNormal(iEdge);
327327
auto residual_ij = ComputeFlux(iPoint, jPoint, normal);
328+
329+
JacobianScalarType *Block_ii = nullptr, *Block_ij = nullptr, *Block_ji = nullptr, *Block_jj = nullptr;
330+
if (implicit) {
331+
Jacobian.GetBlocks(iEdge, iPoint, jPoint, Block_ii, Block_ij, Block_ji, Block_jj);
332+
}
328333
if (ReducerStrategy) {
329334
EdgeFluxes.SubtractBlock(iEdge, residual_ij);
330-
EdgeFluxes_Diff.SetBlock(iEdge, residual_ij);
335+
EdgeFluxesDiff.SetBlock(iEdge, residual_ij);
331336
if (implicit) {
332-
auto* Block_ij = Jacobian.GetBlock(iPoint, jPoint);
333-
auto* Block_ji = Jacobian.GetBlock(jPoint, iPoint);
334-
337+
/*--- For the reducer strategy the Jacobians are averaged for simplicity. ---*/
338+
assert(nVar == 2);
335339
for (int iVar=0; iVar<nVar; iVar++)
336340
for (int jVar=0; jVar<nVar; jVar++) {
337-
Block_ij[iVar*nVar + jVar] -= 0.5*SU2_TYPE::GetValue(residual_ij.jacobian_j[iVar][jVar]);
338-
Block_ji[iVar*nVar + jVar] += 0.5*SU2_TYPE::GetValue(residual_ij.jacobian_i[iVar][jVar]);
341+
Block_ij[iVar*nVar + jVar] -= 0.5 * SU2_TYPE::GetValue(residual_ij.jacobian_j[iVar][jVar]);
342+
Block_ji[iVar*nVar + jVar] += 0.5 * SU2_TYPE::GetValue(residual_ij.jacobian_i[iVar][jVar]);
339343
}
340344
}
341-
}
342-
else {
343-
LinSysRes.SubtractBlock(iPoint, residual_ij);
345+
} else {
346+
LinSysRes.SubtractBlock(iPoint, residual_ij);
344347
if (implicit) {
345-
auto* Block_ii = Jacobian.GetBlock(iPoint, iPoint);
346-
auto* Block_ij = Jacobian.GetBlock(iPoint, jPoint);
347-
348+
assert(nVar == 2);
348349
for (int iVar=0; iVar<nVar; iVar++)
349350
for (int jVar=0; jVar<nVar; jVar++) {
350351
Block_ii[iVar*nVar + jVar] -= SU2_TYPE::GetValue(residual_ij.jacobian_i[iVar][jVar]);
@@ -355,40 +356,40 @@ void CTurbSSTSolver::Viscous_Residual(const unsigned long iEdge, const CGeometry
355356

356357
/*--- Compute fluxes and jacobians j->i ---*/
357358
su2double flipped_normal[MAXNDIM];
358-
for (int iDim=0; iDim<nDim; iDim++)
359-
flipped_normal[iDim] = -normal[iDim];
359+
for (auto iDim = 0u; iDim < nDim; iDim++) flipped_normal[iDim] = -normal[iDim];
360360

361361
auto residual_ji = ComputeFlux(jPoint, iPoint, flipped_normal);
362362
if (ReducerStrategy) {
363-
EdgeFluxes_Diff.AddBlock(iEdge, residual_ji);
363+
EdgeFluxesDiff.AddBlock(iEdge, residual_ji);
364364
if (implicit) {
365-
auto* Block_ij = Jacobian.GetBlock(iPoint, jPoint);
366-
auto* Block_ji = Jacobian.GetBlock(jPoint, iPoint);
367-
365+
assert(nVar == 2);
368366
for (int iVar=0; iVar<nVar; iVar++)
369367
for (int jVar=0; jVar<nVar; jVar++) {
370-
Block_ij[iVar*nVar + jVar] += 0.5*SU2_TYPE::GetValue(residual_ji.jacobian_i[iVar][jVar]);
371-
Block_ji[iVar*nVar + jVar] -= 0.5*SU2_TYPE::GetValue(residual_ji.jacobian_j[iVar][jVar]);
368+
Block_ij[iVar*nVar + jVar] += 0.5 * SU2_TYPE::GetValue(residual_ji.jacobian_i[iVar][jVar]);
369+
Block_ji[iVar*nVar + jVar] -= 0.5 * SU2_TYPE::GetValue(residual_ji.jacobian_j[iVar][jVar]);
372370
}
373-
}
374-
}
375-
else {
371+
}
372+
} else {
376373
LinSysRes.SubtractBlock(jPoint, residual_ji);
377374
if (implicit) {
378-
auto* Block_ji = Jacobian.GetBlock(jPoint, iPoint);
379-
auto* Block_jj = Jacobian.GetBlock(jPoint, jPoint);
380-
381-
//the order of arguments were flipped in the evaluation of residual_ji, the jacobian associated with point i is stored in jacobian_j and point j in jacobian_i
375+
/*--- The order of arguments were flipped in the evaluation of residual_ji, the Jacobian
376+
* associated with point i is stored in jacobian_j and point j in jacobian_i. ---*/
377+
assert(nVar == 2);
382378
for (int iVar=0; iVar<nVar; iVar++)
383379
for (int jVar=0; jVar<nVar; jVar++) {
384380
Block_ji[iVar*nVar + jVar] -= SU2_TYPE::GetValue(residual_ji.jacobian_j[iVar][jVar]);
385381
Block_jj[iVar*nVar + jVar] -= SU2_TYPE::GetValue(residual_ji.jacobian_i[iVar][jVar]);
386382
}
387383
}
388384
}
389-
su2double DC_kw[2];
385+
su2double DC_kw[6];
390386
DC_kw[0] = numerics->GetDiffCoeff_kw(0);
391387
DC_kw[1] = numerics->GetDiffCoeff_kw(1);
388+
DC_kw[2] = numerics->GetDiffCoeff_kw(2);
389+
DC_kw[3] = numerics->GetDiffCoeff_kw(3);
390+
DC_kw[4] = numerics->GetDiffCoeff_kw(4);
391+
DC_kw[5] = numerics->GetDiffCoeff_kw(5);
392+
392393
nodes->SetDiffCoeff_kw(iPoint, DC_kw);
393394
}
394395

0 commit comments

Comments
 (0)