ROL
ROL_RieszVector.hpp
Go to the documentation of this file.
1 
2 // @HEADER
3 // ************************************************************************
4 //
5 // Rapid Optimization Library (ROL) Package
6 // Copyright (2014) Sandia Corporation
7 //
8 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9 // license for use of this work by or on behalf of the U.S. Government.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact lead developers:
39 // Drew Kouri (dpkouri@sandia.gov) and
40 // Denis Ridzal (dridzal@sandia.gov)
41 //
42 // ************************************************************************
43 // @HEADER
44 
45 #ifndef ROL_RIESZVECTOR_H
46 #define ROL_RIESZVECTOR_H
47 
48 #include <ostream>
49 
51 #include "ROL_LinearOperator.hpp"
52 
53 /*
54  \class ROL::RieszPrimalVector
55  \brief Abstract implementation of a primal vector corresponding to
56  an inner-product that involves the application of a linear
57  operator
58 
59  \class ROL::RieszDualVector
60  \brief Abstract implementation of a dual vector corresponding to
61  an inner-product that involves the application of a linear
62  operator inverse
63 
64 */
65 
66 
67 namespace ROL {
68 
69 template<class Real>
71 
72 template<class Real>
74 
75 
76 template <class Real>
77 class RieszPrimalVector : public ElementwiseVector<Real> {
78 
79  template<typename T> using RCP = Teuchos::RCP<T>;
80 
81  using V = Vector<Real>;
84 
85 private:
86 
87  const RCP<V> v_;
89  const RCP<OP> op_;
90  mutable Real tol_;
91 
92  mutable bool isDualInitialized_;
93 
94  void initialize_dual( void ) const {
95 
96  dual_ = Teuchos::rcp( new DualVector(v_->clone(),op_,tol_) );
97  op_->apply(*(dual_->getVector()),*v_,tol_);
98  isDualInitialized_ = true;
99  }
100 
101 public:
102 
104  const RCP<OP> &op,
105  Real tol=std::sqrt(ROL_EPSILON<Real>()) ) :
106  v_(v), op_(op), tol_(tol), isDualInitialized_(false) {
107  }
108 
109  virtual ~RieszPrimalVector() {}
110 
111  virtual Real dot( const V &x ) const {
112  if( !isDualInitialized_ ) {
113  initialize_dual();
114  }
115 
116  const RieszPrimalVector &ex = Teuchos::dyn_cast<const RieszPrimalVector>(x);
117  return dual_->getVector()->dot(*(ex.getVector()));
118  }
119 
120  virtual RCP<V> clone() const {
121  return Teuchos::rcp( new RieszPrimalVector( v_->clone(), op_, tol_ ) );
122  }
123 
124  virtual const V & dual() const {
125  if( !isDualInitialized_ ) {
126  initialize_dual();
127  }
128  return *dual_;
129  }
130 
131  void applyUnary( const Elementwise::UnaryFunction<Real> &f ) {
132  v_->applyUnary(f);
133  }
134 
135  void applyBinary( const Elementwise::BinaryFunction<Real> &f, const V &x ) {
136  const RieszPrimalVector &ex = Teuchos::dyn_cast<const RieszPrimalVector>(x);
137  v_->applyBinary(f,*(ex.getVector()));
138  }
139 
140  Real reduce( const Elementwise::ReductionOp<Real> &r ) const {
141  return v_->reduce(r);
142  }
143 
144 
145  RCP<V> getVector( void ) {
146  return v_;
147  }
148 
149  RCP<const V> getVector( void ) const {
150  return v_;
151  }
152 
153 }; // class RieszPrimalVector
154 
155 
156 
157 template<class Real>
158 class RieszDualVector : public ElementwiseVector<Real> {
159 
160  template<typename T> using RCP = Teuchos::RCP<T>;
161 
162  using V = Vector<Real>;
165 
166 private:
167 
168  const RCP<V> v_;
170  const RCP<OP> op_;
171  mutable Real tol_;
172 
173  mutable bool isPrimalInitialized_;
174 
175  void initialize_primal( void ) const {
176 
177  primal_ = Teuchos::rcp( new PrimalVector(v_->clone(),op_,tol_) );
178  op_->applyInverse(*(primal_->getVector()),*v_,tol_);
179  isPrimalInitialized_ = true;
180  }
181 
182 public:
183 
185  const RCP<OP> &op,
186  Real tol=std::sqrt(ROL_EPSILON<Real>()) ) :
187  v_(v), op_(op), tol_(tol), isPrimalInitialized_(false) {
188  }
189 
190  virtual ~RieszDualVector() {}
191 
192  virtual Real dot( const V &x ) const {
193  if( !isPrimalInitialized_ ) {
194  initialize_primal();
195  }
196 
197  const RieszDualVector &ex = Teuchos::dyn_cast<const RieszDualVector>(x);
198  return primal_->getVector()->dot(*(ex.getVector()));
199  }
200 
201  virtual RCP<V> clone() const {
202  return Teuchos::rcp( new RieszDualVector( v_->clone(), op_, tol_ ) );
203  }
204 
205  virtual const V & dual() const {
206  if( !isPrimalInitialized_ ) {
207  initialize_primal();
208  }
209  return *primal_;
210  }
211 
212  void applyUnary( const Elementwise::UnaryFunction<Real> &f ) {
213  v_->applyUnary(f);
214  }
215 
216  void applyBinary( const Elementwise::BinaryFunction<Real> &f, const V &x ) {
217  const RieszDualVector &ex = Teuchos::dyn_cast<const RieszDualVector>(x);
218  v_->applyBinary(f,*(ex.getVector()));
219  }
220 
221  Real reduce( const Elementwise::ReductionOp<Real> &r ) const {
222  return v_->reduce(r);
223  }
224 
225 
226  RCP<V> getVector( void ) {
227  return v_;
228  }
229 
230  RCP<const V> getVector( void ) const {
231  return v_;
232  }
233 
234 }; // class RieszDualVector
235 
236 
237 
238 
239 
240 
241 } // namespace ROL
242 
243 #endif // ROL_RIESZVECTOR_H
Teuchos::RCP< T > RCP
void initialize_primal(void) const
void applyUnary(const Elementwise::UnaryFunction< Real > &f)
RCP< const V > getVector(void) const
Intermediate abstract class which does not require users implements plus, set, scale, axpy, norm, dot, or zero if they implement the three elementwise functions: applyUnary, applyBinary, and reduce.
Real reduce(const Elementwise::ReductionOp< Real > &r) const
RieszDualVector(const RCP< V > &v, const RCP< OP > &op, Real tol=std::sqrt(ROL_EPSILON< Real >()))
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:76
Teuchos::RCP< T > RCP
RCP< DualVector > dual_
virtual const V & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
RCP< V > getVector(void)
RCP< const V > getVector(void) const
virtual RCP< V > clone() const
Clone to make a new (uninitialized) vector.
void applyUnary(const Elementwise::UnaryFunction< Real > &f)
Provides the interface to apply a linear operator.
void applyBinary(const Elementwise::BinaryFunction< Real > &f, const V &x)
RCP< PrimalVector > primal_
Real reduce(const Elementwise::ReductionOp< Real > &r) const
void initialize_dual(void) const
virtual Real dot(const V &x) const
Compute where .
RieszPrimalVector(const RCP< V > &v, const RCP< OP > &op, Real tol=std::sqrt(ROL_EPSILON< Real >()))
virtual Real dot(const V &x) const
Compute where .
void applyBinary(const Elementwise::BinaryFunction< Real > &f, const V &x)
RieszDualVector< Real > DualVector
virtual const V & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
virtual RCP< V > clone() const
Clone to make a new (uninitialized) vector.