ROL
ROL_NullSpaceOperator.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_NULL_SPACE_OPERATOR_H
45 #define ROL_NULL_SPACE_OPERATOR_H
46 
47 #include "ROL_Constraint.hpp"
49 #include "ROL_Krylov.hpp"
52 
60 namespace ROL {
61 
62 template <class Real>
63 class NullSpaceOperator : public LinearOperator<Real> {
64 private:
65  const Ptr<Constraint<Real>> con_;
66  const bool useInexact_;
67 
68  Ptr<LinearOperator<Real>> augsys_, augsysprec_;
69  Ptr<Krylov<Real>> krylov_;
70  mutable int iterKrylov_;
71  mutable int flagKrylov_;
72 
73  mutable Ptr<Vector<Real>> v1_;
74  mutable Ptr<Vector<Real>> v2_;
75  mutable Ptr<PartitionedVector<Real>> vv_;
76  mutable Ptr<Vector<Real>> b1_;
77  mutable Ptr<Vector<Real>> b2_;
78  mutable Ptr<PartitionedVector<Real>> bb_;
79  mutable Ptr<Vector<Real>> w1_;
80  mutable Ptr<Vector<Real>> w2_;
81  mutable Ptr<PartitionedVector<Real>> ww_;
82  mutable Ptr<Vector<Real>> mul_;
83 
84  int dim_;
85  Real b1sqr_;
86 
88  Vector<Real> &b,
89  Real &tol,
90  bool refine = false) const {
91  if( refine ) {
92  // TODO: Make sure this tol is actually ok...
93  Real origTol = tol;
94  ww_->set(v);
95  augsys_->apply(*vv_, *ww_, tol);
96  tol = origTol;
97  b.axpy( static_cast<Real>(-1), *vv_ );
98  }
99  vv_->zero();
100  // If inexact, change tolerance
101  if( useInexact_ ) {
102  krylov_->resetAbsoluteTolerance(tol);
103  }
104 
105  flagKrylov_ = 0;
107 
108  if( refine ) {
109  v.plus(*vv_);
110  }
111  else {
112  v.set(*vv_);
113  }
114  }
115 
116 public:
117  virtual ~NullSpaceOperator() {}
119  const Ptr<Vector<Real>> &dom,
120  const Ptr<Vector<Real>> &ran)
121  : con_(con), useInexact_(false) {
122  iterKrylov_ = 0;
123  flagKrylov_ = 0;
124  dim_ = ran->dimension();
125  if (dim_==1) {
126  Real tol = std::sqrt(ROL_EPSILON<Real>());
127  b1_ = dom->dual().clone();
128  b2_ = ran->clone(); b2_->setScalar(1.0);
129  con_->applyAdjointJacobian(*b1_,*b2_,*dom,tol);
130  b1sqr_ = b1_->dot(*b1_);
131  }
132  else {
133  ParameterList list;
134  Real atol = static_cast<Real>(1e-12);
135  Real rtol = static_cast<Real>(1e-2);
136  list.sublist("General").sublist("Krylov").set("Type", "GMRES");
137  list.sublist("General").sublist("Krylov").set("Absolute Tolerance", atol);
138  list.sublist("General").sublist("Krylov").set("Relative Tolerance", rtol);
139  list.sublist("General").sublist("Krylov").set("Iteration Limit", 200);
140  krylov_ = KrylovFactory<Real>(list);
141 
142  augsys_ = makePtr<AugmentedSystemOperator<Real>>(con,dom);
143  augsysprec_ = makePtr<AugmentedSystemPrecOperator<Real>>(con,dom);
144 
145  v1_ = dom->dual().clone();
146  v2_ = ran->dual().clone();
147  vv_ = makePtr<PartitionedVector<Real>>(std::vector<Ptr<Vector<Real>>>({v1_, v2_}));
148 
149  w1_ = dom->dual().clone();
150  w2_ = ran->dual().clone();
151  ww_ = makePtr<PartitionedVector<Real>>(std::vector<Ptr<Vector<Real>>>({w1_, w2_}));
152 
153  b1_ = dom->dual().clone();
154  b2_ = ran->clone();
155  bb_ = makePtr<PartitionedVector<Real>>(std::vector<Ptr<Vector<Real>>>({b1_, b2_}));
156 
157  mul_ = ran->dual().clone();
158  }
159  }
160 
161  virtual void apply( Vector<Real> &Hv, const Vector<Real> &v, Real &tol ) const {
162  if (dim_==1) {
163  Real dot = v.dot(*b1_);
164  Hv.set(v);
165  Hv.axpy(-dot/b1sqr_,*b1_);
166  }
167  else {
168  b1_->set(v); b2_->zero();
169  Ptr<PartitionedVector<Real>> sol = makePtr<PartitionedVector<Real>>(std::vector<Ptr<Vector<Real>>>({makePtrFromRef(Hv),mul_}));
170  solveAugmentedSystem(*sol,*bb_,tol);
171  }
172  }
173 
174  void applyAdjoint( Vector<Real> &Hv, const Vector<Real> &v, Real &tol ) const {
175  apply(Hv,v,tol);
176  }
177 
178  void applyInverse( Vector<Real> &Hv, const Vector<Real> &v, Real &tol ) const {
179  throw Exception::NotImplemented(">>> NullSpaceOperator::applyInverse : Not Implemented!");
180  }
181 
182  void applyAdjointInverse( Vector<Real> &Hv, const Vector<Real> &v, Real &tol ) const {
183  throw Exception::NotImplemented(">>> NullSpaceOperator::applyAdjointInverse : Not Implemented!");
184  }
185 
186 }; // class NullSpaceOperator
187 
188 } // namespace ROL
189 
190 #endif
Ptr< Vector< Real > > b1_
virtual void plus(const Vector &x)=0
Compute , where .
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Definition: ROL_Vector.hpp:153
Ptr< Vector< Real > > v1_
Ptr< PartitionedVector< Real > > ww_
Ptr< PartitionedVector< Real > > bb_
Ptr< Vector< Real > > mul_
Ptr< Vector< Real > > w1_
virtual void apply(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply linear operator.
Ptr< LinearOperator< Real > > augsys_
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:80
virtual Real dot(const Vector &x) const =0
Compute where .
void applyAdjointInverse(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply adjoint of the inverse linear operator.
Ptr< PartitionedVector< Real > > vv_
Ptr< LinearOperator< Real > > augsysprec_
Projects on to the null space of a linear constraint.
const Ptr< Constraint< Real > > con_
Ptr< Vector< Real > > v2_
Ptr< Vector< Real > > w2_
Ptr< Krylov< Real > > krylov_
void solveAugmentedSystem(Vector< Real > &v, Vector< Real > &b, Real &tol, bool refine=false) const
Provides the interface to apply a linear operator.
void applyInverse(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply inverse of linear operator.
NullSpaceOperator(const Ptr< Constraint< Real >> &con, const Ptr< Vector< Real >> &dom, const Ptr< Vector< Real >> &ran)
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:209
void applyAdjoint(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply adjoint of linear operator.
Ptr< Vector< Real > > b2_
Defines the general constraint operator interface.