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
49namespace ROL {
50
51template <class Real>
53private:
55
56public:
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
365private:
366 std::vector<Real> param_;
367
368protected:
369 const std::vector<Real> getParameter(void) const {
370 return param_;
371 }
372
373public:
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
Contains definitions of custom data types in ROL.
#define ROL_NUM_CHECKDERIV_STEPS
Number of steps for derivative checks.
Definition ROL_Types.hpp:40
#define ROL_UNUSED(x)
Defines the general constraint operator interface.
virtual void value(Vector< Real > &c, const Vector< Real > &x, Real &tol)=0
Evaluate the constraint operator at .
virtual ~Constraint(void)
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.
bool isActivated(void)
Check if constraints are on.
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 ,...
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 void update(const Vector< Real > &x, UpdateType type, int iter=-1)
Update constraint function.
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 void applyJacobian(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the constraint Jacobian at , , to vector .
virtual void setParameter(const std::vector< Real > &param)
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.
std::vector< Real > param_
void activate(void)
Turn on constraints.
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 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 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 i...
void deactivate(void)
Turn off constraints.
const std::vector< Real > getParameter(void) const
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
Defines the linear algebra or vector space interface.
virtual void set(const Vector &x)
Set where .
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis,...