47 #ifndef ROL_SIMULATED_VECTOR_H 48 #define ROL_SIMULATED_VECTOR_H 65 typedef Teuchos::RCP<V>
RCPV;
66 typedef Teuchos::RCP<BatchManager<Real> >
RCPBM;
71 Teuchos::RCP<BatchManager<Real> >
bman_;
76 typedef typename std::vector<PV>::size_type
size_type;
78 SimulatedVector(
const std::vector<RCPV> &vecs,
const RCPBM &bman ) : vecs_(vecs), bman_(bman) {
79 for( size_type i=0; i<vecs_.size(); ++i ) {
80 dual_vecs_.push_back((vecs_[i]->
dual()).
clone());
84 void set(
const V &x ) {
85 using Teuchos::dyn_cast;
86 const PV &xs = dyn_cast<
const PV>(dyn_cast<
const V>(x));
89 std::invalid_argument,
90 "Error: Vectors must have the same number of subvectors." );
92 for( size_type i=0; i<vecs_.size(); ++i ) {
93 vecs_[i]->set(*xs.
get(i));
98 using Teuchos::dyn_cast;
99 const PV &xs = dyn_cast<
const PV>(dyn_cast<
const V>(x));
102 std::invalid_argument,
103 "Error: Vectors must have the same number of subvectors." );
105 for( size_type i=0; i<vecs_.size(); ++i ) {
106 vecs_[i]->plus(*xs.
get(i));
111 for( size_type i=0; i<vecs_.size(); ++i ) {
112 vecs_[i]->scale(alpha);
116 void axpy(
const Real alpha,
const V &x ) {
117 using Teuchos::dyn_cast;
118 const PV &xs = dyn_cast<
const PV>(x);
121 std::invalid_argument,
122 "Error: Vectors must have the same number of subvectors." );
124 for( size_type i=0; i<vecs_.size(); ++i ) {
125 vecs_[i]->axpy(alpha,*xs.
get(i));
129 Real
dot(
const V &x )
const {
130 using Teuchos::dyn_cast;
131 const PV &xs = dyn_cast<
const PV>(x);
134 std::invalid_argument,
135 "Error: Vectors must have the same number of subvectors." );
139 for( size_type i=0; i<vecs_.size(); ++i ) {
140 locresult += vecs_[i]->dot(*xs.
get(i));
143 bman_->sumAll(&locresult, &result, 1);
151 for( size_type i=0; i<vecs_.size(); ++i ) {
152 locresult += std::pow(vecs_[i]->
norm(),2);
155 bman_->sumAll(&locresult, &result, 1);
157 return std::sqrt(result);
164 std::vector<RCPV> clonevec;
165 for( size_type i=0; i<vecs_.size(); ++i ) {
166 clonevec.push_back(vecs_[i]->
clone());
168 return rcp(
new PV(clonevec, bman_) );
174 for( size_type i=0; i<vecs_.size(); ++i ) {
175 dual_vecs_[i]->
set(vecs_[i]->
dual());
177 dual_pvec_ = rcp(
new PV( dual_vecs_, bman_ ) );
183 TEUCHOS_TEST_FOR_EXCEPTION( i >=
dimension() || i<0,
184 std::invalid_argument,
185 "Error: Basis index must be between 0 and vector dimension." );
189 using Teuchos::dyn_cast;
194 PV &eb = dyn_cast<PV>(*bvec);
200 for( size_type j=0; j<vecs_.size(); ++j ) {
202 end += vecs_[j]->dimension();
204 if( begin<= i && i<end ) {
205 eb.
set(j, *(vecs_[j]->
basis(i-begin)) );
219 for( size_type j=0; j<vecs_.size(); ++j ) {
220 total_dim += vecs_[j]->dimension();
226 for( size_type j=0; j<vecs_.size(); ++j ) {
232 void applyUnary(
const Elementwise::UnaryFunction<Real> &f ) {
233 for( size_type i=0; i<vecs_.size(); ++i ) {
234 vecs_[i]->applyUnary(f);
239 void applyBinary(
const Elementwise::BinaryFunction<Real> &f,
const V &x ) {
240 const PV &xs = Teuchos::dyn_cast<
const PV>(x);
242 for( size_type i=0; i<vecs_.size(); ++i ) {
243 vecs_[i]->applyBinary(f,*xs.
get(i));
247 Real
reduce(
const Elementwise::ReductionOp<Real> &r )
const {
248 Real result = r.initialValue();
250 for( size_type i=0; i<vecs_.size(); ++i ) {
251 r.reduce(vecs_[i]->
reduce(r),result);
260 Teuchos::RCP<const Vector<Real> >
get(size_type i)
const {
264 Teuchos::RCP<Vector<Real> >
get(size_type i) {
268 void set(size_type i,
const V &x) {
287 typedef RCP<Vector<Real> >
RCPV;
291 return rcp(
new PV( std::vector<RCPV>(temp, temp+1), bman ) );
298 typedef RCP<const Vector<Real> >
RCPV;
302 return rcp(
new PV( std::vector<RCPV>(temp, temp+1), bman ) );
311 typedef RCP<Vector<Real> >
RCPV;
315 return rcp(
new PV( std::vector<RCPV>(temp, temp+2), bman ) );
324 typedef RCP<const Vector<Real> >
RCPV;
328 return rcp(
new PV( std::vector<RCPV>(temp, temp+2), bman ) );
338 typedef RCP<Vector<Real> >
RCPV;
341 RCPV temp[] = {a,b,c};
342 return rcp(
new PV( std::vector<RCPV>(temp, temp+3), bman ) );
352 typedef RCP<const Vector<Real> >
RCPV;
355 RCPV temp[] = {a,b,c};
356 return rcp(
new PV( std::vector<RCPV>(temp, temp+3), bman ) );
367 typedef RCP<Vector<Real> >
RCPV;
370 RCPV temp[] = {a,b,c,d};
371 return rcp(
new PV( std::vector<RCPV>(temp, temp+4), bman ) );
382 typedef RCP<const Vector<Real> >
RCPV;
385 RCPV temp[] = {a,b,c,d};
386 return rcp(
new PV( std::vector<RCPV>(temp, temp+4), bman ) );
391 #endif // ROL_SIMULATED_VECTOR_H void set(const V &x)
Set where .
std::vector< PV >::size_type size_type
size_type numVectors() const
std::vector< RCPV > dual_vecs_
Teuchos::RCP< Vector< Real > > CreateSimulatedVector(const Teuchos::RCP< Vector< Real > > &a, const Teuchos::RCP< BatchManager< Real > > &bman)
void applyBinary(const Elementwise::BinaryFunction< Real > &f, const V &x)
Defines the linear algebra or vector space interface.
Real norm() const
Returns where .
Defines the linear algebra of a vector space on a generic partitioned vector where the individual vec...
const V & dual(void) const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
SimulatedVector(const std::vector< RCPV > &vecs, const RCPBM &bman)
Teuchos::RCP< PV > dual_pvec_
RCPV clone() const
Clone to make a new (uninitialized) vector.
const std::vector< RCPV > vecs_
Teuchos::RCP< BatchManager< Real > > bman_
Real dot(const V &x) const
Compute where .
int dimension() const
Return dimension of the vector space.
RCPV basis(const int i) const
Return i-th basis vector.
void zero()
Set to zero vector.
void plus(const V &x)
Compute , where .
Teuchos::RCP< BatchManager< Real > > RCPBM
SimulatedVector< Real > PV
Real reduce(const Elementwise::ReductionOp< Real > &r) const
void scale(const Real alpha)
Compute where .
void axpy(const Real alpha, const V &x)
Compute where .
void applyUnary(const Elementwise::UnaryFunction< Real > &f)
virtual void set(const Vector &x)
Set where .
Teuchos::RCP< const Vector< Real > > get(size_type i) const