47 #ifndef ROL_SIMULATED_VECTOR_H
48 #define ROL_SIMULATED_VECTOR_H
71 typedef ROL::Ptr<V>
Vp;
72 typedef ROL::Ptr<BatchManager<Real> >
VBMp;
77 ROL::Ptr<BatchManager<Real> >
bman_;
92 const PV &xs =
dynamic_cast<const PV&
>(x);
95 std::invalid_argument,
96 "Error: Vectors must have the same number of subvectors." );
105 const PV &xs =
dynamic_cast<const PV&
>(x);
108 std::invalid_argument,
109 "Error: Vectors must have the same number of subvectors." );
118 vecs_[i]->scale(alpha);
122 void axpy(
const Real alpha,
const V &x ) {
124 const PV &xs =
dynamic_cast<const PV&
>(x);
127 std::invalid_argument,
128 "Error: Vectors must have the same number of subvectors." );
135 virtual Real
dot(
const V &x )
const {
137 const PV &xs =
dynamic_cast<const PV&
>(x);
140 std::invalid_argument,
141 "Error: Vectors must have the same number of subvectors." );
146 locresult +=
vecs_[i]->dot(*xs.
get(i));
149 bman_->sumAll(&locresult, &result, 1);
155 return std::sqrt(
dot(*
this));
162 std::vector<Vp> clonevec;
166 return ROL::makePtr<PV>(clonevec,
bman_);
181 ROL_TEST_FOR_EXCEPTION( i >=
dimension() || i<0,
182 std::invalid_argument,
183 "Error: Basis index must be between 0 and vector dimension." );
187 PV &eb =
dynamic_cast<PV&
>(*bvec);
195 end +=
vecs_[j]->dimension();
197 if( begin<= i && i<end ) {
213 total_dim +=
vecs_[j]->dimension();
225 void applyUnary(
const Elementwise::UnaryFunction<Real> &f ) {
227 vecs_[i]->applyUnary(f);
232 void applyBinary(
const Elementwise::BinaryFunction<Real> &f,
const V &x ) {
233 const PV &xs =
dynamic_cast<const PV&
>(x);
236 vecs_[i]->applyBinary(f,*xs.
get(i));
240 Real
reduce(
const Elementwise::ReductionOp<Real> &r )
const {
241 Real result = r.initialValue();
251 vecs_[i]->setScalar(C);
257 vecs_[i]->randomize(l,u);
289 ROL::Ptr<Vector<Real> >
293 typedef ROL::Ptr<Vector<Real> > Vp;
297 return ROL::makePtr<PV>(std::vector<Vp>(temp, temp+1), bman );
301 class PrimalSimulatedVector :
public SimulatedVector<Real> {
303 const std::vector<ROL::Ptr<Vector<Real>>>
vecs_;
304 const ROL::Ptr<BatchManager<Real>>
bman_;
316 for(
int i=0; i<
sampler_->numMySamples(); ++i ) {
325 ROL_TEST_FOR_EXCEPTION(
sampler_->numMySamples() !=
static_cast<int>(xs.
numVectors()),
326 std::invalid_argument,
327 "Error: Vectors must have the same number of subvectors." );
332 for(
int i=0; i<
sampler_->numMySamples(); ++i ) {
335 Real t = locresult + y;
336 c = (t - locresult) - y;
340 bman_->sumAll(&locresult, &result, 1);
345 ROL::Ptr<Vector<Real> >
clone(
void)
const {
346 std::vector<ROL::Ptr<Vector<Real> > > clonevec;
347 for(
int i=0; i<
sampler_->numMySamples(); ++i ) {
350 return ROL::makePtr<PrimalSimulatedVector<Real>>(clonevec,
bman_,
sampler_);
358 for(
int i=0; i<
sampler_->numMySamples(); ++i ) {
368 class DualSimulatedVector :
public SimulatedVector<Real> {
370 const std::vector<ROL::Ptr<Vector<Real> > >
vecs_;
371 const ROL::Ptr<BatchManager<Real> >
bman_;
383 for(
int i=0; i<
sampler_->numMySamples(); ++i ) {
392 ROL_TEST_FOR_EXCEPTION(
sampler_->numMySamples() !=
static_cast<Real
>(xs.
numVectors()),
393 std::invalid_argument,
394 "Error: Vectors must have the same number of subvectors." );
399 for(
int i=0; i<
sampler_->numMySamples(); ++i ) {
402 Real t = locresult + y;
403 c = (t - locresult) - y;
407 bman_->sumAll(&locresult, &result, 1);
412 ROL::Ptr<Vector<Real> >
clone(
void)
const {
413 std::vector<ROL::Ptr<Vector<Real> > > clonevec;
414 for(
int i=0; i<
sampler_->numMySamples(); ++i ) {
417 return ROL::makePtr<DualSimulatedVector<Real>>(clonevec,
bman_,
sampler_);
426 for(
int i=0; i<
sampler_->numMySamples(); ++i ) {
436 ROL::Ptr<const Vector<Real> >
440 typedef ROL::Ptr<const Vector<Real> > Vp;
444 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+1), bman );
448 ROL::Ptr<Vector<Real> >
453 typedef ROL::Ptr<Vector<Real> > Vp;
457 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+2), bman );
461 ROL::Ptr<const Vector<Real> >
467 typedef ROL::Ptr<const Vector<Real> > Vp;
471 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+2), bman );
475 ROL::Ptr<Vector<Real> >
482 typedef ROL::Ptr<Vector<Real> > Vp;
486 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+3), bman );
490 ROL::Ptr<const Vector<Real> >
497 typedef ROL::Ptr<const Vector<Real> > Vp;
501 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+3), bman );
505 ROL::Ptr<Vector<Real> >
513 typedef ROL::Ptr<Vector<Real> > Vp;
516 Vp temp[] = {a,b,c,d};
517 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+4), bman );
521 ROL::Ptr<const Vector<Real> >
529 typedef ROL::Ptr<const Vector<Real> > Vp;
532 Vp temp[] = {a,b,c,d};
533 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+4), bman );
538 #endif // ROL_SIMULATED_VECTOR_H
PartitionedVector< Real > PV
ROL::Ptr< BatchManager< Real > > VBMp
typename PV< Real >::size_type size_type
PrimalSimulatedVector(const std::vector< ROL::Ptr< Vector< Real >>> &vecs, const ROL::Ptr< BatchManager< Real >> &bman, const ROL::Ptr< SampleGenerator< Real >> &sampler)
void set(const V &x)
Set where .
ROL::Ptr< Vector< Real > > clone(void) const
Clone to make a new (uninitialized) vector.
int dimension() const
Return dimension of the vector space.
const ROL::Ptr< SampleGenerator< Real > > sampler_
DualSimulatedVector(const std::vector< ROL::Ptr< Vector< Real > > > &vecs, const ROL::Ptr< BatchManager< Real > > &bman, const ROL::Ptr< SampleGenerator< Real > > &sampler)
virtual const V & dual(void) const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
std::vector< PV >::size_type size_type
ROL::Ptr< PV > dual_pvec_
virtual Vp clone() const
Clone to make a new (uninitialized) vector.
void setScalar(const Real C)
Set where .
void applyBinary(const Elementwise::BinaryFunction< Real > &f, const V &x)
ROL::Ptr< BatchManager< Real > > bman_
const ROL::Ptr< BatchManager< Real > > bman_
Defines the linear algebra or vector space interface.
const ROL::Ptr< BatchManager< Real > > bman_
SimulatedVector(const std::vector< Vp > &vecs, const VBMp &bman)
Defines the linear algebra of a vector space on a generic partitioned vector where the individual vec...
ROL::Ptr< const Vector< Real > > get(size_type i) const
ROL::Ptr< Vector< Real > > CreateSimulatedVector(const ROL::Ptr< Vector< Real >> &a, const ROL::Ptr< BatchManager< Real >> &bman)
void set(size_type i, const V &x)
size_type numVectors() const
const std::vector< ROL::Ptr< Vector< Real > > > vecs_
Real dot(const Vector< Real > &x) const
Compute where .
Vp basis(const int i) const
Return i-th basis vector.
std::vector< ROL::Ptr< Vector< Real > > > dual_vecs_
void zero()
Set to zero vector.
const ROL::Ptr< SampleGenerator< Real > > sampler_
void plus(const V &x)
Compute , where .
Real norm() const
Returns where .
const Vector< Real > & dual(void) const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
Real dot(const Vector< Real > &x) const
Compute where .
Real reduce(const Elementwise::ReductionOp< Real > &r) const
virtual Real dot(const V &x) const
Compute where .
SimulatedVector< Real > PV
void scale(const Real alpha)
Compute where .
const std::vector< Vp > vecs_
ROL::Ptr< Vector< Real > > clone(void) const
Clone to make a new (uninitialized) vector.
void axpy(const Real alpha, const V &x)
Compute where .
void applyUnary(const Elementwise::UnaryFunction< Real > &f)
std::vector< Vp > dual_vecs_
std::vector< ROL::Ptr< Vector< Real > > > primal_vecs_
ROL::Ptr< DualSimulatedVector< Real > > dual_pvec_
bool isPrimalInitialized_
void randomize(const Real l=0.0, const Real u=1.0)
Set vector to be uniform random between [l,u].
ROL::Ptr< PrimalSimulatedVector< Real > > primal_pvec_
const Vector< Real > & dual(void) const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
const std::vector< ROL::Ptr< Vector< Real > > > vecs_