52 #include "Teuchos_LAPACK.hpp" 67 template <
typename T>
using RCP = Teuchos::RCP<T>;
68 template <
typename T>
using vector = std::vector<T>;
75 typedef Teuchos::ParameterList
PL;
112 alpha_.reserve(maxit_);
113 beta_.reserve(maxit_);
118 du2_.reserve(maxit_);
120 work_.reserve(4*maxit_);
122 ipiv_.reserve(maxit_);
126 alpha_.reserve(maxit_);
127 beta_.reserve(maxit_);
129 for( uint j=0; j<
maxit_; ++j ) {
130 Q_.push_back(b.clone());
153 PL &krylovList = parlist.sublist(
"General").sublist(
"Krylov");
154 PL &lanczosList = krylovList.sublist(
"Lanczos");
156 Real tol_default = std::sqrt(ROL_EPSILON<Real>());
158 maxit_ = krylovList_.get(
"Iteration Limit",10);
159 tol_beta_ = lanczosList.get(
"Beta Relative Tolerance", tol_default);
160 tol_ortho_ = lanczosList.get(
"Orthogonality Tolerance", tol_default);
170 void initialize(
const V &x0,
const V &b,
const LO &A, Real &tol ) {
181 beta_[0] = Q_[0]->norm();
182 max_beta_ = std::max(max_beta_,beta_[0]);
183 Q_[0]->scale(1.0/beta_[0]);
186 void reset(
const V &x0,
const V &b,
const LO &A, Real &tol ) {
191 Q_[0]->axpy(-1.0,*u_);
192 beta_[0] = Q_[0]->norm();
193 max_beta_ = std::max(max_beta_,beta_[0]);
194 Q_[0]->scale(1.0/beta_[0]);
203 A.
apply(*u_,*(Q_[k]),tol);
207 u_->axpy(-beta_[k],V_[k_-1]);
209 alpha_[k] = u_->dot(*(V_[k]));
210 u_->axpy(alpha_[k],V_[k_]);
213 delta = u_->dot(*(V_[k-1]));
214 u_->axpy(-delta,*(V_[k-1]));
216 delta = u_->dot(*(V_[k]));
219 if( k_ < maxit_-1 ) {
220 u_->axpy(-delta,*(V_[k_]));
221 beta_[k+1] = u_->norm();
222 max_beta_ = std::max(max_beta_,beta_[k+1]);
223 if(beta_[k+1] < tol_beta_*max_beta_) {
228 V_[k+1]->scale(1.0/beta_[k+1]);
231 Real dotprod = V_[k+1]->dot(*(V_[0]));
233 if( std::sqrt(dotprod) > tol_ortho_ ) {
245 std::vector<Real> Z(1,0);
249 const char COMPZ =
'N':
253 lapack_->STEQR(COMPZ,k_,&d_[0],&du_[0],&Z[0],LDZ,&work_[0],&INFO);
256 return SOLVE_ILLEGAL_VALUE;
258 else if( INFO > 0 ) {
259 return SOLVE_SINGULAR_U;
266 const char TRANS =
'N';
271 for(uint j=0;j<
k_;++j) {
272 d_[j] = alpha_[j]+tau;
277 du2_.assign(maxit_,0);
280 lapack_->GTTRF(k_,&dl_[0],&d_[0],&du_[0],&du2_[0],&ipiv_[0],&INFO);
283 lapack_->GTTRS(TRANS,k_,1,&dl[0],&d_[0],&du_[0],&du2_[0],&ipiv_[0],&y_[0],k_,&INFO);
292 #endif // ROL_LANCZOS_H
void reset(const V &x0, const V &b, const LO &A, Real &tol)
FLAG_SOLVE solve(V &x, Real tau=0)
Contains definitions of custom data types in ROL.
LinearOperator< Real > OP
virtual void apply(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const =0
Apply linear operator.
Teuchos::LAPACK< int, Real > lapack_
Defines the linear algebra or vector space interface.
FLAG_ITERATE iterate(const OP &A, Real &tol)
Interface for computing the Lanczos vectors and approximate solutions to symmetric indefinite linear ...
Provides the interface to apply a linear operator.
void initialize(const V &b)
Teuchos::ParameterList PL
template vector< Real > size_type uint
void initialize(const V &x0, const V &b, const LO &A, Real &tol)
Lanczos(Teuchos::ParameterList &PL)
void eigenvalues(std::vector< Real > &E)