ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
example
sacado
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
19
20
21
22
#include "
ROL_StdVector.hpp
"
23
24
using namespace
ROL
;
25
26
template
<
class
Real>
27
class
Zakharov
{
28
29
public
:
30
31
template
<
class
ScalarT>
32
ScalarT
value
(
const
Vector<ScalarT>
&x, Real &tol );
33
34
};
35
36
37
48
template
<
class
Real>
49
template
<
class
ScalarT>
50
ScalarT
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
ROL_StdVector.hpp
ROL::StdVector
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
Definition
ROL_StdVector.hpp:27
ROL::Vector
Defines the linear algebra or vector space interface.
Definition
ROL_Vector.hpp:51
Zakharov
Definition
example_01a.hpp:27
Zakharov::value
ScalarT value(const Vector< ScalarT > &x, Real &tol)
A Sacado-accessible version of the Zakharov function to differentiate.
Definition
example_01a.hpp:50
ROL
Definition
ROL_ElementwiseVector.hpp:27
Generated by
1.17.0