54 int main(
int argc,
char *argv[]) {
56 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
59 int iprint = argc - 1;
60 ROL::Ptr<std::ostream> outStream;
63 outStream = ROL::makePtrFromRef(std::cout);
65 outStream = ROL::makePtrFromRef(bhs);
79 ROL::ParameterList list;
80 list.sublist(
"SimOpt").sublist(
"Solve").set(
"Absolute Residual Tolerance",1.e2*ROL::ROL_EPSILON<RealT>());
83 ROL::Ptr<std::vector<RealT> > z_ptr = ROL::makePtr<std::vector<RealT>>(nx+2, 1.0);
84 ROL::Ptr<std::vector<RealT> > gz_ptr = ROL::makePtr<std::vector<RealT>>(nx+2, 1.0);
85 ROL::Ptr<std::vector<RealT> > yz_ptr = ROL::makePtr<std::vector<RealT>>(nx+2, 1.0);
86 for (
int i=0; i<nx+2; i++) {
93 ROL::Ptr<ROL::Vector<RealT> > zp = ROL::makePtrFromRef(z);
94 ROL::Ptr<ROL::Vector<RealT> > gzp = ROL::makePtrFromRef(z);
95 ROL::Ptr<ROL::Vector<RealT> > yzp = ROL::makePtrFromRef(yz);
97 ROL::Ptr<std::vector<RealT> > u_ptr = ROL::makePtr<std::vector<RealT>>(nx, 1.0);
98 ROL::Ptr<std::vector<RealT> > gu_ptr = ROL::makePtr<std::vector<RealT>>(nx, 1.0);
99 ROL::Ptr<std::vector<RealT> > yu_ptr = ROL::makePtr<std::vector<RealT>>(nx, 1.0);
100 for (
int i=0; i<nx; i++) {
107 ROL::Ptr<ROL::Vector<RealT> > up = ROL::makePtrFromRef(u);
108 ROL::Ptr<ROL::Vector<RealT> > gup = ROL::makePtrFromRef(gu);
109 ROL::Ptr<ROL::Vector<RealT> > yup = ROL::makePtrFromRef(yu);
111 ROL::Ptr<std::vector<RealT> > c_ptr = ROL::makePtr<std::vector<RealT>>(nx, 1.0);
112 ROL::Ptr<std::vector<RealT> > l_ptr = ROL::makePtr<std::vector<RealT>>(nx, 1.0);
128 ROL::Ptr<std::vector<RealT> > p_ptr = ROL::makePtr<std::vector<RealT>>(nx, 1.0);
130 ROL::Ptr<ROL::Vector<RealT> > pp = ROL::makePtrFromRef(p);
131 ROL::Ptr<ROL::Objective_SimOpt<RealT> > pobj = ROL::makePtrFromRef(obj);
132 ROL::Ptr<ROL::Constraint_SimOpt<RealT> > pcon = ROL::makePtrFromRef(con);
139 std::string filename =
"input.xml";
140 auto parlist = ROL::getParametersFromXmlFile( filename );
141 parlist->sublist(
"Status Test").set(
"Gradient Tolerance",1.e-14);
142 parlist->sublist(
"Status Test").set(
"Constraint Tolerance",1.e-14);
143 parlist->sublist(
"Status Test").set(
"Step Tolerance",1.e-16);
144 parlist->sublist(
"Status Test").set(
"Iteration Limit",1000);
146 ROL::Ptr<ROL::Algorithm<RealT>> algo;
147 ROL::Ptr<ROL::Step<RealT>> step;
148 ROL::Ptr<ROL::StatusTest<RealT>> status;
151 step = ROL::makePtr<ROL::CompositeStep<RealT>>(*parlist);
152 status = ROL::makePtr<ROL::ConstraintStatusTest<RealT>>(*parlist);
153 algo = ROL::makePtr<ROL::Algorithm<RealT>>(step,status,
false);
154 RealT zerotol = std::sqrt(ROL::ROL_EPSILON<RealT>());
156 con.
solve(c,u,z,zerotol);
158 algo->run(x, g, l, c, obj, con,
true, *outStream);
159 ROL::Ptr<ROL::Vector<RealT> > zCS = z.
clone();
163 step = ROL::makePtr<ROL::TrustRegionStep<RealT>>(*parlist);
164 status = ROL::makePtr<ROL::StatusTest<RealT>>(*parlist);
165 algo = ROL::makePtr<ROL::Algorithm<RealT>>(step,status,
false);
167 algo->run(z,robj,
true,*outStream);
170 ROL::Ptr<ROL::Vector<RealT> > err = z.
clone();
171 err->set(*zCS); err->axpy(-1.,z);
172 errorFlag += ((err->norm()) > 1.e-8) ? 1 : 0;
174 catch (std::logic_error& err) {
175 *outStream << err.what() <<
"\n";
180 std::cout <<
"End Result: TEST FAILED\n";
182 std::cout <<
"End Result: TEST PASSED\n";
Defines the linear algebra or vector space interface for simulation-based optimization.
virtual std::vector< std::vector< Real > > checkApplyAdjointJacobian(const Vector< Real > &x, const Vector< Real > &v, const Vector< Real > &c, const Vector< Real > &ajv, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS)
Finite-difference check for the application of the adjoint of constraint Jacobian.
void solve(ROL::Vector< Real > &c, ROL::Vector< Real > &u, const ROL::Vector< Real > &z, Real &tol)
Given , solve for .
virtual void zero()
Set to zero vector.
virtual std::vector< std::vector< Real > > checkGradient(const Vector< Real > &x, const Vector< Real > &d, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
Finite-difference gradient check.
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
virtual Ptr< Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
virtual std::vector< std::vector< Real > > checkApplyAdjointHessian(const Vector< Real > &x, const Vector< Real > &u, const Vector< Real > &v, const Vector< Real > &hv, const std::vector< Real > &step, const bool printToScreen=true, std::ostream &outStream=std::cout, const int order=1)
Finite-difference check for the application of the adjoint of constraint Hessian. ...
virtual std::vector< std::vector< Real > > checkApplyJacobian(const Vector< Real > &x, const Vector< Real > &v, const Vector< Real > &jv, const std::vector< Real > &steps, const bool printToStream=true, std::ostream &outStream=std::cout, const int order=1)
Finite-difference check for the constraint Jacobian application.
basic_nullstream< char, char_traits< char >> nullstream
int main(int argc, char *argv[])
virtual std::vector< std::vector< Real > > checkHessVec(const Vector< Real > &x, const Vector< Real > &v, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
Finite-difference Hessian-applied-to-vector check.
virtual void setSolveParameters(ParameterList &parlist)
Set solve parameters.