53 int main(
int argc,
char *argv[]) {
55 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
58 int iprint = argc - 1;
59 Teuchos::RCP<std::ostream> outStream;
60 Teuchos::oblackholestream bhs;
62 outStream = Teuchos::rcp(&std::cout,
false);
64 outStream = Teuchos::rcp(&bhs,
false);
81 Teuchos::RCP<std::vector<RealT> > z_rcp = Teuchos::rcp(
new std::vector<RealT> ((nx+2)*(nt+1), 1.0) );
82 Teuchos::RCP<std::vector<RealT> > gz_rcp = Teuchos::rcp(
new std::vector<RealT> ((nx+2)*(nt+1), 1.0) );
83 Teuchos::RCP<std::vector<RealT> > yz_rcp = Teuchos::rcp(
new std::vector<RealT> ((nx+2)*(nt+1), 1.0) );
84 for (
int i=0; i<(nx+2)*(nt+1); i++) {
91 Teuchos::RCP<ROL::Vector<RealT> > zp = Teuchos::rcp(&z,
false);
92 Teuchos::RCP<ROL::Vector<RealT> > gzp = Teuchos::rcp(&gz,
false);
93 Teuchos::RCP<ROL::Vector<RealT> > yzp = Teuchos::rcp(&yz,
false);
95 Teuchos::RCP<std::vector<RealT> > u_rcp = Teuchos::rcp(
new std::vector<RealT> (nx*nt, 1.0) );
96 Teuchos::RCP<std::vector<RealT> > gu_rcp = Teuchos::rcp(
new std::vector<RealT> (nx*nt, 1.0) );
97 Teuchos::RCP<std::vector<RealT> > yu_rcp = Teuchos::rcp(
new std::vector<RealT> (nx*nt, 1.0) );
98 for (
int i=0; i<nx*nt; i++) {
105 Teuchos::RCP<ROL::Vector<RealT> > up = Teuchos::rcp(&u,
false);
106 Teuchos::RCP<ROL::Vector<RealT> > gup = Teuchos::rcp(&gu,
false);
107 Teuchos::RCP<ROL::Vector<RealT> > yup = Teuchos::rcp(&yu,
false);
109 Teuchos::RCP<std::vector<RealT> > c_rcp = Teuchos::rcp(
new std::vector<RealT> (nx*nt, 1.0) );
110 Teuchos::RCP<std::vector<RealT> > l_rcp = Teuchos::rcp(
new std::vector<RealT> (nx*nt, 1.0) );
132 Teuchos::RCP<std::vector<RealT> > p_rcp = Teuchos::rcp(
new std::vector<RealT> (nx*nt, 1.0) );
134 Teuchos::RCP<ROL::Vector<RealT> > pp = Teuchos::rcp(&p,
false);
135 Teuchos::RCP<ROL::Objective_SimOpt<RealT> > pobj = Teuchos::rcp(&obj,
false);
136 Teuchos::RCP<ROL::EqualityConstraint_SimOpt<RealT> > pcon = Teuchos::rcp(&con,
false);
142 std::string filename =
"input.xml";
143 Teuchos::RCP<Teuchos::ParameterList> parlist = Teuchos::rcp(
new Teuchos::ParameterList() );
144 Teuchos::updateParametersFromXmlFile( filename, parlist.ptr() );
145 parlist->sublist(
"Status Test").set(
"Gradient Tolerance",1.e-14);
146 parlist->sublist(
"Status Test").set(
"Constraint Tolerance",1.e-14);
147 parlist->sublist(
"Status Test").set(
"Step Tolerance",1.e-16);
148 parlist->sublist(
"Status Test").set(
"Iteration Limit",100);
150 Teuchos::RCP<ROL::Algorithm<RealT> > algo;
155 std::clock_t timer_tr = std::clock();
156 algo->run(z,robj,
true,*outStream);
157 *outStream <<
"Trust-Region Newton required " << (std::clock()-timer_tr)/(
RealT)CLOCKS_PER_SEC
159 Teuchos::RCP<ROL::Vector<RealT> > zTR = z.
clone();
165 std::clock_t timer_cs = std::clock();
166 algo->run(x,g,l,c,obj,con,
true,*outStream);
167 *outStream <<
"Composite Step required " << (std::clock()-timer_cs)/(
RealT)CLOCKS_PER_SEC
171 Teuchos::RCP<ROL::Vector<RealT> > err = z.
clone();
172 err->set(*zTR); err->axpy(-1.,z);
173 errorFlag += (err->norm() > 1.e-8) ? 1 : 0;
197 catch (std::logic_error err) {
198 *outStream << err.what() <<
"\n";
203 std::cout <<
"End Result: TEST FAILED\n";
205 std::cout <<
"End Result: TEST PASSED\n";
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)
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.
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.
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.
Provides the interface to evaluate simulation-based reduced objective functions.
Provides the std::vector implementation of the ROL::Vector interface.
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)
Provides an interface to run optimization algorithms.
virtual Teuchos::RCP< Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
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)
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 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.