42 int main(
int argc,
char **argv) {
45 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
48 int iprint = argc - 1;
49 ROL::Ptr<std::ostream> outStream;
52 outStream = ROL::makePtrFromRef(std::cout);
54 outStream = ROL::makePtrFromRef(bhs);
58 ROL::ParameterList parlist;
60 std::string paramfile =
"parameters.xml";
61 auto gplist = ROL::getParametersFromXmlFile( paramfile );
63 int nx = gplist ->
get(
"Interior Grid Points",100);
64 RealT gnl = gplist ->
get(
"Nonlinearity Coefficient g",50.0);
67 RealT dx = 1.0/(nx+1);
70 ROL::Ptr<std::vector<RealT> > xi_ptr = ROL::makePtr<std::vector<RealT>>(nx, 0.0);
72 for(
int i=0; i<nx; ++i) {
73 (*xi_ptr)[i] =
RealT(i+1)/(nx+1);
77 ROL::Ptr<std::vector<RealT> > V_ptr = ROL::makePtr<std::vector<RealT>>(nx, 0.0);
78 for(
int i=0; i<nx; ++i) {
79 (*V_ptr)[i] = 100.0*pow((*xi_ptr)[i]-0.5,2);
85 ROL::Ptr<std::vector<RealT> > psi_ptr = ROL::makePtr<std::vector<RealT>>(nx, 0.0);
89 RealT sqrt30 = sqrt(30);
91 for (
int i=0; i<nx; i++) {
92 (*psi_ptr)[i] = sqrt30*(*xi_ptr)[i]*(1.0-(*xi_ptr)[i]);
98 ROL::Ptr<std::vector<RealT> > c_ptr = ROL::makePtr<std::vector<RealT>>(1, 0.0);
102 ROL::Ptr<std::vector<RealT> > lam_ptr = ROL::makePtr<std::vector<RealT>>(1, 0.0);
106 ROL::Ptr<std::vector<RealT> > g_ptr = ROL::makePtr<std::vector<RealT>>(nx, 0.0);
116 std::string stepname =
"Composite Step";
117 parlist.sublist(
"Step").sublist(stepname).sublist(
"Optimality System Solver").set(
"Nominal Relative Tolerance",1e-4);
118 parlist.sublist(
"Step").sublist(stepname).sublist(
"Optimality System Solver").set(
"Fix Tolerance",
true);
119 parlist.sublist(
"Step").sublist(stepname).sublist(
"Tangential Subproblem Solver").set(
"Iteration Limit",20);
120 parlist.sublist(
"Step").sublist(stepname).sublist(
"Tangential Subproblem Solver").set(
"Relative Tolerance",1e-2);
121 parlist.sublist(
"Step").sublist(stepname).set(
"Output Level",0);
122 parlist.sublist(
"Status Test").set(
"Gradient Tolerance",1.e-12);
123 parlist.sublist(
"Status Test").set(
"Constraint Tolerance",1.e-12);
124 parlist.sublist(
"Status Test").set(
"Step Tolerance",1.e-14);
125 parlist.sublist(
"Status Test").set(
"Iteration Limit",100);
126 ROL::Ptr<ROL::StatusTest<RealT>>
127 status = ROL::makePtr<ROL::ConstraintStatusTest<RealT>>(parlist);
128 ROL::Ptr<ROL::Step<RealT>>
129 step = ROL::makePtr<ROL::CompositeStep<RealT>>(parlist);
133 algo.run(psi, g, lam, c, obj, constr,
true, *outStream);
136 if(algo.getState()->gnorm>1e-6) {
141 std::cout <<
"End Result: TEST FAILED\n";
143 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[])