51 #include "ROL_LAPACK.hpp" 66 template <
typename T>
using ROL::Ptr = ROL::Ptr<T>;
67 template <
typename T>
using vector = std::vector<T>;
74 typedef ROL::ParameterList
PL;
111 alpha_.reserve(maxit_);
112 beta_.reserve(maxit_);
117 du2_.reserve(maxit_);
119 work_.reserve(4*maxit_);
121 ipiv_.reserve(maxit_);
125 alpha_.reserve(maxit_);
126 beta_.reserve(maxit_);
128 for( uint j=0; j<
maxit_; ++j ) {
129 Q_.push_back(b.clone());
152 PL &krylovList = parlist.sublist(
"General").sublist(
"Krylov");
153 PL &lanczosList = krylovList.sublist(
"Lanczos");
155 Real tol_default = std::sqrt(ROL_EPSILON<Real>());
157 maxit_ = krylovList_.get(
"Iteration Limit",10);
158 tol_beta_ = lanczosList.get(
"Beta Relative Tolerance", tol_default);
159 tol_ortho_ = lanczosList.get(
"Orthogonality Tolerance", tol_default);
169 void initialize(
const V &x0,
const V &b,
const LO &A, Real &tol ) {
180 beta_[0] = Q_[0]->norm();
181 max_beta_ = std::max(max_beta_,beta_[0]);
182 Q_[0]->scale(1.0/beta_[0]);
185 void reset(
const V &x0,
const V &b,
const LO &A, Real &tol ) {
190 Q_[0]->axpy(-1.0,*u_);
191 beta_[0] = Q_[0]->norm();
192 max_beta_ = std::max(max_beta_,beta_[0]);
193 Q_[0]->scale(1.0/beta_[0]);
202 A.
apply(*u_,*(Q_[k]),tol);
206 u_->axpy(-beta_[k],V_[k_-1]);
208 alpha_[k] = u_->dot(*(V_[k]));
209 u_->axpy(alpha_[k],V_[k_]);
212 delta = u_->dot(*(V_[k-1]));
213 u_->axpy(-delta,*(V_[k-1]));
215 delta = u_->dot(*(V_[k]));
218 if( k_ < maxit_-1 ) {
219 u_->axpy(-delta,*(V_[k_]));
220 beta_[k+1] = u_->norm();
221 max_beta_ = std::max(max_beta_,beta_[k+1]);
222 if(beta_[k+1] < tol_beta_*max_beta_) {
227 V_[k+1]->scale(1.0/beta_[k+1]);
230 Real dotprod = V_[k+1]->dot(*(V_[0]));
232 if( std::sqrt(dotprod) > tol_ortho_ ) {
244 std::vector<Real> Z(1,0);
248 const char COMPZ =
'N':
252 lapack_->STEQR(COMPZ,k_,&d_[0],&du_[0],&Z[0],LDZ,&work_[0],&INFO);
255 return SOLVE_ILLEGAL_VALUE;
257 else if( INFO > 0 ) {
258 return SOLVE_SINGULAR_U;
265 const char TRANS =
'N';
270 for(uint j=0;j<
k_;++j) {
271 d_[j] = alpha_[j]+tau;
276 du2_.assign(maxit_,0);
279 lapack_->GTTRF(k_,&dl_[0],&d_[0],&du_[0],&du2_[0],&ipiv_[0],&INFO);
282 lapack_->GTTRS(TRANS,k_,1,&dl[0],&d_[0],&du_[0],&du2_[0],&ipiv_[0],&y_[0],k_,&INFO);
291 #endif // ROL_LANCZOS_H
void reset(const V &x0, const V &b, const LO &A, Real &tol)
typename PV< Real >::size_type size_type
FLAG_SOLVE solve(V &x, Real tau=0)
ROL::LAPACK< int, Real > lapack_
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.
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 ...
Lanczos(ROL::ParameterList &PL)
Provides the interface to apply a linear operator.
vector< ROL::Ptr< V > > Q_
void initialize(const V &b)
template vector< Real > size_type uint
void initialize(const V &x0, const V &b, const LO &A, Real &tol)
void eigenvalues(std::vector< Real > &E)