ROL
example_01a.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Rapid Optimization Library (ROL) Package
4//
5// Copyright 2014 NTESS and the ROL contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
22#include "ROL_StdVector.hpp"
23
24using namespace ROL;
25
26template<class Real>
27class Zakharov {
28
29 public:
30
31 template<class ScalarT>
32 ScalarT value(const Vector<ScalarT> &x, Real &tol );
33
34};
35
36
37
48template<class Real>
49template<class ScalarT>
50ScalarT Zakharov<Real>::value(const Vector<ScalarT>& x, Real &tol) {
51
52
53
54 ROL::Ptr<const std::vector<ScalarT> > xp = (dynamic_cast<const StdVector<ScalarT>&>(x)).getVector();
55
56 int n = xp->size();
57
58 ScalarT xdotx = 0;
59 ScalarT kdotx = 0;
60 ScalarT J = 0;
61
62 // Compute dot products
63 for(int i=0; i<n; ++i) {
64 xdotx += pow((*xp)[i],2); // (k,x)
65 kdotx += Real(i+1)*(*xp)[i]; // (x,x)
66 }
67
68 // Sum terms in objective function
69 J = xdotx + pow(kdotx,2)/4.0 + pow(kdotx,4)/16.0;
70
71 return J;
72}
73
74
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
Defines the linear algebra or vector space interface.
ScalarT value(const Vector< ScalarT > &x, Real &tol)
A Sacado-accessible version of the Zakharov function to differentiate.