20 #include "Teuchos_GlobalMPISession.hpp"
26 int main(
int argc,
char *argv[]) {
28 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
31 int iprint = argc - 1;
32 ROL::Ptr<std::ostream> outStream;
35 outStream = ROL::makePtrFromRef(std::cout);
37 outStream = ROL::makePtrFromRef(bhs);
41 oldFormatState.copyfmt(std::cout);
46 RealT left = -1.0, right = 1.0;
53 ROL::Ptr<std::vector<RealT> > x_ptr = ROL::makePtr<std::vector<RealT>>(
dim, 0.0);
54 ROL::Ptr<std::vector<RealT> > y_ptr = ROL::makePtr<std::vector<RealT>>(
dim, 0.0);
55 ROL::Ptr<std::vector<RealT> > z_ptr = ROL::makePtr<std::vector<RealT>>(
dim, 0.0);
61 for (
int i=0; i<
dim; i++) {
62 (*x_ptr)[i] = 10.0* (1.0 + (
RealT)rand() / (
RealT)RAND_MAX);
63 (*y_ptr)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
64 (*z_ptr)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
72 std::vector<std::vector<RealT> > gCheck = obj.
checkGradient(x, y);
74 for (
unsigned i=0; i<gCheck.size(); i++) {
76 *outStream << std::right
77 << std::setw(20) <<
"Step size"
78 << std::setw(20) <<
"grad'*dir"
79 << std::setw(20) <<
"FD approx"
80 << std::setw(20) <<
"abs error"
83 *outStream << std::scientific << std::setprecision(8) << std::right
84 << std::setw(20) << gCheck[i][0]
85 << std::setw(20) << gCheck[i][1]
86 << std::setw(20) << gCheck[i][2]
87 << std::setw(20) << gCheck[i][3]
92 std::vector<std::vector<RealT> > hvCheck = obj.
checkHessVec(x, y);
94 for (
unsigned i=0; i<hvCheck.size(); i++) {
96 *outStream << std::right
97 << std::setw(20) <<
"Step size"
98 << std::setw(20) <<
"norm(Hess*vec)"
99 << std::setw(20) <<
"norm(FD approx)"
100 << std::setw(20) <<
"norm(abs error)"
103 *outStream << std::scientific << std::setprecision(8) << std::right
104 << std::setw(20) << hvCheck[i][0]
105 << std::setw(20) << hvCheck[i][1]
106 << std::setw(20) << hvCheck[i][2]
107 << std::setw(20) << hvCheck[i][3]
112 std::vector<RealT> hsymCheck = obj.
checkHessSym(x, y, z);
114 *outStream << std::right
115 << std::setw(20) <<
"<w, H(x)v>"
116 << std::setw(20) <<
"<v, H(x)w>"
117 << std::setw(20) <<
"abs error"
119 *outStream << std::scientific << std::setprecision(8) << std::right
120 << std::setw(20) << hsymCheck[0]
121 << std::setw(20) << hsymCheck[1]
122 << std::setw(20) << hsymCheck[2]
132 for (
unsigned i=0; i<(eigenvals[0]).size(); i++) {
134 *outStream << std::right
135 << std::setw(20) <<
"Real"
136 << std::setw(20) <<
"Imag"
139 *outStream << std::scientific << std::setprecision(8) << std::right
140 << std::setw(20) << (eigenvals[0])[i]
141 << std::setw(20) << (eigenvals[1])[i]
146 catch (std::logic_error& err) {
147 *outStream << err.what() <<
"\n";
152 std::cout <<
"End Result: TEST FAILED\n";
154 std::cout <<
"End Result: TEST PASSED\n";
157 std::cout.copyfmt(oldFormatState);
Contains definitions of test objective functions.
Contains definitions for helper functions in ROL.
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
Teuchos::SerialDenseMatrix< int, Real > computeDenseHessian(Objective< Real > &obj, const Vector< Real > &x)
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.
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
std::vector< std::vector< Real > > computeEigenvalues(const Teuchos::SerialDenseMatrix< int, Real > &mat)
int dimension() const
Return dimension of the vector space.
basic_nullstream< char, char_traits< char >> nullstream
int main(int argc, char *argv[])
virtual std::vector< std::vector< Real > > checkHessVec(const Vector< Real > &x, const Vector< Real > &v, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
Finite-difference Hessian-applied-to-vector check.
virtual std::vector< Real > checkHessSym(const Vector< Real > &x, const Vector< Real > &v, const Vector< Real > &w, const bool printToStream=true, std::ostream &outStream=std::cout)
Hessian symmetry check.
Poisson material inversion.