ROL
step/trustregion/test_01.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 "Teuchos_GlobalMPISession.hpp"
16 
17 #include "ROL_Stream.hpp"
18 #include "ROL_RandomVector.hpp"
19 #include "ROL_Rosenbrock.hpp"
20 #include "ROL_ConicApproximationModel.hpp"
21 
22 #include <iostream>
23 
24 
25 int main(int argc, char *argv[]) {
26 
27  using RealT = double;
28  using namespace ROL;
29 
30  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
31 
32  // This little trick lets us print to std::cout only if a (dummy) command-line argument is provided.
33  auto outStream = makeStreamPtr( std::cout, argc > 1 );
34 
35  int errorFlag = 0;
36 
37  // *** Test body.
38 
39  try {
40 
41  ZOO::getRosenbrock<RealT> rosenbrock;
42 
43  auto x = rosenbrock.getInitialGuess();
44  auto a = x->clone();
45  auto s = x->clone();
46  auto d = x->clone();
47  auto obj = rosenbrock.getObjective();
48 
49  RandomizeVector( *s );
50  RandomizeVector( *a );
51  RandomizeVector( *d );
52 
53  ConicApproximationModel<RealT> conic( obj, x, s, a );
54  conic.checkGradient( *x, *d, true, *outStream );
55 
56  }
57  catch (std::logic_error& err) {
58  *outStream << err.what() << std::endl;
59  errorFlag = -1000;
60  }; // end try
61 
62  if (errorFlag != 0)
63  std::cout << "End Result: TEST FAILED" << std::endl;
64  else
65  std::cout << "End Result: TEST PASSED" << std::endl;
66 
67  return 0;
68 
69 }
70 
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].
Contains definitions for Rosenbrock&#39;s function.
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
Ptr< ostream > makeStreamPtr(ostream &os, bool noSuppressOutput=true)
Definition: ROL_Stream.hpp:41
virtual std::vector< std::vector< Real > > checkGradient(const Vector< Real > &x, const Vector< Real > &d, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
Finite-difference gradient check.
Ptr< Objective< Real > > getObjective(void) const
int main(int argc, char *argv[])
Ptr< Vector< Real > > getInitialGuess(void) const