11 #include "Teuchos_GlobalMPISession.hpp"
21 Real
value(
const std::vector<Real> &x, Real &tol ) {
23 unsigned size = x.size();
24 std::vector<Real> p(size+2,1);
25 for (
unsigned i = 0; i < size; i++ ) {
29 return std::exp(p[0])*quad + lin + p[size+1];
32 void gradient( std::vector<Real> &g,
const std::vector<Real> &x, Real &tol ) {
33 unsigned size = x.size();
34 std::vector<Real> p(size+2,1);
36 for (
unsigned i = 0; i < size; i++ ) {
37 g[i] = two*std::exp(p[0])*x[i] + p[i+1];
41 void hessVec( std::vector<Real> &hv,
const std::vector<Real> &v,
const std::vector<Real> &x, Real &tol ) {
42 unsigned size = x.size();
43 std::vector<Real> p(size+2,1);
45 for (
unsigned i = 0; i < size; i++ ) {
46 hv[i] = two*std::exp(p[0])*v[i];
52 unsigned dim = x.size();
53 for (
unsigned i = 0; i <
dim; i++ ) {
58 int main(
int argc,
char* argv[]) {
60 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
63 int iprint = argc - 1;
64 ROL::Ptr<std::ostream> outStream;
67 outStream = ROL::makePtrFromRef(std::cout);
69 outStream = ROL::makePtrFromRef(bhs);
79 ROL::Ptr<std::vector<RealT> > x_ptr = ROL::makePtr<std::vector<RealT>>(
dim,0.0);
80 ROL::Ptr<ROL::Vector<RealT> > x = ROL::makePtr<ROL::StdVector<RealT>>(x_ptr);
82 ROL::Ptr<std::vector<RealT> > d_ptr = ROL::makePtr<std::vector<RealT>>(
dim,0.0);
83 ROL::Ptr<ROL::Vector<RealT> > d = ROL::makePtr<ROL::StdVector<RealT>>(d_ptr);
86 ROL::Ptr<ROL::StdObjective<RealT> > obj =
87 ROL::makePtr<ObjectiveFunctionTest06<RealT>>();
89 *outStream <<
"Check Derivatives of StdObjective\n";
90 obj->checkGradient(*x,*d,
true,*outStream);
91 obj->checkHessVec(*x,*d,
true,*outStream);
93 catch (std::logic_error& err) {
94 *outStream << err.what() <<
"\n";
99 std::cout <<
"End Result: TEST FAILED\n";
101 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[])