ROL
ROL_Constraint.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_CONSTRAINT_H
11 #define ROL_CONSTRAINT_H
12 
13 #include "ROL_Vector.hpp"
14 #include "ROL_UpdateType.hpp"
15 #include "ROL_Types.hpp"
16 #include <iostream>
17 
49 namespace ROL {
50 
51 template <class Real>
52 class Constraint {
53 private:
54  bool activated_;
55 
56 public:
57  virtual ~Constraint(void) {}
58 
59  Constraint(void) : activated_(true) {}
60 
68  virtual void update( const Vector<Real> &x, UpdateType type, int iter = -1 ) {
69  ROL_UNUSED(x);
70  ROL_UNUSED(type);
71  ROL_UNUSED(iter);
72  }
73 
79  virtual void update( const Vector<Real> &x, bool flag = true, int iter = -1 ) {}
80 
93  virtual void value(Vector<Real> &c,
94  const Vector<Real> &x,
95  Real &tol) = 0;
96 
97 
112  virtual void applyJacobian(Vector<Real> &jv,
113  const Vector<Real> &v,
114  const Vector<Real> &x,
115  Real &tol);
116 
117 
132  virtual void applyAdjointJacobian(Vector<Real> &ajv,
133  const Vector<Real> &v,
134  const Vector<Real> &x,
135  Real &tol);
136 
137 
154  virtual void applyAdjointJacobian(Vector<Real> &ajv,
155  const Vector<Real> &v,
156  const Vector<Real> &x,
157  const Vector<Real> &dualv,
158  Real &tol);
159 
160 
177  virtual void applyAdjointHessian(Vector<Real> &ahuv,
178  const Vector<Real> &u,
179  const Vector<Real> &v,
180  const Vector<Real> &x,
181  Real &tol);
182 
183 
222  virtual std::vector<Real> solveAugmentedSystem(Vector<Real> &v1,
223  Vector<Real> &v2,
224  const Vector<Real> &b1,
225  const Vector<Real> &b2,
226  const Vector<Real> &x,
227  Real &tol);
228 
229 
250  const Vector<Real> &v,
251  const Vector<Real> &x,
252  const Vector<Real> &g,
253  Real &tol) {
254  pv.set(v.dual());
255  }
256 
259  void activate(void) { activated_ = true; }
260 
263  void deactivate(void) { activated_ = false; }
264 
267  bool isActivated(void) { return activated_; }
268 
273  virtual std::vector<std::vector<Real> > checkApplyJacobian( const Vector<Real> &x,
274  const Vector<Real> &v,
275  const Vector<Real> &jv,
276  const std::vector<Real> &steps,
277  const bool printToStream = true,
278  std::ostream & outStream = std::cout,
279  const int order = 1 ) ;
280 
281 
287  virtual std::vector<std::vector<Real> > checkApplyJacobian( const Vector<Real> &x,
288  const Vector<Real> &v,
289  const Vector<Real> &jv,
290  const bool printToStream = true,
291  std::ostream & outStream = std::cout,
292  const int numSteps = ROL_NUM_CHECKDERIV_STEPS,
293  const int order = 1 ) ;
294 
300  virtual std::vector<std::vector<Real> > checkApplyAdjointJacobian(const Vector<Real> &x,
301  const Vector<Real> &v,
302  const Vector<Real> &c,
303  const Vector<Real> &ajv,
304  const bool printToStream = true,
305  std::ostream & outStream = std::cout,
306  const int numSteps = ROL_NUM_CHECKDERIV_STEPS ) ;
307 
308  /* \brief Check the consistency of the Jacobian and its adjoint. Verify that the deviation
309  \f$|\langle w^\top,Jv\rangle-\langle adj(J)w,v|\f$ is sufficiently small.
310 
311  @param[in] w is a dual constraint-space vector \f$w\in \mathcal{C}^\ast\f$
312  @param[in] v is an optimization space vector \f$v\in \mathcal{X}\f$
313  @param[in] x is the constraint argument \f$x\in\mathcal{X}\f$
314  @param[in] printToStream is is a flag that turns on/off output
315  @param[in] outStream is the output stream
316 
317  Returns the deviation.
318  */
319 
321  const Vector<Real> &v,
322  const Vector<Real> &x,
323  const bool printToStream = true,
324  std::ostream & outStream = std::cout) {
325  return checkAdjointConsistencyJacobian(w, v, x, w.dual(), v.dual(), printToStream, outStream);
326  }
327 
328  virtual Real checkAdjointConsistencyJacobian(const Vector<Real> &w,
329  const Vector<Real> &v,
330  const Vector<Real> &x,
331  const Vector<Real> &dualw,
332  const Vector<Real> &dualv,
333  const bool printToStream = true,
334  std::ostream & outStream = std::cout);
335 
336 
342  virtual std::vector<std::vector<Real> > checkApplyAdjointHessian(const Vector<Real> &x,
343  const Vector<Real> &u,
344  const Vector<Real> &v,
345  const Vector<Real> &hv,
346  const std::vector<Real> &step,
347  const bool printToScreen = true,
348  std::ostream & outStream = std::cout,
349  const int order = 1 ) ;
355  virtual std::vector<std::vector<Real> > checkApplyAdjointHessian(const Vector<Real> &x,
356  const Vector<Real> &u,
357  const Vector<Real> &v,
358  const Vector<Real> &hv,
359  const bool printToScreen = true,
360  std::ostream & outStream = std::cout,
361  const int numSteps = ROL_NUM_CHECKDERIV_STEPS,
362  const int order = 1 ) ;
363 
364 // Definitions for parametrized (stochastic) constraints
365 private:
366  std::vector<Real> param_;
367 
368 protected:
369  const std::vector<Real> getParameter(void) const {
370  return param_;
371  }
372 
373 public:
374  virtual void setParameter(const std::vector<Real> &param) {
375  param_.assign(param.begin(),param.end());
376  }
377 
378 }; // class Constraint
379 
380 } // namespace ROL
381 
382 #include "ROL_ConstraintDef.hpp"
383 
384 #endif
virtual void update(const Vector< Real > &x, 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:192
virtual void applyJacobian(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the constraint Jacobian at , , to vector .
virtual void applyPreconditioner(Vector< Real > &pv, const Vector< Real > &v, const Vector< Real > &x, const Vector< Real > &g, Real &tol)
Apply a constraint preconditioner at , , to vector . Ideally, this preconditioner satisfies the follo...
virtual Real checkAdjointConsistencyJacobian(const Vector< Real > &w, const Vector< Real > &v, const Vector< Real > &x, const bool printToStream=true, std::ostream &outStream=std::cout)
virtual void update(const Vector< Real > &x, UpdateType type, int iter=-1)
Update constraint function.
virtual std::vector< std::vector< Real > > checkApplyAdjointJacobian(const Vector< Real > &x, const Vector< Real > &v, const Vector< Real > &c, const Vector< Real > &ajv, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS)
Finite-difference check for the application of the adjoint of constraint Jacobian.
Contains definitions of custom data types in ROL.
void deactivate(void)
Turn off constraints.
const std::vector< Real > getParameter(void) const
void activate(void)
Turn on constraints.
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
virtual void value(Vector< Real > &c, const Vector< Real > &x, Real &tol)=0
Evaluate the constraint operator at .
#define ROL_UNUSED(x)
Definition: ROL_Vector.hpp:14
virtual 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 ...
std::vector< Real > param_
virtual void setParameter(const std::vector< Real > &param)
virtual std::vector< std::vector< Real > > checkApplyAdjointHessian(const Vector< Real > &x, const Vector< Real > &u, const Vector< Real > &v, const Vector< Real > &hv, const std::vector< Real > &step, const bool printToScreen=true, std::ostream &outStream=std::cout, const int order=1)
Finite-difference check for the application of the adjoint of constraint Hessian. ...
virtual std::vector< std::vector< Real > > checkApplyJacobian(const Vector< Real > &x, const Vector< Real > &v, const Vector< Real > &jv, const std::vector< Real > &steps, const bool printToStream=true, std::ostream &outStream=std::cout, const int order=1)
Finite-difference check for the constraint Jacobian application.
#define ROL_NUM_CHECKDERIV_STEPS
Number of steps for derivative checks.
Definition: ROL_Types.hpp:40
virtual void applyAdjointJacobian(Vector< Real > &ajv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the adjoint of the the constraint Jacobian at , , to vector .
virtual std::vector< Real > solveAugmentedSystem(Vector< Real > &v1, Vector< Real > &v2, const Vector< Real > &b1, const Vector< Real > &b2, const Vector< Real > &x, Real &tol)
Approximately solves the augmented system where , , , , is an identity or Riesz operator...
bool isActivated(void)
Check if constraints are on.
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:175
virtual ~Constraint(void)
Defines the general constraint operator interface.