53 int main(
int argc,
char *argv[]) {
55 typedef std::vector<RealT> vector;
59 typedef typename vector::size_type uint;
61 using Teuchos::RCP;
using Teuchos::rcp;
63 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
66 int iprint = argc - 1;
67 Teuchos::RCP<std::ostream> outStream;
68 Teuchos::oblackholestream bhs;
70 outStream = Teuchos::rcp(&std::cout,
false);
72 outStream = Teuchos::rcp(&bhs,
false);
84 RCP<vector> x_rcp = rcp(
new vector(nx+2, 1.0) );
85 RCP<vector> y_rcp = rcp(
new vector(nx+2, 0.0) );
86 for (uint i=0; i<nx+2; i++) {
99 RCP<vector> l_rcp = rcp(
new vector(nx+2,0.0) );
100 RCP<vector> u_rcp = rcp(
new vector(nx+2,1.0) );
101 RCP<V> lo = rcp(
new SV(l_rcp) );
102 RCP<V> up = rcp(
new SV(u_rcp) );
107 RCP<ROL::Algorithm<RealT> > algo;
110 std::string filename =
"input.xml";
111 RCP<Teuchos::ParameterList> parlist = rcp(
new Teuchos::ParameterList() );
112 Teuchos::updateParametersFromXmlFile( filename, parlist.ptr() );
114 parlist->sublist(
"General").sublist(
"Krylov").set(
"Absolute Tolerance",1.e-8);
115 parlist->sublist(
"General").sublist(
"Krylov").set(
"Relative Tolerance",1.e-4);
116 parlist->sublist(
"General").sublist(
"Krylov").set(
"Iteration Limit",50);
118 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Relative Step Tolerance",1.e-10);
119 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Relative Gradient Tolerance",1.e-8);
120 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Iteration Limit", 10);
121 parlist->sublist(
"Step").sublist(
"Primal Dual Active Set").set(
"Dual Scaling",(alpha>0.0)?alpha:1.e-4);
123 parlist->sublist(
"Status Test").set(
"Gradient Tolerance",1.e-12);
124 parlist->sublist(
"Status Test").set(
"Step Tolerance",1.e-16);
125 parlist->sublist(
"Status Test").set(
"Iteration Limit",100);
130 algo->run(x, obj, icon,
true, *outStream);
132 std::ofstream file_pdas;
133 file_pdas.open(
"control_PDAS.txt");
134 for (
unsigned i = 0; i < (unsigned)nx+2; i++ ) {
135 file_pdas << (*x_rcp)[i] <<
"\n";
140 parlist->sublist(
"General").sublist(
"Krylov").set(
"Absolute Tolerance",1.e-4);
141 parlist->sublist(
"General").sublist(
"Krylov").set(
"Relative Tolerance",1.e-2);
142 parlist->sublist(
"General").sublist(
"Krylov").set(
"Iteration Limit",50);
147 algo->run(y,obj,icon,
true,*outStream);
149 std::ofstream file_tr;
150 file_tr.open(
"control_TR.txt");
151 for (
unsigned i = 0; i < (unsigned)nx+2; i++ ) {
152 file_tr << (*y_rcp)[i] <<
"\n";
156 std::vector<RealT> u(nx,0.0);
157 std::vector<RealT> param(4,0.0);
160 file.open(
"state.txt");
161 for (
unsigned i=0; i<(unsigned)nx; i++) {
162 file << i/((
RealT)(nx+1)) <<
" " << u[i] <<
"\n";
166 Teuchos::RCP<ROL::Vector<RealT> > diff = x.clone();
169 RealT error = diff->norm();
170 *outStream <<
"\nError between PDAS solution and TR solution is " << error <<
"\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";
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 std::vector implementation of the ROL::Vector interface.
Provides an interface to run optimization algorithms.
Provides the interface to apply upper and lower bound constraints.
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.
static const double ROL_EPSILON
Platform-dependent machine epsilon.