55 #include "ROL_LAPACK.hpp"
56 #include "ROL_LinearAlgebra.hpp"
69 ROL::Ptr<Vector<Real> >
r_;
70 ROL::Ptr<Vector<Real> >
z_;
71 ROL::Ptr<Vector<Real> >
w_;
73 ROL::Ptr<SDMatrix>
H_;
74 ROL::Ptr<SDVector>
cs_;
75 ROL::Ptr<SDVector>
sn_;
76 ROL::Ptr<SDVector>
s_;
77 ROL::Ptr<SDVector>
y_;
80 ROL::Ptr<std::vector<Real> >
res_;
98 ROL::ParameterList &gList = parlist.sublist(
"General");
99 ROL::ParameterList &kList = gList.sublist(
"Krylov");
101 useInexact_ = gList.get(
"Inexact Hessian-Times-A-Vector",
false);
105 H_ = ROL::makePtr<SDMatrix>( maxit+1, maxit );
106 cs_ = ROL::makePtr<SDVector>( maxit );
107 sn_ = ROL::makePtr<SDVector>( maxit );
108 s_ = ROL::makePtr<SDVector>( maxit+1 );
109 y_ = ROL::makePtr<SDVector>( maxit+1 );
110 cnorm_ = ROL::makePtr<SDVector>( maxit );
111 res_ = ROL::makePtr<std::vector<Real>>(maxit+1,
zero);
124 Real
zero(0), one(1);
134 Real itol = std::sqrt(ROL_EPSILON<Real>());
151 std::vector<ROL::Ptr<Vector<Real > > >
V;
152 std::vector<ROL::Ptr<Vector<Real > > > Z;
154 (*res_)[0] =
r_->norm();
157 Real rtol = std::min(absTol,relTol*(*
res_)[0]);
158 if ((*
res_)[0] <= rtol) {
164 V.push_back(b.
clone());
166 (V[0])->scale(one/(*
res_)[0]);
168 (*s_)(0) = (*
res_)[0];
170 for( iter=0; iter<maxit; ++iter ) {
175 itol = rtol/(maxit*(*res_)[iter]);
178 Z.push_back(x.
clone());
187 for(
int k=0; k<=iter; ++k ) {
188 (*H_)(k,iter) =
w_->dot(*(V[k]));
189 w_->axpy( -(*
H_)(k,iter), *(V[k]) );
192 (*H_)(iter+1,iter) =
w_->norm();
194 V.push_back( b.
clone() );
195 (V[iter+1])->set(*
w_);
196 (V[iter+1])->scale(one/((*
H_)(iter+1,iter)));
199 for(
int k=0; k<=iter-1; ++k ) {
200 temp = (*cs_)(k)*(*
H_)(k,iter) + (*
sn_)(k)*(*
H_)(k+1,iter);
201 (*H_)(k+1,iter) = -(*
sn_)(k)*(*
H_)(k,iter) + (*
cs_)(k)*(*
H_)(k+1,iter);
202 (*H_)(k,iter) = temp;
206 if( (*
H_)(iter+1,iter) ==
zero ) {
210 else if ( std::abs((*
H_)(iter+1,iter)) > std::abs((*
H_)(iter,iter)) ) {
211 temp = (*H_)(iter,iter) / (*
H_)(iter+1,iter);
212 (*sn_)(iter) = one / std::sqrt( one + temp*temp );
213 (*cs_)(iter) = temp*(*
sn_)(iter);
216 temp = (*H_)(iter+1,iter) / (*
H_)(iter,iter);
217 (*cs_)(iter) = one / std::sqrt( one + temp*temp );
218 (*sn_)(iter) = temp*(*
cs_)(iter);
222 temp = (*cs_)(iter)*(*
s_)(iter);
223 (*s_)(iter+1) = -(*
sn_)(iter)*(*
s_)(iter);
225 (*H_)(iter,iter) = (*
cs_)(iter)*(*
H_)(iter,iter) + (*
sn_)(iter)*(*
H_)(iter+1,iter);
226 (*H_)(iter+1,iter) =
zero;
227 (*res_)[iter+1] = std::abs((*
s_)(iter+1));
230 const char uplo =
'U';
231 const char trans =
'N';
232 const char diag =
'N';
233 const char normin =
'N';
237 lapack_.LATRS(uplo, trans, diag, normin, iter+1,
H_->values(), maxit+1,
y_->values(), &scaling,
cnorm_->values(), &info);
241 for(
int k=0; k<=iter;++k ) {
242 z_->axpy((*
y_)(k),*(Z[k]));
245 if( (*res_)[iter+1] <= rtol ) {
255 return (*
res_)[iter];
258 return (*
res_)[iter+1];
265 #endif // ROL_GMRES_H
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
Real getRelativeTolerance(void) const
Real getAbsoluteTolerance(void) const
virtual void plus(const Vector &x)=0
Compute , where .
GMRES(ROL::ParameterList &parlist)
Contains definitions of custom data types in ROL.
virtual void apply(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const =0
Apply linear operator.
unsigned getMaximumIteration(void) const
virtual void zero()
Set to zero vector.
Defines the linear algebra or vector space interface.
ROL::Ptr< Vector< Real > > r_
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
LA::Matrix< Real > SDMatrix
Real run(Vector< Real > &x, LinearOperator< Real > &A, const Vector< Real > &b, LinearOperator< Real > &M, int &iter, int &flag)
ROL::Ptr< std::vector< Real > > res_
Preconditioned GMRES solver.
virtual void applyInverse(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply inverse of linear operator.
Provides definitions for Krylov solvers.
Provides the interface to apply a linear operator.
ROL::Ptr< SDVector > cnorm_
ROL::Ptr< Vector< Real > > w_
LA::Vector< Real > SDVector
ROL::Ptr< Vector< Real > > z_
ROL::LAPACK< int, Real > lapack_