ROL
ROL_HS29.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ************************************************************************
3 //
4 // Rapid Optimization Library (ROL) Package
5 // Copyright (2014) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact lead developers:
38 // Drew Kouri (dpkouri@sandia.gov) and
39 // Denis Ridzal (dridzal@sandia.gov)
40 //
41 // ************************************************************************
42 // @HEADER
43 
49 #ifndef ROL_HS29_HPP
50 #define ROL_HS29_HPP
51 
52 #include "ROL_StdVector.hpp"
53 #include "ROL_Objective.hpp"
55 
56 
57 namespace ROL {
58 namespace ZOO {
59 
60 template<class Real>
61 class Objective_HS29 : public Objective<Real> {
62 
63  typedef std::vector<Real> vector;
64  typedef Vector<Real> V;
66 
67 private:
68 
69  Teuchos::RCP<const vector> getVector( const V& x ) {
70  using Teuchos::dyn_cast;
71  return dyn_cast<const SV>(x).getVector();
72  }
73 
74  Teuchos::RCP<vector> getVector( V& x ) {
75  using Teuchos::dyn_cast;
76  return dyn_cast<SV>(x).getVector();
77  }
78 
79 public:
80 
81  Real value( const Vector<Real> &x, Real &tol ) {
82 
83  using Teuchos::RCP;
84  RCP<const vector> xp = getVector(x);
85 
86  return -(*xp)[0]*(*xp)[1]*(*xp)[2];
87 
88  }
89 
90  void gradient( Vector<Real> &g, const Vector<Real> &x, Real &tol ) {
91 
92  using Teuchos::RCP;
93  RCP<const vector> xp = getVector(x);
94  RCP<vector> gp = getVector(g);
95 
96  (*gp)[0] = -(*xp)[1]*(*xp)[2];
97  (*gp)[1] = -(*xp)[0]*(*xp)[2];
98  (*gp)[2] = -(*xp)[0]*(*xp)[1];
99 
100  }
101 
102  void hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
103 
104  using Teuchos::RCP;
105  RCP<const vector> xp = getVector(x);
106  RCP<const vector> vp = getVector(v);
107  RCP<vector> hvp = getVector(hv);
108 
109  (*hvp)[0] = -( (*xp)[2]*(*vp)[1] + (*xp)[1]*(*vp)[2] );
110  (*hvp)[1] = -( (*xp)[2]*(*vp)[0] + (*xp)[0]*(*vp)[2] );
111  (*hvp)[2] = -( (*xp)[1]*(*vp)[0] + (*xp)[0]*(*vp)[1] );
112 
113  }
114 
115 }; // class Objective_HS29
116 
117 
118 template<class Real>
120 
121  typedef std::vector<Real> vector;
122  typedef Vector<Real> V;
124 
125 private:
126 
127  Teuchos::RCP<const vector> getVector( const V& x ) {
128  using Teuchos::dyn_cast;
129  return dyn_cast<const SV>(x).getVector();
130  }
131 
132  Teuchos::RCP<vector> getVector( V& x ) {
133  using Teuchos::dyn_cast;
134  return dyn_cast<SV>(x).getVector();
135  }
136 
137 public:
138 
139  void value( Vector<Real> &c, const Vector<Real> &x, Real &tol ) {
140 
141  using Teuchos::RCP;
142 
143  RCP<vector> cp = getVector(c);
144  RCP<const vector> xp = getVector(x);
145 
146  (*cp)[0] = -std::pow((*xp)[0],2) - 2*std::pow((*xp)[1],2) - 4*std::pow((*xp)[2],2) + 48;
147 
148  }
149 
151  const Vector<Real> &x, Real &tol ) {
152 
153  using Teuchos::RCP;
154 
155  RCP<vector> jvp = getVector(jv);
156  RCP<const vector> vp = getVector(v);
157  RCP<const vector> xp = getVector(x);
158 
159  (*jvp)[0] = -2*(*xp)[0]*(*vp)[0] - 4*(*xp)[1]*(*vp)[1] - 8*(*xp)[2]*(*vp)[2];
160 
161  }
162 
164  const Vector<Real> &x, Real &tol ) {
165 
166  using Teuchos::RCP;
167 
168  RCP<vector> ajvp = getVector(ajv);
169  RCP<const vector> vp = getVector(v);
170  RCP<const vector> xp = getVector(x);
171 
172  (*ajvp)[0] = -2*(*xp)[0]*(*vp)[0];
173  (*ajvp)[1] = -4*(*xp)[1]*(*vp)[0];
174  (*ajvp)[2] = -8*(*xp)[2]*(*vp)[0];
175 
176  }
177 
179  const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
180 
181  using Teuchos::RCP;
182 
183  RCP<vector> ahuvp = getVector(ahuv);
184  RCP<const vector> up = getVector(u);
185  RCP<const vector> vp = getVector(v);
186  RCP<const vector> xp = getVector(x);
187 
188  (*ahuvp)[0] = -2*(*up)[0]*(*vp)[0];
189  (*ahuvp)[1] = -4*(*up)[0]*(*vp)[1];
190  (*ahuvp)[2] = -8*(*up)[0]*(*vp)[2];
191 
192  }
193 
194 }; // class InequalityConstraint_HS29
195 
196 }
197 } // namespace ROL
198 
199 
200 #endif // ROL_HS29_HPP
Provides the interface to evaluate objective functions.
void applyAdjointJacobian(Vector< Real > &ajv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the adjoint of the the constraint Jacobian at , , to vector .
Definition: ROL_HS29.hpp:163
Vector< Real > V
Definition: ROL_HS29.hpp:64
StdVector< Real > SV
Definition: ROL_HS29.hpp:65
void value(Vector< Real > &c, const Vector< Real > &x, Real &tol)
Evaluate the constraint operator at .
Definition: ROL_HS29.hpp:139
Teuchos::RCP< const vector > getVector(const V &x)
Definition: ROL_HS29.hpp:127
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:74
Teuchos::RCP< const vector > getVector(const V &x)
Definition: ROL_HS29.hpp:69
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
Definition: ROL_HS29.hpp:102
Real value(const Vector< Real > &x, Real &tol)
Compute value.
Definition: ROL_HS29.hpp:81
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
Definition: ROL_HS29.hpp:90
Teuchos::RCP< vector > getVector(V &x)
Definition: ROL_HS29.hpp:74
Teuchos::RCP< vector > getVector(V &x)
Definition: ROL_HS29.hpp:132
Provides a unique argument for inequality constraints, which otherwise behave exactly as equality con...
void applyJacobian(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the constraint Jacobian at , , to vector .
Definition: ROL_HS29.hpp:150
std::vector< Real > vector
Definition: ROL_HS29.hpp:63
void applyAdjointHessian(Vector< Real > &ahuv, const Vector< Real > &u, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the derivative of the adjoint of the constraint Jacobian at to vector in direction ...
Definition: ROL_HS29.hpp:178