ROL
function/test_11.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 
15 #include "ROL_ColemanLiModel.hpp"
16 #include "ROL_HS2.hpp"
17 #include "ROL_StdVector.hpp"
18 #include "ROL_RandomVector.hpp"
19 #include "ROL_Stream.hpp"
20 #include "Teuchos_GlobalMPISession.hpp"
21 //#include <fenv.h>
22 
23 typedef double RealT;
24 
25 int main(int argc, char *argv[]) {
26  //feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
27 
28  typedef ROL::Vector<RealT> V;
29  typedef ROL::Objective<RealT> OBJ;
30  typedef ROL::BoundConstraint<RealT> CON;
31 
32  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
33 
34  // This little trick lets us print to std::cout only if a (dummy) command-line argument is provided.
35  int iprint = argc - 1;
36  ROL::Ptr<std::ostream> outStream;
37  ROL::nullstream bhs; // outputs nothing
38  if (iprint > 0)
39  outStream = ROL::makePtrFromRef(std::cout);
40  else
41  outStream = ROL::makePtrFromRef(bhs);
42 
43  // Save the format state of the original std::cout.
44  ROL::nullstream oldFormatState;
45  oldFormatState.copyfmt(std::cout);
46 
47  RealT zero(0);
48 
49  ROL::Ptr<V> x0;
50  ROL::Ptr<V> x;
51  ROL::Ptr<V> g;
52  ROL::Ptr<OBJ> obj;
53  ROL::Ptr<CON> con;
54  ROL::Ptr<OBJ> model;
55 
57  obj = HS2.getObjective();
58  con = HS2.getBoundConstraint();
59  x0 = HS2.getInitialGuess();
60  x = HS2.getSolution();
61 
62  g = x->dual().clone();
63 
64  // Need to evaluate the gradient to construct the model
65  obj->gradient(*g,*x,zero);
66 
67  model = ROL::makePtr<ROL::ColemanLiModel<RealT>>(*obj,*con,*x,*g);
68 
69  ROL::Ptr<V> s = x->clone();
70  ROL::Ptr<V> v = x->clone();
71  ROL::Ptr<V> u = x->clone();
72 
73  ROL::RandomizeVector(*s,-1.0,1.0);
74  ROL::RandomizeVector(*u,-1.0,1.0);
75  ROL::RandomizeVector(*v,-1.0,1.0);
76 
77  model->checkGradient(*s,*v);
78  model->checkHessVec(*s,*v);
79  model->checkHessSym(*s,*u,*v);
80 
81  return 0;
82 }
83 
84 
Provides the interface to evaluate objective functions.
void RandomizeVector(Vector< Real > &x, const Real &lower=0.0, const Real &upper=1.0)
Fill a ROL::Vector with uniformly-distributed random numbers in the interval [lower,upper].
Ptr< Vector< Real > > getInitialGuess(void) const
Definition: ROL_HS2.hpp:123
Ptr< Objective< Real > > getObjective(void) const
Definition: ROL_HS2.hpp:118
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
Vector< Real > V
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition: ROL_HS2.hpp:132
Provides the interface to apply upper and lower bound constraints.
basic_nullstream< char, char_traits< char >> nullstream
Definition: ROL_Stream.hpp:38
int main(int argc, char *argv[])
Contains definitions for W. Hock and K. Schittkowski 2nd test function.
Ptr< BoundConstraint< Real > > getBoundConstraint(void) const
Definition: ROL_HS2.hpp:144