ROL
ROL_CompositeEqualityConstraint_SimOpt.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 
44 #ifndef ROL_COMPOSITE_EQUALITY_CONSTRAINT_SIMOPT_H
45 #define ROL_COMPOSITE_EQUALITY_CONSTRAINT_SIMOPT_H
46 
48 
71 namespace ROL {
72 
73 template <class Real>
75 private:
76  // Constraints
77  const Teuchos::RCP<EqualityConstraint_SimOpt<Real> > conVal_;
78  const Teuchos::RCP<EqualityConstraint_SimOpt<Real> > conRed_;
79  // Additional vector storage for solve
80  Teuchos::RCP<Vector<Real> > Sz_;
81  Teuchos::RCP<Vector<Real> > primRed_;
82  Teuchos::RCP<Vector<Real> > dualRed_;
83  Teuchos::RCP<Vector<Real> > primZ_;
84  Teuchos::RCP<Vector<Real> > dualZ_;
85  Teuchos::RCP<Vector<Real> > dualZ1_;
86  // Boolean variables
87  bool isSolved_;
88 
89  void solveConRed(const Vector<Real> &z, Real &tol) {
90  if ( !isSolved_ ) {
91  conRed_->solve(*primRed_, *Sz_, z, tol);
92  isSolved_ = true;
93  }
94  }
95 
96  void applySens(Vector<Real> &jv, const Vector<Real> &v, const Vector<Real> &z, Real &tol) {
97  solveConRed(z, tol);
98  conRed_->applyJacobian_2(*primRed_, v, *Sz_, z, tol);
99  conRed_->applyInverseJacobian_1(jv, *primRed_, *Sz_, z, tol);
100  jv.scale(static_cast<Real>(-1));
101  }
102 
103  void applyAdjointSens(Vector<Real> &ajv, const Vector<Real> &v, const Vector<Real> &z, Real &tol) {
104  solveConRed(z, tol);
105  conRed_->applyInverseAdjointJacobian_1(*dualRed_, v, *Sz_, z, tol);
106  conRed_->applyAdjointJacobian_2(ajv, *dualRed_, *Sz_, z, tol);
107  ajv.scale(static_cast<Real>(-1));
108  }
109 
110 public:
112  const Teuchos::RCP<EqualityConstraint_SimOpt<Real> > &conRed,
113  const Vector<Real> &cVal, const Vector<Real> &cRed,
114  const Vector<Real> &u, const Vector<Real> &Sz, const Vector<Real> &z)
115  : EqualityConstraint_SimOpt<Real>(), conVal_(conVal), conRed_(conRed), isSolved_(false) {
116  Sz_ = Sz.clone();
117  primRed_ = cRed.clone();
118  dualRed_ = cRed.dual().clone();
119  primZ_ = z.clone();
120  dualZ_ = z.dual().clone();
121  dualZ1_ = z.dual().clone();
122  }
123 
124  void update(const Vector<Real> &u, const Vector<Real> &z, bool flag = true, int iter = -1 ) {
125  Real ctol = std::sqrt(ROL_EPSILON<Real>());
126  update_1(u, flag, iter);
127  update_2(z, flag, iter);
128  isSolved_ = false;
129  solveConRed(z, ctol);
130  conRed_->update(*Sz_, z, flag, iter);
131  conVal_->update(u, *Sz_, flag, iter);
132  }
133 
134  void update_1( const Vector<Real> &u, bool flag = true, int iter = -1 ) {
135  conVal_->update_1(u, flag, iter);
136  }
137 
138  void update_2( const Vector<Real> &z, bool flag = true, int iter = -1 ) {
139  conRed_->update_2(z, flag, iter);
140  }
141 
142  void value(Vector<Real> &c, const Vector<Real> &u, const Vector<Real> &z, Real &tol) {
143  solveConRed(z, tol);
144  conVal_->value(c, u, *Sz_, tol);
145  }
146 
148  const Vector<Real> &z, Real &tol) {
149  solveConRed(z, tol);
150  conVal_->applyJacobian_1(jv, v, u, *Sz_, tol);
151  }
152 
154  const Vector<Real> &z, Real &tol) {
155  applySens(*primZ_, v, z, tol);
156  conVal_->applyJacobian_2(jv, *primZ_, u, *Sz_, tol);
157  }
158 
160  const Vector<Real> &z, Real &tol) {
161  solveConRed(z, tol);
162  conVal_->applyInverseJacobian_1(ijv, v, u, *Sz_, tol);
163  }
164 
166  const Vector<Real> &z, Real &tol) {
167  solveConRed(z, tol);
168  conVal_->applyAdjointJacobian_1(ajv, v, u, *Sz_, tol);
169  }
170 
172  const Vector<Real> &z, Real &tol) {
173  solveConRed(z, tol);
174  conVal_->applyAdjointJacobian_2(*dualZ_, v, u, *Sz_, tol);
175  applyAdjointSens(ajv, *dualZ_, z, tol);
176  }
177 
179  const Vector<Real> &z, Real &tol) {
180  solveConRed(z, tol);
181  conVal_->applyInverseAdjointJacobian_1(ijv, v, u, *Sz_, tol);
182  }
183 
185  const Vector<Real> &u, const Vector<Real> &z, Real &tol) {
186  solveConRed(z, tol);
187  conVal_->applyAdjointHessian_11(ahwv, w, v, u, z, tol);
188  }
189 
191  const Vector<Real> &u, const Vector<Real> &z, Real &tol) {
192  solveConRed(z, tol);
193  conVal_->applyAdjointHessian_12(*dualZ_, w, v, u, *Sz_, tol);
194  applyAdjointSens(ahwv, *dualZ_, z, tol);
195  }
196 
198  const Vector<Real> &u, const Vector<Real> &z, Real &tol) {
199  applySens(*primZ_, v, z, tol);
200  conVal_->applyAdjointHessian_21(ahwv, w, *primZ_, u, *Sz_, tol);
201  }
202 
204  const Vector<Real> &u, const Vector<Real> &z, Real &tol) {
205  ahwv.zero();
206  applySens(*primZ_, v, z, tol);
207 
208  conVal_->applyAdjointJacobian_2(*dualZ_, w, u, *Sz_, tol);
209  conRed_->applyInverseAdjointJacobian_1(*dualRed_, *dualZ_, *Sz_, z, tol);
210  conRed_->applyAdjointHessian_22(*dualZ_, *dualRed_, v, *Sz_, z, tol);
211  ahwv.axpy(static_cast<Real>(-1), *dualZ_);
212  conRed_->applyAdjointHessian_12(*dualZ_, *dualRed_, *primZ_, *Sz_, z, tol);
213  ahwv.axpy(static_cast<Real>(-1), *dualZ_);
214 
215  conRed_->applyAdjointHessian_11(*dualZ1_, *dualRed_, *primZ_, *Sz_, z, tol);
216  conRed_->applyAdjointHessian_21(*dualZ_, *dualRed_, v, *Sz_, z, tol);
217  dualZ1_->plus(*dualZ_);
218  dualZ1_->scale(static_cast<Real>(-1));
219 
220  conVal_->applyAdjointHessian_22(*dualZ_, w, *primZ_, u, *Sz_, tol);
221  dualZ1_->plus(*dualZ_);
222 
223  applyAdjointSens(*dualZ_, *dualZ1_, z, tol);
224  ahwv.plus(*dualZ_);
225  }
226 
227 // Definitions for parametrized (stochastic) equality constraints
228 public:
229  void setParameter(const std::vector<Real> &param) {
231  conVal_->setParameter(param);
232  conRed_->setParameter(param);
233  isSolved_ = false; // Resolve constraint every time
234  }
235 }; // class CompositeEqualityConstraint_SimOpt
236 
237 } // namespace ROL
238 
239 #endif
void update_2(const Vector< Real > &z, bool flag=true, int iter=-1)
Update constraint functions with respect to Opt variable. x is the optimization variable, flag = true if optimization variable is changed, iter is the outer algorithm iterations count.
virtual void scale(const Real alpha)=0
Compute where .
void applyInverseAdjointJacobian_1(Vector< Real > &ijv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
Apply the inverse of the adjoint of the partial constraint Jacobian at , , to the vector ...
virtual void plus(const Vector &x)=0
Compute , where .
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Definition: ROL_Vector.hpp:143
void applyAdjointHessian_21(Vector< Real > &ahwv, const Vector< Real > &w, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
Apply the simulation-space derivative of the adjoint of the constraint optimization-space Jacobian at...
virtual void setParameter(const std::vector< Real > &param)
virtual Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
const Teuchos::RCP< EqualityConstraint_SimOpt< Real > > conRed_
virtual void zero()
Set to zero vector.
Definition: ROL_Vector.hpp:157
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:74
Defines the equality constraint operator interface for simulation-based optimization.
void update_1(const Vector< Real > &u, bool flag=true, int iter=-1)
Update constraint functions with respect to Sim variable. x is the optimization variable...
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
Definition: ROL_Vector.hpp:213
void applySens(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &z, Real &tol)
void applyAdjointHessian_12(Vector< Real > &ahwv, const Vector< Real > &w, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
Apply the optimization-space derivative of the adjoint of the constraint simulation-space Jacobian at...
void update(const Vector< Real > &u, const Vector< Real > &z, bool flag=true, int iter=-1)
Update constraint functions. x is the optimization variable, flag = true if optimization variable i...
void applyAdjointHessian_11(Vector< Real > &ahwv, const Vector< Real > &w, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
Apply the simulation-space derivative of the adjoint of the constraint simulation-space Jacobian at ...
CompositeEqualityConstraint_SimOpt(const Teuchos::RCP< EqualityConstraint_SimOpt< Real > > &conVal, const Teuchos::RCP< EqualityConstraint_SimOpt< Real > > &conRed, const Vector< Real > &cVal, const Vector< Real > &cRed, const Vector< Real > &u, const Vector< Real > &Sz, const Vector< Real > &z)
void applyAdjointSens(Vector< Real > &ajv, const Vector< Real > &v, const Vector< Real > &z, Real &tol)
void applyAdjointJacobian_2(Vector< Real > &ajv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
Apply the adjoint of the partial constraint Jacobian at , , to vector . This is the primary interface...
void applyAdjointHessian_22(Vector< Real > &ahwv, const Vector< Real > &w, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
Apply the optimization-space derivative of the adjoint of the constraint optimization-space Jacobian ...
const Teuchos::RCP< EqualityConstraint_SimOpt< Real > > conVal_
void applyJacobian_1(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
Apply the partial constraint Jacobian at , , to the vector .
void applyAdjointJacobian_1(Vector< Real > &ajv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
Apply the adjoint of the partial constraint Jacobian at , , to the vector . This is the primary inter...
void applyInverseJacobian_1(Vector< Real > &ijv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
Apply the inverse partial constraint Jacobian at , , to the vector .
void applyJacobian_2(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
Apply the partial constraint Jacobian at , , to the vector .
void value(Vector< Real > &c, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
Evaluate the constraint operator at .
Defines a composite equality constraint operator interface for simulation-based optimization.