92int main(
int argc,
char *argv[]) {
96 typedef ROL::ParameterList PL;
104 typedef ROL::NonlinearProgram<RealT> NLP;
115 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
117 int iprint = argc - 1;
118 ROL::Ptr<std::ostream> outStream;
121 outStream = ROL::makePtrFromRef(std::cout);
123 outStream = ROL::makePtrFromRef(bhs);
131 RealT tol = std::sqrt(ROL::ROL_EPSILON<RealT>());
135 PL &iplist = parlist.sublist(
"Step").sublist(
"Primal Dual Interior Point");
136 PL &lblist = iplist.sublist(
"Barrier Objective");
138 lblist.set(
"Use Linear Damping",
true);
139 lblist.set(
"Linear Damping Coefficient",1.e-4);
140 lblist.set(
"Initial Barrier Parameter", mu);
142 PL &krylist = parlist.sublist(
"General").sublist(
"Krylov");
144 krylist.set(
"Absolute Tolerance", 1.e-6);
145 krylist.set(
"Relative Tolerance", 1.e-6);
146 krylist.set(
"Iteration Limit", 50);
149 krylist.set(
"Type",
"Conjugate Gradients");
150 ROL::Ptr<KRYLOV> cg = ROL::KrylovFactory<RealT>(parlist);
151 HS::ProblemFactory<RealT> problemFactory;
155 ROL::Ptr<NLP> nlp = problemFactory.getProblem(16);
156 ROL::Ptr<OPT> opt = nlp->getOptimizationProblem();
158 ROL::Ptr<V> x = opt->getSolutionVector();
159 ROL::Ptr<V> l = opt->getMultiplierVector();
160 ROL::Ptr<V> zl = x->clone(); zl->zero();
161 ROL::Ptr<V> zu = x->clone(); zu->zero();
163 ROL::Ptr<V> scratch = x->clone();
165 ROL::Ptr<PV> x_pv = ROL::dynamicPtrCast<PV>(x);
169 (*ROL::dynamicPtrCast<ROL::StdVector<RealT> >(x_pv->get(1))->getVector())[0] = 1.0;
171 ROL::Ptr<V> sol = CreatePartitionedVector(x,l,zl,zu);
173 std::vector< ROL::Ptr<V> > I;
174 std::vector< ROL::Ptr<V> > J;
176 for(
int k=0; k<sol->dimension(); ++k ) {
177 I.push_back(sol->basis(k));
178 J.push_back(sol->clone());
181 ROL::Ptr<V> u = sol->clone();
182 ROL::Ptr<V> v = sol->clone();
184 ROL::Ptr<V> rhs = sol->clone();
185 ROL::Ptr<V> symrhs = sol->clone();
187 ROL::Ptr<V> gmres_sol = sol->clone(); gmres_sol->set(*sol);
188 ROL::Ptr<V> cg_sol = sol->clone(); cg_sol->set(*sol);
192 RandomizeVector(*u,-1.0,1.0);
193 RandomizeVector(*v,-1.0,1.0);
195 ROL::Ptr<OBJ> obj = opt->getObjective();
196 ROL::Ptr<CON> con = opt->getConstraint();
197 ROL::Ptr<BND> bnd = opt->getBoundConstraint();
199 PENALTY penalty(obj,bnd,parlist);
201 ROL::Ptr<const V> maskL = penalty.getLowerMask();
202 ROL::Ptr<const V> maskU = penalty.getUpperMask();
215 ROL::Ptr<CON> res = ROL::makePtr<RESIDUAL>(obj,con,bnd,*sol,maskL,maskU,scratch,mu,
false);
216 ROL::Ptr<LOP> lop = ROL::makePtr<LOPEC>( sol, res );
219 res->value(*rhs,*sol,tol);
222 krylist.set(
"Type",
"GMRES");
223 ROL::Ptr<KRYLOV> gmres = ROL::KrylovFactory<RealT>(parlist);
225 for(
int k=0; k<sol->dimension(); ++k ) {
226 res->applyJacobian(*(J[k]),*(I[k]),*sol,tol);
229 *outStream <<
"Nonsymmetric Jacobian" << std::endl;
233 gmres->run( *gmres_sol, *lop, *rhs, identity, gmres_iter, gmres_flag );
235 errorFlag += gmres_flag;
237 *outStream <<
"GMRES terminated after " << gmres_iter <<
" iterations "
238 <<
"with exit flag " << gmres_flag << std::endl;
248 ROL::Ptr<V> jv = v->clone();
249 ROL::Ptr<V> ju = u->clone();
251 iplist.set(
"Symmetrize Primal Dual System",
true);
252 ROL::Ptr<CON> symres = ROL::makePtr<RESIDUAL>(obj,con,bnd,*sol,maskL,maskU,scratch,mu,
true);
253 ROL::Ptr<LOP> symlop = ROL::makePtr<LOPEC>( sol, res );
254 symres->value(*symrhs,*sol,tol);
256 symres->applyJacobian(*jv,*v,*sol,tol);
257 symres->applyJacobian(*ju,*u,*sol,tol);
258 *outStream <<
"Symmetry check |u.dot(jv)-v.dot(ju)| = "
259 << std::abs(u->dot(*jv)-v->dot(*ju)) << std::endl;
261 cg->run( *cg_sol, *symlop, *symrhs, identity, cg_iter, cg_flag );
263 *outStream <<
"CG terminated after " << cg_iter <<
" iterations "
264 <<
"with exit flag " << cg_flag << std::endl;
266 *outStream <<
"Check that GMRES solution also is a solution to the symmetrized system"
269 symres->applyJacobian(*ju,*gmres_sol,*sol,tol);
270 ju->axpy(-1.0,*symrhs);
271 RealT mismatch = ju->norm();
275 *outStream <<
"||J_sym*sol_nonsym-rhs_sym|| = " << mismatch << std::endl;
278 catch (std::logic_error& err) {
279 *outStream << err.what() << std::endl;
284 std::cout <<
"End Result: TEST FAILED" << std::endl;
286 std::cout <<
"End Result: TEST PASSED" << std::endl;