90 int main(
int argc,
char **argv) {
94 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
97 int iprint = argc - 1;
98 ROL::Ptr<std::ostream> outStream;
101 outStream = ROL::makePtrFromRef(std::cout);
103 outStream = ROL::makePtrFromRef(bhs);
108 ROL::ParameterList parlist;
109 std::string paramfile =
"parameters.xml";
110 auto gplist = ROL::getParametersFromXmlFile( paramfile );
112 int nx = gplist->get(
"Interior Grid Points",100);
113 RealT gnl = gplist->get(
"Nonlinearity Coefficient g",50.0);
114 bool exactsolve = gplist->get(
"Solve Exact Augmented System",
false);
118 std::string input = argv[1];
119 std::transform(input.begin(), input.end(), input.begin(), ::tolower);
120 if(input==
"exactsolve") {
127 RealT dx = 1.0/(nx+1);
130 ROL::Ptr<FiniteDifference<RealT> > fd = ROL::makePtr<FiniteDifference<RealT>>(nx,dx);
133 ROL::Ptr<std::vector<RealT> > xi_ptr = ROL::makePtr<std::vector<RealT>>(nx, 0.0);
135 for(
int i=0; i<nx; ++i) {
136 (*xi_ptr)[i] =
RealT(i+1)/(nx+1);
140 ROL::Ptr<std::vector<RealT> > V_ptr = ROL::makePtr<std::vector<RealT>>(nx, 0.0);
141 for(
int i=0; i<nx; ++i) {
142 (*V_ptr)[i] = 100.0*pow((*xi_ptr)[i]-0.5,2);
148 ROL::Ptr<std::vector<RealT> > psi_ptr = ROL::makePtr<std::vector<RealT>>(nx, 0.0);
152 RealT sqrt30 = sqrt(30);
154 for (
int i=0; i<nx; i++) {
155 (*psi_ptr)[i] = sqrt30*(*xi_ptr)[i]*(1.0-(*xi_ptr)[i]);
160 ROL::Ptr<std::vector<RealT> > c_ptr = ROL::makePtr<std::vector<RealT>>(1, 0.0);
164 ROL::Ptr<std::vector<RealT> > lam_ptr = ROL::makePtr<std::vector<RealT>>(1, 0.0);
168 ROL::Ptr<std::vector<RealT> > g_ptr = ROL::makePtr<std::vector<RealT>>(nx, 0.0);
180 std::string stepname =
"Composite Step";
181 parlist.sublist(
"Step").sublist(stepname).sublist(
"Optimality System Solver").set(
"Nominal Relative Tolerance",1e-4);
182 parlist.sublist(
"Step").sublist(stepname).sublist(
"Optimality System Solver").set(
"Fix Tolerance",
true);
183 parlist.sublist(
"Step").sublist(stepname).sublist(
"Tangential Subproblem Solver").set(
"Iteration Limit",20);
184 parlist.sublist(
"Step").sublist(stepname).sublist(
"Tangential Subproblem Solver").set(
"Relative Tolerance",1e-2);
185 parlist.sublist(
"Step").sublist(stepname).set(
"Output Level",0);
186 parlist.sublist(
"Status Test").set(
"Gradient Tolerance",1.e-12);
187 parlist.sublist(
"Status Test").set(
"Constraint Tolerance",1.e-12);
188 parlist.sublist(
"Status Test").set(
"Step Tolerance",1.e-14);
189 parlist.sublist(
"Status Test").set(
"Iteration Limit",100);
190 ROL::Ptr<ROL::StatusTest<RealT>>
191 status = ROL::makePtr<ROL::ConstraintStatusTest<RealT>>(parlist);
192 ROL::Ptr<ROL::Step<RealT>>
193 step = ROL::makePtr<ROL::CompositeStep<RealT>>(parlist);
197 algo.run(psi, g, lam, c, obj, constr,
true, *outStream);
199 if(algo.getState()->gnorm>1e-6) {
204 std::cout <<
"End Result: TEST FAILED\n";
206 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[])