53 int main(
int argc,
char *argv[]) {
55 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
58 int iprint = argc - 1;
59 ROL::Ptr<std::ostream> outStream;
62 outStream = ROL::makePtrFromRef(std::cout);
64 outStream = ROL::makePtrFromRef(bhs);
81 ROL::Ptr<std::vector<RealT> > z_ptr = ROL::makePtr<std::vector<RealT>>((nx+2)*(nt+1), 1.0);
82 ROL::Ptr<std::vector<RealT> > gz_ptr = ROL::makePtr<std::vector<RealT>>((nx+2)*(nt+1), 1.0);
83 ROL::Ptr<std::vector<RealT> > yz_ptr = ROL::makePtr<std::vector<RealT>>((nx+2)*(nt+1), 1.0);
84 for (
int i=0; i<(nx+2)*(nt+1); i++) {
91 ROL::Ptr<ROL::Vector<RealT> > zp = ROL::makePtrFromRef(z);
92 ROL::Ptr<ROL::Vector<RealT> > gzp = ROL::makePtrFromRef(gz);
93 ROL::Ptr<ROL::Vector<RealT> > yzp = ROL::makePtrFromRef(yz);
95 ROL::Ptr<std::vector<RealT> > u_ptr = ROL::makePtr<std::vector<RealT>>(nx*nt, 1.0);
96 ROL::Ptr<std::vector<RealT> > gu_ptr = ROL::makePtr<std::vector<RealT>>(nx*nt, 1.0);
97 ROL::Ptr<std::vector<RealT> > yu_ptr = ROL::makePtr<std::vector<RealT>>(nx*nt, 1.0);
98 for (
int i=0; i<nx*nt; i++) {
105 ROL::Ptr<ROL::Vector<RealT> > up = ROL::makePtrFromRef(u);
106 ROL::Ptr<ROL::Vector<RealT> > gup = ROL::makePtrFromRef(gu);
107 ROL::Ptr<ROL::Vector<RealT> > yup = ROL::makePtrFromRef(yu);
109 ROL::Ptr<std::vector<RealT> > c_ptr = ROL::makePtr<std::vector<RealT>>(nx*nt, 1.0);
110 ROL::Ptr<std::vector<RealT> > l_ptr = ROL::makePtr<std::vector<RealT>>(nx*nt, 1.0);
132 ROL::Ptr<std::vector<RealT> > p_ptr = ROL::makePtr<std::vector<RealT>>(nx*nt, 1.0);
134 ROL::Ptr<ROL::Vector<RealT> > pp = ROL::makePtrFromRef(p);
135 ROL::Ptr<ROL::Objective_SimOpt<RealT> > pobj = ROL::makePtrFromRef(obj);
136 ROL::Ptr<ROL::Constraint_SimOpt<RealT> > pcon = ROL::makePtrFromRef(con);
142 std::string filename =
"input.xml";
143 auto parlist = ROL::getParametersFromXmlFile( filename );
144 parlist->sublist(
"Status Test").set(
"Gradient Tolerance",1.e-10);
145 parlist->sublist(
"Status Test").set(
"Constraint Tolerance",1.e-10);
146 parlist->sublist(
"Status Test").set(
"Step Tolerance",1.e-16);
147 parlist->sublist(
"Status Test").set(
"Iteration Limit",100);
149 ROL::Ptr<ROL::Algorithm<RealT> > algo;
152 algo = ROL::makePtr<ROL::Algorithm<RealT>>(
"Trust Region",*parlist,
false);
154 std::clock_t timer_tr = std::clock();
155 algo->run(z,robj,
true,*outStream);
156 *outStream <<
"Trust-Region Newton required " << (std::clock()-timer_tr)/(
RealT)CLOCKS_PER_SEC
158 ROL::Ptr<ROL::Vector<RealT> > zTR = z.
clone();
162 algo = ROL::makePtr<ROL::Algorithm<RealT>>(
"Composite Step",*parlist,
false);
164 ROL::Elementwise::Fill<RealT> setFunc(0.25);
166 std::clock_t timer_cs = std::clock();
167 algo->run(x,g,l,c,obj,con,
true,*outStream);
168 *outStream <<
"Composite Step required " << (std::clock()-timer_cs)/(
RealT)CLOCKS_PER_SEC
172 ROL::Ptr<ROL::Vector<RealT> > err = z.
clone();
173 err->set(*zTR); err->axpy(-1.,z);
174 errorFlag += (err->norm() > 1.e-4) ? 1 : 0;
176 *outStream <<
"\n\nControl error = " << err->norm() <<
"\n";
201 catch (std::logic_error err) {
202 *outStream << err.what() <<
"\n";
207 std::cout <<
"End Result: TEST FAILED\n";
209 std::cout <<
"End Result: TEST PASSED\n";
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 checkSolve(const ROL::Vector< Real > &u, const ROL::Vector< Real > &z, const ROL::Vector< Real > &c, const bool printToStream=true, std::ostream &outStream=std::cout)
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)