ROL
step/test_16.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Rapid Optimization Library (ROL) Package
4 //
5 // Copyright 2014 NTESS and the ROL contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
14 #include "ROL_GetTestProblems.hpp"
16 #include "ROL_Stream.hpp"
17 #include "Teuchos_GlobalMPISession.hpp"
18 #include "Teuchos_XMLParameterListHelpers.hpp"
19 
20 #include <iostream>
21 
22 typedef double RealT;
23 
24 int main(int argc, char *argv[]) {
25 
26  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
27 
28  // This little trick lets us print to std::cout only if a (dummy) command-line argument is provided.
29  int iprint = argc - 1;
30  ROL::Ptr<std::ostream> outStream;
31  ROL::nullstream bhs; // outputs nothing
32  if (iprint > 0)
33  outStream = ROL::makePtrFromRef(std::cout);
34  else
35  outStream = ROL::makePtrFromRef(bhs);
36 
37  int errorFlag = 0;
38 
39  // *** Test body.
40 
41  try {
42  std::string filename = "input.xml";
43  auto parlist = ROL::getParametersFromXmlFile( filename );
44 
45  // Setup optimization problem
46  ROL::Ptr<ROL::Vector<RealT>> x0;
47  std::vector<ROL::Ptr<ROL::Vector<RealT>>> z;
48  ROL::Ptr<ROL::OptimizationProblem<RealT>> optProblem;
49  //ROL::GetTestProblem<RealT>(optProblem,x0,z,ROL::TESTOPTPROBLEM_CANTILEVERBEAM);
50  //ROL::GetTestProblem<RealT>(optProblem,x0,z,ROL::TESTOPTPROBLEM_CYLINDERHEAD);
51  //ROL::GetTestProblem<RealT>(optProblem,x0,z,ROL::TESTOPTPROBLEM_QUARTIC);
52  ROL::GetTestProblem<RealT>(optProblem,x0,z,ROL::TESTOPTPROBLEM_CANTILEVER);
53 
54  // Get Dimension of Problem
55  int dim = x0->dimension();
56  parlist->sublist("General").sublist("Krylov").set("Iteration Limit", 2*dim);
57 
58  // Check Derivatives
59  optProblem->check(*outStream);
60 
61  // Error Vector
62 // ROL::Ptr<ROL::Vector<RealT>> e = x0->clone();
63 // e->zero();
64 
65  // Setup optimization solver
66  parlist->sublist("Status Test").set("Gradient Tolerance",static_cast<RealT>(1e-6));
67  parlist->sublist("Step").set("Type", "Augmented Lagrangian");
68  ROL::OptimizationSolver<RealT> optSolver(*optProblem,*parlist);
69  optSolver.solve(*outStream);
70 
71  // Compute Error
72 // RealT err(0);
73 // for (int i = 0; i < static_cast<int>(z.size()); ++i) {
74 // e->set(*x0);
75 // e->axpy(-1.0,*z[i]);
76 // if (i == 0) {
77 // err = e->norm();
78 // }
79 // else {
80 // err = std::min(err,e->norm());
81 // }
82 // }
83 // *outStream << std::endl << "Norm of Error: " << err << std::endl;
84 //
85 // RealT tol = static_cast<RealT>(1e-3)*std::max(z[0]->norm(),static_cast<RealT>(1));
86 // errorFlag += ((err < tol) ? 0 : 1);
87  }
88  catch (std::logic_error& err) {
89  *outStream << err.what() << std::endl;
90  errorFlag = -1000;
91  }; // end try
92 
93  if (errorFlag != 0)
94  std::cout << "End Result: TEST FAILED" << std::endl;
95  else
96  std::cout << "End Result: TEST PASSED" << std::endl;
97 
98  return 0;
99 
100 }
101 
Contains definitions of test objective functions.
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
Provides a simplified interface for solving a wide range of optimization problems.
basic_nullstream< char, char_traits< char >> nullstream
Definition: ROL_Stream.hpp:38
int main(int argc, char *argv[])
int solve(const ROL::Ptr< StatusTest< Real > > &status=ROL::nullPtr, const bool combineStatus=true)
Solve optimization problem with no iteration output.
constexpr auto dim