52 #include "ROL_ParameterList.hpp"
55 #include "Teuchos_GlobalMPISession.hpp"
64 void apply(
V& Hv,
const V& v, Real &tol )
const {
93 void apply(
V &Hv,
const V &v, Real &tol )
const {
97 SV &Hvs =
dynamic_cast<SV&
>(Hv);
100 const SV &vs =
dynamic_cast<const SV&
>(v);
101 ROL::Ptr<const vector> vp = vs.
getVector();
105 (*Hvp)[0] =
b_*(*vp)[0] +
c_*(*vp)[1];
107 for(
uint k=1; k<n-1; ++k) {
108 (*Hvp)[k] =
a_*(*vp)[k-1] +
b_*(*vp)[k] +
c_*(*vp)[k+1];
111 (*Hvp)[n-1] =
a_*(*vp)[n-2] +
b_*(*vp)[n-1];
120 SV &Hvs =
dynamic_cast<SV&
>(Hv);
123 const SV &vs =
dynamic_cast<const SV&
>(v);
124 ROL::Ptr<const vector> vp = vs.
getVector();
128 const char TRANS =
'N';
136 std::vector<int> ipiv(n);
142 lapack_.GTTRF(n,&dl[0],&d[0],&du[0],&du2[0],&ipiv[0],&info);
145 lapack_.GTTRS(TRANS,n,NRHS,&dl[0],&d[0],&du[0],&du2[0],&ipiv[0],&(*Hvp)[0],n,&info);
155 int main(
int argc,
char *argv[]) {
160 typedef std::vector<RealT> vector;
165 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
167 int iprint = argc - 1;
168 ROL::Ptr<std::ostream> outStream;
171 outStream = ROL::makePtrFromRef(std::cout);
173 outStream = ROL::makePtrFromRef(bhs);
179 ROL::ParameterList parlist;
180 ROL::ParameterList &gList = parlist.sublist(
"General");
181 ROL::ParameterList &kList = gList.sublist(
"Krylov");
183 kList.set(
"Type",
"GMRES");
184 kList.set(
"Iteration Limit",20);
185 kList.set(
"Absolute Tolerance",1.e-8);
186 kList.set(
"Relative Tolerance",1.e-6);
187 kList.set(
"Use Initial Guess",
false);
191 ROL::Ptr<vector> xp = ROL::makePtr<vector>(
dim,0.0);
192 ROL::Ptr<vector> yp = ROL::makePtr<vector>(
dim,0.0);
193 ROL::Ptr<vector> zp = ROL::makePtr<vector>(
dim,0.0);
194 ROL::Ptr<vector> bp = ROL::makePtr<vector>(
dim,0.0);
220 ROL::Ptr<ROL::Krylov<RealT> > krylov = ROL::KrylovFactory<RealT>( parlist );
225 krylov->run(z,T,b,I,iter,flag);
227 *outStream << std::setw(10) <<
"Exact"
228 << std::setw(10) <<
"LAPACK"
229 << std::setw(10) <<
"GMRES " << std::endl;
230 *outStream <<
"---------------------------------" << std::endl;
232 for(uint k=0;k<
dim;++k) {
233 *outStream << std::setw(10) << (*xp)[k] <<
" "
234 << std::setw(10) << (*yp)[k] <<
" "
235 << std::setw(10) << (*zp)[k] <<
" " << std::endl;
238 *outStream <<
"GMRES performed " << iter <<
" iterations." << std::endl;
242 if( z.norm() > std::sqrt(ROL::ROL_EPSILON<RealT>()) ) {
247 catch (std::logic_error& err) {
248 *outStream << err.what() <<
"\n";
253 std::cout <<
"End Result: TEST FAILED\n";
255 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