GEOS
CgSolver.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2024 Total, S.A
7  * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
8  * Copyright (c) 2023-2024 Chevron
9  * Copyright (c) 2019- GEOS/GEOSX Contributors
10  * All rights reserved
11  *
12  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
13  * ------------------------------------------------------------------------------------------------------------
14  */
15 
20 #ifndef GEOS_LINEARALGEBRA_SOLVERS_CGSOLVER_HPP_
21 #define GEOS_LINEARALGEBRA_SOLVERS_CGSOLVER_HPP_
22 
23 #include "linearAlgebra/solvers/KrylovSolver.hpp"
24 
25 namespace geos
26 {
27 
37 template< typename VECTOR >
38 class CgSolver : public KrylovSolver< VECTOR >
39 {
40 public:
41 
44 
46  using Vector = typename Base::Vector;
47 
52 
60  LinearOperator< Vector > const & A,
61  LinearOperator< Vector > const & M );
62 
64 
69 
75  virtual void solve( Vector const & b, Vector & x ) const override final;
76 
77  virtual string methodName() const override final
78  {
79  return "CG";
80  };
81 
83 
84 protected:
85 
88 
89  using Base::m_params;
90  using Base::m_operator;
91  using Base::m_precond;
92  using Base::m_result;
95  using Base::logProgress;
96  using Base::logResult;
97 
98 };
99 
100 } // namespace GEOSX
101 
102 #endif /*GEOS_LINEARALGEBRA_SOLVERS_CGSOLVER_HPP_*/
This class implements Conjugate Gradient method for monolithic and block linear operators.
Definition: CgSolver.hpp:39
virtual string methodName() const override final
Get name of the Krylov subspace method.
Definition: CgSolver.hpp:77
virtual void solve(Vector const &b, Vector &x) const override final
Solve preconditioned system.
typename KrylovSolver< VECTOR >::VectorTemp VectorTemp
Alias for vector type that can be used for temporaries.
Definition: CgSolver.hpp:87
CgSolver(LinearSolverParameters params, LinearOperator< Vector > const &A, LinearOperator< Vector > const &M)
Constructor.
Base class for Krylov solvers.
LinearSolverResult m_result
results of a solve
LinearOperator< Vector > const & m_operator
reference to the operator to be solved
static VectorTemp createTempVector(Vector const &src)
Helper function to create temporary vectors based on a source vector.
void logResult() const
Output convergence result (called by implementations).
typename Base::Vector Vector
Alias for template parameter.
typename VectorStorageHelper< VECTOR >::type VectorTemp
Alias for vector type that can be used for temporaries.
LinearOperator< Vector > const & m_precond
reference to the preconditioning operator
void logProgress() const
Output iteration progress (called by implementations).
array1d< real64 > m_residualNorms
Absolute residual norms at each iteration (if available)
LinearSolverParameters m_params
parameters of the solver
VECTOR Vector
Alias for template parameter.
Set of parameters for a linear solver or preconditioner.