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
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
67namespace ROL {
68
69template<class Real>
70class RieszPrimalVector;
71
72template<class Real>
73class RieszDualVector;
74
75
76template <class Real>
78
79 using V = Vector<Real>;
82
83private:
84
85 const ROL::Ptr<V> v_;
86 mutable ROL::Ptr<DualVector> dual_;
87 const ROL::Ptr<OP> op_;
88 mutable Real tol_;
89
90 mutable bool isDualInitialized_;
91
92 void initialize_dual( void ) const {
93
94 dual_ = ROL::makePtr<DualVector>(v_->clone(),op_,tol_);
95 op_->apply(*(dual_->getVector()),*v_,tol_);
96 isDualInitialized_ = true;
97 }
98
99public:
100
101 RieszPrimalVector( const ROL::Ptr<V> &v,
102 const ROL::Ptr<OP> &op,
103 Real tol=std::sqrt(ROL_EPSILON<Real>()) ) :
104 v_(v), op_(op), tol_(tol), isDualInitialized_(false) {
105 }
106
108
109 virtual Real dot( const V &x ) const {
110 if( !isDualInitialized_ ) {
112 }
113
114 const RieszPrimalVector &ex = dynamic_cast<const RieszPrimalVector&>(x);
115 return dual_->getVector()->dot(*(ex.getVector()));
116 }
117
118 virtual ROL::Ptr<V> clone() const {
119 return ROL::makePtr<RieszPrimalVector>( v_->clone(), op_, tol_ );
120 }
121
122 virtual const V & dual() const {
123 if( !isDualInitialized_ ) {
125 }
126 return *dual_;
127 }
128
129 void applyUnary( const Elementwise::UnaryFunction<Real> &f ) {
130 v_->applyUnary(f);
131 }
132
133 void applyBinary( const Elementwise::BinaryFunction<Real> &f, const V &x ) {
134 const RieszPrimalVector &ex = dynamic_cast<const RieszPrimalVector&>(x);
135 v_->applyBinary(f,*(ex.getVector()));
136 }
137
138 Real reduce( const Elementwise::ReductionOp<Real> &r ) const {
139 return v_->reduce(r);
140 }
141
142 void setScalar( const Real C ) {
143 v_->setScalar(C);
144 }
145
146 void randomize( const Real l=0.0, const Real u=1.0 ) {
147 v_->randomize(l,u);
148 }
149
150 ROL::Ptr<V> getVector( void ) {
151 return v_;
152 }
153
154 ROL::Ptr<const V> getVector( void ) const {
155 return v_;
156 }
157
158}; // class RieszPrimalVector
159
160
161
162template<class Real>
163class RieszDualVector : public ElementwiseVector<Real> {
164
168
169private:
170
171 const ROL::Ptr<V> v_;
172 mutable ROL::Ptr<PrimalVector> primal_;
173 const ROL::Ptr<OP> op_;
174 mutable Real tol_;
175
177
178 void initialize_primal( void ) const {
179
180 primal_ = ROL::makePtr<PrimalVector>(v_->clone(),op_,tol_);
181 op_->applyInverse(*(primal_->getVector()),*v_,tol_);
183 }
184
185public:
186
187 RieszDualVector( const ROL::Ptr<V> &v,
188 const ROL::Ptr<OP> &op,
189 Real tol=std::sqrt(ROL_EPSILON<Real>()) ) :
190 v_(v), op_(op), tol_(tol), isPrimalInitialized_(false) {
191 }
192
193 virtual ~RieszDualVector() {}
194
195 virtual Real dot( const V &x ) const {
196 if( !isPrimalInitialized_ ) {
198 }
199
200 const RieszDualVector &ex = dynamic_cast<const RieszDualVector&>(x);
201 return primal_->getVector()->dot(*(ex.getVector()));
202 }
203
204 virtual ROL::Ptr<V> clone() const {
205 return ROL::makePtr<RieszDualVector>( v_->clone(), op_, tol_ );
206 }
207
208 virtual const V & dual() const {
209 if( !isPrimalInitialized_ ) {
211 }
212 return *primal_;
213 }
214
215 void applyUnary( const Elementwise::UnaryFunction<Real> &f ) {
216 v_->applyUnary(f);
217 }
218
219 void applyBinary( const Elementwise::BinaryFunction<Real> &f, const V &x ) {
220 const RieszDualVector &ex = dynamic_cast<const RieszDualVector&>(x);
221 v_->applyBinary(f,*(ex.getVector()));
222 }
223
224 Real reduce( const Elementwise::ReductionOp<Real> &r ) const {
225 return v_->reduce(r);
226 }
227
228 void setScalar( const Real C ) {
229 v_->setScalar(C);
230 }
231
232 void randomize( const Real l=0.0, const Real u=1.0 ) {
233 v_->randomize(l,u);
234 }
235
236 ROL::Ptr<V> getVector( void ) {
237 return v_;
238 }
239
240 ROL::Ptr<const V> getVector( void ) const {
241 return v_;
242 }
243
244}; // class RieszDualVector
245
246
247
248} // namespace ROL
249
250#endif // ROL_RIESZVECTOR_H
Intermediate abstract class which does not require users implements plus, set, scale,...
Provides the interface to apply a linear operator.
ROL::Ptr< PrimalVector > primal_
void applyBinary(const Elementwise::BinaryFunction< Real > &f, const V &x)
const ROL::Ptr< V > v_
ROL::Ptr< V > getVector(void)
Real reduce(const Elementwise::ReductionOp< Real > &r) const
RieszDualVector(const ROL::Ptr< V > &v, const ROL::Ptr< OP > &op, Real tol=std::sqrt(ROL_EPSILON< Real >()))
void initialize_primal(void) const
virtual ROL::Ptr< V > clone() const
Clone to make a new (uninitialized) vector.
void setScalar(const Real C)
Set where .
void applyUnary(const Elementwise::UnaryFunction< Real > &f)
void randomize(const Real l=0.0, const Real u=1.0)
Set vector to be uniform random between [l,u].
virtual const V & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis,...
virtual Real dot(const V &x) const
Compute where .
ROL::Ptr< const V > getVector(void) const
const ROL::Ptr< OP > op_
ROL::Ptr< DualVector > dual_
Real reduce(const Elementwise::ReductionOp< Real > &r) const
virtual ROL::Ptr< V > clone() const
Clone to make a new (uninitialized) vector.
void applyBinary(const Elementwise::BinaryFunction< Real > &f, const V &x)
ROL::Ptr< V > getVector(void)
void initialize_dual(void) const
const ROL::Ptr< OP > op_
ROL::Ptr< const V > getVector(void) const
virtual Real dot(const V &x) const
Compute where .
void randomize(const Real l=0.0, const Real u=1.0)
Set vector to be uniform random between [l,u].
void setScalar(const Real C)
Set where .
virtual const V & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis,...
const ROL::Ptr< V > v_
void applyUnary(const Elementwise::UnaryFunction< Real > &f)
RieszPrimalVector(const ROL::Ptr< V > &v, const ROL::Ptr< OP > &op, Real tol=std::sqrt(ROL_EPSILON< Real >()))
Defines the linear algebra or vector space interface.