ROL
ROL_Cantilever.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 USE_HESSVEC
50 #define USE_HESSVEC 1
51 #endif
52 
53 #ifndef ROL_CANTILEVER_HPP
54 #define ROL_CANTILEVER_HPP
55 
56 #include "ROL_ScaledStdVector.hpp"
57 #include "ROL_StdObjective.hpp"
58 #include "ROL_StdConstraint.hpp"
59 #include "ROL_TestProblem.hpp"
60 
61 namespace ROL {
62 namespace ZOO {
63 
64  template<class Real>
65  class Objective_Cantilever : public StdObjective<Real> {
66  public:
68 
69  Real value( const std::vector<Real> &x, Real &tol ) {
70  return x[0]*x[1];
71  }
72 
73  void gradient( std::vector<Real> &g, const std::vector<Real> &x, Real &tol ) {
74  g[0] = x[1];
75  g[1] = x[0];
76  }
77 #if USE_HESSVEC
78  void hessVec( std::vector<Real> &hv, const std::vector<Real> &v, const std::vector<Real> &x, Real &tol ) {
79  hv[0] = v[1];
80  hv[1] = v[0];
81  }
82 #endif
83  };
84 
85  template<class Real>
86  class Constraint_Cantilever : public StdConstraint<Real> {
87  private:
88  Real stress(const Real w, const Real t, const int deriv = 0, const int comp1 = 0, const int comp2 = 0) const {
89  const Real scale(600), X(500), Y(1000);
90  Real val(0);
91  if (deriv == 0) {
92  val = scale*(Y/(w*t*t) + X/(w*w*t));
93  }
94  else if (deriv == 1) {
95  if (comp1 == 0) {
96  const Real two(2);
97  val = scale*(-Y/(w*w*t*t) - two*X/(w*w*w*t));
98  }
99  else if (comp1 == 1) {
100  const Real two(2);
101  val = scale*(-two*Y/(w*t*t*t) - X/(w*w*t*t));
102  }
103  }
104  else if (deriv == 2) {
105  if (comp1 == 0 && comp2 == 0) {
106  const Real two(2), six(6);
107  val = scale*(two*Y/(w*w*w*t*t) + six*X/(w*w*w*w*t));
108  }
109  else if (comp1 == 1 && comp2 == 1) {
110  const Real two(2), six(6);
111  val = scale*(six*Y/(w*t*t*t*t) + two*X/(w*w*t*t*t));
112  }
113  else if (comp1 == 0 && comp2 == 1) {
114  const Real two(2);
115  val = scale*two*(Y/(w*w*t*t*t) + X/(w*w*w*t*t));
116  }
117  else if (comp1 == 1 && comp2 == 0) {
118  const Real two(2);
119  val = scale*two*(Y/(w*w*t*t*t) + X/(w*w*w*t*t));
120  }
121  }
122  return val;
123  }
124 
125  Real displacement(const Real w, const Real t, const int deriv = 0, const int comp1 = 0, const int comp2 = 0) const {
126  const Real four(4), L(100), E(2.9e7), X(500), Y(1000);
127  const Real C = four*std::pow(L,3)/E;
128  Real arg1 = std::pow(Y/(t*t),2), arg2 = std::pow(X/(w*w),2);
129  Real mag = std::sqrt(arg1 + arg2);
130  Real val(0);
131  if (deriv == 0) {
132  val = C/(w*t)*mag;
133  }
134  else if (deriv == 1) {
135  if (comp1 == 0) {
136  const Real three(3);
137  val = -C * (three * std::pow(X*t*t,2) + std::pow(Y*w*w,2))
138  / (std::pow(w,6)*std::pow(t,5)*mag);
139  }
140  else if (comp1 == 1) {
141  const Real three(3);
142  val = -C * (std::pow(X*t*t,2) + three*std::pow(Y*w*w,2))
143  / (std::pow(w,5)*std::pow(t,6)*mag);
144  }
145  }
146  else if (deriv == 2) {
147  if (comp1 == 0 && comp2 == 0) {
148  const Real two(2), six(6), nine(9);
149  val = C * two * mag * (std::pow(Y*w*w,4) + nine*std::pow(Y*X*w*w*t*t,2) + six*std::pow(X*t*t,4))
150  / (std::pow(w,3)*t*std::pow(std::pow(Y*w*w,2)+std::pow(X*t*t,2),2));
151  }
152  else if (comp1 == 1 && comp2 == 1) {
153  const Real two(2), six(6), nine(9);
154  val = C * two * mag * (six*std::pow(Y*w*w,4) + nine*std::pow(Y*X*w*w*t*t,2) + std::pow(X*t*t,4))
155  / (std::pow(t,3)*w*std::pow(std::pow(Y*w*w,2)+std::pow(X*t*t,2),2));
156  }
157  else if (comp1 == 0 && comp2 == 1) {
158  const Real two(2), three(3);
159  val = C * (three*std::pow(X*t*t,4) + two*std::pow(X*Y*t*t*w*w,2) + three*std::pow(Y*w*w,4))
160  / (std::pow(t*w,6)*mag*(std::pow(X*t*t,2) + std::pow(Y*w*w,2)));
161  }
162  else if (comp1 == 1 && comp2 == 0) {
163  const Real two(2), three(3);
164  val = C * (three*std::pow(X*t*t,4) + two*std::pow(X*Y*t*t*w*w,2) + three*std::pow(Y*w*w,4))
165  / (std::pow(t*w,6)*mag*(std::pow(X*t*t,2) + std::pow(Y*w*w,2)));
166  }
167  }
168  return val;
169  }
170  public:
172 
173  void value( std::vector<Real> &c, const std::vector<Real> &x, Real &tol ) {
174  const Real R(40000), D(2.2535), one(1);
175  Real s = stress(x[0],x[1],0)/R;
176  Real d = displacement(x[0],x[1],0)/D;
177  c[0] = s - one;
178  c[1] = d - one;
179  }
180 
181  void applyJacobian( std::vector<Real> &jv, const std::vector<Real> &v, const std::vector<Real> &x, Real &tol ) {
182  const Real R(40000), D(2.2535);
183  Real s0 = stress(x[0],x[1],1,0)/R, s1 = stress(x[0],x[1],1,1)/R;
184  Real d0 = displacement(x[0],x[1],1,0)/D, d1 = displacement(x[0],x[1],1,1)/D;
185  jv[0] = s0*v[0] + s1*v[1];
186  jv[1] = d0*v[0] + d1*v[1];
187  }
188 
189  void applyAdjointJacobian( std::vector<Real> &ajv, const std::vector<Real> &v, const std::vector<Real> &x, Real &tol ) {
190  const Real R(40000), D(2.2535);
191  Real s0 = stress(x[0],x[1],1,0)/R, s1 = stress(x[0],x[1],1,1)/R;
192  Real d0 = displacement(x[0],x[1],1,0)/D, d1 = displacement(x[0],x[1],1,1)/D;
193  ajv[0] = s0*v[0] + d0*v[1];
194  ajv[1] = s1*v[0] + d1*v[1];
195  }
196 #if USE_HESSVEC
197  void applyAdjointHessian( std::vector<Real> &ahuv, const std::vector<Real> &u, const std::vector<Real> &v, const std::vector<Real> &x, Real &tol ) {
198  const Real R(40000), D(2.2535);
199  Real s00 = stress(x[0],x[1],2,0,0)/R, s01 = stress(x[0],x[1],2,0,1)/R;
200  Real s10 = stress(x[0],x[1],2,1,0)/R, s11 = stress(x[0],x[1],2,1,1)/R;
201  Real d00 = displacement(x[0],x[1],2,0,0)/D, d01 = displacement(x[0],x[1],2,0,1)/D;
202  Real d10 = displacement(x[0],x[1],2,1,0)/D, d11 = displacement(x[0],x[1],2,1,1)/D;
203  ahuv[0] = (s00*u[0] + d00*u[1])*v[0] + (s01*u[0] + d01*u[1])*v[1];
204  ahuv[1] = (s10*u[0] + d10*u[1])*v[0] + (s11*u[0] + d11*u[1])*v[1];
205  }
206 #endif
207  };
208 
209  template<class Real>
210  class getCantilever : public TestProblem<Real> {
211  public:
213 
214  Ptr<Objective<Real>> getObjective(void) const {
215  return makePtr<Objective_Cantilever<Real>>();
216  }
217 
218  Ptr<Vector<Real>> getInitialGuess(void) const {
219  int n = 2;
220  Ptr<std::vector<Real>> scale = makePtr<std::vector<Real>>(n,static_cast<Real>(1.0));
221  Ptr<std::vector<Real>> xp = makePtr<std::vector<Real>>(n,static_cast<Real>(0.0));
222  (*xp)[0] = static_cast<Real>(2.0);
223  (*xp)[1] = static_cast<Real>(2.0);
224  return makePtr<PrimalScaledStdVector<Real>>(xp,scale);
225  }
226 
227  Ptr<Vector<Real>> getSolution(const int i = 0) const {
228  int n = 2;
229  Ptr<std::vector<Real>> scale = makePtr<std::vector<Real>>(n,static_cast<Real>(1.0));
230  Ptr<std::vector<Real>> xp = makePtr<std::vector<Real>>(n,static_cast<Real>(0.0));
231  (*xp)[0] = static_cast<Real>(2.3520341271);
232  (*xp)[1] = static_cast<Real>(3.3262784077);
233  return makePtr<PrimalScaledStdVector<Real>>(xp,scale);
234  }
235 
236  Ptr<BoundConstraint<Real>> getBoundConstraint(void) const {
237  int n = 2;
238  Ptr<std::vector<Real>> scale = makePtr<std::vector<Real>>(n,static_cast<Real>(1.0));
239  Ptr<std::vector<Real>> lp = makePtr<std::vector<Real>>(n,static_cast<Real>(1.0));
240  Ptr<std::vector<Real>> up = makePtr<std::vector<Real>>(n,static_cast<Real>(4.0));
241  Ptr<Vector<Real>> l = makePtr<PrimalScaledStdVector<Real>>(lp,scale);
242  Ptr<Vector<Real>> u = makePtr<PrimalScaledStdVector<Real>>(up,scale);
243  return makePtr<Bounds<Real>>(l,u);
244  }
245 
246  Ptr<Constraint<Real>> getInequalityConstraint(void) const {
247  return makePtr<Constraint_Cantilever<Real>>();
248  }
249 
250  Ptr<Vector<Real>> getInequalityMultiplier(void) const {
251  Ptr<std::vector<Real>> scale = makePtr<std::vector<Real>>(2,static_cast<Real>(1.0));
252  Ptr<std::vector<Real>> lp = makePtr<std::vector<Real>>(2,static_cast<Real>(0.0));
253  return makePtr<DualScaledStdVector<Real>>(lp,scale);
254  }
255 
256  Ptr<BoundConstraint<Real>> getSlackBoundConstraint(void) const {
257  Ptr<std::vector<Real>> scale = makePtr<std::vector<Real>>(2,static_cast<Real>(1.0));
258  Ptr<std::vector<Real>> up = makePtr<std::vector<Real>>(2,static_cast<Real>(0.0));
259  Ptr<Vector<Real>> u = makePtr<DualScaledStdVector<Real>>(up,scale);
260  return makePtr<Bounds<Real>>(*u,false);
261  }
262  };
263 
264 }// End ZOO Namespace
265 }// End ROL Namespace
266 
267 #endif
Ptr< Objective< Real > > getObjective(void) const
void gradient(std::vector< Real > &g, const std::vector< Real > &x, Real &tol)
void applyJacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
virtual void hessVec(std::vector< Real > &hv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Ptr< BoundConstraint< Real > > getSlackBoundConstraint(void) const
Real displacement(const Real w, const Real t, const int deriv=0, const int comp1=0, const int comp2=0) const
void applyAdjointJacobian(std::vector< Real > &ajv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
Real stress(const Real w, const Real t, const int deriv=0, const int comp1=0, const int comp2=0) const
Defines the equality constraint operator interface for StdVectors.
Specializes the ROL::Objective interface for objective functions that operate on ROL::StdVector&#39;s.
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 ...
Contains definitions of test objective functions.
void value(std::vector< Real > &c, const std::vector< Real > &x, Real &tol)
Ptr< Vector< Real > > getSolution(const int i=0) const
Ptr< Constraint< Real > > getInequalityConstraint(void) const
Ptr< BoundConstraint< Real > > getBoundConstraint(void) const
Real value(const std::vector< Real > &x, Real &tol)
Ptr< Vector< Real > > getInitialGuess(void) const
Ptr< Vector< Real > > getInequalityMultiplier(void) const