19 int main(
int argc,
char *argv[]) {
21 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
24 int iprint = argc - 1;
25 ROL::Ptr<std::ostream> outStream;
28 outStream = ROL::makePtrFromRef(std::cout);
30 outStream = ROL::makePtrFromRef(bhs);
47 ROL::Ptr<std::vector<RealT> > z_ptr = ROL::makePtr<std::vector<RealT>>((nx+2)*(nt+1), 1.0);
48 ROL::Ptr<std::vector<RealT> > gz_ptr = ROL::makePtr<std::vector<RealT>>((nx+2)*(nt+1), 1.0);
49 ROL::Ptr<std::vector<RealT> > yz_ptr = ROL::makePtr<std::vector<RealT>>((nx+2)*(nt+1), 1.0);
50 for (
int i=0; i<(nx+2)*(nt+1); i++) {
57 ROL::Ptr<ROL::Vector<RealT> > zp = ROL::makePtrFromRef(z);
58 ROL::Ptr<ROL::Vector<RealT> > gzp = ROL::makePtrFromRef(gz);
59 ROL::Ptr<ROL::Vector<RealT> > yzp = ROL::makePtrFromRef(yz);
61 ROL::Ptr<std::vector<RealT> > u_ptr = ROL::makePtr<std::vector<RealT>>(nx*nt, 1.0);
62 ROL::Ptr<std::vector<RealT> > gu_ptr = ROL::makePtr<std::vector<RealT>>(nx*nt, 1.0);
63 ROL::Ptr<std::vector<RealT> > yu_ptr = ROL::makePtr<std::vector<RealT>>(nx*nt, 1.0);
64 for (
int i=0; i<nx*nt; i++) {
71 ROL::Ptr<ROL::Vector<RealT> > up = ROL::makePtrFromRef(u);
72 ROL::Ptr<ROL::Vector<RealT> > gup = ROL::makePtrFromRef(gu);
73 ROL::Ptr<ROL::Vector<RealT> > yup = ROL::makePtrFromRef(yu);
75 ROL::Ptr<std::vector<RealT> > c_ptr = ROL::makePtr<std::vector<RealT>>(nx*nt, 1.0);
76 ROL::Ptr<std::vector<RealT> > l_ptr = ROL::makePtr<std::vector<RealT>>(nx*nt, 1.0);
98 ROL::Ptr<std::vector<RealT> > p_ptr = ROL::makePtr<std::vector<RealT>>(nx*nt, 1.0);
100 ROL::Ptr<ROL::Vector<RealT> > pp = ROL::makePtrFromRef(p);
101 ROL::Ptr<ROL::Objective_SimOpt<RealT> > pobj = ROL::makePtrFromRef(obj);
102 ROL::Ptr<ROL::Constraint_SimOpt<RealT> > pcon = ROL::makePtrFromRef(con);
108 std::string filename =
"input.xml";
109 auto parlist = ROL::getParametersFromXmlFile( filename );
110 parlist->sublist(
"Status Test").set(
"Gradient Tolerance",1.e-10);
111 parlist->sublist(
"Status Test").set(
"Constraint Tolerance",1.e-10);
112 parlist->sublist(
"Status Test").set(
"Step Tolerance",1.e-16);
113 parlist->sublist(
"Status Test").set(
"Iteration Limit",100);
115 ROL::Ptr<ROL::Algorithm<RealT>> algo;
116 ROL::Ptr<ROL::Step<RealT>> step;
117 ROL::Ptr<ROL::StatusTest<RealT>> status;
120 step = ROL::makePtr<ROL::TrustRegionStep<RealT>>(*parlist);
121 status = ROL::makePtr<ROL::StatusTest<RealT>>(*parlist);
122 algo = ROL::makePtr<ROL::Algorithm<RealT>>(step,status,
false);
124 std::clock_t timer_tr = std::clock();
125 algo->run(z,robj,
true,*outStream);
126 *outStream <<
"Trust-Region Newton required " << (std::clock()-timer_tr)/(
RealT)CLOCKS_PER_SEC
128 ROL::Ptr<ROL::Vector<RealT> > zTR = z.
clone();
132 step = ROL::makePtr<ROL::CompositeStep<RealT>>(*parlist);
133 status = ROL::makePtr<ROL::ConstraintStatusTest<RealT>>(*parlist);
134 algo = ROL::makePtr<ROL::Algorithm<RealT>>(step,status,
false);
136 ROL::Elementwise::Fill<RealT> setFunc(0.25);
138 std::clock_t timer_cs = std::clock();
139 algo->run(x,g,l,c,obj,con,
true,*outStream);
140 *outStream <<
"Composite Step required " << (std::clock()-timer_cs)/(
RealT)CLOCKS_PER_SEC
144 ROL::Ptr<ROL::Vector<RealT> > err = z.
clone();
145 err->set(*zTR); err->axpy(-1.,z);
146 errorFlag += (err->norm() > 1.e-4) ? 1 : 0;
148 *outStream <<
"\n\nControl error = " << err->norm() <<
"\n";
173 catch (std::logic_error& err) {
174 *outStream << err.what() <<
"\n";
179 std::cout <<
"End Result: TEST FAILED\n";
181 std::cout <<
"End Result: TEST PASSED\n";
virtual Real checkSolve(const Vector< Real > &u, const Vector< Real > &z, const Vector< Real > &c, const bool printToStream=true, std::ostream &outStream=std::cout)
Defines the linear algebra or vector space interface for simulation-based optimization.
virtual Real checkAdjointConsistencyJacobian_2(const Vector< Real > &w, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, const bool printToStream=true, std::ostream &outStream=std::cout)
Check the consistency of the Jacobian and its adjoint. This is the primary interface.
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.
void applyUnary(const Elementwise::UnaryFunction< Real > &f)
virtual Real checkInverseJacobian_1(const Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, const bool printToStream=true, std::ostream &outStream=std::cout)
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 Real checkAdjointConsistencyJacobian_1(const Vector< Real > &w, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, const bool printToStream=true, std::ostream &outStream=std::cout)
Check the consistency of the Jacobian and its adjoint. This is the primary interface.
virtual Real checkInverseAdjointJacobian_1(const Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, const bool printToStream=true, std::ostream &outStream=std::cout)