25 template<
class ScalarT>
32 ScalarT eval(
const std::vector<ScalarT> &x);
46 template<
class ScalarT>
56 for(uint i=0; i<x.size(); ++i) {
58 kdotx += ScalarT(i+1)*x[i];
62 J = xdotx + pow(kdotx,2)/4.0 + pow(kdotx,4)/16.0;
95 return dynamic_cast<const SV&
>(x).getVector();
100 return dynamic_cast<SV&
>(x).getVector();
110 ROL::Ptr<const vector> xp = getVector(x);
111 return zfunc_.eval(*xp);
117 ROL::Ptr<const vector> xp = getVector(x);
118 ROL::Ptr<vector> gp = getVector(g);
122 std::vector<GradType> x_grad(n);
124 for(
uint i=0; i<n; ++i) {
125 x_grad[i] = (*xp)[i];
129 GradType J_grad = zfuncGrad_.eval(x_grad);
131 for(
uint i=0; i<n; ++i) {
132 (*gp)[i] = J_grad.dx(i);
141 ROL::Ptr<vector> hvp = getVector(hv);
142 ROL::Ptr<const vector> vp = getVector(v);
143 ROL::Ptr<const vector> xp = getVector(x);
147 std::vector<HessVecType> x_hessvec(n);
149 for(
uint i=0; i<n; ++i) {
151 tmp.fastAccessDx(0)= (*vp)[i];
153 x_hessvec[i].diff(i,n);
157 HessVecType J_hessvec = zfuncHessVec_.eval(x_hessvec);
159 for(
uint i=0; i<n; ++i) {
160 (*hvp)[i] = (J_hessvec.dx(i)).fastAccessDx(0);
Provides the interface to evaluate objective functions.
FunctionZakharov< HessVecType > zfuncHessVec_
ScalarT eval(const std::vector< ScalarT > &x)
A Sacado-accessible version of the Zakharov function to differentiate Where .
typename PV< Real >::size_type size_type
FunctionZakharov< Real > zfunc_
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
FunctionZakharov< GradType > zfuncGrad_
Defines the linear algebra or vector space interface.
ROL::Ptr< vector > getVector(V &x)
Sacado::Fad::SFad< Real, 1 > DirDerivType
ROL::Ptr< const vector > getVector(const V &x)
Sacado::Fad::DFad< Real > GradType
std::vector< Real > vector
Zakharov_Sacado_Objective()
Real value(const Vector< Real > &x, Real &tol)
Compute value.
Sacado::Fad::DFad< DirDerivType > HessVecType
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.