Advanced Multi-Physics (AMP)
On-Line Documentation
GMRESSolver.h
Go to the documentation of this file.
1#ifndef included_AMP_GMRESSolver
2#define included_AMP_GMRESSolver
3
4#include "AMP/solvers/SolverStrategy.h"
5#include "AMP/solvers/SolverStrategyParameters.h"
6#include "AMP/utils/AMP_MPI.h"
7#include "AMP/utils/Array.h"
8
9namespace AMP::Solver {
10
21template<typename T = double>
23{
24public:
29
47 explicit GMRESSolver( std::shared_ptr<SolverStrategyParameters> params );
48
54 static std::unique_ptr<SolverStrategy>
55 createSolver( std::shared_ptr<SolverStrategyParameters> params )
56 {
57 return std::make_unique<GMRESSolver<T>>( params );
58 }
59
63 virtual ~GMRESSolver() = default;
64
65 std::string type() const override { return "GMRESSolver"; }
66
77
82 void initialize( std::shared_ptr<const SolverStrategyParameters> params ) override;
83
88 void registerOperator( std::shared_ptr<AMP::Operator::Operator> op ) override;
89
93 bool restarted() { return d_bRestart; }
94
95protected:
97 // stored internally. Store the coefficients of the Arnoldi
98 // iteration internally in a upper Hessenberg matrix
99 virtual void orthogonalize( const int k, std::shared_ptr<AMP::LinearAlgebra::Vector> v );
100
102 std::vector<T> basisInnerProducts( const int k, std::shared_ptr<AMP::LinearAlgebra::Vector> v );
103
105 // stored internally using classical Gram-Schmidt. Store the coefficients of the Arnoldi
106 // iteration internally in a upper Hessenberg matrix
107 void cgs( const int k, std::shared_ptr<AMP::LinearAlgebra::Vector> v );
108
110 // stored internally using classical Gram-Schmidt with re-orthogonalization. Store the
111 // coefficients of the Arnoldi iteration internally in a upper Hessenberg matrix
112 void cgs2( const int k, std::shared_ptr<AMP::LinearAlgebra::Vector> v );
113
115 void applyGivensRotation( const int i, const int k );
116
120 void computeGivensRotation( const int k );
121
125 void backwardSolve( const int nr );
126
134 void addCorrection( const int nr,
135 std::shared_ptr<AMP::LinearAlgebra::Vector> z,
136 std::shared_ptr<AMP::LinearAlgebra::Vector> z1,
137 std::shared_ptr<AMP::LinearAlgebra::Vector> u );
138
148 std::shared_ptr<const AMP::LinearAlgebra::Vector> f,
149 std::shared_ptr<AMP::LinearAlgebra::Vector> u,
150 std::shared_ptr<AMP::LinearAlgebra::Vector> tmp,
151 std::shared_ptr<AMP::LinearAlgebra::Vector> res );
152
153 void getFromInput( std::shared_ptr<AMP::Database> db );
154
155private:
159 void allocateBasis( std::shared_ptr<const AMP::LinearAlgebra::Vector> u = nullptr );
160
161 bool d_bRestart = false;
162
165
167
169
175 std::string d_sOrthogonalizationMethod = "MGS";
176
181 std::string d_preconditioner_side = "right";
182
185
188 bool d_bFlexibleGMRES = false;
189
192
194 // when Givens is being used
195 std::vector<T> d_dcos;
196 std::vector<T> d_dsin;
197
199 std::vector<T> d_dw;
200
202 std::vector<T> d_dy;
203
206 std::vector<std::shared_ptr<AMP::LinearAlgebra::Vector>> d_vBasis;
207
210 std::vector<std::shared_ptr<AMP::LinearAlgebra::Vector>> d_zBasis;
211
213 std::shared_ptr<AMP::LinearAlgebra::Vector> d_z;
214 std::shared_ptr<AMP::LinearAlgebra::Vector> d_z1;
215};
216} // namespace AMP::Solver
217
218#endif
std::shared_ptr< Vector > shared_ptr
Shorthand for shared pointer to Vector.
Definition Vector.h:60
std::shared_ptr< const Vector > const_shared_ptr
Definition Vector.h:65
std::string d_sOrthogonalizationMethod
logs number of times the solver is restarted
int d_restarts
size of the allocation increases for the vector basis
void getFromInput(std::shared_ptr< AMP::Database > db)
std::vector< T > d_dsin
void backwardSolve(const int nr)
AMP::Array< T > d_dHessenberg
stores the upper Hessenberg matrix formed during the GMRES iteration
virtual void orthogonalize(const int k, std::shared_ptr< AMP::LinearAlgebra::Vector > v)
orthogonalize the vector against the existing vectors in the basis
void apply(AMP::LinearAlgebra::Vector::const_shared_ptr f, AMP::LinearAlgebra::Vector::shared_ptr u) override
std::vector< T > d_dw
stores the right hand side for the Hessenberg least squares system
std::vector< T > basisInnerProducts(const int k, std::shared_ptr< AMP::LinearAlgebra::Vector > v)
return the inner products of v against the first k basis vectors
int d_iMaxKrylovDimension
whether to restart
void computeGivensRotation(const int k)
std::string d_preconditioner_side
std::vector< std::shared_ptr< AMP::LinearAlgebra::Vector > > d_zBasis
std::shared_ptr< AMP::LinearAlgebra::Vector > d_z
stores the vectors needed for right and left preconditioning
void registerOperator(std::shared_ptr< AMP::Operator::Operator > op) override
void computeInitialResidual(bool use_zero_guess, std::shared_ptr< const AMP::LinearAlgebra::Vector > f, std::shared_ptr< AMP::LinearAlgebra::Vector > u, std::shared_ptr< AMP::LinearAlgebra::Vector > tmp, std::shared_ptr< AMP::LinearAlgebra::Vector > res)
void allocateBasis(std::shared_ptr< const AMP::LinearAlgebra::Vector > u=nullptr)
bool d_bUsesPreconditioner
boolean, for whether a preconditioner present or not
std::vector< std::shared_ptr< AMP::LinearAlgebra::Vector > > d_vBasis
std::vector< T > d_dcos
stores the cosine and sine values required for Givens rotations
std::shared_ptr< AMP::LinearAlgebra::Vector > d_z1
void cgs2(const int k, std::shared_ptr< AMP::LinearAlgebra::Vector > v)
orthogonalize the vector against the existing vectors in the basis
static std::unique_ptr< SolverStrategy > createSolver(std::shared_ptr< SolverStrategyParameters > params)
Definition GMRESSolver.h:55
void addCorrection(const int nr, std::shared_ptr< AMP::LinearAlgebra::Vector > z, std::shared_ptr< AMP::LinearAlgebra::Vector > z1, std::shared_ptr< AMP::LinearAlgebra::Vector > u)
void applyGivensRotation(const int i, const int k)
apply the i-th Givens rotation to the k-th column of the Hessenberg matrix
virtual ~GMRESSolver()=default
void initialize(std::shared_ptr< const SolverStrategyParameters > params) override
void cgs(const int k, std::shared_ptr< AMP::LinearAlgebra::Vector > v)
orthogonalize the vector against the existing vectors in the basis
std::string type() const override
Return the name of the solver.
Definition GMRESSolver.h:65
std::vector< T > d_dy
stores the solution for the least squares system
GMRESSolver(std::shared_ptr< SolverStrategyParameters > params)
std::shared_ptr< AMP::Solver::SolverStrategy > shared_ptr



Advanced Multi-Physics (AMP)
Oak Ridge National Laboratory
Idaho National Laboratory
Los Alamos National Laboratory
This page automatically produced from the
source code by doxygen
Last updated: Tue Mar 10 2026 13:06:41.
Comments on this page