20 #include "Teuchos_GlobalMPISession.hpp"
29 void apply(
V& Hv,
const V& v, Real &tol )
const {
58 void apply(
V &Hv,
const V &v, Real &tol )
const {
60 SV &Hvs =
dynamic_cast<SV&
>(Hv);
63 const SV &vs =
dynamic_cast<const SV&
>(v);
64 ROL::Ptr<const vector> vp = vs.
getVector();
68 (*Hvp)[0] =
b_*(*vp)[0] +
c_*(*vp)[1];
70 for(
uint k=1; k<n-1; ++k) {
71 (*Hvp)[k] =
a_*(*vp)[k-1] +
b_*(*vp)[k] +
c_*(*vp)[k+1];
74 (*Hvp)[n-1] =
a_*(*vp)[n-2] +
b_*(*vp)[n-1];
83 SV &Hvs =
dynamic_cast<SV&
>(Hv);
86 const SV &vs =
dynamic_cast<const SV&
>(v);
87 ROL::Ptr<const vector> vp = vs.
getVector();
91 const char TRANS =
'N';
99 std::vector<int> ipiv(n);
105 lapack_.GTTRF(n,&dl[0],&d[0],&du[0],&du2[0],&ipiv[0],&info);
108 lapack_.GTTRS(TRANS,n,NRHS,&dl[0],&d[0],&du[0],&du2[0],&ipiv[0],&(*Hvp)[0],n,&info);
118 int main(
int argc,
char *argv[]) {
120 typedef std::vector<RealT> vector;
125 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
127 int iprint = argc - 1;
128 ROL::Ptr<std::ostream> outStream;
131 outStream = ROL::makePtrFromRef(std::cout);
133 outStream = ROL::makePtrFromRef(bhs);
139 ROL::ParameterList parlist;
140 ROL::ParameterList &gList = parlist.sublist(
"General");
141 ROL::ParameterList &kList = gList.sublist(
"Krylov");
143 kList.set(
"Type",
"MINRES");
144 kList.set(
"Iteration Limit",20);
145 kList.set(
"Absolute Tolerance",1.e-8);
146 kList.set(
"Relative Tolerance",1.e-6);
147 kList.set(
"Use Initial Guess",
false);
151 auto xp = ROL::makePtr<vector>(
dim,0.0);
152 auto yp = ROL::makePtr<vector>(
dim,0.0);
153 auto zp = ROL::makePtr<vector>(
dim,0.0);
154 auto bp = ROL::makePtr<vector>(
dim,0.0);
180 auto krylov = ROL::KrylovFactory<RealT>( parlist );
185 krylov->run(z,T,b,I,iter,flag);
187 *outStream << std::setw(10) <<
"Exact"
188 << std::setw(10) <<
"LAPACK"
189 << std::setw(10) <<
"MINRES" << std::endl;
190 *outStream <<
"---------------------------------" << std::endl;
192 for(uint k=0;k<
dim;++k) {
193 *outStream << std::setw(10) << (*xp)[k] <<
" "
194 << std::setw(10) << (*yp)[k] <<
" "
195 << std::setw(10) << (*zp)[k] <<
" " << std::endl;
198 *outStream <<
"MINRES performed " << iter <<
" iterations." << std::endl;
202 if( z.norm() > std::sqrt(ROL::ROL_EPSILON<RealT>()) ) {
207 catch (std::logic_error& err) {
208 *outStream << err.what() <<
"\n";
213 std::cout <<
"End Result: TEST FAILED\n";
215 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