54 #include "Teuchos_GlobalMPISession.hpp"
63 void apply(
V& Hv,
const V& v, Real &tol )
const {
92 void apply(
V &Hv,
const V &v, Real &tol )
const {
94 SV &Hvs =
dynamic_cast<SV&
>(Hv);
97 const SV &vs =
dynamic_cast<const SV&
>(v);
98 ROL::Ptr<const vector> vp = vs.
getVector();
102 (*Hvp)[0] =
b_*(*vp)[0] +
c_*(*vp)[1];
104 for(
uint k=1; k<n-1; ++k) {
105 (*Hvp)[k] =
a_*(*vp)[k-1] +
b_*(*vp)[k] +
c_*(*vp)[k+1];
108 (*Hvp)[n-1] =
a_*(*vp)[n-2] +
b_*(*vp)[n-1];
117 SV &Hvs =
dynamic_cast<SV&
>(Hv);
120 const SV &vs =
dynamic_cast<const SV&
>(v);
121 ROL::Ptr<const vector> vp = vs.
getVector();
125 const char TRANS =
'N';
133 std::vector<int> ipiv(n);
139 lapack_.GTTRF(n,&dl[0],&d[0],&du[0],&du2[0],&ipiv[0],&info);
142 lapack_.GTTRS(TRANS,n,NRHS,&dl[0],&d[0],&du[0],&du2[0],&ipiv[0],&(*Hvp)[0],n,&info);
152 int main(
int argc,
char *argv[]) {
154 typedef std::vector<RealT> vector;
159 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
161 int iprint = argc - 1;
162 ROL::Ptr<std::ostream> outStream;
165 outStream = ROL::makePtrFromRef(std::cout);
167 outStream = ROL::makePtrFromRef(bhs);
173 ROL::ParameterList parlist;
174 ROL::ParameterList &gList = parlist.sublist(
"General");
175 ROL::ParameterList &kList = gList.sublist(
"Krylov");
177 kList.set(
"Type",
"MINRES");
178 kList.set(
"Iteration Limit",20);
179 kList.set(
"Absolute Tolerance",1.e-8);
180 kList.set(
"Relative Tolerance",1.e-6);
181 kList.set(
"Use Initial Guess",
false);
185 auto xp = ROL::makePtr<vector>(
dim,0.0);
186 auto yp = ROL::makePtr<vector>(
dim,0.0);
187 auto zp = ROL::makePtr<vector>(
dim,0.0);
188 auto bp = ROL::makePtr<vector>(
dim,0.0);
214 auto krylov = ROL::KrylovFactory<RealT>( parlist );
219 krylov->run(z,T,b,I,iter,flag);
221 *outStream << std::setw(10) <<
"Exact"
222 << std::setw(10) <<
"LAPACK"
223 << std::setw(10) <<
"MINRES" << std::endl;
224 *outStream <<
"---------------------------------" << std::endl;
226 for(uint k=0;k<
dim;++k) {
227 *outStream << std::setw(10) << (*xp)[k] <<
" "
228 << std::setw(10) << (*yp)[k] <<
" "
229 << std::setw(10) << (*zp)[k] <<
" " << std::endl;
232 *outStream <<
"MINRES performed " << iter <<
" iterations." << std::endl;
236 if( z.norm() > std::sqrt(ROL::ROL_EPSILON<RealT>()) ) {
241 catch (std::logic_error& err) {
242 *outStream << err.what() <<
"\n";
247 std::cout <<
"End Result: TEST FAILED\n";
249 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