88 int main(
int argc,
char **argv) {
92 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
95 int iprint = argc - 1;
96 ROL::Ptr<std::ostream> outStream;
99 outStream = ROL::makePtrFromRef(std::cout);
101 outStream = ROL::makePtrFromRef(bhs);
106 ROL::ParameterList parlist;
107 std::string paramfile =
"parameters.xml";
108 auto gplist = ROL::getParametersFromXmlFile( paramfile );
110 int nx = gplist->get(
"Interior Grid Points",100);
111 RealT gnl = gplist->get(
"Nonlinearity Coefficient g",50.0);
112 bool exactsolve = gplist->get(
"Solve Exact Augmented System",
false);
116 std::string input = argv[1];
117 std::transform(input.begin(), input.end(), input.begin(), ::tolower);
118 if(input==
"exactsolve") {
125 RealT dx = 1.0/(nx+1);
128 ROL::Ptr<FiniteDifference<RealT> > fd = ROL::makePtr<FiniteDifference<RealT>>(nx,dx);
131 ROL::Ptr<std::vector<RealT> > xi_ptr = ROL::makePtr<std::vector<RealT>>(nx, 0.0);
133 for(
int i=0; i<nx; ++i) {
134 (*xi_ptr)[i] =
RealT(i+1)/(nx+1);
138 ROL::Ptr<std::vector<RealT> > V_ptr = ROL::makePtr<std::vector<RealT>>(nx, 0.0);
139 for(
int i=0; i<nx; ++i) {
140 (*V_ptr)[i] = 100.0*pow((*xi_ptr)[i]-0.5,2);
146 ROL::Ptr<std::vector<RealT> > psi_ptr = ROL::makePtr<std::vector<RealT>>(nx, 0.0);
150 RealT sqrt30 = sqrt(30);
152 for (
int i=0; i<nx; i++) {
153 (*psi_ptr)[i] = sqrt30*(*xi_ptr)[i]*(1.0-(*xi_ptr)[i]);
158 ROL::Ptr<std::vector<RealT> > c_ptr = ROL::makePtr<std::vector<RealT>>(1, 0.0);
162 ROL::Ptr<std::vector<RealT> > lam_ptr = ROL::makePtr<std::vector<RealT>>(1, 0.0);
166 ROL::Ptr<std::vector<RealT> > g_ptr = ROL::makePtr<std::vector<RealT>>(nx, 0.0);
178 std::string stepname =
"Composite Step";
179 parlist.sublist(
"Step").sublist(stepname).sublist(
"Optimality System Solver").set(
"Nominal Relative Tolerance",1e-4);
180 parlist.sublist(
"Step").sublist(stepname).sublist(
"Optimality System Solver").set(
"Fix Tolerance",
true);
181 parlist.sublist(
"Step").sublist(stepname).sublist(
"Tangential Subproblem Solver").set(
"Iteration Limit",20);
182 parlist.sublist(
"Step").sublist(stepname).sublist(
"Tangential Subproblem Solver").set(
"Relative Tolerance",1e-2);
183 parlist.sublist(
"Step").sublist(stepname).set(
"Output Level",0);
184 parlist.sublist(
"Status Test").set(
"Gradient Tolerance",1.e-12);
185 parlist.sublist(
"Status Test").set(
"Constraint Tolerance",1.e-12);
186 parlist.sublist(
"Status Test").set(
"Step Tolerance",1.e-14);
187 parlist.sublist(
"Status Test").set(
"Iteration Limit",100);
191 algo.
run(psi, g, lam, c, obj, constr,
true, *outStream);
198 std::cout <<
"End Result: TEST FAILED\n";
200 std::cout <<
"End Result: TEST PASSED\n";
virtual std::vector< std::string > run(Vector< Real > &x, Objective< Real > &obj, bool print=false, std::ostream &outStream=std::cout, bool printVectors=false, std::ostream &vectorStream=std::cout)
Run algorithm on unconstrained problems (Type-U). This is the primary Type-U interface.
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
Provides an interface to run optimization algorithms.
ROL::Ptr< const AlgorithmState< Real > > getState(void) const
basic_nullstream< char, char_traits< char >> nullstream
int main(int argc, char *argv[])