Logo  0.95.0-final
Finite Element Embedded Library and Language in C++
Feel++ Feel++ on Github Feel++ community
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Feel::Vector< T > Class Template Referenceabstract

#include <vector.hpp>

Detailed Description

template<typename T>
class Feel::Vector< T >

Numeric vector. Provides a uniform interface to vector storage schemes for different linear algebra libraries.

Author
Benjamin S. Kirk, 2003
Christophe Prud'homme 2005
+ Inheritance diagram for Feel::Vector< T >:

Public Types

typedef boost::shared_ptr
< Vector< T > > 
clone_ptrtype
 
typedef boost::shared_ptr
< datamap_type
datamap_ptrtype
 
typedef DataMap datamap_type
 
typedef type_traits< T >::real_type real_type
 
typedef boost::shared_ptr
< Vector< T > > 
self_ptrtype
 
typedef Vector< T > self_type
 
typedef T value_type
 

Public Member Functions

virtual void add (const size_type i, const value_type &value)=0
 
virtual void add (const value_type &s)=0
 
virtual void add (const Vector< value_type > &V)=0
 
virtual void add (const value_type &a, const Vector< value_type > &v)=0
 
void add (const value_type &a, const boost::shared_ptr< Vector< value_type > > &v)
 
virtual void addVector (int *i, int n, value_type *v)=0
 
virtual void addVector (const std::vector< T > &v, const std::vector< size_type > &dof_indices)=0
 
virtual void addVector (const Vector< T > &V, const std::vector< size_type > &dof_indices)=0
 
virtual void addVector (const Vector< T > &V_in, const MatrixSparse< T > &A_in)=0
 
void addVector (const boost::shared_ptr< Vector< T > > &V_in, const boost::shared_ptr< MatrixSparse< T > > &A_in)
 
void addVector (const Vector< T > &V_in, const MatrixShell< T > &A_in)
 
void addVector (const boost::shared_ptr< Vector< T > > &V_in, const boost::shared_ptr< MatrixShell< T > > &A_in)
 
virtual void clear ()
 
virtual clone_ptrtype clone () const =0
 
virtual void close ()=0
 
virtual bool closed () const
 
WorldComm const & comm () const
 
template<>
int compare (const Vector< float > &other_vector, const real_type threshold) const
 
template<>
int compare (const Vector< double > &other_vector, const real_type threshold) const
 
virtual int compare (const Vector< T > &other_vector, const real_type threshold=1e-10) const
 
virtual void createSubvector (Vector< T > &, const std::vector< size_type > &) const
 
virtual value_type dot (Vector< T > const &v)=0
 
virtual value_type dot (boost::shared_ptr< Vector< T > > const &v)
 
virtual size_type firstLocalIndex () const
 
virtual void init (const size_type, const size_type, const bool=false)
 
virtual void init (const size_type, const bool=false)
 
void init (datamap_ptrtype const &dm)
 
virtual void insert (const std::vector< T > &v, const std::vector< size_type > &dof_indices)=0
 
virtual void insert (const Vector< T > &V, const std::vector< size_type > &dof_indices)=0
 
virtual void insert (const ublas::vector< T > &V, const std::vector< size_type > &dof_indices)=0
 
virtual bool isInitialized () const
 
virtual real_type l1Norm () const =0
 
virtual real_type l2Norm () const =0
 
virtual size_type lastLocalIndex () const
 
virtual real_type linftyNorm () const =0
 
virtual bool localIndexIsGhost (size_type localDof) const
 
void localize (const Vector< T > &V)
 
virtual size_type localSize () const
 
datamap_type const & map () const
 
datamap_ptrtype const & mapPtr () const
 
virtual real_type max () const =0
 
virtual real_type min () const =0
 
virtual T operator() (const size_type i) const =0
 
virtual Vector< T > & operator+= (const Vector< value_type > &V)=0
 
virtual Vector< T > & operator-= (const Vector< value_type > &V)=0
 
Vector< T > & operator= (const T s)
 
virtual Vector< T > & operator= (const Vector< T > &V)
 
Vector< T > & operator= (const std::vector< T > &v)
 
virtual void print (std::ostream &os=std::cout) const
 
virtual void printMatlab (const std::string name="NULL", bool renumber=false) const
 
virtual void scale (const T factor)=0
 
virtual void set (const size_type i, const value_type &value)=0
 
virtual void setConstant (value_type v)=0
 
void setMap (datamap_ptrtype const &d)
 
virtual void setOnes ()
 
virtual void setZero ()
 
virtual size_type size () const
 
virtual value_type sum () const =0
 
 Vector ()
 
 Vector (datamap_ptrtype const &n)
 
 Vector (const size_type n, WorldComm const &_worldComm=Environment::worldComm())
 
 Vector (const size_type n, const size_type n_local, WorldComm const &_worldComm=Environment::worldComm())
 
 Vector (Vector const &v)
 
virtual void zero ()=0
 
virtual void zero (size_type, size_type)=0
 
virtual ~Vector ()
 

Protected Attributes

bool M_is_closed
 
bool M_is_initialized
 
datamap_ptrtype M_map
 

Friends

std::ostream & operator<< (std::ostream &os, const Vector< T > &v)
 

Constructor & Destructor Documentation

template<typename T >
Feel::Vector< T >::Vector ( )

Dummy-Constructor. Dimension=0

template<typename T >
Feel::Vector< T >::Vector ( const size_type  n,
WorldComm const &  _worldComm = Environment::worldComm() 
)

Constructor. Set dimension to n and initialize all elements with zero.

template<typename T >
Feel::Vector< T >::Vector ( const size_type  n,
const size_type  n_local,
WorldComm const &  _worldComm = Environment::worldComm() 
)

Constructor. Set local dimension to n_local, the global dimension to n, and initialize all elements with zero.

template<typename T >
Feel::Vector< T >::~Vector ( )
virtual

Destructor, deallocates memory. Made virtual to allow for derived classes to behave properly.

Member Function Documentation

template<typename T>
virtual void Feel::Vector< T >::add ( const size_type  i,
const value_type &  value 
)
pure virtual

v(i) += value

Implemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

template<typename T>
virtual void Feel::Vector< T >::add ( const value_type &  s)
pure virtual

$U(0-DIM)+=s$. Addition of s to all components. Note that s is a scalar and not a vector.

Implemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

template<typename T>
virtual void Feel::Vector< T >::add ( const Vector< value_type > &  V)
pure virtual

$U+=V$: Simple vector addition, equal to the operator +=.

Implemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

template<typename T>
virtual void Feel::Vector< T >::add ( const value_type &  a,
const Vector< value_type > &  v 
)
pure virtual

$U+=a*V$. Simple vector addition, equal to the operator +=.

Implemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

template<typename T>
void Feel::Vector< T >::add ( const value_type &  a,
const boost::shared_ptr< Vector< value_type > > &  v 
)
inline

$U+=a*V$. Simple vector addition, equal to the operator +=.

References Feel::Vector< T >::add().

template<typename T>
virtual void Feel::Vector< T >::addVector ( int *  i,
int  n,
value_type *  v 
)
pure virtual

v([i1,i2,...,in]) += [value1,...,valuen]

Implemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

template<typename T>
virtual void Feel::Vector< T >::addVector ( const std::vector< T > &  v,
const std::vector< size_type > &  dof_indices 
)
pure virtual

$ U+=v $ where v is a ublas::vector<T> and you want to specify WHERE to add it

Implemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

template<typename T>
virtual void Feel::Vector< T >::addVector ( const Vector< T > &  V,
const std::vector< size_type > &  dof_indices 
)
pure virtual

$U+=V$, where U and V are type Vector<T> and you want to specify WHERE to add the Vector<T> V

Implemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

template<typename T>
virtual void Feel::Vector< T >::addVector ( const Vector< T > &  V_in,
const MatrixSparse< T > &  A_in 
)
pure virtual

$U+=A*V$, add the product of a SparseMatrix A and a Vector V to this, where this=U.

Implemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

template<typename T>
void Feel::Vector< T >::addVector ( const boost::shared_ptr< Vector< T > > &  V_in,
const boost::shared_ptr< MatrixSparse< T > > &  A_in 
)
inline

$U+=A*V$, add the product of a SparseMatrix A and a Vector V to this, where this=U.

References Feel::Vector< T >::addVector().

template<typename T >
void Feel::Vector< T >::addVector ( const Vector< T > &  V_in,
const MatrixShell< T > &  A_in 
)

$U+=A*V$, add the product of a MatrixShell A and a Vector V to this, where this=U.

References Feel::MatrixShell< T >::multVector().

template<typename T >
void Feel::Vector< T >::addVector ( const boost::shared_ptr< Vector< T > > &  V_in,
const boost::shared_ptr< MatrixShell< T > > &  A_in 
)

$U+=A*V$, add the product of a MatrixShell A and a Vector V to this, where this=U.

template<typename T >
void Feel::Vector< T >::clear ( )
virtual
Returns
the Vector<T> to a pristine state.

Reimplemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

template<typename T>
virtual clone_ptrtype Feel::Vector< T >::clone ( ) const
pure virtual

Creates a copy of this vector and returns it in an shared_ptr<>. This must be overloaded in the derived classes.

Implemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

template<typename T>
virtual void Feel::Vector< T >::close ( )
pure virtual

Call the assemble functions

Implemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

template<typename T>
virtual bool Feel::Vector< T >::closed ( ) const
inlinevirtual
Returns
true if the vector is closed and ready for computation, false otherwise.

Reimplemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

References Feel::Vector< T >::M_is_closed.

template<typename T>
WorldComm const& Feel::Vector< T >::comm ( ) const
inline
Returns
the communicator

References Feel::Vector< T >::M_map.

template<typename T>
virtual int Feel::Vector< T >::compare ( const Vector< T > &  other_vector,
const real_type  threshold = 1e-10 
) const
virtual
Returns
-1 when this is equivalent to other_vector, up to the given threshold. When differences occur, the return value contains the first index where the difference exceeded the threshold. When no threshold is given, the Application TOLERANCE is used.
template<typename T>
virtual void Feel::Vector< T >::createSubvector ( Vector< T > &  ,
const std::vector< size_type > &   
) const
inlinevirtual

Creates the subvector "subvector" from the indices in the "rows" array. Similar to the create_submatrix routine for the SparseMatrix class, it is currently only implemented for PetscVectors.

template<typename T>
virtual size_type Feel::Vector< T >::firstLocalIndex ( ) const
inlinevirtual
Returns
the index of the first vector element actually stored on this processor. Hint: the minimum for this index is 0.

References Feel::Vector< T >::M_map.

template<typename T >
void Feel::Vector< T >::init ( const size_type  n,
const size_type  nl,
const bool  fast = false 
)
virtual

Change the dimension of the vector to N. The reserved memory for this vector remains unchanged if possible, to make things faster, but this may waste some memory, so take this in the back of your head. However, if N==0 all memory is freed, i.e. if you want to resize the vector and release the memory not needed, you have to first call init(0) and then init(N). This cited behaviour is analogous to that of the STL containers.

On fast==false, the vector is filled by zeros.

Reimplemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

template<typename T >
void Feel::Vector< T >::init ( const size_type  n,
const bool  fast = false 
)
virtual

call init with n_local = N,

Reimplemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

template<typename T>
virtual void Feel::Vector< T >::insert ( const std::vector< T > &  v,
const std::vector< size_type > &  dof_indices 
)
pure virtual

$ U=v $ where v is a DenseVector<T> and you want to specify WHERE to insert it

Implemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

template<typename T>
virtual void Feel::Vector< T >::insert ( const Vector< T > &  V,
const std::vector< size_type > &  dof_indices 
)
pure virtual

$U=V$, where U and V are type Vector<T> and you want to specify WHERE to insert the Vector<T> V

Implemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

template<typename T>
virtual void Feel::Vector< T >::insert ( const ublas::vector< T > &  V,
const std::vector< size_type > &  dof_indices 
)
pure virtual

$ U+=V $ where U and V are type DenseVector<T> and you want to specify WHERE to insert the DenseVector<T> V

Implemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

template<typename T>
virtual bool Feel::Vector< T >::isInitialized ( ) const
inlinevirtual
Returns
true if the vector has been initialized, false otherwise.

Reimplemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

References Feel::Vector< T >::M_is_initialized.

template<typename T>
virtual real_type Feel::Vector< T >::l1Norm ( ) const
pure virtual

retrieve the max component as well as the index of the max component

Returns
the $l_1$-norm of the vector, i.e. the sum of the absolute values.

Implemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

template<typename T>
virtual real_type Feel::Vector< T >::l2Norm ( ) const
pure virtual
Returns
the $l_2$-norm of the vector, i.e. the square root of the sum of the squares of the elements.

Implemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

template<typename T>
virtual size_type Feel::Vector< T >::lastLocalIndex ( ) const
inlinevirtual
Returns
the index+1 of the last vector element actually stored on this processor. Hint: the maximum for this index is size().

References Feel::Vector< T >::M_map.

template<typename T>
virtual real_type Feel::Vector< T >::linftyNorm ( ) const
pure virtual
Returns
the maximum absolute value of the elements of this vector, which is the $l_\infty$-norm of a vector.

Implemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

template<typename T>
virtual size_type Feel::Vector< T >::localSize ( ) const
inlinevirtual
Returns
the local size of the vector (index_stop-index_start)

References Feel::Vector< T >::M_map.

template<typename T>
virtual real_type Feel::Vector< T >::max ( ) const
pure virtual

retrieve the min component as well as the index of the min component

Returns
the maximum element in the vector. In case of complex numbers, this returns the maximum Real part.

Implemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

template<typename T>
virtual real_type Feel::Vector< T >::min ( ) const
pure virtual
Returns
the minimum element in the vector. In case of complex numbers, this returns the minimum Real part.

Implemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

template<typename T>
virtual T Feel::Vector< T >::operator() ( const size_type  i) const
pure virtual

Access components, returns U(i).

Implemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

template<typename T>
virtual Vector<T>& Feel::Vector< T >::operator+= ( const Vector< value_type > &  V)
pure virtual

Addition operator. Fast equivalent to U.add(1, V).

Implemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

template<typename T>
virtual Vector<T>& Feel::Vector< T >::operator-= ( const Vector< value_type > &  V)
pure virtual

Subtraction operator. Fast equivalent to U.add(-1, V).

Implemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

template<typename T >
Vector< T > & Feel::Vector< T >::operator= ( const T  s)

Change the dimension to that of the vector V. The same applies as for the other init function.

The elements of V are not copied, i.e. this function is the same as calling init(V.size(),fast). $U(0-N) = s$: fill all components.

template<typename T >
Vector< T > & Feel::Vector< T >::operator= ( const Vector< T > &  V)
virtual

$U = V$: copy all components.

Reimplemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

References Feel::Vector< T >::firstLocalIndex().

template<typename T >
Vector< T > & Feel::Vector< T >::operator= ( const std::vector< T > &  v)

$U = V$: copy all components.

template<typename T >
void Feel::Vector< T >::print ( std::ostream &  os = std::cout) const
virtual

Prints the contents of the vector to the screen.

template<typename T>
virtual void Feel::Vector< T >::printMatlab ( const std::string  name = "NULL",
bool  renumber = false 
) const
inlinevirtual

Print the contents of the matrix in Matlab's sparse matrix format. Optionally prints the matrix to the file named name. If name is not specified it is dumped to the screen.

Reimplemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

template<typename T>
virtual void Feel::Vector< T >::scale ( const T  factor)
pure virtual

Scale each element of the vector by the given factor.

Implemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

template<typename T>
virtual void Feel::Vector< T >::set ( const size_type  i,
const value_type &  value 
)
pure virtual

v(i) = value

Implemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

template<typename T>
virtual void Feel::Vector< T >::setConstant ( value_type  v)
pure virtual

set the entries to the constant v

Implemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

template<typename T>
virtual void Feel::Vector< T >::setOnes ( )
inlinevirtual

set the entries to 1

References Feel::Vector< T >::setConstant().

template<typename T>
virtual void Feel::Vector< T >::setZero ( )
inlinevirtual

set the entries to 0

References Feel::Vector< T >::zero().

template<typename T>
virtual size_type Feel::Vector< T >::size ( ) const
inlinevirtual
Returns
dimension of the vector. This function was formerly called n(), but was renamed to get the Vector<T> class closer to the C++ standard library's std::vector container.

References Feel::Vector< T >::M_map.

template<typename T>
virtual value_type Feel::Vector< T >::sum ( ) const
pure virtual
Returns
the sum of the components of the vector

Implemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

template<typename T>
virtual void Feel::Vector< T >::zero ( )
pure virtual

Set all entries to zero. Equivalent to v = 0, but more obvious and faster.

Implemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

template<typename T>
virtual void Feel::Vector< T >::zero ( size_type  ,
size_type   
)
pure virtual

Set entries to zero between start and stop

Implemented in Feel::VectorUblas< T, Storage >, and Feel::VectorEigen< T >.

Friends And Related Function Documentation

template<typename T>
std::ostream& operator<< ( std::ostream &  os,
const Vector< T > &  v 
)
friend

Same as above but allows you to use stream syntax.

Member Data Documentation

template<typename T>
bool Feel::Vector< T >::M_is_closed
protected

Flag to see if the Numeric assemble routines have been called yet

template<typename T>
bool Feel::Vector< T >::M_is_initialized
protected

Flag to tell if init has been called yet

template<typename T>
datamap_ptrtype Feel::Vector< T >::M_map
protected

data distribution map of the vector over the processors


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

Generated on Sun Oct 20 2013 08:25:09 for Feel++ by doxygen 1.8.4