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
ROL::Vector::scale
virtual void scale(const Real alpha)=0
Compute where .
ROL::Vector::clone
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
ROL::CompositeConstraint_SimOpt::conVal_
const ROL::Ptr< Constraint_SimOpt< Real > > conVal_
Definition: ROL_CompositeConstraint_SimOpt.hpp:78
ROL::CompositeConstraint_SimOpt::applyAdjointHessian_12
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...
Definition: ROL_CompositeConstraint_SimOpt.hpp:230
ROL::Vector::axpy
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Definition: ROL_Vector.hpp:153
ROL::CompositeConstraint_SimOpt::solve
void solve(Vector< Real > &c, Vector< Real > &u, const Vector< Real > &z, Real &tol)
Given , solve for .
Definition: ROL_CompositeConstraint_SimOpt.hpp:182
ROL::CompositeConstraint_SimOpt::CompositeConstraint_SimOpt
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)
Definition: ROL_CompositeConstraint_SimOpt.hpp:138
ROL::CompositeConstraint_SimOpt::applyAdjointHessian_11
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 ...
Definition: ROL_CompositeConstraint_SimOpt.hpp:224
ROL::CompositeConstraint_SimOpt::stateStore_
ROL::Ptr< SimController< Real > > stateStore_
Definition: ROL_CompositeConstraint_SimOpt.hpp:88
ROL::Vector::zero
virtual void zero()
Set to zero vector.
Definition: ROL_Vector.hpp:167
ROL::CompositeConstraint_SimOpt::Sz_
ROL::Ptr< Vector< Real > > Sz_
Definition: ROL_CompositeConstraint_SimOpt.hpp:81
ROL::CompositeConstraint_SimOpt::value
void value(Vector< Real > &c, const Vector< Real > &u, const Vector< Real > &z, Real &tol)
Evaluate the constraint operator at .
Definition: ROL_CompositeConstraint_SimOpt.hpp:177
ROL::CompositeConstraint_SimOpt::update
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...
Definition: ROL_CompositeConstraint_SimOpt.hpp:155
ROL::CompositeConstraint_SimOpt::applyAdjointSens
void applyAdjointSens(Vector< Real > &ajv, const Vector< Real > &v, const Vector< Real > &z, Real &tol)
Definition: ROL_CompositeConstraint_SimOpt.hpp:128
ROL::CompositeConstraint_SimOpt::updateFlag_
bool updateFlag_
Definition: ROL_CompositeConstraint_SimOpt.hpp:90
ROL::CompositeConstraint_SimOpt::solveConRed
void solveConRed(const Vector< Real > &z, Real &tol)
Definition: ROL_CompositeConstraint_SimOpt.hpp:95
ROL::CompositeConstraint_SimOpt::dualZ_
ROL::Ptr< Vector< Real > > dualZ_
Definition: ROL_CompositeConstraint_SimOpt.hpp:85
ROL::Vector::plus
virtual void plus(const Vector &x)=0
Compute , where .
ROL::CompositeConstraint_SimOpt::update_2
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,...
Definition: ROL_CompositeConstraint_SimOpt.hpp:167
ROL::CompositeConstraint_SimOpt
Defines a composite equality constraint operator interface for simulation-based optimization.
Definition: ROL_CompositeConstraint_SimOpt.hpp:75
ROL_Constraint_SimOpt.hpp
ROL::CompositeConstraint_SimOpt::primZ_
ROL::Ptr< Vector< Real > > primZ_
Definition: ROL_CompositeConstraint_SimOpt.hpp:84
ROL::CompositeConstraint_SimOpt::dualZ1_
ROL::Ptr< Vector< Real > > dualZ1_
Definition: ROL_CompositeConstraint_SimOpt.hpp:86
ROL::Constraint::getParameter
const std::vector< Real > getParameter(void) const
Definition: ROL_Constraint.hpp:389
ROL::CompositeConstraint_SimOpt::primRed_
ROL::Ptr< Vector< Real > > primRed_
Definition: ROL_CompositeConstraint_SimOpt.hpp:82
ROL::Vector
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:80
ROL::CompositeConstraint_SimOpt::applyInverseAdjointJacobian_1
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 .
Definition: ROL_CompositeConstraint_SimOpt.hpp:218
ROL::Constraint::setParameter
virtual void setParameter(const std::vector< Real > &param)
Definition: ROL_Constraint.hpp:394
ROL::CompositeConstraint_SimOpt::applyAdjointHessian_22
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 ...
Definition: ROL_CompositeConstraint_SimOpt.hpp:243
ROL::CompositeConstraint_SimOpt::storage_
const bool storage_
Definition: ROL_CompositeConstraint_SimOpt.hpp:93
ROL::CompositeConstraint_SimOpt::applyJacobian_2
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 .
Definition: ROL_CompositeConstraint_SimOpt.hpp:193
ROL::CompositeConstraint_SimOpt::update_1
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,...
Definition: ROL_CompositeConstraint_SimOpt.hpp:161
ROL
Definition: ROL_ElementwiseVector.hpp:61
ROL::CompositeConstraint_SimOpt::isConRedParametrized_
const bool isConRedParametrized_
Definition: ROL_CompositeConstraint_SimOpt.hpp:93
ROL::CompositeConstraint_SimOpt::conRed_
const ROL::Ptr< Constraint_SimOpt< Real > > conRed_
Definition: ROL_CompositeConstraint_SimOpt.hpp:79
ROL::Constraint_SimOpt
Defines the constraint operator interface for simulation-based optimization.
Definition: ROL_Constraint_SimOpt.hpp:100
ROL::Vector::dual
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
ROL::CompositeConstraint_SimOpt::applySens
void applySens(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &z, Real &tol)
Definition: ROL_CompositeConstraint_SimOpt.hpp:119
ROL::CompositeConstraint_SimOpt::applyAdjointJacobian_1
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...
Definition: ROL_CompositeConstraint_SimOpt.hpp:205
ROL::CompositeConstraint_SimOpt::applyAdjointHessian_21
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...
Definition: ROL_CompositeConstraint_SimOpt.hpp:237
ROL_SimController.hpp
ROL::CompositeConstraint_SimOpt::updateIter_
int updateIter_
Definition: ROL_CompositeConstraint_SimOpt.hpp:91
ROL::CompositeConstraint_SimOpt::setParameter
void setParameter(const std::vector< Real > &param)
Definition: ROL_CompositeConstraint_SimOpt.hpp:269
ROL::CompositeConstraint_SimOpt::dualRed_
ROL::Ptr< Vector< Real > > dualRed_
Definition: ROL_CompositeConstraint_SimOpt.hpp:83
ROL::CompositeConstraint_SimOpt::applyAdjointJacobian_2
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...
Definition: ROL_CompositeConstraint_SimOpt.hpp:211
ROL::CompositeConstraint_SimOpt::applyJacobian_1
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 .
Definition: ROL_CompositeConstraint_SimOpt.hpp:187
ROL::CompositeConstraint_SimOpt::applyInverseJacobian_1
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 .
Definition: ROL_CompositeConstraint_SimOpt.hpp:199