53 int main(
int argc,
char *argv[]) {
55 typedef std::vector<RealT> vector;
63 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
66 int iprint = argc - 1;
67 ROL::Ptr<std::ostream> outStream;
70 outStream = ROL::makePtrFromRef(std::cout);
72 outStream = ROL::makePtrFromRef(bhs);
84 ROL::Ptr<vector> x_ptr = ROL::makePtr<vector>(nx+2, 1.0);
85 ROL::Ptr<vector> y_ptr = ROL::makePtr<vector>(nx+2, 0.0);
86 for (uint i=0; i<nx+2; i++) {
99 ROL::Ptr<vector> l_ptr = ROL::makePtr<vector>(nx+2,0.0);
100 ROL::Ptr<vector> u_ptr = ROL::makePtr<vector>(nx+2,1.0);
101 ROL::Ptr<V> lo = ROL::makePtr<SV>(l_ptr);
102 ROL::Ptr<V> up = ROL::makePtr<SV>(u_ptr);
107 ROL::Ptr<ROL::Algorithm<RealT>> algo;
108 ROL::Ptr<ROL::Step<RealT>> step;
109 ROL::Ptr<ROL::StatusTest<RealT>> status;
112 std::string filename =
"input.xml";
113 auto parlist = ROL::getParametersFromXmlFile( filename );
116 parlist->sublist(
"General").sublist(
"Krylov").set(
"Absolute Tolerance",1.e-8);
117 parlist->sublist(
"General").sublist(
"Krylov").set(
"Relative Tolerance",1.e-4);
118 parlist->sublist(
"General").sublist(
"Krylov").set(
"Iteration Limit",50);
120 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Relative Step Tolerance",1.e-10);
121 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Relative Gradient Tolerance",1.e-8);
122 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Iteration Limit", 10);
123 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Dual Scaling",(alpha>0.0)?alpha:1.e-4);
125 parlist->sublist(
"Status Test").set(
"Gradient Tolerance",1.e-12);
126 parlist->sublist(
"Status Test").set(
"Step Tolerance",1.e-16);
127 parlist->sublist(
"Status Test").set(
"Iteration Limit",100);
129 step = ROL::makePtr<ROL::PrimalDualActiveSetStep<RealT>>(*parlist);
130 status = ROL::makePtr<ROL::StatusTest<RealT>>(*parlist);
131 algo = ROL::makePtr<ROL::Algorithm<RealT>>(step,status,
false);
134 algo->run(x, obj, icon,
true, *outStream);
136 std::ofstream file_pdas;
137 file_pdas.open(
"control_PDAS.txt");
138 for (
unsigned i = 0; i < (unsigned)nx+2; i++ ) {
139 file_pdas << (*x_ptr)[i] <<
"\n";
144 parlist->sublist(
"General").sublist(
"Krylov").set(
"Absolute Tolerance",1.e-4);
145 parlist->sublist(
"General").sublist(
"Krylov").set(
"Relative Tolerance",1.e-2);
146 parlist->sublist(
"General").sublist(
"Krylov").set(
"Iteration Limit",50);
148 step = ROL::makePtr<ROL::TrustRegionStep<RealT>>(*parlist);
149 status = ROL::makePtr<ROL::StatusTest<RealT>>(*parlist);
150 algo = ROL::makePtr<ROL::Algorithm<RealT>>(step,status,
false);
153 algo->run(y,obj,icon,
true,*outStream);
155 std::ofstream file_tr;
156 file_tr.open(
"control_TR.txt");
157 for (
unsigned i = 0; i < (unsigned)nx+2; i++ ) {
158 file_tr << (*y_ptr)[i] <<
"\n";
162 std::vector<RealT> u(nx,0.0);
163 std::vector<RealT> param(4,0.0);
166 file.open(
"state.txt");
167 for (
unsigned i=0; i<(unsigned)nx; i++) {
168 file << i/((
RealT)(nx+1)) <<
" " << u[i] <<
"\n";
172 ROL::Ptr<ROL::Vector<RealT> > diff = x.clone();
175 RealT error = diff->norm();
176 *outStream <<
"\nError between PDAS solution and TR solution is " << error <<
"\n";
177 errorFlag = ((error > 1e2*std::sqrt(ROL::ROL_EPSILON<RealT>())) ? 1 : 0);
179 catch (std::logic_error& err) {
180 *outStream << err.what() <<
"\n";
185 std::cout <<
"End Result: TEST FAILED\n";
187 std::cout <<
"End Result: TEST PASSED\n";
typename PV< Real >::size_type size_type
void solve_state(std::vector< Real > &u, const std::vector< Real > &z, const std::vector< Real > ¶m)
Defines the linear algebra or vector space interface.
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...
Provides the elementwise interface to apply upper and lower bound constraints.
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.