46 #ifndef ROL_PARTITIONED_VECTOR_H 47 #define ROL_PARTITIONED_VECTOR_H 61 typedef Teuchos::RCP<V>
RCPV;
70 typedef typename std::vector<PV>::size_type
size_type;
73 for( size_type i=0; i<vecs_.size(); ++i ) {
74 dual_vecs_.push_back((vecs_[i]->
dual()).
clone());
78 void set(
const V &x ) {
79 using Teuchos::dyn_cast;
80 const PV &xs = dyn_cast<
const PV>(dyn_cast<
const V>(x));
83 std::invalid_argument,
84 "Error: Vectors must have the same number of subvectors." );
86 for( size_type i=0; i<vecs_.size(); ++i ) {
87 vecs_[i]->set(*xs.
get(i));
92 using Teuchos::dyn_cast;
93 const PV &xs = dyn_cast<
const PV>(dyn_cast<
const V>(x));
96 std::invalid_argument,
97 "Error: Vectors must have the same number of subvectors." );
99 for( size_type i=0; i<vecs_.size(); ++i ) {
100 vecs_[i]->plus(*xs.
get(i));
105 for( size_type i=0; i<vecs_.size(); ++i ) {
106 vecs_[i]->scale(alpha);
110 void axpy(
const Real alpha,
const V &x ) {
111 using Teuchos::dyn_cast;
112 const PV &xs = dyn_cast<
const PV>(x);
115 std::invalid_argument,
116 "Error: Vectors must have the same number of subvectors." );
118 for( size_type i=0; i<vecs_.size(); ++i ) {
119 vecs_[i]->axpy(alpha,*xs.
get(i));
123 Real
dot(
const V &x )
const {
124 using Teuchos::dyn_cast;
125 const PV &xs = dyn_cast<
const PV>(x);
128 std::invalid_argument,
129 "Error: Vectors must have the same number of subvectors." );
132 for( size_type i=0; i<vecs_.size(); ++i ) {
133 result += vecs_[i]->dot(*xs.
get(i));
140 for( size_type i=0; i<vecs_.size(); ++i ) {
141 result += std::pow(vecs_[i]->
norm(),2);
143 return std::sqrt(result);
150 std::vector<RCPV> clonevec;
151 for( size_type i=0; i<vecs_.size(); ++i ) {
152 clonevec.push_back(vecs_[i]->
clone());
154 return rcp(
new PV(clonevec) );
160 for( size_type i=0; i<vecs_.size(); ++i ) {
161 dual_vecs_[i]->
set(vecs_[i]->
dual());
163 dual_pvec_ = rcp(
new PV( dual_vecs_ ) );
169 TEUCHOS_TEST_FOR_EXCEPTION( i >=
dimension() || i<0,
170 std::invalid_argument,
171 "Error: Basis index must be between 0 and vector dimension." );
175 using Teuchos::dyn_cast;
180 PV &eb = dyn_cast<PV>(*bvec);
186 for( size_type j=0; j<vecs_.size(); ++j ) {
188 end += vecs_[j]->dimension();
190 if( begin<= i && i<end ) {
191 eb.
set(j, *(vecs_[j]->
basis(i-begin)) );
205 for( size_type j=0; j<vecs_.size(); ++j ) {
206 total_dim += vecs_[j]->dimension();
212 for( size_type j=0; j<vecs_.size(); ++j ) {
218 void applyUnary(
const Elementwise::UnaryFunction<Real> &f ) {
219 for( size_type i=0; i<vecs_.size(); ++i ) {
220 vecs_[i]->applyUnary(f);
225 void applyBinary(
const Elementwise::BinaryFunction<Real> &f,
const V &x ) {
226 const PV &xs = Teuchos::dyn_cast<
const PV>(x);
228 for( size_type i=0; i<vecs_.size(); ++i ) {
229 vecs_[i]->applyBinary(f,*xs.
get(i));
233 Real
reduce(
const Elementwise::ReductionOp<Real> &r )
const {
234 Real result = r.initialValue();
236 for( size_type i=0; i<vecs_.size(); ++i ) {
237 r.reduce(vecs_[i]->
reduce(r),result);
242 void print( std::ostream &outStream )
const {
243 for( size_type i=0; i<vecs_.size(); ++i ) {
244 outStream <<
"V[" << i <<
"]: ";
245 vecs_[i]->print(outStream);
251 Teuchos::RCP<const Vector<Real> >
get(size_type i)
const {
255 Teuchos::RCP<Vector<Real> >
get(size_type i) {
259 void set(size_type i,
const V &x) {
278 typedef RCP<Vector<Real> >
RCPV;
282 return rcp(
new PV( std::vector<RCPV>(temp, temp+1) ) );
289 typedef RCP<const Vector<Real> >
RCPV;
293 return rcp(
new PV( std::vector<RCPV>(temp, temp+1) ) );
301 typedef RCP<Vector<Real> >
RCPV;
305 return rcp(
new PV( std::vector<RCPV>(temp, temp+2) ) );
313 typedef RCP<const Vector<Real> >
RCPV;
317 return rcp(
new PV( std::vector<RCPV>(temp, temp+2) ) );
326 typedef RCP<Vector<Real> >
RCPV;
329 RCPV temp[] = {a,b,c};
330 return rcp(
new PV( std::vector<RCPV>(temp, temp+3) ) );
339 typedef RCP<const Vector<Real> >
RCPV;
342 RCPV temp[] = {a,b,c};
343 return rcp(
new PV( std::vector<RCPV>(temp, temp+3) ) );
353 typedef RCP<Vector<Real> >
RCPV;
356 RCPV temp[] = {a,b,c,d};
357 return rcp(
new PV( std::vector<RCPV>(temp, temp+4) ) );
367 typedef RCP<const Vector<Real> >
RCPV;
370 RCPV temp[] = {a,b,c,d};
371 return rcp(
new PV( std::vector<RCPV>(temp, temp+4) ) );
376 #endif // ROL_PARTITIONED_VECTOR_H Real norm() const
Returns where .
Defines the linear algebra of vector space on a generic partitioned vector.
const std::vector< RCPV > vecs_
Teuchos::RCP< const Vector< Real > > get(size_type i) const
RCPV basis(const int i) const
Return i-th basis vector.
void applyBinary(const Elementwise::BinaryFunction< Real > &f, const V &x)
Real dot(const V &x) const
Compute where .
Teuchos::RCP< Vector< Real > > CreatePartitionedVector(const Teuchos::RCP< Vector< Real > > &a)
const V & dual(void) const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
Defines the linear algebra or vector space interface.
int dimension() const
Return dimension of the vector space.
void zero()
Set to zero vector.
void applyUnary(const Elementwise::UnaryFunction< Real > &f)
PartitionedVector< Real > PV
PartitionedVector(const std::vector< RCPV > &vecs)
void scale(const Real alpha)
Compute where .
std::vector< RCPV > dual_vecs_
void set(const V &x)
Set where .
Real reduce(const Elementwise::ReductionOp< Real > &r) const
std::vector< PV >::size_type size_type
RCPV clone() const
Clone to make a new (uninitialized) vector.
virtual void set(const Vector &x)
Set where .
void print(std::ostream &outStream) const
Teuchos::RCP< PV > dual_pvec_
void plus(const V &x)
Compute , where .
void axpy(const Real alpha, const V &x)
Compute where .
size_type numVectors() const