15 Teuchos::RCP<const std::vector<Real> > xp =
26 for(
int i=0; i<n; ++i) {
27 xdotx += pow((*xp)[i],2);
28 kdotx += double(i+1)*(*xp)[i];
32 J = xdotx + pow(kdotx,2)/4.0 + pow(kdotx,4)/16.0;
44 Teuchos::RCP<Objective<FadType> >
obj_;
51 Teuchos::RCP<const std::vector<Real> > xp =
56 Teuchos::RCP<std::vector<FadType> > x_fad_rcp = Teuchos::rcp(
new std::vector<FadType>);
57 x_fad_rcp->reserve(n);
58 for(
int i=0; i<n; ++i) {
59 x_fad_rcp->push_back((*xp)[i]);
64 FadType J_fad = obj_->value(x_fad,tol_fad);
71 Teuchos::RCP<const std::vector<Real> > xp =
74 Teuchos::RCP<std::vector<Real> > gp =
75 Teuchos::rcp_const_cast<std::vector<Real> > ((Teuchos::dyn_cast<
StdVector<Real> > (g)).getVector());
79 Teuchos::RCP<std::vector<FadType> > x_fad_rcp = Teuchos::rcp(
new std::vector<FadType> );
80 x_fad_rcp->reserve(n);
82 for(
int i=0; i<n; ++i) {
83 x_fad_rcp->push_back(
FadType(n,i,(*xp)[i]));
89 FadType J_fad = obj_->value(x_fad,tol_fad);
91 for(
int i=0; i<n; ++i) {
92 (*gp)[i] = J_fad.dx(i);
105 Teuchos::RCP<Objective<FadType> >
obj_;
112 Teuchos::RCP<const std::vector<Real> > xp =
117 Teuchos::RCP<std::vector<FadType> > x_fad_rcp = Teuchos::rcp(
new std::vector<FadType>);
118 x_fad_rcp->reserve(n);
119 for(
int i=0; i<n; ++i) {
120 x_fad_rcp->push_back((*xp)[i]);
125 FadType J_fad = obj_->value(x_fad,tol_fad);
132 Teuchos::RCP<const std::vector<Real> > xp =
135 Teuchos::RCP<std::vector<Real> > gp =
136 Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<
StdVector<Real> >(g)).getVector());
140 Teuchos::RCP<std::vector<FadType> > x_fad_rcp = Teuchos::rcp(
new std::vector<FadType>);
141 Teuchos::RCP<std::vector<FadType> > g_fad_rcp = Teuchos::rcp(
new std::vector<FadType>);
143 x_fad_rcp->reserve(n);
144 g_fad_rcp->reserve(n);
146 for(
int i=0; i<n; ++i) {
147 x_fad_rcp->push_back((*xp)[i]);
148 g_fad_rcp->push_back((*xp)[i]);
154 obj_->gradient(g_fad,x_fad,tol_fad);
156 for(
int i=0; i<n; ++i) {
157 (*gp)[i] = (*g_fad_rcp)[i].val();
163 Teuchos::RCP<const std::vector<Real> > xp =
165 Teuchos::RCP<const std::vector<Real> > vp =
167 Teuchos::RCP<std::vector<Real> > hvp =
168 Teuchos::rcp_const_cast<std::vector<Real> >((Teuchos::dyn_cast<
StdVector<Real> >(hv)).getVector());
173 Teuchos::RCP<std::vector<FadType> > x_fad_rcp = Teuchos::rcp(
new std::vector<FadType> );
174 x_fad_rcp->reserve(n);
177 Teuchos::RCP<std::vector<FadType> > g_fad_rcp = Teuchos::rcp(
new std::vector<FadType> );
178 g_fad_rcp->reserve(n);
180 for(
int i=0; i<n; ++i) {
181 x_fad_rcp->push_back(
FadType(1,(*xp)[i]));
182 g_fad_rcp->push_back(0);
183 (*x_fad_rcp)[i].fastAccessDx(0) = (*vp)[i];
189 obj_->gradient(g_fad,x_fad,tol_fad);
191 for(
int i=0; i<n; ++i) {
192 (*hvp)[i] = (*g_fad_rcp)[i].dx(0);
Provides the interface to evaluate objective functions.
GradientEnabler(Teuchos::RCP< Objective< FadType > > obj)
Teuchos::RCP< Objective< FadType > > obj_
Sacado::Fad::DFad< Real > FadType
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
Defines the linear algebra or vector space interface.
HessianEnabler(Teuchos::RCP< Objective< FadType > > obj)
Provides the std::vector implementation of the ROL::Vector interface.
Sacado::Fad::SFad< Real, 1 > FadType
Real value(const Vector< Real > &x, Real &tol)
Compute value.
Real value(const Vector< Real > &x, Real &tol)
Compute value.
Teuchos::RCP< Objective< FadType > > obj_
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
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.