1#ifndef included_AMP_GMRESSolver
2#define included_AMP_GMRESSolver
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"
21template<
typename T =
double>
47 explicit GMRESSolver( std::shared_ptr<SolverStrategyParameters> params );
54 static std::unique_ptr<SolverStrategy>
57 return std::make_unique<GMRESSolver<T>>( params );
65 std::string
type()
const override {
return "GMRESSolver"; }
82 void initialize( std::shared_ptr<const SolverStrategyParameters> params )
override;
99 virtual void orthogonalize(
const int k, std::shared_ptr<AMP::LinearAlgebra::Vector>
v );
107 void cgs(
const int k, std::shared_ptr<AMP::LinearAlgebra::Vector>
v );
112 void cgs2(
const int k, std::shared_ptr<AMP::LinearAlgebra::Vector>
v );
135 std::shared_ptr<AMP::LinearAlgebra::Vector> z,
136 std::shared_ptr<AMP::LinearAlgebra::Vector>
z1,
137 std::shared_ptr<AMP::LinearAlgebra::Vector>
u );
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 );
159 void allocateBasis( std::shared_ptr<const AMP::LinearAlgebra::Vector>
u =
nullptr );
206 std::vector<std::shared_ptr<AMP::LinearAlgebra::Vector>>
d_vBasis;
210 std::vector<std::shared_ptr<AMP::LinearAlgebra::Vector>>
d_zBasis;
213 std::shared_ptr<AMP::LinearAlgebra::Vector>
d_z;
214 std::shared_ptr<AMP::LinearAlgebra::Vector>
d_z1;
std::shared_ptr< Vector > shared_ptr
Shorthand for shared pointer to Vector.
std::shared_ptr< const Vector > const_shared_ptr
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)
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)
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.
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