libROM  v1.0
Data-driven physical simulation library
 All Classes Functions Variables Enumerations
Public Member Functions | List of all members
CAROM::Vector Class Reference

#include <Vector.h>

Public Member Functions

 Vector (int dim, bool distributed)
 Constructor creating a Vector with uninitialized values. More...
 
 Vector (double *vec, int dim, bool distributed, bool copy_data=true)
 Constructor in which the Vector is given its initial values. More...
 
 Vector (const Vector &other)
 Copy constructor. More...
 
 ~Vector ()
 Destructor.
 
Vectoroperator= (const Vector &rhs)
 Assignment operator. More...
 
Vectoroperator+= (const Vector &rhs)
 Addition operator. More...
 
Vectoroperator= (const double &a)
 Equal operator. More...
 
Vectortransform (std::function< void(const int size, double *vector)> transformer)
 Transform the vector using a supplied function. More...
 
void transform (Vector &result, std::function< void(const int size, double *vector)> transformer) const
 Transform a vector using a supplied function and store the results in another vector. More...
 
void transform (Vector *&result, std::function< void(const int size, double *vector)> transformer) const
 Transform a vector using a supplied function and store the results in another vector. More...
 
Vectortransform (std::function< void(const int size, double *origVector, double *resultVector)> transformer)
 Transform the vector using a supplied function. More...
 
void transform (Vector &result, std::function< void(const int size, double *origVector, double *resultVector)> transformer) const
 Transform a vector using a supplied function and store the results in another vector. More...
 
void transform (Vector *&result, std::function< void(const int size, double *origVector, double *resultVector)> transformer) const
 Transform a vector using a supplied function and store the results in another vector. More...
 
void setSize (int dim)
 Sets the length of the vector and reallocates storage if needed. All values are initialized to zero. More...
 
bool distributed () const
 Returns true if the Vector is distributed. More...
 
int dim () const
 Returns the dimension of the Vector on this processor. More...
 
double inner_product (const Vector &other) const
 Inner product, reference form. More...
 
double inner_product (const Vector *other) const
 Inner product, pointer version. More...
 
double norm () const
 Form the norm of this. More...
 
double norm2 () const
 Form the squared norm of this. More...
 
double normalize ()
 Normalizes the Vector and returns its norm. More...
 
Vectorplus (const Vector &other) const
 Adds other and this and returns the result, reference version. More...
 
Vectorplus (const Vector *other) const
 Adds other and this and returns the result, pointer version. More...
 
void plus (const Vector &other, Vector *&result) const
 Adds other and this and fills result with the answer. More...
 
void plus (const Vector &other, Vector &result) const
 Adds other and this and fills result with the answer. More...
 
VectorplusAx (double factor, const Vector &other)
 Adds factor*other and this and returns the result, reference version. More...
 
VectorplusAx (double factor, const Vector *other)
 Adds factor*other and this and returns the result, pointer version. More...
 
void plusAx (double factor, const Vector &other, Vector *&result) const
 Adds factor*other and this and fills result with the answer. More...
 
void plusAx (double factor, const Vector &other, Vector &result) const
 Adds factor*other and this and fills result with the answer. More...
 
void plusEqAx (double factor, const Vector &other)
 Adds factor*other to this, reference version. More...
 
void plusEqAx (double factor, const Vector *other)
 Adds factor*other to this, pointer version. More...
 
Vectorminus (const Vector &other) const
 Subtracts other and this and returns the result, reference version. More...
 
Vectorminus (const Vector *other) const
 Subtracts other and this and returns the result, pointer version. More...
 
void minus (const Vector &other, Vector *&result) const
 Subtracts other and this and fills result with the answer. More...
 
void minus (const Vector &other, Vector &result) const
 Subtracts other and this and fills result with the answer. More...
 
Vectormult (double factor) const
 Multiplies this by the supplied constant and returns the result. More...
 
void mult (double factor, Vector *&result) const
 Multiplies this by the supplied constant and fills result with the answer. More...
 
void mult (double factor, Vector &result) const
 Multiplies this by the supplied constant and fills result with the answer. More...
 
const double & item (int i) const
 Const Vector member access. More...
 
double & item (int i)
 Non-const Vector member access. More...
 
const double & operator() (int i) const
 Const Vector member access. More...
 
double & operator() (int i)
 Non-const Vector member access. More...
 
void print (const char *prefix)
 print Vector into (a) ascii file(s). More...
 
void write (const std::string &base_file_name)
 write Vector into (a) HDF file(s). More...
 
void read (const std::string &base_file_name)
 read Vector from (a) HDF file(s). More...
 
void local_read (const std::string &base_file_name, int rank)
 read read a single rank of a distributed Vector from (a) HDF file(s). More...
 
double * getData () const
 Get the vector data as a pointer.
 

Detailed Description

Class Vector is a simple vector class in which the dimensions may be distributed across multiple processes. This class supports only the basic operations that are needed by the SVD library.

Constructor & Destructor Documentation

CAROM::Vector::Vector ( int  dim,
bool  distributed 
)

Constructor creating a Vector with uninitialized values.

Precondition
dim > 0
Parameters
[in]dimWhen undistributed, the total dimension of the Vector. When distributed, the part of the total dimension of the Vector on this processor.
[in]distributedIf true the dimensions of the Vector are spread over all processors.
CAROM::Vector::Vector ( double *  vec,
int  dim,
bool  distributed,
bool  copy_data = true 
)

Constructor in which the Vector is given its initial values.

Precondition
vec != 0
dim > 0
Parameters
[in]vecThe initial values of the Vector.
[in]dimWhen undistributed, the total dimension of the Vector. When distributed, the part of the total dimension of the Vector on this processor.
[in]distributedIf true the dimensions of the Vector are spread over all processors.
[in]copy_dataIf true the vector allocates is own storage and copies the contents of vec into its own storage. Otherwise it uses vec as its storage.
CAROM::Vector::Vector ( const Vector other)

Copy constructor.

Parameters
[in]otherThe Vector to copy.

Member Function Documentation

int CAROM::Vector::dim ( ) const
inline

Returns the dimension of the Vector on this processor.

Returns
The part of the Vector's dimension on this processor.
bool CAROM::Vector::distributed ( ) const
inline

Returns true if the Vector is distributed.

Returns
True if the Vector is distributed.
double CAROM::Vector::inner_product ( const Vector other) const

Inner product, reference form.

For distributed Vectors this is a parallel operation.

Precondition
dim() == other.dim()
distributed() == other.distributed()
Parameters
[in]otherThe Vector to form the inner product with this.
Returns
The inner product of this and other.
double CAROM::Vector::inner_product ( const Vector other) const
inline

Inner product, pointer version.

For distributed Vectors this is a parallel operation.

Precondition
other != 0
dim() == other->dim()
distributed() == other->distributed()
Parameters
[in]otherThe Vector to form the inner product with this.
Returns
The inner product of this and other.
const double& CAROM::Vector::item ( int  i) const
inline

Const Vector member access.

Precondition
(0 <= i) && (i < dim())
Parameters
[in]iThe component of the Vector on this processor requested.
Returns
The requested component of the Vector on this processor.
double& CAROM::Vector::item ( int  i)
inline

Non-const Vector member access.

Allows constructs of the form vec[i] = val;

Precondition
(0 <= i) && (i < dim())
Parameters
[in]iThe component of the Vector on this processor requested.
Returns
The requested component of the Vector on this processor.
void CAROM::Vector::local_read ( const std::string &  base_file_name,
int  rank 
)

read read a single rank of a distributed Vector from (a) HDF file(s).

Parameters
[in]base_file_nameThe base part of the file name.
[in]rankThe rank to read from.
Vector* CAROM::Vector::minus ( const Vector other) const
inline

Subtracts other and this and returns the result, reference version.

Precondition
distributed() == other.distributed()
dim() == other.dim()
Parameters
[in]otherThe other subtrahand.
Returns
this - other
Vector* CAROM::Vector::minus ( const Vector other) const
inline

Subtracts other and this and returns the result, pointer version.

Precondition
other != 0
distributed() == other->distributed()
dim() == other->dim()
Parameters
[in]otherThe other subtrahand.
Returns
this - other
void CAROM::Vector::minus ( const Vector other,
Vector *&  result 
) const

Subtracts other and this and fills result with the answer.

Result will be allocated if unallocated or resized appropriately if already allocated.

Precondition
result == 0 || result->distributed() == distributed()
distributed() == other.distributed()
dim() == other.dim()
Parameters
[in]otherThe other subtrahend.
[out]resultthis - other
void CAROM::Vector::minus ( const Vector other,
Vector result 
) const

Subtracts other and this and fills result with the answer.

Result will be resized appropriately.

Precondition
result.distributed() == distributed()
distributed() == other.distributed()
dim() == other.dim()
Parameters
[in]otherThe other subtrahend.
[out]resultthis - other
Vector* CAROM::Vector::mult ( double  factor) const
inline

Multiplies this by the supplied constant and returns the result.

Parameters
[in]factorFactor to multiply by.
Returns
factor*this
void CAROM::Vector::mult ( double  factor,
Vector *&  result 
) const

Multiplies this by the supplied constant and fills result with the answer.

Precondition
result == 0 || result->distributed() == distributed()
Parameters
[in]factorFactor to multiply by.
[out]resultfactor*this
void CAROM::Vector::mult ( double  factor,
Vector result 
) const

Multiplies this by the supplied constant and fills result with the answer.

Precondition
result.distributed() == distributed()
Parameters
[in]factorFactor to multiply by.
[out]resultfactor*this
double CAROM::Vector::norm ( ) const

Form the norm of this.

For a distributed Vector this is a parallel operation.

Returns
The norm of this.
double CAROM::Vector::norm2 ( ) const

Form the squared norm of this.

For a distributed Vector this is a parallel operation.

Returns
The squared norm of this.
double CAROM::Vector::normalize ( )

Normalizes the Vector and returns its norm.

For a distributed Vector this is a parallel operation.

Returns
The norm of this.
const double& CAROM::Vector::operator() ( int  i) const
inline

Const Vector member access.

Precondition
(0 <= i) && (i < dim())
Parameters
[in]iThe component of the Vector on this processor requested.
Returns
The requested component of the Vector on this processor.
double& CAROM::Vector::operator() ( int  i)
inline

Non-const Vector member access.

Allows constructs of the form vec[i] = val;

Precondition
(0 <= i) && (i < dim())
Parameters
[in]iThe component of the Vector on this processor requested.
Returns
The requested component of the Vector on this processor.
Vector& CAROM::Vector::operator+= ( const Vector rhs)

Addition operator.

Parameters
[in]rhsThe Vector to add to this.
Returns
This after rhs has been added to it.
Vector& CAROM::Vector::operator= ( const Vector rhs)

Assignment operator.

Parameters
[in]rhsThe Vector to assign to this.
Returns
This after rhs has been assigned to it.
Vector& CAROM::Vector::operator= ( const double &  a)

Equal operator.

Parameters
[in]aThe double precision number to which every Vector entry should be set.
Returns
This with every element of the Vector set to a.
Vector* CAROM::Vector::plus ( const Vector other) const
inline

Adds other and this and returns the result, reference version.

Precondition
distributed() == other.distributed()
dim() == other.dim()
Parameters
[in]otherThe other summand.
Returns
this + other
Vector* CAROM::Vector::plus ( const Vector other) const
inline

Adds other and this and returns the result, pointer version.

Precondition
other != 0
distributed() == other->distributed()
dim() == other->dim()
Parameters
[in]otherThe other summand.
Returns
this + other
void CAROM::Vector::plus ( const Vector other,
Vector *&  result 
) const

Adds other and this and fills result with the answer.

Result will be allocated if unallocated or resized appropriately if already allocated.

Precondition
result == 0 || result->distributed() == distributed()
distributed() == other.distributed()
dim() == other.dim()
Parameters
[in]otherThe other summand.
[out]resultthis + other
void CAROM::Vector::plus ( const Vector other,
Vector result 
) const

Adds other and this and fills result with the answer.

Result will be resized appropriately.

Precondition
result.distributed() == distributed()
distributed() == other.distributed()
dim() == other.dim()
Parameters
[in]otherThe other summand.
[out]resultthis + other
Vector* CAROM::Vector::plusAx ( double  factor,
const Vector other 
)
inline

Adds factor*other and this and returns the result, reference version.

Precondition
distributed() == other.distributed()
dim() == other.dim()
Parameters
[in]factorMultiplicative factor applied to other.
[in]otherThe other summand.
Returns
this + factor*other
Vector* CAROM::Vector::plusAx ( double  factor,
const Vector other 
)
inline

Adds factor*other and this and returns the result, pointer version.

Precondition
distributed() == other->distributed()
dim() == other->dim()
Parameters
[in]factorMultiplicative factor applied to other.
[in]otherThe other summand.
Returns
this + factor*other
void CAROM::Vector::plusAx ( double  factor,
const Vector other,
Vector *&  result 
) const

Adds factor*other and this and fills result with the answer.

Result will be allocated if unallocated or resized appropriately if already allocated.

Precondition
result == 0 || result->distributed() == distributed()
distributed() == other.distributed()
dim() == other.dim()
Parameters
[in]factorMultiplicative factor applied to other.
[in]otherThe other summand.
[out]resultthis + factor*other
void CAROM::Vector::plusAx ( double  factor,
const Vector other,
Vector result 
) const

Adds factor*other and this and fills result with the answer.

Result will be resized appropriately.

Precondition
result.distributed() == distributed()
distributed() == other.distributed()
dim() == other.dim()
Parameters
[in]factorMultiplicative factor applied to other.
[in]otherThe other summand.
[out]resultthis + factor*other
void CAROM::Vector::plusEqAx ( double  factor,
const Vector other 
)

Adds factor*other to this, reference version.

Precondition
distributed() == other.distributed()
dim() == other.dim()
Parameters
[in]factorMultiplicative factor applied to other.
[in]otherThe other summand.
void CAROM::Vector::plusEqAx ( double  factor,
const Vector other 
)
inline

Adds factor*other to this, pointer version.

Precondition
other != 0
distributed() == other->distributed()
dim() == other->dim()
Parameters
[in]factorMultiplicative factor applied to other.
[in]otherThe other summand.
void CAROM::Vector::print ( const char *  prefix)

print Vector into (a) ascii file(s).

Parameters
[in]prefixThe name of the prefix of the file name.
void CAROM::Vector::read ( const std::string &  base_file_name)

read Vector from (a) HDF file(s).

Parameters
[in]base_file_nameThe base part of the file name.
void CAROM::Vector::setSize ( int  dim)
inline

Sets the length of the vector and reallocates storage if needed. All values are initialized to zero.

Parameters
[in]dimWhen undistributed, the total dimension of the Vector. When distributed, the part of the total dimension of the Vector on this processor.
Vector& CAROM::Vector::transform ( std::function< void(const int size, double *vector)>  transformer)

Transform the vector using a supplied function.

Parameters
[in]transformerA transformer function which takes in as input a size and a vector.
Returns
The newly transformed vector.
void CAROM::Vector::transform ( Vector result,
std::function< void(const int size, double *vector)>  transformer 
) const

Transform a vector using a supplied function and store the results in another vector.

Parameters
[out]resultA vector which will store the transformed result.
[in]transformerA transformer function which takes in as input a size and transforms the vector.
void CAROM::Vector::transform ( Vector *&  result,
std::function< void(const int size, double *vector)>  transformer 
) const

Transform a vector using a supplied function and store the results in another vector.

Parameters
[out]resultA vector which will store the transformed result.
[in]transformerA transformer function which takes in as input a size and transforms the vector.
Vector& CAROM::Vector::transform ( std::function< void(const int size, double *origVector, double *resultVector)>  transformer)

Transform the vector using a supplied function.

Parameters
[in]transformerA transformer function which takes in as input a size and transforms the origVector and stores the result in resultVector.
Returns
The newly transformed vector.
void CAROM::Vector::transform ( Vector result,
std::function< void(const int size, double *origVector, double *resultVector)>  transformer 
) const

Transform a vector using a supplied function and store the results in another vector.

Parameters
[out]resultA vector which will store the transformed result.
[in]transformerA transformer function which takes in as input a size and transforms the origVector and stores the result in resultVector.
void CAROM::Vector::transform ( Vector *&  result,
std::function< void(const int size, double *origVector, double *resultVector)>  transformer 
) const

Transform a vector using a supplied function and store the results in another vector.

Parameters
[out]resultA vector which will store the transformed result.
[in]transformerA transformer function which takes in as input a size and transforms the origVector and stores the result in resultVector.
void CAROM::Vector::write ( const std::string &  base_file_name)

write Vector into (a) HDF file(s).

Parameters
[in]base_file_nameThe base part of the file name.

The documentation for this class was generated from the following file: