Skip to content

Commit 24cc96c

Browse files
committed
cleanup
1 parent fc97426 commit 24cc96c

9 files changed

Lines changed: 46 additions & 55 deletions

File tree

SU2_CFD/include/numerics_simd/flow/convection/common.hpp

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@
3434

3535
/*!
3636
* \brief Blended difference for U-MUSCL reconstruction.
37-
* \param[in] grad_proj - Gradient projection at point i: dot(grad_i, vector_ij).
37+
* \param[in] gradProj - Gradient projection at point i: dot(grad_i, vector_ij).
3838
* \param[in] delta - Centered difference: V_j - V_i.
3939
* \param[in] kappa - Blending parameter.
4040
* \return Blended difference for reconstruction from point i.
4141
*/
42-
FORCEINLINE Double umusclProjection(Double grad_proj,
42+
FORCEINLINE Double umusclProjection(Double gradProj,
4343
Double delta,
4444
Double kappa) {
4545
/*-------------------------------------------------------------------*/
@@ -51,7 +51,7 @@ FORCEINLINE Double umusclProjection(Double grad_proj,
5151
/*--- To maintain proper scaling for edge limiters, the result of ---*/
5252
/*--- this function is 0.5 * dV_ij^kap. ---*/
5353
/*-------------------------------------------------------------------*/
54-
return (1.0 - kappa) * grad_proj + kappa * delta;
54+
return (1.0 - kappa) * gradProj + kappa * delta;
5555
}
5656

5757
/*!
@@ -62,7 +62,7 @@ FORCEINLINE Double umusclProjection(Double grad_proj,
6262
* \param[in] delta - Centered difference: V_j - V_i.
6363
* \param[in] iVar - Variable index.
6464
* \param[in] kappa - Blending coefficient.
65-
* \param[in] relax - Newton-Krylov relaxation.
65+
* \param[in] umusclRamp - MUSCL 1st-2nd order ramp times Newton-Krylov relaxation.
6666
* \return Variable reconstructed from point i.
6767
*/
6868
template<class GradType, size_t nDim>
@@ -71,10 +71,9 @@ FORCEINLINE Double musclReconstruction(const GradType& grad,
7171
const Double delta,
7272
size_t iVar,
7373
Double kappa,
74-
Double relax,
75-
Double ramp_val) {
74+
Double umusclRamp) {
7675
const Double proj = dot(grad[iVar], vector_ij);
77-
return ramp_val * relax * umusclProjection(proj, delta, kappa);
76+
return umusclRamp * umusclProjection(proj, delta, kappa);
7877
}
7978

8079
/*!
@@ -87,8 +86,7 @@ FORCEINLINE void musclUnlimited(Int iPoint,
8786
const Gradient_t& gradient,
8887
CPair<VarType>& V,
8988
Double kappa,
90-
Double relax,
91-
Double ramp_val) {
89+
Double umusclRamp) {
9290
constexpr auto nVarGrad = nVarGrad_ > 0 ? nVarGrad_ : VarType::nVar;
9391

9492
auto grad_i = gatherVariables<nVarGrad,nDim>(iPoint, gradient);
@@ -99,8 +97,8 @@ FORCEINLINE void musclUnlimited(Int iPoint,
9997
const Double delta_ij = V.j.all(iVar) - V.i.all(iVar);
10098

10199
/*--- U-MUSCL reconstructed variables ---*/
102-
const Double proj_i = musclReconstruction(grad_i, vector_ij, delta_ij, iVar, kappa, relax, ramp_val);
103-
const Double proj_j = musclReconstruction(grad_j, vector_ij, delta_ij, iVar, kappa, relax, ramp_val);
100+
const Double proj_i = musclReconstruction(grad_i, vector_ij, delta_ij, iVar, kappa, umusclRamp);
101+
const Double proj_j = musclReconstruction(grad_j, vector_ij, delta_ij, iVar, kappa, umusclRamp);
104102

105103
/*--- Apply reconstruction: V_L = V_i + 0.5 * dV_ij^kap ---*/
106104
V.i.all(iVar) += 0.5 * proj_i;
@@ -119,8 +117,7 @@ FORCEINLINE void musclPointLimited(Int iPoint,
119117
const Gradient_t& gradient,
120118
CPair<VarType>& V,
121119
Double kappa,
122-
Double relax,
123-
Double ramp_val) {
120+
Double umusclRamp) {
124121
constexpr auto nVarGrad = nVarGrad_ > 0 ? nVarGrad_ : VarType::nVar;
125122

126123
auto lim_i = gatherVariables<nVarGrad>(iPoint, limiter);
@@ -134,8 +131,8 @@ FORCEINLINE void musclPointLimited(Int iPoint,
134131
const Double delta_ij = V.j.all(iVar) - V.i.all(iVar);
135132

136133
/*--- U-MUSCL reconstructed variables ---*/
137-
const Double proj_i = musclReconstruction(grad_i, vector_ij, delta_ij, iVar, kappa, relax, ramp_val);
138-
const Double proj_j = musclReconstruction(grad_j, vector_ij, delta_ij, iVar, kappa, relax, ramp_val);
134+
const Double proj_i = musclReconstruction(grad_i, vector_ij, delta_ij, iVar, kappa, umusclRamp);
135+
const Double proj_j = musclReconstruction(grad_j, vector_ij, delta_ij, iVar, kappa, umusclRamp);
139136

140137
/*--- Apply reconstruction: V_L = V_i + 0.5 * lim * dV_ij^kap ---*/
141138
V.i.all(iVar) += 0.5 * lim_i(iVar) * proj_i;
@@ -153,8 +150,7 @@ FORCEINLINE void musclEdgeLimited(Int iPoint,
153150
const Gradient_t& gradient,
154151
CPair<VarType>& V,
155152
Double kappa,
156-
Double relax,
157-
Double ramp_val) {
153+
Double umusclRamp) {
158154
constexpr auto nVarGrad = nVarGrad_ > 0 ? nVarGrad_ : VarType::nVar;
159155

160156
auto grad_i = gatherVariables<nVarGrad,nDim>(iPoint, gradient);
@@ -166,8 +162,8 @@ FORCEINLINE void musclEdgeLimited(Int iPoint,
166162
const Double delta_ij_2 = pow(delta_ij, 2) + 1e-6;
167163

168164
/*--- U-MUSCL reconstructed variables ---*/
169-
const Double proj_i = musclReconstruction(grad_i, vector_ij, delta_ij, iVar, kappa, relax, ramp_val);
170-
const Double proj_j = musclReconstruction(grad_j, vector_ij, delta_ij, iVar, kappa, relax, ramp_val);
165+
const Double proj_i = musclReconstruction(grad_i, vector_ij, delta_ij, iVar, kappa, umusclRamp);
166+
const Double proj_j = musclReconstruction(grad_j, vector_ij, delta_ij, iVar, kappa, umusclRamp);
171167

172168
/// TODO: Customize the limiter function.
173169
const Double lim_i = (delta_ij_2 + proj_i*delta_ij) / (pow(proj_i,2) + delta_ij_2);
@@ -187,7 +183,7 @@ FORCEINLINE void musclEdgeLimited(Int iPoint,
187183
* \param[in] gasConst - Specific gas constant.
188184
* \param[in] muscl - If true, reconstruct, else simply fetch.
189185
* \param[in] kappa - Blending coefficient for MUSCL reconstruction.
190-
* \param[in] relax - Newton-Krylov relaxation.
186+
* \param[in] umusclRamp - MUSCL 1st-2nd order ramp times Newton-Krylov relaxation.
191187
* \param[in] limiterType - Type of flux limiter.
192188
* \param[in] V1st - Pair of compressible flow primitives for nodes i,j.
193189
* \param[in] vector_ij - Distance vector from i to j.
@@ -200,12 +196,11 @@ FORCEINLINE CPair<ReconVarType> reconstructPrimitives(Int iEdge, Int iPoint, Int
200196
const su2double& gasConst,
201197
bool muscl,
202198
const su2double& kappa,
203-
const su2double& relax,
199+
const su2double& umusclRamp,
204200
LIMITER limiterType,
205201
const CPair<PrimVarType>& V1st,
206202
const VectorDbl<nDim>& vector_ij,
207-
const VariableType& solution,
208-
const su2double& ramp_val) {
203+
const VariableType& solution) {
209204
static_assert(ReconVarType::nVar <= PrimVarType::nVar);
210205

211206
const auto& gradients = solution.GetGradient_Reconstruction();
@@ -223,13 +218,13 @@ FORCEINLINE CPair<ReconVarType> reconstructPrimitives(Int iEdge, Int iPoint, Int
223218
constexpr auto nVarGrad = ReconVarType::nVar - 2;
224219
switch (limiterType) {
225220
case LIMITER::NONE:
226-
musclUnlimited<nVarGrad>(iPoint, jPoint, vector_ij, gradients, V, kappa, relax, ramp_val);
221+
musclUnlimited<nVarGrad>(iPoint, jPoint, vector_ij, gradients, V, kappa, umusclRamp);
227222
break;
228223
case LIMITER::VAN_ALBADA_EDGE:
229-
musclEdgeLimited<nVarGrad>(iPoint, jPoint, vector_ij, gradients, V, kappa, relax, ramp_val);
224+
musclEdgeLimited<nVarGrad>(iPoint, jPoint, vector_ij, gradients, V, kappa, umusclRamp);
230225
break;
231226
default:
232-
musclPointLimited<nVarGrad>(iPoint, jPoint, vector_ij, limiters, gradients, V, kappa, relax, ramp_val);
227+
musclPointLimited<nVarGrad>(iPoint, jPoint, vector_ij, limiters, gradients, V, kappa, umusclRamp);
233228
break;
234229
}
235230
/*--- Recompute density using the reconstructed pressure and temperature. ---*/

SU2_CFD/include/numerics_simd/flow/convection/roe.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class CRoeBase : public Base {
9898
AD::StartPreacc();
9999

100100
const bool implicit = (config.GetKind_TimeIntScheme() == EULER_IMPLICIT);
101-
const auto nkRelax = config.GetNewtonKrylovRelaxation();
101+
const auto umusclRamp = config.GetMUSCLRampValue() * config.GetNewtonKrylovRelaxation();
102102
const auto& solution = static_cast<const CEulerVariable&>(solution_);
103103

104104
const auto iPoint = geometry.edges->GetNode(iEdge,0);
@@ -123,7 +123,7 @@ class CRoeBase : public Base {
123123

124124
/*--- Recompute density and enthalpy instead of reconstructing. ---*/
125125
auto V = reconstructPrimitives<CCompressiblePrimitives<nDim,nPrimVarGrad> >(
126-
iEdge, iPoint, jPoint, gamma, gasConst, muscl, umusclKappa, nkRelax, typeLimiter, V1st, vector_ij, solution, config.GetMUSCLRampValue());
126+
iEdge, iPoint, jPoint, gamma, gasConst, muscl, umusclKappa, umusclRamp, typeLimiter, V1st, vector_ij, solution);
127127

128128
/*--- Compute conservative variables. ---*/
129129

SU2_CFD/include/solvers/CScalarSolver.inl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ void CScalarSolver<VariableType>::Upwind_Residual(CGeometry* geometry, CSolver**
145145
/*--- U-MUSCL reconstruction ---*/
146146
const su2double kappa = config->GetMUSCL_Kappa();
147147
const su2double kappaFlow = config->GetMUSCL_Kappa_Flow();
148+
const su2double musclRamp = config->GetMUSCLRampValue();
148149

149150
auto* flowNodes = su2staticcast_p<CFlowVariable*>(solver_container[FLOW_SOL]->GetNodes());
150151
const auto& edgeMassFluxes = *(solver_container[FLOW_SOL]->GetEdgeMassFluxes());
@@ -222,8 +223,8 @@ void CScalarSolver<VariableType>::Upwind_Residual(CGeometry* geometry, CSolver**
222223
for (auto iVar = 0u; iVar < solver_container[FLOW_SOL]->GetnPrimVarGrad(); iVar++) {
223224
const su2double V_ij = V_j[iVar] - V_i[iVar];
224225

225-
su2double Project_Grad_i = MUSCL_Reconstruction(Gradient_i[iVar], Vector_ij, V_ij, kappaFlow, config->GetMUSCLRampValue());
226-
su2double Project_Grad_j = MUSCL_Reconstruction(Gradient_j[iVar], Vector_ij, V_ij, kappaFlow, config->GetMUSCLRampValue());
226+
su2double Project_Grad_i = MUSCL_Reconstruction(Gradient_i[iVar], Vector_ij, V_ij, kappaFlow, musclRamp);
227+
su2double Project_Grad_j = MUSCL_Reconstruction(Gradient_j[iVar], Vector_ij, V_ij, kappaFlow, musclRamp);
227228

228229
if (limiterFlow) {
229230
Project_Grad_i *= Limiter_i[iVar];
@@ -251,8 +252,8 @@ void CScalarSolver<VariableType>::Upwind_Residual(CGeometry* geometry, CSolver**
251252
for (auto iVar = 0u; iVar < nVar; iVar++) {
252253
const su2double U_ij = Scalar_j[iVar] - Scalar_i[iVar];
253254

254-
su2double Project_Grad_i = MUSCL_Reconstruction(Gradient_i[iVar], Vector_ij, U_ij, kappa, config->GetMUSCLRampValue());
255-
su2double Project_Grad_j = MUSCL_Reconstruction(Gradient_j[iVar], Vector_ij, U_ij, kappa, config->GetMUSCLRampValue());
255+
su2double Project_Grad_i = MUSCL_Reconstruction(Gradient_i[iVar], Vector_ij, U_ij, kappa, musclRamp);
256+
su2double Project_Grad_j = MUSCL_Reconstruction(Gradient_j[iVar], Vector_ij, U_ij, kappa, musclRamp);
256257

257258
if (limiter) {
258259
Project_Grad_i *= Limiter_i[iVar];

SU2_CFD/include/solvers/CSolver.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,10 +587,11 @@ class CSolver {
587587
* \param[in] vector_ij - Distance vector.
588588
* \param[in] delta_ij - Centered difference.
589589
* \param[in] kappa - Blending coefficient for U-MUSCL reconstruction.
590-
* \param[in] ramp_val - Value of the ramp
590+
* \param[in] ramp_val - Value of the 1st-2nd order MUSCL ramp.
591591
* \return - Projected variable.
592592
*/
593-
inline su2double MUSCL_Reconstruction(const su2double* grad, const su2double* vector_ij, su2double delta_ij, su2double kappa, su2double ramp_val) {
593+
FORCEINLINE su2double MUSCL_Reconstruction(const su2double* grad, const su2double* vector_ij, su2double delta_ij,
594+
su2double kappa, su2double ramp_val) const {
594595
su2double project_grad = GeometryToolbox::DotProduct(nDim, grad, vector_ij);
595596
return ramp_val * LimiterHelpers<>::umusclProjection(project_grad, delta_ij, kappa);
596597
}

SU2_CFD/src/integration/CNewtonIntegration.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,11 @@ void CNewtonIntegration::MultiGrid_Iteration(CGeometry ****geometry_, CSolver **
184184

185185
if (!setup) { Setup(); setup = true; }
186186

187-
// Ramp from 1st to 2nd order during the startup.
188-
su2double baseNkRelaxation = 1;
189-
if (startupPeriod && startupIters > 0 && !config->GetRestart()) {
190-
baseNkRelaxation = su2double(startupIters - iter) / startupIters;
191-
}
192-
config->SetNewtonKrylovRelaxation(baseNkRelaxation);
187+
/*--- Remove NK relaxation to compute the current residual. ---*/
188+
config->SetNewtonKrylovRelaxation(1.0);
193189

194-
// When using NK relaxation (not fully 2nd order Jacobian products) we need an additional
195-
// residual evaluation that is used as the reference for finite differences.
190+
/*--- When using NK relaxation (not fully 2nd order Jacobian products) we need an additional
191+
* residual evaluation that is used as the reference for finite differences. ---*/
196192
LinSysRes0 = (!startupPeriod && nkRelaxation < 1) ? &LinSysResRelax : &LinSysRes;
197193

198194
SU2_OMP_PARALLEL_(if(solvers[FLOW_SOL]->GetHasHybridParallel())) {

SU2_CFD/src/solvers/CEulerSolver.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,7 +1799,6 @@ void CEulerSolver::Upwind_Residual(CGeometry *geometry, CSolver **solver_contain
17991799
}
18001800

18011801
const bool implicit = (config->GetKind_TimeIntScheme() == EULER_IMPLICIT);
1802-
const su2double nkRelax = config->GetNewtonKrylovRelaxation();
18031802

18041803
const bool roe_turkel = (config->GetKind_Upwind_Flow() == UPWIND::TURKEL);
18051804
const auto kind_dissipation = config->GetKind_RoeLowDiss();
@@ -1809,6 +1808,7 @@ void CEulerSolver::Upwind_Residual(CGeometry *geometry, CSolver **solver_contain
18091808
const bool van_albada = (config->GetKind_SlopeLimit_Flow() == LIMITER::VAN_ALBADA_EDGE);
18101809

18111810
const su2double kappa = config->GetMUSCL_Kappa_Flow();
1811+
const su2double musclRamp = config->GetMUSCLRampValue() * config->GetNewtonKrylovRelaxation();
18121812

18131813
/*--- Non-physical counter. ---*/
18141814
unsigned long counter_local = 0;
@@ -1886,8 +1886,8 @@ void CEulerSolver::Upwind_Residual(CGeometry *geometry, CSolver **solver_contain
18861886
for (auto iVar = 0u; iVar < nPrimVarGrad; iVar++) {
18871887
const su2double V_ij = V_j[iVar] - V_i[iVar];
18881888

1889-
const su2double Project_Grad_i = nkRelax * MUSCL_Reconstruction(Gradient_i[iVar], Vector_ij, V_ij, kappa, config->GetMUSCLRampValue());
1890-
const su2double Project_Grad_j = nkRelax * MUSCL_Reconstruction(Gradient_j[iVar], Vector_ij, V_ij, kappa, config->GetMUSCLRampValue());
1889+
const su2double Project_Grad_i = MUSCL_Reconstruction(Gradient_i[iVar], Vector_ij, V_ij, kappa, musclRamp);
1890+
const su2double Project_Grad_j = MUSCL_Reconstruction(Gradient_j[iVar], Vector_ij, V_ij, kappa, musclRamp);
18911891

18921892
su2double lim_i = 1.0;
18931893
su2double lim_j = 1.0;

SU2_CFD/src/solvers/CIncEulerSolver.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,9 +1239,9 @@ void CIncEulerSolver::Upwind_Residual(CGeometry *geometry, CSolver **solver_cont
12391239
const bool van_albada = (config->GetKind_SlopeLimit_Flow() == LIMITER::VAN_ALBADA_EDGE);
12401240
const bool bounded_scalar = config->GetBounded_Scalar();
12411241
const bool multicomponent = (config->GetKind_FluidModel() == FLUID_MIXTURE);
1242-
const su2double nkRelax = config->GetNewtonKrylovRelaxation();
12431242

12441243
const su2double kappa = config->GetMUSCL_Kappa_Flow();
1244+
const su2double musclRamp = config->GetMUSCLRampValue() * config->GetNewtonKrylovRelaxation();
12451245

12461246
/*--- For hybrid parallel AD, pause preaccumulation if there is shared reading of
12471247
* variables, otherwise switch to the faster adjoint evaluation mode. ---*/
@@ -1289,8 +1289,8 @@ void CIncEulerSolver::Upwind_Residual(CGeometry *geometry, CSolver **solver_cont
12891289
for (auto iVar = 0u; iVar < nPrimVarGrad; iVar++) {
12901290
const su2double V_ij = V_j[iVar] - V_i[iVar];
12911291

1292-
const su2double Project_Grad_i = nkRelax * MUSCL_Reconstruction(Gradient_i[iVar], Vector_ij, V_ij, kappa, config->GetMUSCLRampValue());
1293-
const su2double Project_Grad_j = nkRelax * MUSCL_Reconstruction(Gradient_j[iVar], Vector_ij, V_ij, kappa, config->GetMUSCLRampValue());
1292+
const su2double Project_Grad_i = MUSCL_Reconstruction(Gradient_i[iVar], Vector_ij, V_ij, kappa, musclRamp);
1293+
const su2double Project_Grad_j = MUSCL_Reconstruction(Gradient_j[iVar], Vector_ij, V_ij, kappa, musclRamp);
12941294

12951295
su2double lim_i = 1.0;
12961296
su2double lim_j = 1.0;
@@ -2150,9 +2150,9 @@ void CIncEulerSolver::SetPreconditioner(const CConfig *config, unsigned long iPo
21502150
Therefore, we build inv(Precon) here and multiply by the residual
21512151
later in the R-K and Euler Explicit time integration schemes. ---*/
21522152

2153-
2153+
21542154
Preconditioner[0][0] = Enthalpy * BetaInc2 * dRhodh / Density + BetaInc2;
2155-
2155+
21562156
for (iDim = 0; iDim < nDim; iDim++) Preconditioner[iDim + 1][0] = -1.0 * Velocity[iDim] / Density;
21572157

21582158
if (energy) {

SU2_CFD/src/solvers/CNEMOEulerSolver.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,9 @@ void CNEMOEulerSolver::Upwind_Residual(CGeometry *geometry, CSolver **solver_con
466466
const bool muscl = (config->GetMUSCL_Flow() && (iMesh == MESH_0));
467467
const bool limiter = (config->GetKind_SlopeLimit_Flow() != LIMITER::NONE);
468468
const bool van_albada = (config->GetKind_SlopeLimit_Flow() == LIMITER::VAN_ALBADA_EDGE);
469-
const su2double nkRelax = config->GetNewtonKrylovRelaxation();
470469

471470
const su2double kappa = config->GetMUSCL_Kappa_Flow();
471+
const su2double musclRamp = config->GetMUSCLRampValue() * config->GetNewtonKrylovRelaxation();
472472

473473
/*--- Non-physical counter. ---*/
474474
unsigned long counter_local = 0;
@@ -542,8 +542,8 @@ void CNEMOEulerSolver::Upwind_Residual(CGeometry *geometry, CSolver **solver_con
542542
for (auto iVar = 0ul; iVar < nPrimVarGrad; iVar++) {
543543
const su2double V_ij = V_j[iVar] - V_i[iVar];
544544

545-
Project_Grad_i[iVar] = nkRelax * MUSCL_Reconstruction(Gradient_i[iVar], Vector_ij, V_ij, kappa, config->GetMUSCLRampValue());
546-
Project_Grad_j[iVar] = nkRelax * MUSCL_Reconstruction(Gradient_j[iVar], Vector_ij, V_ij, kappa, config->GetMUSCLRampValue());
545+
Project_Grad_i[iVar] = MUSCL_Reconstruction(Gradient_i[iVar], Vector_ij, V_ij, kappa, musclRamp);
546+
Project_Grad_j[iVar] = MUSCL_Reconstruction(Gradient_j[iVar], Vector_ij, V_ij, kappa, musclRamp);
547547

548548
if (limiter) {
549549
if (van_albada) {

TestCases/rans/oneram6/turb_ONERAM6_nk.cfg

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ LINEAR_SOLVER_ERROR= 0.2
3333
% matrix-free system). 0 is the same as not using NK, 1 is full MUSCL, a negative
3434
% values means "automatic", the solver changes the value so that the linear system
3535
% can be solved.
36-
% If "n0">0, and RESTART_SOL=NO, the NK relaxation is applied to the residual (not
37-
% just to the NK system) to ramp from MUSCL=OFF to ON during "n0" iterations.
3836
NEWTON_KRYLOV_IPARAM= (200, 0, 1) % n0, np, ft
3937
NEWTON_KRYLOV_DPARAM= (0, 0, 0, 1e-5, -1) % r0, tp, rf, e, rnk
4038

0 commit comments

Comments
 (0)