xc
Public Types | Public Member Functions | Friends | List of all members
XC::Vector Class Reference

Float vector abstraction. More...

#include <Vector.h>

Inheritance diagram for XC::Vector:
Inheritance graph
[legend]
Collaboration diagram for XC::Vector:
Collaboration graph
[legend]

Public Types

typedef double * iterator
 
- Public Types inherited from EntityWithProperties
typedef std::map< std::string, boost::python::object > PythonDict
 

Public Member Functions

 Vector (void)
 Default constructor, sets size= 0;.
 
 Vector (const int &, const double &value=0.0)
 Constructor used to allocate a vector of size szt. More...
 
 Vector (const std::vector< double > &v)
 Copy from a std::vector.
 
 Vector (const Vector2d &v)
 Copy from Vector2d.
 
 Vector (const Vector3d &v)
 Copy from Vector2d.
 
 Vector (const double &, const double &, const double &)
 Create from x,y,z coordinates.
 
 Vector (const Vector &)
 Copy constructor.
 
 Vector (double *data, int size)
 Constructor. More...
 
 Vector (const boost::python::list &)
 Constructor (Python interface).
 
virtual ~Vector (void)
 Destructor, free memory.
 
iterator begin (void)
 Iterator that points to the first vector component.
 
iterator end (void)
 Iterator that points one past the last vector component.
 
int setData (double *newData, int size)
 Help to construct a Vector of order size whose data will be stored in the array pointed to by data. More...
 
const double * getDataPtr (void) const
 Return a pointer to the float date.
 
double * getDataPtr (void)
 Return a pointer to the float date.
 
bool isEmpty (void) const
 Return true if the vector has no data.
 
int Assemble (const Vector &V, const ID &l, double fact=1.0)
 Method to assemble into this vector the Vector V using the ID l. More...
 
double Norm2 (void) const
 Returns the square of the vector modulus. More...
 
double Norm (void) const
 Return the norm of vector. More...
 
double pNorm (int p) const
 
double NormInf (void) const
 Returns the maximum of the absolute values of the components (infinite norm). More...
 
int Size (void) const
 Returns the size of the Vector.
 
int getNumBytes (void) const
 Number of bytes occupied by the vector.
 
int resize (int newSize)
 Changes vector size.
 
void Zero (void)
 Zeros out the Vector, i.e. More...
 
bool isnan (void) const
 Return true if one of the component is not a number.
 
int reset (const int &newSize)
 Resize the vector and set all components equal to 0.
 
int Normalize (void)
 Normalizes the vector using the euclidean norm.
 
int NormalizeInf (void)
 Normalize the vector using the infinity norm.
 
Vector Normalized (void) const
 Returns the normalized vector (euclidean norm).
 
Vector NormalizedInf (void) const
 Returns the normalized vector (infinity norm).
 
int addVector (double factThis, const Vector &other, double factOther)
 To add a factor fact times the Vector other to the current Vector. More...
 
int addMatrixVector (double factThis, const Matrix &m, const Vector &v, double factOther)
 To add a factor fact times the Vector formed by the product of the matrix m and the Vector v to the current Vector. More...
 
int addMatrixTransposeVector (double factThis, const Matrix &m, const Vector &v, double factOther)
 
virtual double & at (const size_t &f)
 Returns the element at the row being passed as parameter. More...
 
virtual const double & at (const size_t &f) const
 Returns the element at the row being passed as parameter. More...
 
virtual bool CheckIndice0 (const size_t &i) const
 Check the index being passed as parameter. More...
 
const double & operator() (int x) const
 Returns the data at location x in the Vector. More...
 
double & operator() (int x)
 Used to set the data at location(x) in the Vector. More...
 
const double & operator[] (int x) const
 If debug flag is on, safely get the data at location x in the Vector. More...
 
double & operator[] (int x)
 If debug flag is on, safely set/get the data at location x in the Vector. More...
 
Vector operator() (const ID &rows) const
 Method to return a vector whose components are the components of the current vector located in positions given by the ID rows. More...
 
Vectoroperator= (const Vector &V)
 the assignment operator, This is assigned to be a copy of V. More...
 
template<class TNSR >
Vectoroperator= (const TNSR &T)
 
Vectoroperator+= (double fact)
 The += operator adds fact to each element of the vector, data[i]= data[i]+fact. More...
 
Vectoroperator-= (double fact)
 The -= operator subtracts fact from each element of the vector, data[i]= data[i]-fact. More...
 
Vectoroperator*= (double fact)
 The *= operator multiplies each element by the factor.
 
Vectoroperator/= (double fact)
 The /= operator divides each element of the vector by fact, theData[i]= theData[i]/fact. More...
 
Vector operator- (void) const
 Unary minus operator.
 
Vector operator+ (double fact) const
 The + operator returns a Vector of the same size as current, whose components are: return(i)= theData[i]+fact. More...
 
Vector operator- (double fact) const
 The + operator returns a Vector of the same size as current, whose components are: return(i)= theData[i]-fact. More...
 
Vector operator* (double fact) const
 The + operator returns a vector of the same size as current, whose components are: return(i)= theData[i]*fact. More...
 
Vector operator/ (double fact) const
 The + operator returns a vector of the same size as current, whose components are return(i)= theData[i]/fact. More...
 
Vectoroperator+= (const Vector &V)
 The += operator adds V's data to data, data[i]+=V(i). More...
 
Vectoroperator-= (const Vector &V)
 The -= operator subtracts V's data from data, data[i]-=V(i). More...
 
Vector operator+ (const Vector &V) const
 The + operator checks the two vectors are of the same size if _G3DEBUG is defined. More...
 
Vector operator- (const Vector &V) const
 The - operator checks the two vectors are of the same size if _G3DEBUG is defined and then returns a Vector whose components are the vector difference of current and V's data. More...
 
double operator^ (const Vector &V) const
 Method to perform (Vector)transposed * vector. More...
 
Vector operator/ (const Matrix &M) const
 Method to return inv(M)*this. More...
 
double dot (const Vector &) const
 
int Assemble (const Vector &V, int init_row, double fact=1.0)
 
int Extract (const Vector &V, int init_row, double fact=1.0)
 
Vector getComponents (const ID &) const
 Returns a vector with the specified subset of components.
 
void putComponents (const Vector &, const ID &)
 Assigns the specified values to the specified set of vector's components.
 
void addComponents (const Vector &, const ID &)
 Sums the specified values to the specified set of vector's components.
 
void write (std::ofstream &)
 Write vector on a binary file.
 
void read (std::ifstream &)
 Read vector from a binary file.
 
std::string toString (void) const
 
boost::python::list getPyList (void) const
 Return the vector values in a Python list.
 
- Public Member Functions inherited from CommandEntity
 CommandEntity (CommandEntity *owr=nullptr)
 Default constructor.
 
CommandEntityOwner (void)
 Return a pointer to the object owner.
 
const CommandEntityOwner (void) const
 Return un puntero al objeto propietario de ESTE.
 
const StandardOutputWrappergetStandardOutputWrapper (void) const
 Return the regular output stream wrapper.
 
StandardOutputWrappergetStandardOutputWrapper (void)
 Return the regular output stream wrapper.
 
const std::string & getLogFileName (void) const
 Returns log file name.
 
void setLogFileName (const std::string &)
 Sets log file name.
 
const std::string & getErrFileName (void) const
 Returns err file name.
 
void setErrFileName (const std::string &)
 Sets error file name.
 
const std::string & getOutputFileName (void) const
 Returns regular output file name.
 
void setOutputFileName (const std::string &)
 Sets regular output file name.
 
boost::python::object evalPy (boost::python::object dict, const std::string &)
 Return the Python object that results from evaluating the argument.
 
boost::python::object execPy (boost::python::object dict, const std::string &)
 Return the Python objects that results from executing the code in the string argument.
 
boost::python::object execFilePy (boost::python::object dict, const std::string &)
 Return the Python object that results from executing the code in the file.
 
- Public Member Functions inherited from EntityWithProperties
 EntityWithProperties (EntityWithProperties *owr=nullptr)
 Default constructor.
 
virtual bool operator== (const EntityWithProperties &) const
 Comparison operator.
 
void clearPyProps (void)
 Clear python properties map.
 
bool hasPyProp (const std::string &)
 Returns true if property exists.
 
boost::python::object getPyProp (const std::string &str)
 Return the Python object with the name being passed as parameter.
 
void setPyProp (std::string str, boost::python::object val)
 Sets/appends a value tho the Python object's dictionary.
 
void copyPropsFrom (const EntityWithProperties &)
 Copy the properties from the argument.
 
boost::python::list getPropNames (void) const
 Return the names of the object properties weightings.
 
const PythonDict & getPropertiesDict (void) const
 Return a std::map container with the properties of the object.
 
boost::python::dict getPyDict (void) const
 Return a Python dictionary containing the object members values.
 
void setPyDict (const boost::python::dict &)
 Set the values of the object members from a Python dictionary.
 
- Public Member Functions inherited from EntityWithOwner
 EntityWithOwner (EntityWithOwner *owr=nullptr)
 Default constructor.
 
 EntityWithOwner (const EntityWithOwner &)
 Copy constructor.
 
EntityWithOwneroperator= (const EntityWithOwner &)
 Assignment operator.
 
virtual bool operator== (const EntityWithOwner &) const
 Comparison operator.
 
virtual ~EntityWithOwner (void)
 Virtual destructor.
 
virtual std::string getClassName (void) const
 Returns demangled class name.
 
void set_owner (EntityWithOwner *owr)
 Assigns the owner of the object.
 
EntityWithOwnerOwner (void)
 
const EntityWithOwnerOwner (void) const
 

Friends

class Message
 
class SystemOfEqn
 
class Matrix
 
class TCP_SocketNoDelay
 
class TCP_Socket
 
class UDP_Socket
 
class MPI_Channel
 
std::ostream & operator<< (std::ostream &, const Vector &)
 
std::string to_string (const Vector &)
 
Vector operator* (double, const Vector &)
 

Additional Inherited Members

- Static Public Member Functions inherited from CommandEntity
static void resetStandardOutput (void)
 Reset the standard output streams to its defaults buffers.
 
- Static Public Member Functions inherited from EntityWithOwner
static int getVerbosityLevel (void)
 Get the value of the verbosity level.
 
static void setVerbosityLevel (const int &)
 Set the value of the verbosity level.
 
- Protected Member Functions inherited from CommandEntity
template<class T >
void string_to (T &, const std::string &) const
 
- Static Protected Member Functions inherited from CommandEntity
static CommandEntityentcmd_cast (boost::any &data)
 
- Static Protected Attributes inherited from EntityWithOwner
static int verbosity = 1
 Object that owns THIS ONE. More...
 

Detailed Description

Float vector abstraction.

The Vector class provides the vector abstraction. A vector of order size is an ordered 1d array of size numbers. For example a vector of order 5:

\( x = [x_0\) \(x_1\) \(x_2\) \(x_3\) \(x_4]\)

In the Vector class the data is stored in a 1d double array of length equal to the order of the Vector. At present time none of the methods are declared as being virtual. THIS MAY CHANGE FOR PARALLEL.

Constructor & Destructor Documentation

◆ Vector() [1/2]

XC::Vector::Vector ( const int &  szt,
const double &  value = 0.0 
)
explicit

Constructor used to allocate a vector of size szt.

To construct a Vector of order size. The constructor creates an array to store the data and zeroes this array. If not enough memory is available a warning message is printed and a Vector of order \(0\) is returned. The Zero() method is invoked on the new Vector before it is returned.

◆ Vector() [2/2]

XC::Vector::Vector ( double *  data,
int  size 
)

Constructor.

To construct a Vector of order size whose data will be stored in the array pointed to by data. See setData method.

Member Function Documentation

◆ addMatrixVector()

int XC::Vector::addMatrixVector ( double  thisFact,
const Matrix m,
const Vector v,
double  otherFact 
)

To add a factor fact times the Vector formed by the product of the matrix m and the Vector v to the current Vector.

To add a factor fact times the Vector formed by the product of the matrix m and the Vector v to the current Vector. No temporary Vector is created. Returns \(0\) if successful. Prints a warning message and returns \(-1\) if sizes are incompatible. Checks are made to see if the number of operations can be reduced if fact is \(0\) or \(1\).

◆ addVector()

int XC::Vector::addVector ( double  thisFact,
const Vector other,
double  otherFact 
)

To add a factor fact times the Vector other to the current Vector.

To add a factor fact times the Vector other to the current Vector. Returns \(0\) if successful. An error message is printed and \(-1\) is returned if Vectors are not of the same size. Checks are made to see if the number of operations can be reduced if fact is \(0\) or \(1\).

◆ Assemble()

int XC::Vector::Assemble ( const Vector V,
const ID l,
double  fact = 1.0 
)

Method to assemble into this vector the Vector V using the ID l.

Assembles into the current Vector the Vector V. The contents of the current Vector at location ({loc(i)}) is set equal to the current value plus fact times the value of the Vector V at location (i). returns \(0\) if successful. A warning message is printed for each invalid location in the current Vector or V and a \(-1\) is returned.

◆ at() [1/2]

double & XC::Vector::at ( const size_t &  f)
virtual

Returns the element at the row being passed as parameter.

Returns the number at the row being passed as parameter.

◆ at() [2/2]

const double & XC::Vector::at ( const size_t &  f) const
virtual

Returns the element at the row being passed as parameter.

Returns the number at the row being passed as parameter.

◆ CheckIndice0()

bool XC::Vector::CheckIndice0 ( const size_t &  i) const
virtual

Check the index being passed as parameter.

Checks the renge for the index being passed as parameter.

◆ Norm()

double XC::Vector::Norm ( void  ) const

Return the norm of vector.

Return the 2 norm of the Vector. Returns the sqrt() of the result of Norm2.

◆ Norm2()

double XC::Vector::Norm2 ( void  ) const

Returns the square of the vector modulus.

Return the result of invoking the \(\hat{ }\) operator on the current Vector with the current Vector as the argument.

◆ NormInf()

double XC::Vector::NormInf ( void  ) const

Returns the maximum of the absolute values of the components (infinite norm).

◆ operator()() [1/3]

const double & XC::Vector::operator() ( int  x) const
inline

Returns the data at location x in the Vector.

Assumes (x) is a valid location in the Vector, i.e. \(0 <= x \) order, a segmentation fault or erroneous results can occur if this is not the case.

◆ operator()() [2/3]

double & XC::Vector::operator() ( int  x)
inline

Used to set the data at location(x) in the Vector.

Assumes (x) is a valid location in the Vector, i.e. \(0 <= x < \) order, a segmentation fault or erroneous results can occur if this is not the case.

◆ operator()() [3/3]

XC::Vector XC::Vector::operator() ( const ID rows) const

Method to return a vector whose components are the components of the current vector located in positions given by the ID rows.

Returns a Vector of order loc.Size(). The contents of the new Vector are given by the contents of the current Vector at the locations given by the loc. For example the contents of the new Vector at location \(i\) are equal to the contents of the current Vector at location {loc(i)}. Creates a new Vector, copies the data from the current Vector and returns the new Vector. For each invalid location specified in loc for the current Vector, a warning message is printed.

◆ operator*()

XC::Vector XC::Vector::operator* ( double  fact) const

The + operator returns a vector of the same size as current, whose components are: return(i)= theData[i]*fact.

◆ operator+() [1/2]

XC::Vector XC::Vector::operator+ ( double  fact) const

The + operator returns a Vector of the same size as current, whose components are: return(i)= theData[i]+fact.

◆ operator+() [2/2]

XC::Vector XC::Vector::operator+ ( const Vector b) const

The + operator checks the two vectors are of the same size if _G3DEBUG is defined.

Then returns a Vector whose components are the vector sum of current and V's data.

◆ operator+=() [1/2]

XC::Vector & XC::Vector::operator+= ( double  fact)

The += operator adds fact to each element of the vector, data[i]= data[i]+fact.

◆ operator+=() [2/2]

XC::Vector & XC::Vector::operator+= ( const Vector other)

The += operator adds V's data to data, data[i]+=V(i).

A check to see if vectors are of same size is performed if _G3DEBUG is defined.

◆ operator-() [1/2]

XC::Vector XC::Vector::operator- ( double  fact) const

The + operator returns a Vector of the same size as current, whose components are: return(i)= theData[i]-fact.

◆ operator-() [2/2]

XC::Vector XC::Vector::operator- ( const Vector b) const

The - operator checks the two vectors are of the same size if _G3DEBUG is defined and then returns a Vector whose components are the vector difference of current and V's data.

◆ operator-=() [1/2]

XC::Vector & XC::Vector::operator-= ( double  fact)

The -= operator subtracts fact from each element of the vector, data[i]= data[i]-fact.

◆ operator-=() [2/2]

XC::Vector & XC::Vector::operator-= ( const Vector other)

The -= operator subtracts V's data from data, data[i]-=V(i).

A check to see if vectors are of same size is performed if _G3DEBUG is defined.

◆ operator/() [1/2]

XC::Vector XC::Vector::operator/ ( double  fact) const

The + operator returns a vector of the same size as current, whose components are return(i)= theData[i]/fact.

Calls /= operator over the new vector.

◆ operator/() [2/2]

XC::Vector XC::Vector::operator/ ( const Matrix M) const

Method to return inv(M)*this.

A method to return a new Vector, \(x\), equal to the solution of the matrix equation \(Mx=\) the current Vector. A new Vector is created for the return of size M.noRows(). A new Matrix is created of order M.noRows()} x {M.noRows() and set equal to M if {M} is square, or \(M^tM\) if M is not square. The new Vector is then set equal to the result of invoking {Solve(*this)} on the new Matrix.

◆ operator/=()

XC::Vector & XC::Vector::operator/= ( double  fact)

The /= operator divides each element of the vector by fact, theData[i]= theData[i]/fact.

If divide-by-zero would occur it puts a very large value on each component.

◆ operator=()

XC::Vector & XC::Vector::operator= ( const Vector V)

the assignment operator, This is assigned to be a copy of V.

if sizes are not compatible this.theData [] is deleted. The data pointers will not point to the same area in mem after the assignment.

◆ operator[]() [1/2]

const double & XC::Vector::operator[] ( int  x) const

If debug flag is on, safely get the data at location x in the Vector.

Checks to ensure x is a valid location, i.e. \(0 <= x \) order. If x is not a valid location a warning message is printed and VECTOR_NOT_VALID_ENTRY (a static class variable) is returned.

◆ operator[]() [2/2]

double & XC::Vector::operator[] ( int  x)

If debug flag is on, safely set/get the data at location x in the Vector.

Checks to ensure x is a valid location, i.e. \(0 <= x \) order. If x is not a valid location a warning message is printed and VECTOR_NOT_VALID_ENTRY (a static class variable) is returned.

◆ operator^()

double XC::Vector::operator^ ( const Vector V) const

Method to perform (Vector)transposed * vector.

A method to return the dot product of the current Vector and the Vector V. If the current Vector and V are not of the same size, a warning message is printed and \(0\) returned.

◆ setData()

int XC::Vector::setData ( double *  newData,
int  size 
)

Help to construct a Vector of order size whose data will be stored in the array pointed to by data.

The array pointed to by data is not set to zero by the constructor. Note that delete will not be called on this array in the destructor. It is up to the user to ensure that the array pointed to by data is at least as large as size, if this is not the case erroneous results or a segmentation fault may occur.

◆ Zero()

void XC::Vector::Zero ( void  )
inline

Zeros out the Vector, i.e.

sets all the components of the Vector to \(0\).


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