18 #include "ROL_ParameterList.hpp"
21 #include "Teuchos_GlobalMPISession.hpp"
30 void apply(
V& Hv,
const V& v, Real &tol )
const {
59 void apply(
V &Hv,
const V &v, Real &tol )
const {
63 SV &Hvs =
dynamic_cast<SV&
>(Hv);
66 const SV &vs =
dynamic_cast<const SV&
>(v);
67 ROL::Ptr<const vector> vp = vs.
getVector();
71 (*Hvp)[0] =
b_*(*vp)[0] +
c_*(*vp)[1];
73 for(
uint k=1; k<n-1; ++k) {
74 (*Hvp)[k] =
a_*(*vp)[k-1] +
b_*(*vp)[k] +
c_*(*vp)[k+1];
77 (*Hvp)[n-1] =
a_*(*vp)[n-2] +
b_*(*vp)[n-1];
86 SV &Hvs =
dynamic_cast<SV&
>(Hv);
89 const SV &vs =
dynamic_cast<const SV&
>(v);
90 ROL::Ptr<const vector> vp = vs.
getVector();
94 const char TRANS =
'N';
102 std::vector<int> ipiv(n);
108 lapack_.GTTRF(n,&dl[0],&d[0],&du[0],&du2[0],&ipiv[0],&info);
111 lapack_.GTTRS(TRANS,n,NRHS,&dl[0],&d[0],&du[0],&du2[0],&ipiv[0],&(*Hvp)[0],n,&info);
121 int main(
int argc,
char *argv[]) {
126 typedef std::vector<RealT> vector;
131 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
133 int iprint = argc - 1;
134 ROL::Ptr<std::ostream> outStream;
137 outStream = ROL::makePtrFromRef(std::cout);
139 outStream = ROL::makePtrFromRef(bhs);
145 ROL::ParameterList parlist;
146 ROL::ParameterList &gList = parlist.sublist(
"General");
147 ROL::ParameterList &kList = gList.sublist(
"Krylov");
149 kList.set(
"Type",
"GMRES");
150 kList.set(
"Iteration Limit",20);
151 kList.set(
"Absolute Tolerance",1.e-8);
152 kList.set(
"Relative Tolerance",1.e-6);
153 kList.set(
"Use Initial Guess",
false);
157 ROL::Ptr<vector> xp = ROL::makePtr<vector>(
dim,0.0);
158 ROL::Ptr<vector> yp = ROL::makePtr<vector>(
dim,0.0);
159 ROL::Ptr<vector> zp = ROL::makePtr<vector>(
dim,0.0);
160 ROL::Ptr<vector> bp = ROL::makePtr<vector>(
dim,0.0);
186 ROL::Ptr<ROL::Krylov<RealT> > krylov = ROL::KrylovFactory<RealT>( parlist );
191 krylov->run(z,T,b,I,iter,flag);
193 *outStream << std::setw(10) <<
"Exact"
194 << std::setw(10) <<
"LAPACK"
195 << std::setw(10) <<
"GMRES " << std::endl;
196 *outStream <<
"---------------------------------" << std::endl;
198 for(uint k=0;k<
dim;++k) {
199 *outStream << std::setw(10) << (*xp)[k] <<
" "
200 << std::setw(10) << (*yp)[k] <<
" "
201 << std::setw(10) << (*zp)[k] <<
" " << std::endl;
204 *outStream <<
"GMRES performed " << iter <<
" iterations." << std::endl;
208 if( z.norm() > std::sqrt(ROL::ROL_EPSILON<RealT>()) ) {
213 catch (std::logic_error& err) {
214 *outStream << err.what() <<
"\n";
219 std::cout <<
"End Result: TEST FAILED\n";
221 std::cout <<
"End Result: TEST PASSED\n";
ROL::StdVector< Real > SV
typename PV< Real >::size_type size_type
Ptr< const std::vector< Element > > getVector() const
void RandomizeVector(Vector< Real > &x, const Real &lower=0.0, const Real &upper=1.0)
Fill a ROL::Vector with uniformly-distributed random numbers in the interval [lower,upper].
void apply(V &Hv, const V &v, Real &tol) const
Apply linear operator.
Defines the linear algebra or vector space interface.
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
void apply(V &Hv, const V &v, Real &tol) const
Apply linear operator.
TridiagonalToeplitzOperator(Real &a, Real &b, Real &c)
ROL::LAPACK< int, Real > lapack_
Provides the interface to apply a linear operator.
void applyInverse(V &Hv, const V &v, Real &tol) const
Apply inverse of linear operator.
basic_nullstream< char, char_traits< char >> nullstream
int main(int argc, char *argv[])
virtual void set(const Vector &x)
Set where .
std::vector< Real > vector