ROL
ROL_StdConstraint.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_STDEQUALITY_CONSTRAINT_H
45 #define ROL_STDEQUALITY_CONSTRAINT_H
46 
47 #include "ROL_Constraint.hpp"
48 #include "ROL_StdVector.hpp"
49 
56 namespace ROL {
57 
58 template <class Real>
59 class StdConstraint : public virtual Constraint<Real> {
60 public:
61 
62  virtual ~StdConstraint() {}
63 
64 
66  void update( const Vector<Real> &x, bool flag = true, int iter = -1 ) {
67  const StdVector<Real> xs = dynamic_cast<const StdVector<Real>&>(x);
68  update(*(xs.getVector()),flag,true);
69  }
70 
71  virtual void update( const std::vector<Real> &x, bool flag = true, int iter = -1 ) {}
72 
73 
75  void value(Vector<Real> &c, const Vector<Real> &x, Real &tol) {
76  StdVector<Real> cs = dynamic_cast<StdVector<Real>&>(c);
77  const StdVector<Real> xs = dynamic_cast<const StdVector<Real>&>(x);
78  value(*(cs.getVector()),*(xs.getVector()),tol);
79  }
80 
81  virtual void value( std::vector<Real> &c, const std::vector<Real> &x, Real &tol ) = 0;
82 
83 
84 
85 
88  const Vector<Real> &x, Real &tol) {
89  StdVector<Real> jvs = dynamic_cast<StdVector<Real>&>(jv);
90  const StdVector<Real> vs = dynamic_cast<const StdVector<Real>&>(v);
91  const StdVector<Real> xs = dynamic_cast<const StdVector<Real>&>(x);
92  try {
93  applyJacobian(*(jvs.getVector()),*(vs.getVector()),*(xs.getVector()),tol);
94  }
95  catch (std::exception &e ){
97  }
98  }
99 
100  virtual void applyJacobian( std::vector<Real> &jv, const std::vector<Real> &v,
101  const std::vector<Real> &x, Real &tol ) {
102  ROL_TEST_FOR_EXCEPTION(true, std::invalid_argument,
103  ">>> ERROR (ROL::StdConstraint): applyJacobian not implemented!");
104  }
105 
106 
107 
110  const Vector<Real> &x, Real &tol) {
111  StdVector<Real> ajvs = dynamic_cast<StdVector<Real>&>(ajv);
112  const StdVector<Real> vs = dynamic_cast<const StdVector<Real>&>(v);
113  const StdVector<Real> xs = dynamic_cast<const StdVector<Real>&>(x);
114  try {
115  applyAdjointJacobian(*(ajvs.getVector()),*(vs.getVector()),*(xs.getVector()),tol);
116  }
117  catch (std::exception &e ){
119  }
120  }
121 
122  virtual void applyAdjointJacobian( std::vector<Real> &ajv, const std::vector<Real> &v,
123  const std::vector<Real> &x, Real &tol ) {
124  ROL_TEST_FOR_EXCEPTION(true, std::invalid_argument,
125  ">>> ERROR (ROL::StdConstraint): applyAdjointJacobian not implemented!");
126  }
127 
128 
129 
132  const Vector<Real> &x, Real &tol) {
133  StdVector<Real> ahuvs = dynamic_cast<StdVector<Real>&>(ahuv);
134  const StdVector<Real> us = dynamic_cast<const StdVector<Real>&>(u);
135  const StdVector<Real> vs = dynamic_cast<const StdVector<Real>&>(v);
136  const StdVector<Real> xs = dynamic_cast<const StdVector<Real>&>(x);
137  try {
138  applyAdjointHessian( *(ahuvs.getVector()), *(us.getVector()), *(vs.getVector()),
139  *(xs.getVector()), tol );
140  }
141  catch (std::exception &e) {
143  }
144 
145  }
146 
147  virtual void applyAdjointHessian( std::vector<Real> &ahuv, const std::vector<Real> &u,
148  const std::vector<Real> &v, const std::vector<Real> &x,
149  Real &tol ) {
150  ROL_TEST_FOR_EXCEPTION(true, std::invalid_argument,
151  ">>> ERROR (ROL::StdConstraint) : applyAdjointHessian not implemented!");
152  }
153 
154 
155 
156 
158  std::vector<Real> solveAugmentedSystem(Vector<Real> &v1, Vector<Real> &v2,
159  const Vector<Real> &b1, const Vector<Real> &b2,
160  const Vector<Real> &x, Real &tol) {
161  StdVector<Real> v1s = dynamic_cast<StdVector<Real>&>(v1);
162  StdVector<Real> v2s = dynamic_cast<StdVector<Real>&>(v2);
163  const StdVector<Real> b1s = dynamic_cast<const StdVector<Real>&>(b1);
164  const StdVector<Real> b2s = dynamic_cast<const StdVector<Real>&>(b2);
165  const StdVector<Real> xs = dynamic_cast<const StdVector<Real>&>(x);
166  try {
167  return solveAugmentedSystem( *(v1s.getVector()), *(v2s.getVector()), *(b1s.getVector()),
168  *(b2s.getVector()), *(xs.getVector()), tol );
169  }
170  catch (std::exception &e) {
171  return Constraint<Real>::solveAugmentedSystem(v1,v2,b1,b2,x,tol);
172  }
173  }
174 
175  virtual std::vector<Real> solveAugmentedSystem( std::vector<Real> &v1, std::vector<Real> &v2,
176  const std::vector<Real> &b1, const std::vector<Real> &b2,
177  const std::vector<Real> &x, Real tol ) {
178  ROL_TEST_FOR_EXCEPTION(true, std::invalid_argument,
179  ">>> ERROR (ROL::StdConstraint) : solveAugmentedSystem not implemented!");
180  return std::vector<Real>();
181  }
182 
183 
186  const Vector<Real> &g, Real &tol) {
187  StdVector<Real> pvs = dynamic_cast<StdVector<Real>&>(pv);
188  const StdVector<Real> vs = dynamic_cast<const StdVector<Real>&>(v);
189  const StdVector<Real> xs = dynamic_cast<const StdVector<Real>&>(x);
190  const StdVector<Real> gs = dynamic_cast<const StdVector<Real>&>(g);
191  try {
192  applyPreconditioner( *(pvs.getVector()), *(vs.getVector()), *(xs.getVector()),
193  *(gs.getVector()), tol );
194  }
195  catch (std::exception &e) {
197  }
198  }
199 
200  virtual void applyPreconditioner( std::vector<Real> &pv, const std::vector<Real> &v,
201  const std::vector<Real> &x, const std::vector<Real> &g, Real &tol ) {
202  ROL_TEST_FOR_EXCEPTION(true, std::invalid_argument,
203  ">>> ERROR (ROL::StdConstraint) : applyPreconditioner not implemented!");
204  }
205 
206 
207 }; // class StdConstraint
208 
209 } // namespace ROL
210 
211 
212 #endif
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 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...
void value(Vector< Real > &c, const Vector< Real > &x, Real &tol)
Evaluate the constraint operator at .
virtual void applyJacobian(std::vector< Real > &jv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
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 ...
Ptr< const std::vector< Element > > getVector() const
Defines the equality constraint operator interface for StdVectors.
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:80
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...
void applyJacobian(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the constraint Jacobian at , , to vector .
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 applyAdjointHessian(std::vector< Real > &ahuv, const std::vector< Real > &u, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
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 std::vector< Real > solveAugmentedSystem(std::vector< Real > &v1, std::vector< Real > &v2, const std::vector< Real > &b1, const std::vector< Real > &b2, const std::vector< Real > &x, Real tol)
virtual void applyAdjointJacobian(std::vector< Real > &ajv, const std::vector< Real > &v, const std::vector< Real > &x, Real &tol)
virtual void update(const std::vector< Real > &x, bool flag=true, int iter=-1)
virtual void applyPreconditioner(std::vector< Real > &pv, const std::vector< Real > &v, const std::vector< Real > &x, const std::vector< Real > &g, Real &tol)
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...
Defines the general constraint operator interface.
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...