Skip to content

Commit 5401eb6

Browse files
author
Shubham shukla
authored
Merge branch 'develop' into verify-pr-2587-clean
2 parents aa0056c + f541230 commit 5401eb6

File tree

25 files changed

+688
-172
lines changed

25 files changed

+688
-172
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@
3030
[submodule "externals/FADO"]
3131
path = externals/FADO
3232
url = https://github.com/pcarruscag/FADO.git
33+
[submodule "externals/eigen"]
34+
path = externals/eigen
35+
url = https://gitlab.com/libeigen/eigen.git

Common/include/CConfig.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ class CConfig {
430430
unsigned short nQuasiNewtonSamples; /*!< \brief Number of samples used in quasi-Newton solution methods. */
431431
bool UseVectorization; /*!< \brief Whether to use vectorized numerics schemes. */
432432
bool NewtonKrylov; /*!< \brief Use a coupled Newton method to solve the flow equations. */
433-
array<unsigned short,3> NK_IntParam{{20, 3, 2}}; /*!< \brief Integer parameters for NK method. */
433+
array<unsigned short,4> NK_IntParam{{20, 3, 2, 0}}; /*!< \brief Integer parameters for NK method. */
434434
array<su2double,5> NK_DblParam{{-2.0, 0.1, -3.0, 1e-4, 1.0}}; /*!< \brief Floating-point parameters for NK method. */
435435
su2double NK_Relaxation = 1.0;
436436

@@ -642,6 +642,7 @@ class CConfig {
642642
unsigned long Linear_Solver_Iter; /*!< \brief Max iterations of the linear solver for the implicit formulation. */
643643
unsigned long Deform_Linear_Solver_Iter; /*!< \brief Max iterations of the linear solver for the implicit formulation. */
644644
unsigned long Linear_Solver_Restart_Frequency; /*!< \brief Restart frequency of the linear solver for the implicit formulation. */
645+
unsigned long Linear_Solver_Restart_Deflation; /*!< \brief Number of vectors used for deflated restarts. */
645646
unsigned long Linear_Solver_Prec_Threads; /*!< \brief Number of threads per rank for ILU and LU_SGS preconditioners. */
646647
unsigned short Linear_Solver_ILU_n; /*!< \brief ILU fill=in level. */
647648
su2double SemiSpan; /*!< \brief Wing Semi span. */
@@ -4342,6 +4343,11 @@ class CConfig {
43424343
*/
43434344
unsigned long GetLinear_Solver_Restart_Frequency(void) const { return Linear_Solver_Restart_Frequency; }
43444345

4346+
/*!
4347+
* \brief Get the number of vectors used for deflated restarts.
4348+
*/
4349+
unsigned long GetLinear_Solver_Restart_Deflation(void) const { return Linear_Solver_Restart_Deflation; }
4350+
43454351
/*!
43464352
* \brief Get the relaxation factor for iterative linear smoothers.
43474353
* \return Relaxation factor.
@@ -4395,7 +4401,7 @@ class CConfig {
43954401
/*!
43964402
* \brief Get Newton-Krylov integer parameters.
43974403
*/
4398-
array<unsigned short,3> GetNewtonKrylovIntParam() const { return NK_IntParam; }
4404+
array<unsigned short,4> GetNewtonKrylovIntParam() const { return NK_IntParam; }
43994405

44004406
/*!
44014407
* \brief Get Newton-Krylov floating-point parameters.

Common/include/linear_algebra/CSysSolve.hpp

Lines changed: 98 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ class CPreconditioner;
5454
* Absolute tolerance, target residual is tol*||b||. ---*/
5555
enum class LinearToleranceType { RELATIVE, ABSOLUTE };
5656

57+
/*!
58+
* \brief Modes of using FGCRODR.
59+
* \ingroup SpLinSys
60+
*/
61+
enum class FgcrodrMode {
62+
NORMAL, /*!< \brief Solve the linear system. */
63+
SAME_MAT, /*!< \brief "NORMAL" but knowing the matrix did not change. */
64+
};
65+
5766
/*!
5867
* \class CSysSolve
5968
* \ingroup SpLinSys
@@ -83,8 +92,8 @@ class CSysSolve {
8392
ScalarType Residual = 1e-20; /*!< \brief Residual at the end of a call to Solve or Solve_b. */
8493
unsigned long Iterations = 0; /*!< \brief Iterations done in Solve or Solve_b. */
8594

86-
LINEAR_SOLVER_MODE
87-
lin_sol_mode; /*!< \brief Type of operation for the linear system solver, changes the source of solver options. */
95+
/*!< \brief Type of operation for the linear system solver, changes the source of solver options. */
96+
LINEAR_SOLVER_MODE lin_sol_mode;
8897

8998
mutable bool cg_ready; /*!< \brief Indicate if memory used by CG is allocated. */
9099
mutable bool bcg_ready; /*!< \brief Indicate if memory used by BCGSTAB is allocated. */
@@ -98,23 +107,24 @@ class CSysSolve {
98107
mutable VectorType r_0; /*!< \brief The "arbitrary" vector in BCGSTAB. */
99108
mutable VectorType v; /*!< \brief BCGSTAB "v" vector (v = A * M^-1 * p). */
100109

101-
mutable std::vector<VectorType> W; /*!< \brief Large matrix used by FGMRES, w^i+1 = A * z^i. */
102-
mutable std::vector<VectorType> Z; /*!< \brief Large matrix used by FGMRES, preconditioned W. */
103-
104-
VectorType
105-
LinSysSol_tmp; /*!< \brief Temporary used when it is necessary to interface between active and passive types. */
106-
VectorType
107-
LinSysRes_tmp; /*!< \brief Temporary used when it is necessary to interface between active and passive types. */
108-
VectorType*
109-
LinSysSol_ptr; /*!< \brief Pointer to appropriate LinSysSol (set to original or temporary in call to Solve). */
110-
const VectorType*
111-
LinSysRes_ptr; /*!< \brief Pointer to appropriate LinSysRes (set to original or temporary in call to Solve). */
112-
113-
LinearToleranceType tol_type =
114-
LinearToleranceType::ABSOLUTE; /*!< \brief How the linear solvers interpret the tolerance. */
115-
bool xIsZero = false; /*!< \brief If true assume the initial solution is always 0. */
116-
bool recomputeRes = false; /*!< \brief Recompute the residual after inner iterations, if monitoring. */
117-
unsigned long monitorFreq = 10; /*!< \brief Monitoring frequency. */
110+
mutable unsigned long k = 0;
111+
mutable std::vector<VectorType> Z, V; /*!< \brief Large matrices used by FGMRES, v^i+1 = A * z^i. */
112+
mutable std::vector<VectorType> W, T; /*!< \brief Large matrices used by FGCRODR for deflation vectors. */
113+
114+
/*!< \brief Temporary used when it is necessary to interface between active and passive types. */
115+
VectorType LinSysSol_tmp;
116+
/*!< \brief Temporary used when it is necessary to interface between active and passive types. */
117+
VectorType LinSysRes_tmp;
118+
/*!< \brief Pointer to appropriate LinSysSol (set to original or temporary in call to Solve). */
119+
VectorType* LinSysSol_ptr;
120+
/*!< \brief Pointer to appropriate LinSysRes (set to original or temporary in call to Solve). */
121+
const VectorType* LinSysRes_ptr;
122+
123+
/*!< \brief How the linear solvers interpret the tolerance. */
124+
mutable LinearToleranceType tol_type = LinearToleranceType::ABSOLUTE;
125+
mutable bool xIsZero = false; /*!< \brief If true assume the initial solution is always 0. */
126+
bool recomputeRes = false; /*!< \brief Recompute the residual after inner iterations, if monitoring. */
127+
unsigned long monitorFreq = 10; /*!< \brief Monitoring frequency. */
118128

119129
/*!< \brief Inner solver for nested preconditioning. */
120130
std::unique_ptr<CSysSolve<ScalarType>> inner_solver;
@@ -225,72 +235,65 @@ class CSysSolve {
225235

226236
/*!
227237
* \brief Used by Solve for compatibility between passive and active CSysVector.
228-
* \note Same type specialization, temporary variables are not required.
229-
* \param[in] LinSysRes - Linear system residual
230-
* \param[in,out] LinSysSol - Linear system solution
231-
*/
232-
template <class OtherType, su2enable_if<std::is_same<ScalarType, OtherType>::value> = 0>
233-
void HandleTemporariesIn(const CSysVector<OtherType>& LinSysRes, CSysVector<OtherType>& LinSysSol) {
234-
/*--- Set the pointers. ---*/
235-
BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS {
236-
LinSysRes_ptr = &LinSysRes;
237-
LinSysSol_ptr = &LinSysSol;
238-
}
239-
END_SU2_OMP_SAFE_GLOBAL_ACCESS
240-
}
241-
242-
/*!
243-
* \brief Used by Solve for compatibility between passive and active CSysVector.
244-
* \note Different type specialization, copy data into temporary solution and residual vectors.
245238
* \param[in] LinSysRes - Linear system residual
246239
* \param[in,out] LinSysSol - Linear system solution
247240
*/
248-
template <class OtherType, su2enable_if<!std::is_same<ScalarType, OtherType>::value> = 0>
241+
template <class OtherType>
249242
void HandleTemporariesIn(const CSysVector<OtherType>& LinSysRes, CSysVector<OtherType>& LinSysSol) {
250-
/*--- Copy data, the solution is also copied as it serves as initial condition. ---*/
251-
LinSysRes_tmp.PassiveCopy(LinSysRes);
252-
LinSysSol_tmp.PassiveCopy(LinSysSol);
253-
254-
/*--- Set the pointers. ---*/
255-
BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS {
256-
LinSysRes_ptr = &LinSysRes_tmp;
257-
LinSysSol_ptr = &LinSysSol_tmp;
243+
if constexpr (std::is_same_v<ScalarType, OtherType>) {
244+
/*--- Same type specialization, temporary variables are not required. ---*/
245+
BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS {
246+
LinSysRes_ptr = &LinSysRes;
247+
LinSysSol_ptr = &LinSysSol;
248+
}
249+
END_SU2_OMP_SAFE_GLOBAL_ACCESS
250+
} else {
251+
/*--- Copy data, the solution is also copied as it serves as initial condition. ---*/
252+
LinSysRes_tmp.PassiveCopy(LinSysRes);
253+
LinSysSol_tmp.PassiveCopy(LinSysSol);
254+
255+
/*--- Set the pointers. ---*/
256+
BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS {
257+
LinSysRes_ptr = &LinSysRes_tmp;
258+
LinSysSol_ptr = &LinSysSol_tmp;
259+
}
260+
END_SU2_OMP_SAFE_GLOBAL_ACCESS
258261
}
259-
END_SU2_OMP_SAFE_GLOBAL_ACCESS
260262
}
261263

262264
/*!
263265
* \brief Used by Solve for compatibility between passive and active CSysVector.
264-
* \note Same type specialization, temporary variables are not required.
265266
* \param[out] LinSysSol - Linear system solution
266267
*/
267-
template <class OtherType, su2enable_if<std::is_same<ScalarType, OtherType>::value> = 0>
268+
template <class OtherType>
268269
void HandleTemporariesOut(CSysVector<OtherType>& LinSysSol) {
269-
/*--- Reset the pointers. ---*/
270-
BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS {
271-
LinSysRes_ptr = nullptr;
272-
LinSysSol_ptr = nullptr;
270+
if constexpr (std::is_same_v<ScalarType, OtherType>) {
271+
/*--- Same type specialization, temporary variables are not required. ---*/
272+
BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS {
273+
LinSysRes_ptr = nullptr;
274+
LinSysSol_ptr = nullptr;
275+
}
276+
END_SU2_OMP_SAFE_GLOBAL_ACCESS
277+
} else {
278+
/*--- Copy data, only the temporary solution needs to be copied. ---*/
279+
LinSysSol.PassiveCopy(LinSysSol_tmp);
280+
281+
/*--- Reset the pointers. ---*/
282+
BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS {
283+
LinSysRes_ptr = nullptr;
284+
LinSysSol_ptr = nullptr;
285+
}
286+
END_SU2_OMP_SAFE_GLOBAL_ACCESS
273287
}
274-
END_SU2_OMP_SAFE_GLOBAL_ACCESS
275288
}
276289

277-
/*!
278-
* \brief Used by Solve for compatibility between passive and active CSysVector.
279-
* \note Different type specialization, copy data from the temporary solution vector.
280-
* \param[out] LinSysSol - Linear system solution
281-
*/
282-
template <class OtherType, su2enable_if<!std::is_same<ScalarType, OtherType>::value> = 0>
283-
void HandleTemporariesOut(CSysVector<OtherType>& LinSysSol) {
284-
/*--- Copy data, only the temporary solution needs to be copied. ---*/
285-
LinSysSol.PassiveCopy(LinSysSol_tmp);
286-
287-
/*--- Reset the pointers. ---*/
288-
BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS {
289-
LinSysRes_ptr = nullptr;
290-
LinSysSol_ptr = nullptr;
291-
}
292-
END_SU2_OMP_SAFE_GLOBAL_ACCESS
293-
}
290+
/*--- TODO(pedro): The deflation part using Eigen does not compile in forward AD mode.
291+
* So we need a dummy template to avoid instantiating this function for directdiff. ---*/
292+
template <class Dummy = int>
293+
unsigned long FGCRODR_LinSolverImpl(const VectorType& b, VectorType& x, const ProductType& mat_vec,
294+
const PrecondType& precond, ScalarType tol, unsigned long max_iter,
295+
ScalarType& residual, bool monitoring, const CConfig* config,
296+
FgcrodrMode mode) const;
294297

295298
public:
296299
/*!
@@ -335,7 +338,25 @@ class CSysSolve {
335338
*/
336339
unsigned long RFGMRES_LinSolver(const VectorType& b, VectorType& x, const ProductType& mat_vec,
337340
const PrecondType& precond, ScalarType tol, unsigned long m, ScalarType& residual,
338-
bool monitoring, const CConfig* config);
341+
bool monitoring, const CConfig* config) const;
342+
343+
/*!
344+
* \brief Flexible Generalized Conjugate Residual Method with Inner Orthogonalization and Deflated Restarting.
345+
* \param[in] b - the right hand size vector
346+
* \param[in,out] x - on entry the intial guess, on exit the solution
347+
* \param[in] mat_vec - object that defines matrix-vector product
348+
* \param[in] precond - object that defines preconditioner
349+
* \param[in] tol - tolerance with which to solve the system
350+
* \param[in] max_iter - maximum number of iterations
351+
* \param[out] residual - final normalized residual
352+
* \param[in] monitoring - turn on priting residuals from solver to screen.
353+
* \param[in] config - Definition of the particular problem.
354+
* \param[in] mode - See FgcrodrMode.
355+
*/
356+
unsigned long FGCRODR_LinSolver(const VectorType& b, VectorType& x, const ProductType& mat_vec,
357+
const PrecondType& precond, ScalarType tol, unsigned long max_iter,
358+
ScalarType& residual, bool monitoring, const CConfig* config,
359+
FgcrodrMode mode = FgcrodrMode::NORMAL) const;
339360

340361
/*!
341362
* \brief Biconjugate Gradient Stabilized Method (BCGSTAB)
@@ -390,7 +411,7 @@ class CSysSolve {
390411
* \param[in] directCall - If this method is called directly, or in AD context.
391412
*/
392413
unsigned long Solve_b(MatrixType& Jacobian, const CSysVector<su2double>& LinSysRes, CSysVector<su2double>& LinSysSol,
393-
CGeometry* geometry, const CConfig* config, const bool directCall = true);
414+
CGeometry* geometry, const CConfig* config, bool directCall = true);
394415

395416
/*!
396417
* \brief Get the number of iterations.
@@ -423,4 +444,9 @@ class CSysSolve {
423444
* \brief Set the screen output frequency during monitoring.
424445
*/
425446
inline void SetMonitoringFrequency(bool frequency) { monitorFreq = frequency; }
447+
448+
/*!
449+
* \brief Discard FGCRODR's deflation vectors for the next solve.
450+
*/
451+
inline void ResetDeflation() const { k = 0; }
426452
};

Common/include/linear_algebra/CSysVector.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class CSysVector : public VecExpr::CVecExpr<CSysVector<ScalarType>, ScalarType>
6666
private:
6767
enum { OMP_MAX_SIZE = 4096 }; /*!< \brief Maximum chunk size used in parallel for loops. */
6868

69+
/// NOTE: Update swap() if you add member variables.
6970
unsigned long omp_chunk_size = OMP_MAX_SIZE; /*!< \brief Static chunk size used in loops. */
7071
ScalarType* vec_val = nullptr; /*!< \brief Storage, 64 byte aligned (do not use normal new/delete). */
7172
unsigned long nElm = 0; /*!< \brief Total number of elements (or number elements on this processor). */
@@ -155,6 +156,18 @@ class CSysVector : public VecExpr::CVecExpr<CSysVector<ScalarType>, ScalarType>
155156
*/
156157
CSysVector(const CSysVector& u) { Initialize(u.GetNBlk(), u.GetNBlkDomain(), u.nVar, u.vec_val, true); }
157158

159+
/*!
160+
* \brief Swap contents with another vector.
161+
*/
162+
void swap(CSysVector& other) {
163+
std::swap(omp_chunk_size, other.omp_chunk_size);
164+
std::swap(vec_val, other.vec_val);
165+
std::swap(d_vec_val, other.d_vec_val);
166+
std::swap(nElm, other.nElm);
167+
std::swap(nElmDomain, other.nElmDomain);
168+
std::swap(nVar, other.nVar);
169+
}
170+
158171
/*!
159172
* \brief Initialize the class with a scalar.
160173
* \param[in] numBlk - number of blocks locally

Common/include/option_structure.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2352,9 +2352,10 @@ static const MapType<std::string, ENUM_FFD_BLENDING> Blending_Map = {
23522352
*/
23532353
enum ENUM_LINEAR_SOLVER {
23542354
CONJUGATE_GRADIENT, /*!< \brief Preconditionated conjugate gradient method for grid deformation. */
2355-
FGMRES, /*!< \brief Flexible Generalized Minimal Residual method. */
23562355
BCGSTAB, /*!< \brief BCGSTAB - Biconjugate Gradient Stabilized Method (main solver). */
2356+
FGMRES, /*!< \brief Flexible Generalized Minimal Residual method. */
23572357
RESTARTED_FGMRES, /*!< \brief Flexible Generalized Minimal Residual method with restart. */
2358+
FGCRODR, /*!< \brief Flexible Generalized Conjugate Residual Method with Inner Orthogonalization and Deflated Restarting. */
23582359
SMOOTHER, /*!< \brief Iterative smoother. */
23592360
PASTIX_LDLT, /*!< \brief PaStiX LDLT (complete) factorization. */
23602361
PASTIX_LU, /*!< \brief PaStiX LU (complete) factorization. */
@@ -2364,6 +2365,7 @@ static const MapType<std::string, ENUM_LINEAR_SOLVER> Linear_Solver_Map = {
23642365
MakePair("BCGSTAB", BCGSTAB)
23652366
MakePair("FGMRES", FGMRES)
23662367
MakePair("RESTARTED_FGMRES", RESTARTED_FGMRES)
2368+
MakePair("FGCRODR", FGCRODR)
23672369
MakePair("SMOOTHER", SMOOTHER)
23682370
MakePair("PASTIX_LDLT", PASTIX_LDLT)
23692371
MakePair("PASTIX_LU", PASTIX_LU)

Common/src/CConfig.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,6 +1883,8 @@ void CConfig::SetConfig_Options() {
18831883
addUnsignedShortOption("LINEAR_SOLVER_ILU_FILL_IN", Linear_Solver_ILU_n, 0);
18841884
/* DESCRIPTION: Maximum number of iterations of the linear solver for the implicit formulation */
18851885
addUnsignedLongOption("LINEAR_SOLVER_RESTART_FREQUENCY", Linear_Solver_Restart_Frequency, 10);
1886+
/* DESCRIPTION: Number of vectors used for deflated restarts */
1887+
addUnsignedLongOption("LINEAR_SOLVER_RESTART_DEFLATION", Linear_Solver_Restart_Deflation, 4);
18861888
/* DESCRIPTION: Relaxation factor for iterative linear smoothers (SMOOTHER_ILU/JACOBI/LU-SGS/LINELET) */
18871889
addDoubleOption("LINEAR_SOLVER_SMOOTHER_RELAXATION", Linear_Solver_Smoother_Relaxation, 1.0);
18881890
/* DESCRIPTION: Custom number of threads used for additive domain decomposition for ILU and LU_SGS (0 is "auto"). */
@@ -7264,10 +7266,11 @@ void CConfig::SetOutput(SU2_COMPONENT val_software, unsigned short val_izone) {
72647266
if (Kind_Linear_Solver == BCGSTAB) {
72657267
cout << "BCGSTAB is used for solving the linear system." << endl;
72667268
} else {
7269+
const std::string name = Kind_Linear_Solver == FGCRODR ? "FGCRODR" : "FGMRES";
72677270
if (Kind_Linear_Solver_Inner == LINEAR_SOLVER_INNER::BCGSTAB){
7268-
cout << "Nested FGMRES (FGMRES with inner BiCGSTAB) is used for solving the linear system." << endl;
7271+
cout << "Nested " << name << " (with inner BiCGSTAB) is used for solving the linear system." << endl;
72697272
} else {
7270-
cout << "FGMRES is used for solving the linear system." << endl;
7273+
cout << name << " is used for solving the linear system." << endl;
72717274
}
72727275
}
72737276
switch (Kind_Linear_Solver_Prec) {
@@ -7319,6 +7322,11 @@ void CConfig::SetOutput(SU2_COMPONENT val_software, unsigned short val_izone) {
73197322
if (Kind_Linear_Solver_Inner == LINEAR_SOLVER_INNER::BCGSTAB)
73207323
cout << "Nested BiCGSTAB is used as the inner solver." << endl;
73217324
break;
7325+
case FGCRODR:
7326+
cout << "FGCRODR is used for solving the linear system." << endl;
7327+
cout << "Convergence criteria of the linear solver: "<< Linear_Solver_Error <<"."<< endl;
7328+
cout << "Max number of iterations: "<< Linear_Solver_Iter <<"."<< endl;
7329+
break;
73227330
case CONJUGATE_GRADIENT:
73237331
cout << "A Conjugate Gradient method is used for solving the linear system." << endl;
73247332
cout << "Convergence criteria of the linear solver: "<< Linear_Solver_Error <<"."<< endl;

0 commit comments

Comments
 (0)