45 #include "Teuchos_GlobalMPISession.hpp"
55 Real
value(
const std::vector<Real> &x, Real &tol ) {
57 unsigned size = x.size();
58 std::vector<Real> p(size+2,1);
59 for (
unsigned i = 0; i < size; i++ ) {
63 return std::exp(p[0])*quad + lin + p[size+1];
66 void gradient( std::vector<Real> &g,
const std::vector<Real> &x, Real &tol ) {
67 unsigned size = x.size();
68 std::vector<Real> p(size+2,1);
70 for (
unsigned i = 0; i < size; i++ ) {
71 g[i] = two*std::exp(p[0])*x[i] + p[i+1];
75 void hessVec( std::vector<Real> &hv,
const std::vector<Real> &v,
const std::vector<Real> &x, Real &tol ) {
76 unsigned size = x.size();
77 std::vector<Real> p(size+2,1);
79 for (
unsigned i = 0; i < size; i++ ) {
80 hv[i] = two*std::exp(p[0])*v[i];
86 unsigned dim = x.size();
87 for (
unsigned i = 0; i < dim; i++ ) {
92 int main(
int argc,
char* argv[]) {
94 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
97 int iprint = argc - 1;
98 ROL::Ptr<std::ostream> outStream;
101 outStream = ROL::makePtrFromRef(std::cout);
103 outStream = ROL::makePtrFromRef(bhs);
113 ROL::Ptr<std::vector<RealT> > x_ptr = ROL::makePtr<std::vector<RealT>>(dim,0.0);
114 ROL::Ptr<ROL::Vector<RealT> > x = ROL::makePtr<ROL::StdVector<RealT>>(x_ptr);
116 ROL::Ptr<std::vector<RealT> > d_ptr = ROL::makePtr<std::vector<RealT>>(dim,0.0);
117 ROL::Ptr<ROL::Vector<RealT> > d = ROL::makePtr<ROL::StdVector<RealT>>(d_ptr);
120 ROL::Ptr<ROL::StdObjective<RealT> > obj =
121 ROL::makePtr<ObjectiveFunctionTest06<RealT>>();
123 *outStream <<
"Check Derivatives of StdObjective\n";
124 obj->checkGradient(*x,*d,
true,*outStream);
125 obj->checkHessVec(*x,*d,
true,*outStream);
127 catch (std::logic_error err) {
128 *outStream << err.what() <<
"\n";
133 std::cout <<
"End Result: TEST FAILED\n";
135 std::cout <<
"End Result: TEST PASSED\n";
void gradient(std::vector< Real > &g, const std::vector< Real > &x, Real &tol)
void setRandomVector(std::vector< RealT > &x)
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
void hessVec(std::vector< Real > &hv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Specializes the ROL::Objective interface for objective functions that operate on ROL::StdVector's.
Real value(const std::vector< Real > &x, Real &tol)
basic_nullstream< char, char_traits< char >> nullstream
int main(int argc, char *argv[])