ROL
ROL_CompositeConstraint_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 #include "ROL_SimController.hpp"
49 
72 namespace ROL {
73 
74 template <class Real>
76 private:
77  // Constraints
78  const ROL::Ptr<Constraint_SimOpt<Real> > conVal_;
79  const ROL::Ptr<Constraint_SimOpt<Real> > conRed_;
80  // Additional vector storage for solve
81  ROL::Ptr<Vector<Real> > Sz_;
82  ROL::Ptr<Vector<Real> > primRed_;
83  ROL::Ptr<Vector<Real> > dualRed_;
84  ROL::Ptr<Vector<Real> > primZ_;
85  ROL::Ptr<Vector<Real> > dualZ_;
86  ROL::Ptr<Vector<Real> > dualZ1_;
87  // State storage through SimController interface
88  ROL::Ptr<SimController<Real> > stateStore_;
89  // Update information
92  // Boolean variables
94 
95  void solveConRed(const Vector<Real> &z, Real &tol) {
96  std::vector<Real> param = Constraint_SimOpt<Real>::getParameter();
97  // Check if state has been computed.
98  bool isComputed = false;
99  if (storage_) {
100  isComputed = stateStore_->get(*Sz_,param);
101  }
102  // Solve state equation if not done already.
103  if (!isComputed || !storage_) {
104  // Update equality constraint with new Opt variable.
105  conRed_->update_2(z,updateFlag_,updateIter_);
106  // Solve state equation.
107  conRed_->solve(*primRed_,*Sz_,z,tol);
108  // Update equality constraint with new Sim variable.
109  conRed_->update_1(*Sz_,updateFlag_,updateIter_);
110  // Update equality constraint.
111  conRed_->update(*Sz_, z, updateFlag_, updateIter_);
112  // Store state.
113  if (storage_) {
114  stateStore_->set(*Sz_,param);
115  }
116  }
117  }
118 
119  void applySens(Vector<Real> &jv, const Vector<Real> &v, const Vector<Real> &z, Real &tol) {
120  // Solve reducible constraint
121  solveConRed(z, tol);
122  // Solve linearization of reducible constraint in direction v
123  conRed_->applyJacobian_2(*primRed_, v, *Sz_, z, tol);
124  conRed_->applyInverseJacobian_1(jv, *primRed_, *Sz_, z, tol);
125  jv.scale(static_cast<Real>(-1));
126  }
127 
128  void applyAdjointSens(Vector<Real> &ajv, const Vector<Real> &v, const Vector<Real> &z, Real &tol) {
129  // Solve reducible constraint
130  solveConRed(z, tol);
131  // Solve adjoint of linearized reducible constraint
132  conRed_->applyInverseAdjointJacobian_1(*dualRed_, v, *Sz_, z, tol);
133  conRed_->applyAdjointJacobian_2(ajv, *dualRed_, *Sz_, z, tol);
134  ajv.scale(static_cast<Real>(-1));
135  }
136 
137 public:
139  const ROL::Ptr<Constraint_SimOpt<Real> > &conRed,
140  const Vector<Real> &cVal, const Vector<Real> &cRed,
141  const Vector<Real> &u, const Vector<Real> &Sz, const Vector<Real> &z,
142  const bool storage = true, const bool isConRedParametrized = false)
143  : Constraint_SimOpt<Real>(), conVal_(conVal), conRed_(conRed),
144  updateFlag_(true), updateIter_(0), storage_(storage),
145  isConRedParametrized_(isConRedParametrized) {
146  Sz_ = Sz.clone();
147  primRed_ = cRed.clone();
148  dualRed_ = cRed.dual().clone();
149  primZ_ = z.clone();
150  dualZ_ = z.dual().clone();
151  dualZ1_ = z.dual().clone();
152  stateStore_ = ROL::makePtr<SimController<Real>>();
153  }
154 
155  void update(const Vector<Real> &u, const Vector<Real> &z, bool flag = true, int iter = -1 ) {
156  // Update this
157  update_2(z, flag, iter);
158  update_1(u, flag, iter);
159  }
160 
161  void update_1( const Vector<Real> &u, bool flag = true, int iter = -1 ) {
162  conVal_->update_1(u, flag, iter);
163  // Update constraints with solution to reducible constraint
164  conVal_->update(u, *Sz_, flag, iter);
165  }
166 
167  void update_2( const Vector<Real> &z, bool flag = true, int iter = -1 ) {
168  //conRed_->update_2(z, flag, iter);
169  // Solve reducible constraint
170  updateFlag_ = flag;
171  updateIter_ = iter;
172  Real ctol = std::sqrt(ROL_EPSILON<Real>());
173  stateStore_->equalityConstraintUpdate(true);
174  solveConRed(z, ctol);
175  }
176 
177  void value(Vector<Real> &c, const Vector<Real> &u, const Vector<Real> &z, Real &tol) {
178  solveConRed(z, tol);
179  conVal_->value(c, u, *Sz_, tol);
180  }
181 
182  void solve(Vector<Real> &c, Vector<Real> &u, const Vector<Real> &z, Real &tol) {
183  solveConRed(z, tol);
184  conVal_->solve(c, u, *Sz_, tol);
185  }
186 
188  const Vector<Real> &z, Real &tol) {
189  solveConRed(z, tol);
190  conVal_->applyJacobian_1(jv, v, u, *Sz_, tol);
191  }
192 
194  const Vector<Real> &z, Real &tol) {
195  applySens(*primZ_, v, z, tol);
196  conVal_->applyJacobian_2(jv, *primZ_, u, *Sz_, tol);
197  }
198 
200  const Vector<Real> &z, Real &tol) {
201  solveConRed(z, tol);
202  conVal_->applyInverseJacobian_1(ijv, v, u, *Sz_, tol);
203  }
204 
206  const Vector<Real> &z, Real &tol) {
207  solveConRed(z, tol);
208  conVal_->applyAdjointJacobian_1(ajv, v, u, *Sz_, tol);
209  }
210 
212  const Vector<Real> &z, Real &tol) {
213  solveConRed(z, tol);
214  conVal_->applyAdjointJacobian_2(*dualZ_, v, u, *Sz_, tol);
215  applyAdjointSens(ajv, *dualZ_, z, tol);
216  }
217 
219  const Vector<Real> &z, Real &tol) {
220  solveConRed(z, tol);
221  conVal_->applyInverseAdjointJacobian_1(ijv, v, u, *Sz_, tol);
222  }
223 
225  const Vector<Real> &u, const Vector<Real> &z, Real &tol) {
226  solveConRed(z, tol);
227  conVal_->applyAdjointHessian_11(ahwv, w, v, u, z, tol);
228  }
229 
231  const Vector<Real> &u, const Vector<Real> &z, Real &tol) {
232  solveConRed(z, tol);
233  conVal_->applyAdjointHessian_12(*dualZ_, w, v, u, *Sz_, tol);
234  applyAdjointSens(ahwv, *dualZ_, z, tol);
235  }
236 
238  const Vector<Real> &u, const Vector<Real> &z, Real &tol) {
239  applySens(*primZ_, v, z, tol);
240  conVal_->applyAdjointHessian_21(ahwv, w, *primZ_, u, *Sz_, tol);
241  }
242 
244  const Vector<Real> &u, const Vector<Real> &z, Real &tol) {
245  ahwv.zero();
246  applySens(*primZ_, v, z, tol);
247 
248  conVal_->applyAdjointJacobian_2(*dualZ_, w, u, *Sz_, tol);
249  conRed_->applyInverseAdjointJacobian_1(*dualRed_, *dualZ_, *Sz_, z, tol);
250  conRed_->applyAdjointHessian_22(*dualZ_, *dualRed_, v, *Sz_, z, tol);
251  ahwv.axpy(static_cast<Real>(-1), *dualZ_);
252  conRed_->applyAdjointHessian_12(*dualZ_, *dualRed_, *primZ_, *Sz_, z, tol);
253  ahwv.axpy(static_cast<Real>(-1), *dualZ_);
254 
255  conRed_->applyAdjointHessian_11(*dualZ1_, *dualRed_, *primZ_, *Sz_, z, tol);
256  conRed_->applyAdjointHessian_21(*dualZ_, *dualRed_, v, *Sz_, z, tol);
257  dualZ1_->plus(*dualZ_);
258  dualZ1_->scale(static_cast<Real>(-1));
259 
260  conVal_->applyAdjointHessian_22(*dualZ_, w, *primZ_, u, *Sz_, tol);
261  dualZ1_->plus(*dualZ_);
262 
263  applyAdjointSens(*dualZ_, *dualZ1_, z, tol);
264  ahwv.plus(*dualZ_);
265  }
266 
267 // Definitions for parametrized (stochastic) equality constraints
268 public:
269  void setParameter(const std::vector<Real> &param) {
270  conVal_->setParameter(param);
271  if (isConRedParametrized_) {
272  conRed_->setParameter(param);
274  }
275  }
276 }; // class CompositeConstraint_SimOpt
277 
278 } // namespace ROL
279 
280 #endif
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 is ...
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:226
virtual void scale(const Real alpha)=0
Compute where .
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 ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
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 plus(const Vector &x)=0
Compute , where .
void applySens(Vector< Real > &jv, 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...
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Definition: ROL_Vector.hpp:153
void solve(Vector< Real > &c, Vector< Real > &u, const Vector< Real > &z, Real &tol)
Given , solve for .
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 ...
const std::vector< Real > getParameter(void) const
void applyAdjointSens(Vector< Real > &ajv, const Vector< Real > &v, const Vector< Real > &z, Real &tol)
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, flag = true if optimization variable is changed, iter is the outer algorithm iterations count.
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 ...
virtual void zero()
Set to zero vector.
Definition: ROL_Vector.hpp:167
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:80
void solveConRed(const Vector< Real > &z, Real &tol)
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 .
ROL::Ptr< SimController< Real > > stateStore_
virtual void setParameter(const std::vector< Real > &param)
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 .
Defines a composite equality constraint operator interface for simulation-based optimization.
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 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 ...
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...
const ROL::Ptr< Constraint_SimOpt< Real > > conRed_
CompositeConstraint_SimOpt(const ROL::Ptr< Constraint_SimOpt< Real > > &conVal, const ROL::Ptr< Constraint_SimOpt< Real > > &conRed, const Vector< Real > &cVal, const Vector< Real > &cRed, const Vector< Real > &u, const Vector< Real > &Sz, const Vector< Real > &z, const bool storage=true, const bool isConRedParametrized=false)
Defines the constraint operator interface for simulation-based optimization.
void setParameter(const std::vector< Real > &param)
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...
const ROL::Ptr< Constraint_SimOpt< Real > > conVal_
void value(Vector< Real > &c, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
Evaluate the constraint operator at .