76 int main(
int argc,
char **argv) {
79 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
82 int iprint = argc - 1;
83 ROL::Ptr<std::ostream> outStream;
86 outStream = ROL::makePtrFromRef(std::cout);
88 outStream = ROL::makePtrFromRef(bhs);
92 ROL::ParameterList parlist;
94 std::string paramfile =
"parameters.xml";
95 auto gplist = ROL::getParametersFromXmlFile( paramfile );
97 int nx = gplist ->
get(
"Interior Grid Points",100);
98 RealT gnl = gplist ->
get(
"Nonlinearity Coefficient g",50.0);
101 RealT dx = 1.0/(nx+1);
104 ROL::Ptr<std::vector<RealT> > xi_ptr = ROL::makePtr<std::vector<RealT>>(nx, 0.0);
106 for(
int i=0; i<nx; ++i) {
107 (*xi_ptr)[i] =
RealT(i+1)/(nx+1);
111 ROL::Ptr<std::vector<RealT> > V_ptr = ROL::makePtr<std::vector<RealT>>(nx, 0.0);
112 for(
int i=0; i<nx; ++i) {
113 (*V_ptr)[i] = 100.0*pow((*xi_ptr)[i]-0.5,2);
119 ROL::Ptr<std::vector<RealT> > psi_ptr = ROL::makePtr<std::vector<RealT>>(nx, 0.0);
123 RealT sqrt30 = sqrt(30);
125 for (
int i=0; i<nx; i++) {
126 (*psi_ptr)[i] = sqrt30*(*xi_ptr)[i]*(1.0-(*xi_ptr)[i]);
132 ROL::Ptr<std::vector<RealT> > c_ptr = ROL::makePtr<std::vector<RealT>>(1, 0.0);
136 ROL::Ptr<std::vector<RealT> > lam_ptr = ROL::makePtr<std::vector<RealT>>(1, 0.0);
140 ROL::Ptr<std::vector<RealT> > g_ptr = ROL::makePtr<std::vector<RealT>>(nx, 0.0);
150 std::string stepname =
"Composite Step";
151 parlist.sublist(
"Step").sublist(stepname).sublist(
"Optimality System Solver").set(
"Nominal Relative Tolerance",1e-4);
152 parlist.sublist(
"Step").sublist(stepname).sublist(
"Optimality System Solver").set(
"Fix Tolerance",
true);
153 parlist.sublist(
"Step").sublist(stepname).sublist(
"Tangential Subproblem Solver").set(
"Iteration Limit",20);
154 parlist.sublist(
"Step").sublist(stepname).sublist(
"Tangential Subproblem Solver").set(
"Relative Tolerance",1e-2);
155 parlist.sublist(
"Step").sublist(stepname).set(
"Output Level",0);
156 parlist.sublist(
"Status Test").set(
"Gradient Tolerance",1.e-12);
157 parlist.sublist(
"Status Test").set(
"Constraint Tolerance",1.e-12);
158 parlist.sublist(
"Status Test").set(
"Step Tolerance",1.e-14);
159 parlist.sublist(
"Status Test").set(
"Iteration Limit",100);
160 ROL::Ptr<ROL::StatusTest<RealT>>
161 status = ROL::makePtr<ROL::ConstraintStatusTest<RealT>>(parlist);
162 ROL::Ptr<ROL::Step<RealT>>
163 step = ROL::makePtr<ROL::CompositeStep<RealT>>(parlist);
167 algo.run(psi, g, lam, c, obj, constr,
true, *outStream);
170 if(algo.getState()->gnorm>1e-6) {
175 std::cout <<
"End Result: TEST FAILED\n";
177 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[])