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
25int 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
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
Contains definitions for Rosenbrock's function.
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
Provides the interface to evaluate conic approximation function.
Ptr< Objective< Real > > getObjective(void) const
Ptr< Vector< Real > > getInitialGuess(void) const
int main(int argc, char *argv[])