56 int main(
int argc,
char **argv) {
60 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
63 int iprint = argc - 1;
64 ROL::Ptr<std::ostream> outStream;
67 outStream = ROL::makePtrFromRef(std::cout);
69 outStream = ROL::makePtrFromRef(bhs);
74 ROL::ParameterList parlist;
75 std::string paramfile =
"parameters.xml";
76 auto gplist = ROL::getParametersFromXmlFile( paramfile );
78 int nx = gplist->get(
"Interior Grid Points",100);
79 RealT gnl = gplist->get(
"Nonlinearity Coefficient g",50.0);
80 bool exactsolve = gplist->get(
"Solve Exact Augmented System",
false);
84 std::string input = argv[1];
85 std::transform(input.begin(), input.end(), input.begin(), ::tolower);
86 if(input==
"exactsolve") {
93 RealT dx = 1.0/(nx+1);
96 ROL::Ptr<FiniteDifference<RealT> > fd = ROL::makePtr<FiniteDifference<RealT>>(nx,dx);
99 ROL::Ptr<std::vector<RealT> > xi_ptr = ROL::makePtr<std::vector<RealT>>(nx, 0.0);
101 for(
int i=0; i<nx; ++i) {
102 (*xi_ptr)[i] =
RealT(i+1)/(nx+1);
106 ROL::Ptr<std::vector<RealT> > V_ptr = ROL::makePtr<std::vector<RealT>>(nx, 0.0);
107 for(
int i=0; i<nx; ++i) {
108 (*V_ptr)[i] = 100.0*pow((*xi_ptr)[i]-0.5,2);
114 ROL::Ptr<std::vector<RealT> > psi_ptr = ROL::makePtr<std::vector<RealT>>(nx, 0.0);
118 RealT sqrt30 = sqrt(30);
120 for (
int i=0; i<nx; i++) {
121 (*psi_ptr)[i] = sqrt30*(*xi_ptr)[i]*(1.0-(*xi_ptr)[i]);
126 ROL::Ptr<std::vector<RealT> > c_ptr = ROL::makePtr<std::vector<RealT>>(1, 0.0);
130 ROL::Ptr<std::vector<RealT> > lam_ptr = ROL::makePtr<std::vector<RealT>>(1, 0.0);
134 ROL::Ptr<std::vector<RealT> > g_ptr = ROL::makePtr<std::vector<RealT>>(nx, 0.0);
146 std::string stepname =
"Composite Step";
147 parlist.sublist(
"Step").sublist(stepname).sublist(
"Optimality System Solver").set(
"Nominal Relative Tolerance",1e-4);
148 parlist.sublist(
"Step").sublist(stepname).sublist(
"Optimality System Solver").set(
"Fix Tolerance",
true);
149 parlist.sublist(
"Step").sublist(stepname).sublist(
"Tangential Subproblem Solver").set(
"Iteration Limit",20);
150 parlist.sublist(
"Step").sublist(stepname).sublist(
"Tangential Subproblem Solver").set(
"Relative Tolerance",1e-2);
151 parlist.sublist(
"Step").sublist(stepname).set(
"Output Level",0);
152 parlist.sublist(
"Status Test").set(
"Gradient Tolerance",1.e-12);
153 parlist.sublist(
"Status Test").set(
"Constraint Tolerance",1.e-12);
154 parlist.sublist(
"Status Test").set(
"Step Tolerance",1.e-14);
155 parlist.sublist(
"Status Test").set(
"Iteration Limit",100);
156 ROL::Ptr<ROL::StatusTest<RealT>>
157 status = ROL::makePtr<ROL::ConstraintStatusTest<RealT>>(parlist);
158 ROL::Ptr<ROL::Step<RealT>>
159 step = ROL::makePtr<ROL::CompositeStep<RealT>>(parlist);
163 algo.run(psi, g, lam, c, obj, constr,
true, *outStream);
165 if(algo.getState()->gnorm>1e-6) {
170 std::cout <<
"End Result: TEST FAILED\n";
172 std::cout <<
"End Result: TEST PASSED\n";
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
Provides an interface to run optimization algorithms.
basic_nullstream< char, char_traits< char >> nullstream
int main(int argc, char *argv[])