31#include "../containers/C2DContainer.hpp"
42#include "../option_structure.hpp"
85template <
class ScalarType>
97 ScalarType Residual = 1e-20;
98 unsigned long Iterations = 0;
103 mutable bool cg_ready;
104 mutable bool bcg_ready;
105 mutable bool smooth_ready;
116 mutable bool ritz_failed =
false;
117 mutable unsigned long k = 0, k_new = 0;
118 mutable std::vector<VectorType> Z, V;
119 mutable std::vector<VectorType> W, T;
120 mutable Eigen::Matrix<ScalarType, Eigen::Dynamic, Eigen::Dynamic> VkWk, Q, PinvR;
133 mutable bool xIsZero =
false;
134 bool recomputeRes =
false;
135 unsigned long monitorFreq = 10;
138 std::unique_ptr<CSysSolve<ScalarType>> inner_solver;
149 static inline ScalarType Sign(ScalarType x, ScalarType y) {
150 if (y == 0.0)
return 0.0;
151 return fabs(x) * (y < 0.0 ? -1.0 : 1.0);
161 void ApplyGivens(ScalarType s, ScalarType c, ScalarType& h1, ScalarType& h2)
const;
173 void GenerateGivens(ScalarType& dx, ScalarType& dy, ScalarType& s, ScalarType& c)
const;
207 bool ModGramSchmidt(
bool shared_hsbg,
int i,
su2matrix<ScalarType>& Hsbg, std::vector<VectorType>& w)
const;
217 void WriteHeader(
const std::string& solver, ScalarType restol, ScalarType resinit)
const;
226 void WriteHistory(
unsigned long iter, ScalarType res)
const;
234 void WriteFinalResidual(
const std::string& solver,
unsigned long iter, ScalarType res)
const;
242 void WriteWarning(ScalarType res_calc, ScalarType res_true, ScalarType tol)
const;
250 void UploadSystem(
bool useCuda)
const {
251#ifdef SU2_ENABLE_CUDA_KERNELS
252 if constexpr (su2_gpu_capable_v<ScalarType>) {
253 if (!useCuda)
return;
267 void DownloadSolution(
bool useCuda)
const {
268#ifdef SU2_ENABLE_CUDA_KERNELS
269 if constexpr (su2_gpu_capable_v<ScalarType>) {
270 if (!useCuda)
return;
286 template <
class OtherType>
289 if constexpr (std::is_same_v<ScalarType, OtherType>) {
292 LinSysRes_ptr = &LinSysRes;
293 LinSysSol_ptr = &LinSysSol;
296 UploadSystem(useCuda);
304 LinSysRes_ptr = &LinSysRes_tmp;
305 LinSysSol_ptr = &LinSysSol_tmp;
308 UploadSystem(useCuda);
317 template <
class OtherType>
320 DownloadSolution(useCuda);
321 if constexpr (std::is_same_v<ScalarType, OtherType>) {
324 LinSysRes_ptr =
nullptr;
325 LinSysSol_ptr =
nullptr;
334 LinSysRes_ptr =
nullptr;
335 LinSysSol_ptr =
nullptr;
343 template <
class Dummy =
int>
345 const PrecondType& precond, ScalarType tol,
unsigned long max_iter,
347 unsigned long custom_m)
const;
353 bool SetupInnerSolver(
unsigned short kind_solver,
const CConfig* config);
374 ScalarType tol,
unsigned long m, ScalarType& residual,
bool monitoring,
390 const PrecondType& precond, ScalarType tol,
unsigned long m, ScalarType& residual,
391 bool monitoring,
const CConfig* config)
const;
397 const PrecondType& precond, ScalarType tol,
unsigned long m, ScalarType& residual,
398 bool monitoring,
const CConfig* config)
const;
415 const PrecondType& precond, ScalarType tol,
unsigned long max_iter,
416 ScalarType& residual,
bool monitoring,
const CConfig* config,
432 const PrecondType& precond, ScalarType tol,
unsigned long m, ScalarType& residual,
433 bool monitoring,
const CConfig* config)
const;
448 const PrecondType& precond, ScalarType tol,
unsigned long m, ScalarType& residual,
449 bool monitoring,
const CConfig* config)
const;
472 const CConfig* config,
bool directCall =
true);
474 template <
class OtherType, su2enable_if<!std::is_same_v<ScalarType, OtherType>> = 0>
477 HandleTemporariesIn(LinSysRes, LinSysSol,
false);
478 auto iter =
Solve_b(Jacobian, *LinSysRes_ptr, *LinSysSol_ptr, geometry, config, directCall);
479 HandleTemporariesOut(LinSysSol,
false);
LinearToleranceType
Definition CSysSolve.hpp:60
Declararion and inlines of the vector class used in the solution of large, distributed,...
#define BEGIN_SU2_DEVICE_REGION
Definition CSysVector.hpp:101
#define END_SU2_DEVICE_REGION
Definition CSysVector.hpp:102
A templated matrix/vector-like object.
Definition C2DContainer.hpp:374
Main class for defining the problem; basically this class reads the configuration file,...
Definition CConfig.hpp:64
Parent class for defining the geometry of the problem (complete geometry, multigrid agglomerated geom...
Definition CGeometry.hpp:75
Abstract base class for defining matrix-vector products.
Definition CMatrixVectorProduct.hpp:56
Abstract base class for defining a preconditioning operation.
Definition CPreconditioner.hpp:103
Main class for defining block-compressed-row-storage sparse matrices.
Definition CSysMatrix.hpp:256
Class for solving linear systems using classical and Krylov-subspace iterative methods.
Definition CSysSolve.hpp:86
void SetToleranceType(LinearToleranceType type)
Set the type of the tolerance for stoping the linear solvers (RELATIVE or ABSOLUTE).
Definition CSysSolve.hpp:498
ScalarType Scalar
Definition CSysSolve.hpp:89
unsigned long Solve_b(MatrixType &Jacobian, const CSysVector< OtherType > &LinSysRes, CSysVector< OtherType > &LinSysSol, CGeometry *geometry, const CConfig *config, bool directCall=true)
Definition CSysSolve.hpp:475
unsigned long FGCRODR_LinSolver(const VectorType &b, VectorType &x, const ProductType &mat_vec, const PrecondType &precond, ScalarType tol, unsigned long max_iter, ScalarType &residual, bool monitoring, const CConfig *config, FgcrodrMode mode=FgcrodrMode::NORMAL, unsigned long custom_m=0) const
Flexible Generalized Conjugate Residual Method with Inner Orthogonalization and Deflated Restarting.
Definition CSysSolve.cpp:1045
unsigned long Smoother_LinSolver(const VectorType &b, VectorType &x, const ProductType &mat_vec, const PrecondType &precond, ScalarType tol, unsigned long m, ScalarType &residual, bool monitoring, const CConfig *config) const
Generic smoother (modified Richardson iteration with preconditioner)
Definition CSysSolve.cpp:1248
unsigned long Solve_b(MatrixType &Jacobian, const VectorType &LinSysRes, VectorType &LinSysSol, CGeometry *geometry, const CConfig *config, bool directCall=true)
Solve the adjoint linear system using a Krylov subspace method.
Definition CSysSolve.cpp:1639
ScalarType GetResidual() const
Get the final residual.
Definition CSysSolve.hpp:493
void ResetDeflation() const
Discard FGCRODR's deflation vectors for the next solve.
Definition CSysSolve.hpp:518
void SetMonitoringFrequency(bool frequency)
Set the screen output frequency during monitoring.
Definition CSysSolve.hpp:513
CSysMatrix< ScalarType > MatrixType
Definition CSysSolve.hpp:91
unsigned long BCGSTAB_LinSolver(const VectorType &b, VectorType &x, const ProductType &mat_vec, const PrecondType &precond, ScalarType tol, unsigned long m, ScalarType &residual, bool monitoring, const CConfig *config) const
Biconjugate Gradient Stabilized Method (BCGSTAB)
Definition CSysSolve.cpp:1059
void SetxIsZero(bool isZero)
Assume the initial solution is 0 to save one product, or don't.
Definition CSysSolve.hpp:503
unsigned long CG_LinSolver(const VectorType &b, VectorType &x, const ProductType &mat_vec, const PrecondType &precond, ScalarType tol, unsigned long m, ScalarType &residual, bool monitoring, const CConfig *config) const
Conjugate Gradient method.
Definition CSysSolve.cpp:270
CPreconditioner< ScalarType > PrecondType
Definition CSysSolve.hpp:93
unsigned long RFGMRES_LinSolver(const VectorType &b, VectorType &x, const ProductType &mat_vec, const PrecondType &precond, ScalarType tol, unsigned long m, ScalarType &residual, bool monitoring, const CConfig *config) const
Flexible Generalized Minimal Residual method with restarts (frequency comes from config).
Definition CSysSolve.cpp:627
unsigned long Solve(MatrixType &Jacobian, const CSysVector< su2double > &LinSysRes, CSysVector< su2double > &LinSysSol, CGeometry *geometry, const CConfig *config)
Solve the linear system using a Krylov subspace method.
Definition CSysSolve.cpp:1406
CSysVector< ScalarType > VectorType
Definition CSysSolve.hpp:90
unsigned long FGMRES_LinSolver(const VectorType &b, VectorType &x, const ProductType &mat_vec, const PrecondType &precond, ScalarType tol, unsigned long m, ScalarType &residual, bool monitoring, const CConfig *config) const
Flexible Generalized Minimal Residual method.
Definition CSysSolve.cpp:421
unsigned long GetIterations() const
Get the number of iterations.
Definition CSysSolve.hpp:487
CMatrixVectorProduct< ScalarType > ProductType
Definition CSysSolve.hpp:92
void SetRecomputeResidual(bool recompRes)
Set whether to recompute residuals at the end (while monitoring only).
Definition CSysSolve.hpp:508
Class for holding and manipulating vectors needed by linear solvers.
Definition CSysVector.hpp:195
void DtHTransfer(bool trigger=true) const
Performs the memory copy from device to host.
Definition CSysVectorGPU.cu:200
void HtDTransfer(bool trigger=true) const
Performs the memory copy from host to device.
Definition CSysVectorGPU.cu:193
void PassiveCopy(const CSysVector< T > &other)
Set our values (resizing if required) by copying from other, the derivative information is lost.
Definition CSysVector.hpp:379
#define SU2_IGNORE_WARNING(WARNING)
Definition code_config.hpp:219
#define SU2_RESTORE_WARNING
Definition code_config.hpp:220
FgcrodrMode
Modes of using FGCRODR.
Definition CSysSolve.hpp:66
@ SAME_MAT
"NORMAL" but knowing the matrix did not change.
@ NORMAL
Solve the linear system.
void SetUseDeviceExpressions(bool)
Definition CSysVector.hpp:120
#define BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS
Definition omp_structure.hpp:187
#define END_SU2_OMP_SAFE_GLOBAL_ACCESS
Definition omp_structure.hpp:192
LINEAR_SOLVER_MODE
Type of operation for the linear system solver, changes the source of solver options.
Definition option_structure.hpp:3027
@ STANDARD
Operate in standard mode.
#define SU2_ZONE_SCOPED
Definition tracy_structure.hpp:39