13 #ifndef ROL_SIMULATED_VECTOR_H
14 #define ROL_SIMULATED_VECTOR_H
37 typedef ROL::Ptr<V>
Vp;
38 typedef ROL::Ptr<BatchManager<Real> >
VBMp;
43 ROL::Ptr<BatchManager<Real> >
bman_;
58 const PV &xs =
dynamic_cast<const PV&
>(x);
61 std::invalid_argument,
62 "Error: Vectors must have the same number of subvectors." );
71 const PV &xs =
dynamic_cast<const PV&
>(x);
74 std::invalid_argument,
75 "Error: Vectors must have the same number of subvectors." );
82 void scale(
const Real alpha ) {
84 vecs_[i]->scale(alpha);
88 void axpy(
const Real alpha,
const V &x ) {
90 const PV &xs =
dynamic_cast<const PV&
>(x);
93 std::invalid_argument,
94 "Error: Vectors must have the same number of subvectors." );
101 virtual Real
dot(
const V &x )
const {
103 const PV &xs =
dynamic_cast<const PV&
>(x);
106 std::invalid_argument,
107 "Error: Vectors must have the same number of subvectors." );
112 locresult +=
vecs_[i]->dot(*xs.
get(i));
115 bman_->sumAll(&locresult, &result, 1);
121 return std::sqrt(
dot(*
this));
128 std::vector<Vp> clonevec;
132 return ROL::makePtr<PV>(clonevec,
bman_);
147 ROL_TEST_FOR_EXCEPTION( i >=
dimension() || i<0,
148 std::invalid_argument,
149 "Error: Basis index must be between 0 and vector dimension." );
153 PV &eb =
dynamic_cast<PV&
>(*bvec);
161 end +=
vecs_[j]->dimension();
163 if( begin<= i && i<end ) {
179 total_dim +=
vecs_[j]->dimension();
191 void applyUnary(
const Elementwise::UnaryFunction<Real> &f ) {
193 vecs_[i]->applyUnary(f);
198 void applyBinary(
const Elementwise::BinaryFunction<Real> &f,
const V &x ) {
199 const PV &xs =
dynamic_cast<const PV&
>(x);
202 vecs_[i]->applyBinary(f,*xs.
get(i));
206 Real
reduce(
const Elementwise::ReductionOp<Real> &r )
const {
207 Real result = r.initialValue();
217 vecs_[i]->setScalar(C);
223 vecs_[i]->randomize(l,u);
255 ROL::Ptr<Vector<Real> >
259 typedef ROL::Ptr<Vector<Real> > Vp;
263 return ROL::makePtr<PV>(std::vector<Vp>(temp, temp+1), bman );
267 class PrimalSimulatedVector :
public SimulatedVector<Real> {
269 const std::vector<ROL::Ptr<Vector<Real>>>
vecs_;
270 const ROL::Ptr<BatchManager<Real>>
bman_;
282 for(
int i=0; i<
sampler_->numMySamples(); ++i ) {
291 ROL_TEST_FOR_EXCEPTION(
sampler_->numMySamples() !=
static_cast<int>(xs.
numVectors()),
292 std::invalid_argument,
293 "Error: Vectors must have the same number of subvectors." );
298 for(
int i=0; i<
sampler_->numMySamples(); ++i ) {
301 Real t = locresult + y;
302 c = (t - locresult) - y;
306 bman_->sumAll(&locresult, &result, 1);
311 ROL::Ptr<Vector<Real> >
clone(
void)
const {
312 std::vector<ROL::Ptr<Vector<Real> > > clonevec;
313 for(
int i=0; i<
sampler_->numMySamples(); ++i ) {
316 return ROL::makePtr<PrimalSimulatedVector<Real>>(clonevec,
bman_,
sampler_);
324 for(
int i=0; i<
sampler_->numMySamples(); ++i ) {
334 class DualSimulatedVector :
public SimulatedVector<Real> {
336 const std::vector<ROL::Ptr<Vector<Real> > >
vecs_;
337 const ROL::Ptr<BatchManager<Real> >
bman_;
349 for(
int i=0; i<
sampler_->numMySamples(); ++i ) {
358 ROL_TEST_FOR_EXCEPTION(
sampler_->numMySamples() !=
static_cast<Real
>(xs.
numVectors()),
359 std::invalid_argument,
360 "Error: Vectors must have the same number of subvectors." );
365 for(
int i=0; i<
sampler_->numMySamples(); ++i ) {
368 Real t = locresult + y;
369 c = (t - locresult) - y;
373 bman_->sumAll(&locresult, &result, 1);
378 ROL::Ptr<Vector<Real> >
clone(
void)
const {
379 std::vector<ROL::Ptr<Vector<Real> > > clonevec;
380 for(
int i=0; i<
sampler_->numMySamples(); ++i ) {
383 return ROL::makePtr<DualSimulatedVector<Real>>(clonevec,
bman_,
sampler_);
392 for(
int i=0; i<
sampler_->numMySamples(); ++i ) {
402 ROL::Ptr<const Vector<Real> >
406 typedef ROL::Ptr<const Vector<Real> > Vp;
410 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+1), bman );
414 ROL::Ptr<Vector<Real> >
419 typedef ROL::Ptr<Vector<Real> > Vp;
423 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+2), bman );
427 ROL::Ptr<const Vector<Real> >
433 typedef ROL::Ptr<const Vector<Real> > Vp;
437 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+2), bman );
441 ROL::Ptr<Vector<Real> >
448 typedef ROL::Ptr<Vector<Real> > Vp;
452 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+3), bman );
456 ROL::Ptr<const Vector<Real> >
463 typedef ROL::Ptr<const Vector<Real> > Vp;
467 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+3), bman );
471 ROL::Ptr<Vector<Real> >
479 typedef ROL::Ptr<Vector<Real> > Vp;
482 Vp temp[] = {a,b,c,d};
483 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+4), bman );
487 ROL::Ptr<const Vector<Real> >
495 typedef ROL::Ptr<const Vector<Real> > Vp;
498 Vp temp[] = {a,b,c,d};
499 return ROL::makePtr<PV>( std::vector<Vp>(temp, temp+4), bman );
504 #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_