GEOSX
CGsolver.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University
7  * Copyright (c) 2018-2020 Total, S.A
8  * Copyright (c) 2019- GEOSX Contributors
9  * All rights reserved
10  *
11  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
12  * ------------------------------------------------------------------------------------------------------------
13  */
14 
19 #ifndef GEOSX_LINEARALGEBRA_SOLVERS_CGSOLVER_HPP_
20 #define GEOSX_LINEARALGEBRA_SOLVERS_CGSOLVER_HPP_
21 
22 #include "linearAlgebra/solvers/KrylovSolver.hpp"
23 
24 namespace geosx
25 {
26 
36 template< typename VECTOR >
37 class CGsolver : public KrylovSolver< VECTOR >
38 {
39 public:
40 
43 
45  using Vector = typename Base::Vector;
46 
50 
61  LinearOperator< Vector > const & M,
62  real64 const tolerance,
63  localIndex const maxIterations,
64  integer const verbosity = 0 );
65 
69  virtual ~CGsolver() override;
70 
72 
76 
83  virtual void solve( Vector const & b, Vector & x ) const override final;
84 
85  virtual string methodName() const override final
86  {
87  return "CG";
88  };
89 
91 
92 protected:
93 
96 
97  using Base::m_operator;
98  using Base::m_precond;
99  using Base::m_tolerance;
100  using Base::m_maxIterations;
101  using Base::m_logLevel;
102  using Base::m_result;
103  using Base::m_residualNorms;
105  using Base::logProgress;
106  using Base::logResult;
107 
108 };
109 
110 } // namespace GEOSX
111 
112 #endif /*GEOSX_LINEARALGEBRA_SOLVERS_CGSOLVER_HPP_*/
virtual string methodName() const override final
Get name of the Krylov subspace method.
Definition: CGsolver.hpp:85
typename VectorStorageHelper< VECTOR >::type VectorTemp
Alias for vector type that can be used for temporaries.
virtual void solve(Vector const &b, Vector &x) const override final
Solve preconditioned system.
integer m_logLevel
solver verbosity level
LinearOperator< Vector > const & m_operator
reference to the operator to be solved
LinearOperator< Vector > const & m_precond
reference to the preconditioning operator
void logProgress(localIndex const iter, real64 const rnorm) const
Output iteration progress (called by implementations).
This class implements Conjugate Gradient method for monolithic and block linear operators.
Definition: CGsolver.hpp:37
static VectorTemp createTempVector(Vector const &src)
Helper function to create temporary vectors based on a source vector.
double real64
64-bit floating point type.
Definition: DataTypes.hpp:136
array1d< real64 > m_residualNorms
Absolute residual norms at each iteration (if available)
typename Base::Vector Vector
Alias for template parameter.
typename KrylovSolver< VECTOR >::VectorTemp VectorTemp
Alias for vector type that can be used for temporaries.
Definition: CGsolver.hpp:95
real64 m_tolerance
relative residual norm reduction tolerance
virtual ~CGsolver() override
Virtual destructor.
std::int32_t integer
Signed integer type.
Definition: DataTypes.hpp:122
localIndex m_maxIterations
maximum number of Krylov iterations
std::ptrdiff_t localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:125
void logResult() const
Output convergence result (called by implementations).
VECTOR Vector
Alias for template parameter.
LinearSolverResult m_result
results of a solve
Base class for Krylov solvers.
CGsolver(LinearOperator< Vector > const &A, LinearOperator< Vector > const &M, real64 const tolerance, localIndex const maxIterations, integer const verbosity=0)
Constructor.