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);
244 Teuchos::RCP<const Vector<Real> >
get(size_type i)
const {
248 Teuchos::RCP<Vector<Real> >
get(size_type i) {
252 void set(size_type i,
const V &x) {
271 typedef RCP<Vector<Real> >
RCPV;
275 return rcp(
new PV( std::vector<RCPV>(temp, temp+1) ) );
282 typedef RCP<const Vector<Real> >
RCPV;
286 return rcp(
new PV( std::vector<RCPV>(temp, temp+1) ) );
294 typedef RCP<Vector<Real> >
RCPV;
298 return rcp(
new PV( std::vector<RCPV>(temp, temp+2) ) );
306 typedef RCP<const Vector<Real> >
RCPV;
310 return rcp(
new PV( std::vector<RCPV>(temp, temp+2) ) );
319 typedef RCP<Vector<Real> >
RCPV;
322 RCPV temp[] = {a,b,c};
323 return rcp(
new PV( std::vector<RCPV>(temp, temp+3) ) );
332 typedef RCP<const Vector<Real> >
RCPV;
335 RCPV temp[] = {a,b,c};
336 return rcp(
new PV( std::vector<RCPV>(temp, temp+3) ) );
346 typedef RCP<Vector<Real> >
RCPV;
349 RCPV temp[] = {a,b,c,d};
350 return rcp(
new PV( std::vector<RCPV>(temp, temp+4) ) );
360 typedef RCP<const Vector<Real> >
RCPV;
363 RCPV temp[] = {a,b,c,d};
364 return rcp(
new PV( std::vector<RCPV>(temp, temp+4) ) );
369 #endif // ROL_PARTITIONED_VECTOR_H size_type numVectors() const
Real norm() const
Returns where .
Defines the linear algebra of vector space on a generic partitioned vector.
const std::vector< RCPV > vecs_
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
PartitionedVector(const std::vector< RCPV > &vecs)
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.
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 .