ROL
ROL_RangeSpaceOperator.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_RANGE_SPACE_OPERATOR_H
45 #define ROL_RANGE_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 RangeSpaceOperator : 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 
85  Vector<Real> &b,
86  Real &tol,
87  bool refine = false) const {
88  if( refine ) {
89  // TODO: Make sure this tol is actually ok...
90  Real origTol = tol;
91  ww_->set(v);
92  augsys_->apply(*vv_, *ww_, tol);
93  tol = origTol;
94  b.axpy( static_cast<Real>(-1), *vv_ );
95  }
96  vv_->zero();
97  // If inexact, change tolerance
98  if( useInexact_ ) {
99  krylov_->resetAbsoluteTolerance(tol);
100  }
101 
102  flagKrylov_ = 0;
104 
105  if( refine ) {
106  v.plus(*vv_);
107  }
108  else {
109  v.set(*vv_);
110  }
111  }
112 
113 public:
114  virtual ~RangeSpaceOperator() {}
116  const Ptr<Vector<Real>> &dom,
117  const Ptr<Vector<Real>> &ran)
118  : con_(con), useInexact_(false) {
119  iterKrylov_ = 0;
120  flagKrylov_ = 0;
121 
122  ParameterList list;
123  Real atol = static_cast<Real>(1e-12);
124  Real rtol = static_cast<Real>(1e-2);
125  list.sublist("General").sublist("Krylov").set("Type", "GMRES");
126  list.sublist("General").sublist("Krylov").set("Absolute Tolerance", atol);
127  list.sublist("General").sublist("Krylov").set("Relative Tolerance", rtol);
128  list.sublist("General").sublist("Krylov").set("Iteration Limit", 200);
129  krylov_ = KrylovFactory<Real>(list);
130 
131  augsys_ = makePtr<AugmentedSystemOperator<Real>>(con,dom);
132  augsysprec_ = makePtr<AugmentedSystemPrecOperator<Real>>(con,dom);
133 
134  v1_ = dom->dual().clone();
135  v2_ = ran->dual().clone();
136  vv_ = makePtr<PartitionedVector<Real>>(std::vector<Ptr<Vector<Real>>>({v1_, v2_}));
137 
138  w1_ = dom->dual().clone();
139  w2_ = ran->dual().clone();
140  ww_ = makePtr<PartitionedVector<Real>>(std::vector<Ptr<Vector<Real>>>({w1_, w2_}));
141 
142  b1_ = dom->dual().clone();
143  b2_ = ran->clone();
144  bb_ = makePtr<PartitionedVector<Real>>(std::vector<Ptr<Vector<Real>>>({b1_, b2_}));
145 
146  mul_ = ran->dual().clone();
147  }
148 
149  virtual void apply( Vector<Real> &Hv, const Vector<Real> &v, Real &tol ) const {
150  b1_->zero(); b2_->set(v);
151  Ptr<PartitionedVector<Real>> sol = makePtr<PartitionedVector<Real>>(std::vector<Ptr<Vector<Real>>>({makePtrFromRef(Hv),mul_}));
152  solveAugmentedSystem(*sol,*bb_,tol);
153  }
154 
155  void applyAdjoint( Vector<Real> &Hv, const Vector<Real> &v, Real &tol ) const {
156  throw Exception::NotImplemented(">>> RangeSpaceOperator::applyAdjoint : Not Implemented!");
157  }
158 
159  void applyInverse( Vector<Real> &Hv, const Vector<Real> &v, Real &tol ) const {
160  throw Exception::NotImplemented(">>> RangeSpaceOperator::applyInverse : Not Implemented!");
161  }
162 
163  void applyAdjointInverse( Vector<Real> &Hv, const Vector<Real> &v, Real &tol ) const {
164  throw Exception::NotImplemented(">>> RangeSpaceOperator::applyAdjointInverse : Not Implemented!");
165  }
166 
167 }; // class RangeSpaceOperator
168 
169 } // namespace ROL
170 
171 #endif
void applyAdjoint(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply adjoint of linear operator.
Ptr< LinearOperator< Real > > augsysprec_
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
Projects on to the null space of a linear constraint.
Ptr< PartitionedVector< Real > > bb_
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:80
void applyInverse(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply inverse of linear operator.
void solveAugmentedSystem(Vector< Real > &v, Vector< Real > &b, Real &tol, bool refine=false) const
const Ptr< Constraint< Real > > con_
Provides the interface to apply a linear operator.
Ptr< PartitionedVector< Real > > vv_
Ptr< LinearOperator< Real > > augsys_
virtual void apply(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply linear operator.
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:209
Ptr< Krylov< Real > > krylov_
Ptr< PartitionedVector< Real > > ww_
void applyAdjointInverse(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply adjoint of the inverse linear operator.
Defines the general constraint operator interface.
RangeSpaceOperator(const Ptr< Constraint< Real >> &con, const Ptr< Vector< Real >> &dom, const Ptr< Vector< Real >> &ran)