ROL
ROL_ChainRuleConstraint.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 
10 #ifndef ROL_CHAIN_RULE_CONSTRAINT_HPP
11 #define ROL_CHAIN_RULE_CONSTRAINT_HPP
12 
13 #include "ROL_Constraint.hpp"
14 
27 namespace ROL {
28 
29 template<typename Real>
30 class ChainRuleConstraint: public Constraint<Real> {
31 public:
32 
33  ChainRuleConstraint( const Ptr<Constraint<Real>>& outer_con,
34  const Ptr<Constraint<Real>>& inner_con,
35  const Vector<Real>& x,
36  const Vector<Real>& lag_inner )
37  : outer_con_(outer_con), inner_con_(inner_con),
38  y_(lag_inner.dual().clone()), // Inner constraint space vector
39  Jiv_(lag_inner.dual().clone()), // Inner Jacobian applied to optimization space vector
40  aJol_(lag_inner.dual().clone()), // Outer adjoint Jacobian applied to outer dual constaint space vector
41  HiaJol_(x.dual().clone()), // Inner Hessian applied to dual optimization space vector
42  HolJiv_(lag_inner.clone()), // Outer Hessian applied to inner constaint space vector
43  tol_(0) {
44  }
45 
46  virtual ~ChainRuleConstraint() = default;
47 
48  virtual void update( const Vector<Real>& x,
49  UpdateType type,
50  int iter = -1 ) {
51  inner_con_->update(x,type,iter);
52  inner_con_->value(*y_,x,tol_);
53  outer_con_->update(*y_,type,iter);
54  }
55 
56  virtual void update( const Vector<Real>& x,
57  bool flag,
58  int iter = -1 ) {
59  inner_con_->update(x,flag,iter);
60  inner_con_->value(*y_,x,tol_);
61  outer_con_->update(*y_,flag,iter);
62  }
63 
64  virtual void value( Vector<Real>& c,
65  const Vector<Real>& x,
66  Real& tol ) override {
67  inner_con_->value(*y_,x,tol);
68  outer_con_->value(c,*y_,tol);
69  }
70 
71  virtual void applyJacobian( Vector<Real>& jv,
72  const Vector<Real>& v,
73  const Vector<Real>& x,
74  Real& tol ) override {
75  inner_con_->value(*y_,x,tol);
76  inner_con_->applyJacobian(*Jiv_,v,x,tol);
77  outer_con_->applyJacobian(jv,*Jiv_,*y_,tol);
78  }
79 
80  virtual void applyAdjointJacobian( Vector<Real>& ajl,
81  const Vector<Real>& l,
82  const Vector<Real>& x,
83  Real& tol ) override {
84  inner_con_->value(*y_,x,tol);
85  outer_con_->applyAdjointJacobian(*aJol_,l,*y_,tol);
86  inner_con_->applyAdjointJacobian(ajl,*aJol_,x,tol);
87  }
88 
89  virtual void applyAdjointHessian( Vector<Real>& ahlv,
90  const Vector<Real>& l,
91  const Vector<Real>& v,
92  const Vector<Real>& x,
93  Real& tol ) override {
94  inner_con_->value(*y_,x,tol);
95  inner_con_->applyJacobian(*Jiv_,v,x,tol);
96  outer_con_->applyAdjointJacobian(*aJol_,l,*y_,tol);
97  inner_con_->applyAdjointHessian(*HiaJol_,*aJol_,v,x,tol);
98  outer_con_->applyAdjointHessian(*HolJiv_,l,*Jiv_,*y_,tol);
99  inner_con_->applyAdjointJacobian(ahlv,*HolJiv_,x,tol);
100  ahlv.plus(*HiaJol_);
101  }
102 
103 private:
104 
105  const Ptr<Constraint<Real>> outer_con_, inner_con_;
106 
107  Ptr<Vector<Real>> y_; // Inner constraint space vector
108  Ptr<Vector<Real>> Jiv_; // Inner Jacobian applied to optimization space vector
109  Ptr<Vector<Real>> aJol_; // Outer adjoint Jacobian applied to outer dual constaint space vector
110  Ptr<Vector<Real>> HiaJol_; // Inner Hessian applied to dual optimization space vector
111  Ptr<Vector<Real>> HolJiv_; // Outer Hessian applied to inner constaint space vector
112  Real tol_;
113 }; // class ChainRuleConstraint
114 
115 } // namespace ROL
116 
117 #endif // ROL_CHAIN_RULE_CONSTRAINT_HPP
virtual void value(Vector< Real > &c, const Vector< Real > &x, Real &tol) override
Evaluate the constraint operator at .
virtual void update(const Vector< Real > &x, bool flag, int iter=-1)
Update constraint functions. x is the optimization variable, flag = true if optimization variable is ...
virtual void plus(const Vector &x)=0
Compute , where .
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
virtual void applyAdjointJacobian(Vector< Real > &ajl, const Vector< Real > &l, const Vector< Real > &x, Real &tol) override
Apply the adjoint of the the constraint Jacobian at , , to vector .
virtual void update(const Vector< Real > &x, UpdateType type, int iter=-1)
Update constraint function.
virtual void applyAdjointHessian(Vector< Real > &ahlv, const Vector< Real > &l, const Vector< Real > &v, const Vector< Real > &x, Real &tol) override
Apply the derivative of the adjoint of the constraint Jacobian at to vector in direction ...
const Ptr< Constraint< Real > > outer_con_
Defines a constaint formed through function composition .
virtual void applyJacobian(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &x, Real &tol) override
Apply the constraint Jacobian at , , to vector .
ChainRuleConstraint(const Ptr< Constraint< Real >> &outer_con, const Ptr< Constraint< Real >> &inner_con, const Vector< Real > &x, const Vector< Real > &lag_inner)
const Ptr< Constraint< Real > > inner_con_
virtual ~ChainRuleConstraint()=default
Defines the general constraint operator interface.