46 #ifndef ROL_PARTITIONED_VECTOR_H 47 #define ROL_PARTITIONED_VECTOR_H 61 typedef Teuchos::RCP<V>
RCPV;
65 Teuchos::RCP<std::vector<RCPV> >
vecs_;
70 typedef typename std::vector<PV>::size_type
size_type;
74 for( size_type i=0; i<vecs_->size(); ++i ) {
75 dual_vecs_.push_back(((*vecs_)[i]->
dual()).
clone());
79 void set(
const V &x ) {
82 using Teuchos::dyn_cast;
83 const PV &xs = dyn_cast<
const PV>(dyn_cast<
const V>(x));
86 std::invalid_argument,
87 "Error: Vectors must have the same number of subvectors." );
89 for( size_type i=0; i<vecs_->size(); ++i ) {
90 (*vecs_)[i]->set(*xs.
get(i));
95 using Teuchos::dyn_cast;
96 const PV &xs = dyn_cast<
const PV>(dyn_cast<
const V>(x));
99 std::invalid_argument,
100 "Error: Vectors must have the same number of subvectors." );
102 for( size_type i=0; i<vecs_->size(); ++i ) {
103 (*vecs_)[i]->plus(*xs.
get(i));
108 for( size_type i=0; i<vecs_->size(); ++i ) {
109 (*vecs_)[i]->scale(alpha);
113 void axpy(
const Real alpha,
const V &x ) {
114 using Teuchos::dyn_cast;
115 const PV &xs = dyn_cast<
const PV>(x);
118 std::invalid_argument,
119 "Error: Vectors must have the same number of subvectors." );
121 for( size_type i=0; i<vecs_->size(); ++i ) {
122 (*vecs_)[i]->axpy(alpha,*xs.
get(i));
126 Real
dot(
const V &x )
const {
127 using Teuchos::dyn_cast;
128 const PV &xs = dyn_cast<
const PV>(x);
131 std::invalid_argument,
132 "Error: Vectors must have the same number of subvectors." );
135 for( size_type i=0; i<vecs_->size(); ++i ) {
136 result += (*vecs_)[i]->dot(*xs.
get(i));
143 for( size_type i=0; i<vecs_->size(); ++i ) {
144 result += std::pow((*vecs_)[i]->
norm(),2);
146 return std::sqrt(result);
153 RCP<std::vector<RCPV> > clonevec = rcp(
new std::vector<RCPV> );
155 for( size_type i=0; i<vecs_->size(); ++i ) {
156 clonevec->push_back((*vecs_)[i]->
clone());
158 return rcp(
new PV(clonevec) );
165 for( size_type i=0; i<vecs_->size(); ++i ) {
166 dual_vecs_[i]->
set((*vecs_)[i]->
dual());
168 dual_pvec_ = rcp(
new PV( rcp( &dual_vecs_,
false ) ) );
174 TEUCHOS_TEST_FOR_EXCEPTION( i >=
dimension() || i<0,
175 std::invalid_argument,
176 "Error: Basis index must be between 0 and vector dimension." );
180 using Teuchos::dyn_cast;
185 PV &eb = dyn_cast<PV>(*bvec);
191 for( size_type j=0; j<vecs_->size(); ++j ) {
193 end += (*vecs_)[j]->dimension();
195 if( begin<= i && i<end ) {
196 eb.
set(j, *((*vecs_)[j]->
basis(i-begin)) );
210 for( size_type j=0; j<vecs_->size(); ++j ) {
211 total_dim += (*vecs_)[j]->dimension();
217 for( size_type j=0; j<vecs_->size(); ++j ) {
223 void applyUnary(
const Elementwise::UnaryFunction<Real> &f ) {
224 for( size_type i=0; i<vecs_->size(); ++i ) {
225 (*vecs_)[i]->applyUnary(f);
230 void applyBinary(
const Elementwise::BinaryFunction<Real> &f,
const V &x ) {
231 const PV &xs = Teuchos::dyn_cast<
const PV>(x);
233 for( size_type i=0; i<vecs_->size(); ++i ) {
234 (*vecs_)[i]->applyBinary(f,*xs.
get(i));
238 Real
reduce(
const Elementwise::ReductionOp<Real> &r )
const {
240 Real result = r.initialValue();
242 for( size_type i=0; i<vecs_->size(); ++i ) {
243 r.reduce((*vecs_)[i]->
reduce(r),result);
255 Teuchos::RCP<const Vector<Real> >
get(size_type i)
const {
259 Teuchos::RCP<Vector<Real> >
get(size_type i) {
263 void set(size_type i,
const V &x) {
272 return vecs_->size();
282 typedef RCP<Vector<Real> >
RCPV;
286 return rcp(
new PV( rcp(
new std::vector<RCPV>(temp, temp+1) ) ) );
293 typedef RCP<const Vector<Real> >
RCPV;
297 return rcp(
new PV( rcp(
new std::vector<RCPV>(temp, temp+1) ) ) );
305 typedef RCP<Vector<Real> >
RCPV;
309 return rcp(
new PV( rcp(
new std::vector<RCPV>(temp, temp+2) ) ) );
317 typedef RCP<const Vector<Real> >
RCPV;
321 return rcp(
new PV( rcp(
new std::vector<RCPV>(temp, temp+2) ) ) );
330 typedef RCP<Vector<Real> >
RCPV;
333 RCPV temp[] = {a,b,c};
334 return rcp(
new PV( rcp(
new std::vector<RCPV>(temp, temp+3) ) ) );
343 typedef RCP<const Vector<Real> >
RCPV;
346 RCPV temp[] = {a,b,c};
347 return rcp(
new PV( rcp(
new std::vector<RCPV>(temp, temp+3) ) ) );
357 typedef RCP<Vector<Real> >
RCPV;
360 RCPV temp[] = {a,b,c,d};
361 return rcp(
new PV( rcp(
new std::vector<RCPV>(temp, temp+4) ) ) );
371 typedef RCP<const Vector<Real> >
RCPV;
374 RCPV temp[] = {a,b,c,d};
375 return rcp(
new PV( rcp(
new std::vector<RCPV>(temp, temp+4) ) ) );
383 #endif // ROL_PARTITIONED_VECTOR_H PartitionedVector(const Teuchos::RCP< std::vector< RCPV > > &vecs)
size_type numVectors() const
Real norm() const
Returns where .
Defines the linear algebra of vector space on a generic partitioned vector.
const V & dual(void) const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
void applyBinary(const Elementwise::BinaryFunction< Real > &f, const V &x)
Teuchos::RCP< Vector< Real > > CreatePartitionedVector(const Teuchos::RCP< Vector< Real > > &a)
Defines the linear algebra or vector space interface.
Real dot(const V &x) const
Compute where .
void zero()
Set to zero vector.
void applyUnary(const Elementwise::UnaryFunction< Real > &f)
PartitionedVector< Real > PV
void scale(const Real alpha)
Compute where .
int dimension() const
Return dimension of the vector space.
Teuchos::RCP< const Vector< Real > > get(size_type i) const
RCPV basis(const int i) const
Return i-th basis vector.
Teuchos::RCP< std::vector< RCPV > > vecs_
std::vector< RCPV > dual_vecs_
void set(const V &x)
Set where .
RCPV clone() const
Clone to make a new (uninitialized) vector.
std::vector< PV >::size_type size_type
virtual void set(const Vector &x)
Set where .
Teuchos::RCP< PV > dual_pvec_
void plus(const V &x)
Compute , where .
Real reduce(const Elementwise::ReductionOp< Real > &r) const
void axpy(const Real alpha, const V &x)
Compute where .