13 Teuchos::RCP<const std::vector<Real>>
21 Teuchos::RCP<std::vector<Real>>
23 return Teuchos::rcp_const_cast<std::vector<Real>>
45 for(
int i=0; i<n; ++i) {
46 xdotx += pow((*xp)[i],2);
47 kdotx += double(i+1)*(*xp)[i];
51 J = xdotx + pow(kdotx,2)/4.0 + pow(kdotx,4)/16.0;
74 Teuchos::RCP<Objective<FadType>> obj_;
85 auto x_fad_rcp = Teuchos::rcp(
new std::vector<FadType>);
87 x_fad_rcp->reserve(n);
89 for(
int i=0; i<n; ++i) {
90 x_fad_rcp->push_back((*xp)[i]);
96 FadType J_fad = obj_->value(x_fad,tol_fad);
107 auto x_fad_rcp = Teuchos::rcp(
new std::vector<FadType> );
109 x_fad_rcp->reserve(n);
111 for(
int i=0; i<n; ++i) {
112 x_fad_rcp->push_back(
FadType(n,i,(*xp)[i]));
118 FadType J_fad = obj_->value(x_fad,tol_fad);
120 for(
int i=0; i<n; ++i) {
121 (*gp)[i] = J_fad.dx(i);
135 Teuchos::RCP<Objective<FadType>> obj_;
146 auto x_fad_rcp = Teuchos::rcp(
new std::vector<FadType>);
148 x_fad_rcp->reserve(n);
149 for(
int i=0; i<n; ++i) {
150 x_fad_rcp->push_back((*xp)[i]);
156 FadType J_fad = obj_->value(x_fad,tol_fad);
168 auto x_fad_rcp = Teuchos::rcp(
new std::vector<FadType>);
169 auto g_fad_rcp = Teuchos::rcp(
new std::vector<FadType>);
171 x_fad_rcp->reserve(n);
172 g_fad_rcp->reserve(n);
174 for(
int i=0; i<n; ++i) {
175 x_fad_rcp->push_back((*xp)[i]);
176 g_fad_rcp->push_back((*xp)[i]);
183 obj_->gradient(g_fad,x_fad,tol_fad);
185 for(
int i=0; i<n; ++i) {
186 (*gp)[i] = (*g_fad_rcp)[i].val();
197 auto x_fad_rcp = Teuchos::rcp(
new std::vector<FadType> );
198 x_fad_rcp->reserve(n);
201 auto g_fad_rcp = Teuchos::rcp(
new std::vector<FadType> );
203 g_fad_rcp->reserve(n);
205 for(
int i=0; i<n; ++i) {
206 x_fad_rcp->push_back(
FadType(1,(*xp)[i]));
207 g_fad_rcp->push_back(0);
208 (*x_fad_rcp)[i].fastAccessDx(0) = (*vp)[i];
215 obj_->gradient(g_fad,x_fad,tol_fad);
217 for(
int i=0; i<n; ++i) {
218 (*hvp)[i] = (*g_fad_rcp)[i].dx(0);
232 Teuchos::RCP<Objective<FadFadType>>
obj_;
233 Teuchos::RCP<Objective<FadType>>
grad_;
234 Teuchos::RCP<Objective<Real>>
hess_;
246 hess_->gradient(g,x,tol);
250 hess_->hessVec(hv,v,x,tol);
Provides the interface to evaluate objective functions.
StdVector< FadType > FadVector
Sacado::Fad::DFad< Real > FadType
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
Real value(const Vector< Real > &x, Real &tol)
Compute value.
Teuchos::RCP< Objective< Real > > hess_
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
Real value(const Vector< Real > &x, Real &tol)
Compute value.
HessianEnabler(Teuchos::RCP< Objective< FadType >> obj)
Sacado::Fad::DFad< FadType > FadFadType
ObjectiveEnabler(const Zakharov< Real > &zak)
Defines the linear algebra or vector space interface.
Sacado::Fad::SFad< Real, 1 > FadType
StdVector< FadType > FadVector
Provides the std::vector implementation of the ROL::Vector interface.
Sacado::Fad::SFad< Real, 1 > FadType
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
Real value(const Vector< Real > &x, Real &tol)
Compute value.
ObjectiveAD(const Zakharov< FadFadType > &zakharov)
Teuchos::RCP< Objective< FadType > > grad_
Real value(const Vector< Real > &x, Real &tol)
Compute value.
Zakharov< Real > zakharov
Teuchos::RCP< Objective< FadFadType > > obj_
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
Teuchos::RCP< const std::vector< Real > > access_elements(const Vector< Real > &x)
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
Real value(const Vector< Real > &x, Real &tol)
Compute value.
GradientEnabler(Teuchos::RCP< Objective< FadType >> obj)