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";