ROL
ROL_RieszVector.hpp
Go to the documentation of this file.
1
2// @HEADER
3// *****************************************************************************
4// Rapid Optimization Library (ROL) Package
5//
6// Copyright 2014 NTESS and the ROL contributors.
7// SPDX-License-Identifier: BSD-3-Clause
8// *****************************************************************************
9// @HEADER
10
11#ifndef ROL_RIESZVECTOR_H
12#define ROL_RIESZVECTOR_H
13
14#include <ostream>
15
18
19/*
20 \class ROL::RieszPrimalVector
21 \brief Abstract implementation of a primal vector corresponding to
22 an inner-product that involves the application of a linear
23 operator
24
25 \class ROL::RieszDualVector
26 \brief Abstract implementation of a dual vector corresponding to
27 an inner-product that involves the application of a linear
28 operator inverse
29
30*/
31
32
33namespace ROL {
34
35template<class Real>
36class RieszPrimalVector;
37
38template<class Real>
39class RieszDualVector;
40
41
42template <class Real>
44
45 using V = Vector<Real>;
48
49private:
50
51 const ROL::Ptr<V> v_;
52 mutable ROL::Ptr<DualVector> dual_;
53 const ROL::Ptr<OP> op_;
54 mutable Real tol_;
55
56 mutable bool isDualInitialized_;
57
58 void initialize_dual( void ) const {
59
60 dual_ = ROL::makePtr<DualVector>(v_->clone(),op_,tol_);
61 op_->apply(*(dual_->getVector()),*v_,tol_);
62 isDualInitialized_ = true;
63 }
64
65public:
66
67 RieszPrimalVector( const ROL::Ptr<V> &v,
68 const ROL::Ptr<OP> &op,
69 Real tol=std::sqrt(ROL_EPSILON<Real>()) ) :
70 v_(v), op_(op), tol_(tol), isDualInitialized_(false) {
71 }
72
73 virtual ~RieszPrimalVector() {}
74
75 virtual Real dot( const V &x ) const {
76 if( !isDualInitialized_ ) {
78 }
79
80 const RieszPrimalVector &ex = dynamic_cast<const RieszPrimalVector&>(x);
81 return dual_->getVector()->dot(*(ex.getVector()));
82 }
83
84 virtual ROL::Ptr<V> clone() const {
85 return ROL::makePtr<RieszPrimalVector>( v_->clone(), op_, tol_ );
86 }
87
88 virtual const V & dual() const {
89 if( !isDualInitialized_ ) {
91 }
92 return *dual_;
93 }
94
95 void applyUnary( const Elementwise::UnaryFunction<Real> &f ) {
96 v_->applyUnary(f);
97 }
98
99 void applyBinary( const Elementwise::BinaryFunction<Real> &f, const V &x ) {
100 const RieszPrimalVector &ex = dynamic_cast<const RieszPrimalVector&>(x);
101 v_->applyBinary(f,*(ex.getVector()));
102 }
103
104 Real reduce( const Elementwise::ReductionOp<Real> &r ) const {
105 return v_->reduce(r);
106 }
107
108 void setScalar( const Real C ) {
109 v_->setScalar(C);
110 }
111
112 void randomize( const Real l=0.0, const Real u=1.0 ) {
113 v_->randomize(l,u);
114 }
115
116 ROL::Ptr<V> getVector( void ) {
117 return v_;
118 }
119
120 ROL::Ptr<const V> getVector( void ) const {
121 return v_;
122 }
123
124}; // class RieszPrimalVector
125
126
127
128template<class Real>
129class RieszDualVector : public ElementwiseVector<Real> {
130
134
135private:
136
137 const ROL::Ptr<V> v_;
138 mutable ROL::Ptr<PrimalVector> primal_;
139 const ROL::Ptr<OP> op_;
140 mutable Real tol_;
141
143
144 void initialize_primal( void ) const {
145
146 primal_ = ROL::makePtr<PrimalVector>(v_->clone(),op_,tol_);
147 op_->applyInverse(*(primal_->getVector()),*v_,tol_);
149 }
150
151public:
152
153 RieszDualVector( const ROL::Ptr<V> &v,
154 const ROL::Ptr<OP> &op,
155 Real tol=std::sqrt(ROL_EPSILON<Real>()) ) :
156 v_(v), op_(op), tol_(tol), isPrimalInitialized_(false) {
157 }
158
159 virtual ~RieszDualVector() {}
160
161 virtual Real dot( const V &x ) const {
162 if( !isPrimalInitialized_ ) {
164 }
165
166 const RieszDualVector &ex = dynamic_cast<const RieszDualVector&>(x);
167 return primal_->getVector()->dot(*(ex.getVector()));
168 }
169
170 virtual ROL::Ptr<V> clone() const {
171 return ROL::makePtr<RieszDualVector>( v_->clone(), op_, tol_ );
172 }
173
174 virtual const V & dual() const {
175 if( !isPrimalInitialized_ ) {
177 }
178 return *primal_;
179 }
180
181 void applyUnary( const Elementwise::UnaryFunction<Real> &f ) {
182 v_->applyUnary(f);
183 }
184
185 void applyBinary( const Elementwise::BinaryFunction<Real> &f, const V &x ) {
186 const RieszDualVector &ex = dynamic_cast<const RieszDualVector&>(x);
187 v_->applyBinary(f,*(ex.getVector()));
188 }
189
190 Real reduce( const Elementwise::ReductionOp<Real> &r ) const {
191 return v_->reduce(r);
192 }
193
194 void setScalar( const Real C ) {
195 v_->setScalar(C);
196 }
197
198 void randomize( const Real l=0.0, const Real u=1.0 ) {
199 v_->randomize(l,u);
200 }
201
202 ROL::Ptr<V> getVector( void ) {
203 return v_;
204 }
205
206 ROL::Ptr<const V> getVector( void ) const {
207 return v_;
208 }
209
210}; // class RieszDualVector
211
212
213
214} // namespace ROL
215
216#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.