53 #include "Teuchos_oblackholestream.hpp" 54 #include "Teuchos_GlobalMPISession.hpp" 63 void apply( V& Hv,
const V& v, Real &tol )
const {
77 typedef typename vector::size_type
uint;
92 void apply( V &Hv,
const V &v, Real &tol )
const {
94 using Teuchos::RCP;
using Teuchos::dyn_cast;
96 SV &Hvs = dyn_cast<SV>(Hv);
99 const SV &vs = dyn_cast<
const SV>(v);
104 (*Hvp)[0] = b_*(*vp)[0] + c_*(*vp)[1];
106 for(uint k=1; k<n-1; ++k) {
107 (*Hvp)[k] = a_*(*vp)[k-1] + b_*(*vp)[k] + c_*(*vp)[k+1];
110 (*Hvp)[n-1] = a_*(*vp)[n-2] + b_*(*vp)[n-1];
117 using Teuchos::RCP;
using Teuchos::dyn_cast;
119 SV &Hvs = dyn_cast<SV>(Hv);
122 const SV &vs = dyn_cast<
const SV>(v);
127 const char TRANS =
'N';
135 std::vector<int> ipiv(n);
141 lapack_.GTTRF(n,&dl[0],&d[0],&du[0],&du2[0],&ipiv[0],&info);
144 lapack_.GTTRS(TRANS,n,NRHS,&dl[0],&d[0],&du[0],&du2[0],&ipiv[0],&(*Hvp)[0],n,&info);
154 int main(
int argc,
char *argv[]) {
159 typedef std::vector<RealT> vector;
162 typedef typename vector::size_type uint;
164 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
166 int iprint = argc - 1;
167 RCP<std::ostream> outStream;
168 Teuchos::oblackholestream bhs;
170 outStream = rcp(&std::cout,
false);
172 outStream = rcp(&bhs,
false);
178 Teuchos::ParameterList parlist;
179 Teuchos::ParameterList &gList = parlist.sublist(
"General");
180 Teuchos::ParameterList &kList = gList.sublist(
"Krylov");
182 kList.set(
"Type",
"GMRES");
183 kList.set(
"Iteration Limit",20);
184 kList.set(
"Absolute Tolerance",1.e-8);
185 kList.set(
"Relative Tolerance",1.e-6);
186 kList.set(
"Use Initial Guess",
false);
190 RCP<vector> xp = rcp(
new vector(dim,0.0) );
191 RCP<vector> yp = rcp(
new vector(dim,0.0) );
192 RCP<vector> zp = rcp(
new vector(dim,0.0) );
193 RCP<vector> bp = rcp(
new vector(dim,0.0) );
219 RCP<ROL::Krylov<RealT> > krylov = ROL::KrylovFactory<RealT>( parlist );
224 krylov->run(z,T,b,I,iter,flag);
226 *outStream << std::setw(10) <<
"Exact" 227 << std::setw(10) <<
"LAPACK" 228 << std::setw(10) <<
"GMRES " << std::endl;
229 *outStream <<
"---------------------------------" << std::endl;
231 for(uint k=0;k<dim;++k) {
232 *outStream << std::setw(10) << (*xp)[k] <<
" " 233 << std::setw(10) << (*yp)[k] <<
" " 234 << std::setw(10) << (*zp)[k] <<
" " << std::endl;
237 *outStream <<
"GMRES performed " << iter <<
" iterations." << std::endl;
246 catch (std::logic_error err) {
247 *outStream << err.what() <<
"\n";
252 std::cout <<
"End Result: TEST FAILED\n";
254 std::cout <<
"End Result: TEST PASSED\n";
ROL::StdVector< Real > SV
Teuchos::RCP< 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.
void apply(V &Hv, const V &v, Real &tol) const
Apply linear operator.
TridiagonalToeplitzOperator(Real &a, Real &b, Real &c)
int main(int argc, char *argv[])
Provides the interface to apply a linear operator.
void applyInverse(V &Hv, const V &v, Real &tol) const
Apply inverse of linear operator.
Teuchos::LAPACK< int, Real > lapack_
virtual void set(const Vector &x)
Set where .
std::vector< Real > vector
static const double ROL_EPSILON
Platform-dependent machine epsilon.