59 template<
class ScalarT>
66 ScalarT eval(
const std::vector<ScalarT> &x);
80 template<
class ScalarT>
83 typedef typename std::vector<ScalarT>::size_type uint;
90 for(uint i=0; i<x.size(); ++i) {
92 kdotx += ScalarT(i+1)*x[i];
96 J = xdotx + pow(kdotx,2)/4.0 + pow(kdotx,4)/16.0;
113 typedef typename vector::size_type
uint;
128 using Teuchos::dyn_cast;
129 return dyn_cast<
const SV>(x).getVector();
133 using Teuchos::dyn_cast;
134 return dyn_cast<
SV>(x).getVector();
144 RCP<const vector> xp = getVector(x);
145 return zfunc_.
eval(*xp);
151 RCP<const vector> xp = getVector(x);
152 RCP<vector> gp = getVector(g);
156 std::vector<GradType> x_grad(n);
158 for(
uint i=0; i<n; ++i) {
159 x_grad[i] = (*xp)[i];
165 for(
uint i=0; i<n; ++i) {
166 (*gp)[i] = J_grad.dx(i);
175 RCP<vector> hvp = getVector(hv);
176 RCP<const vector> vp = getVector(v);
177 RCP<const vector> xp = getVector(x);
181 std::vector<HessVecType> x_hessvec(n);
183 for(
uint i=0; i<n; ++i) {
185 tmp.fastAccessDx(0)= (*vp)[i];
187 x_hessvec[i].diff(i,n);
193 for(
uint i=0; i<n; ++i) {
194 (*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 .
Teuchos::RCP< vector > getVector(V &x)
FunctionZakharov< Real > zfunc_
Teuchos::RCP< const vector > getVector(const V &x)
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
FunctionZakharov< GradType > zfuncGrad_
Defines the linear algebra or vector space interface.
Sacado::Fad::SFad< Real, 1 > DirDerivType
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.