Feel++ 0.91.0
Public Types | Public Member Functions | Protected Attributes | Friends
Feel::Vector< T > Class Template Reference

#include <vector.hpp>

Inheritance diagram for Feel::Vector< T >:
Feel::VectorPetsc< T > Feel::VectorUblas< T, Storage >

List of all members.

Public Types

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

Public Member Functions

 Vector ()
 Vector (DataMap const &n)
 Vector (const size_type n)
 Vector (const size_type n, const size_type n_local)
virtual ~Vector ()
DataMap const & map () const
virtual bool isInitialized () const
virtual bool closed () const
virtual void close ()=0
virtual void clear ()
virtual void zero ()=0
virtual void zero (size_type, size_type)=0
virtual void setConstant (value_type v)=0
virtual void setZero ()
virtual void setOnes ()
virtual clone_ptrtype clone () const =0
virtual void init (const size_type, const size_type, const bool=false)
virtual void init (const size_type, const bool=false)
virtual Vector< T > & operator= (const T s)
virtual Vector< T > & operator= (const Vector< T > &V)
virtual Vector< T > & operator= (const std::vector< T > &v)
virtual value_type sum () const =0
virtual real_type min () const =0
virtual real_type max () const =0
virtual real_type l1Norm () const =0
virtual real_type l2Norm () const =0
virtual real_type linftyNorm () const =0
virtual size_type size () const
virtual size_type localSize () const
virtual size_type firstLocalIndex () const
virtual size_type lastLocalIndex () const
mpi::communicator const & comm () const
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
virtual void set (const size_type i, const value_type &value)=0
virtual void add (const size_type i, const value_type &value)=0
virtual void addVector (int *i, int n, value_type *v)=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 (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 > &, const MatrixSparse< T > &)=0
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 void scale (const T factor)=0
virtual void localize (std::vector< T > &v_local) const =0
virtual void localize (Vector< T > &v_local) const =0
virtual void localize (Vector< T > &v_local, const std::vector< size_type > &send_list) const =0
virtual void localize (const size_type first_local_idx, const size_type last_local_idx, const std::vector< size_type > &send_list)=0
virtual void localizeToOneProcessor (std::vector< T > &v_local, const size_type proc_id=0) const =0
virtual int compare (const Vector< T > &other_vector, const real_type threshold=1e-10) const
virtual void print (std::ostream &os=std::cout) const
virtual void printMatlab (const std::string name="NULL") const
virtual void createSubvector (Vector< T > &, const std::vector< size_type > &) 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

Protected Attributes

bool M_is_closed
bool M_is_initialized
DataMap M_map

Friends

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

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

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)

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 
)

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]
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::VectorPetsc< T >, and Feel::VectorUblas< T, Storage >.

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::VectorPetsc< T >, and Feel::VectorUblas< T, Storage >.

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::VectorPetsc< T >, and Feel::VectorUblas< T, Storage >.

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::VectorPetsc< T >, and Feel::VectorUblas< T, Storage >.

Referenced by Feel::MatrixSparse< T >::multAddVector().

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::VectorPetsc< T >, and Feel::VectorUblas< T, Storage >.

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::VectorPetsc< T >, and Feel::VectorUblas< T, Storage >.

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

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

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

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

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

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::VectorPetsc< T >, and Feel::VectorUblas< T, Storage >.

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

Call the assemble functions

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

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

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

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

Referenced by Feel::VectorPetsc< T >::operator+=(), and Feel::VectorPetsc< T >::operator-=().

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

References Feel::DataMap::comm(), and Feel::Vector< T >::M_map.

Referenced by Feel::inner_product().

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 [inline, virtual]

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 [inline, virtual]
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::VectorPetsc< T >, and Feel::VectorUblas< T, Storage >.

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::VectorPetsc< T >, and Feel::VectorUblas< T, Storage >.

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::VectorPetsc< T >, and Feel::VectorUblas< T, Storage >.

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::VectorPetsc< T >, and Feel::VectorUblas< T, Storage >.

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::VectorPetsc< T >, and Feel::VectorUblas< T, Storage >.

template<typename T>
virtual bool Feel::Vector< T >::isInitialized ( ) const [inline, virtual]
template<typename T>
virtual real_type Feel::Vector< T >::l1Norm ( ) const [pure virtual]
Returns:
the $l_1$-norm of the vector, i.e. the sum of the absolute values.

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

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::VectorPetsc< T >, and Feel::VectorUblas< T, Storage >.

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

Reimplemented in Feel::VectorPetsc< T >.

References Feel::Vector< T >::M_map, and Feel::DataMap::maxMyGID().

Referenced by Feel::VectorUblas< T, Storage >::localize(), Feel::VectorUblas< T, Storage >::operator()(), Feel::VectorUblas< T, Storage >::operator=(), and Feel::VectorUblas< T, Storage >::operator[]().

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::VectorPetsc< T >, and Feel::VectorUblas< T, Storage >.

template<typename T>
virtual void Feel::Vector< T >::localize ( Vector< T > &  v_local,
const std::vector< size_type > &  send_list 
) const [pure virtual]

Creates a local vector v_local containing only information relevant to this processor, as defined by the send_list.

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

template<typename T>
virtual void Feel::Vector< T >::localize ( std::vector< T > &  v_local) const [pure virtual]

Creates a copy of the global vector in the local vector v_local.

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

template<typename T>
virtual void Feel::Vector< T >::localize ( Vector< T > &  v_local) const [pure virtual]

Same, but fills a Vector<T> instead of a std::vector.

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

template<typename T>
virtual void Feel::Vector< T >::localize ( const size_type  first_local_idx,
const size_type  last_local_idx,
const std::vector< size_type > &  send_list 
) [pure virtual]

Updates a local vector with selected values from neighboring processors, as defined by send_list.

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

template<typename T>
virtual void Feel::Vector< T >::localizeToOneProcessor ( std::vector< T > &  v_local,
const size_type  proc_id = 0 
) const [pure virtual]

Creates a local copy of the global vector in v_local only on processor proc_id. By default the data is sent to processor 0. This method is useful for outputting data from one processor.

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

template<typename T>
virtual size_type Feel::Vector< T >::localSize ( ) const [inline, virtual]
template<typename T>
virtual real_type Feel::Vector< T >::max ( ) const [pure virtual]
Returns:
the maximum element in the vector. In case of complex numbers, this returns the maximum Real part.

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

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::VectorPetsc< T >, and Feel::VectorUblas< T, Storage >.

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

Access components, returns U(i).

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

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::VectorPetsc< T >, and Feel::VectorUblas< T, Storage >.

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::VectorPetsc< T >, and Feel::VectorUblas< T, Storage >.

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

$U = V$: copy all components.

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

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 >.

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

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") const [inline, virtual]

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::VectorPetsc< T >, and Feel::VectorUblas< T, Storage >.

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::VectorPetsc< T >, and Feel::VectorUblas< T, Storage >.

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

set the entries to the constant v

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

Referenced by Feel::Vector< T >::setOnes().

template<typename T>
virtual void Feel::Vector< T >::setOnes ( ) [inline, virtual]

set the entries to 1

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

template<typename T>
virtual void Feel::Vector< T >::setZero ( ) [inline, virtual]

set the entries to 0

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

template<typename T>
virtual size_type Feel::Vector< T >::size ( ) const [inline, virtual]
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.

Reimplemented in Feel::VectorPetsc< T >.

References Feel::Vector< T >::M_map, and Feel::DataMap::nGlobalElements().

Referenced by Feel::VectorUblas< T, Storage >::addVector(), Feel::VectorPetsc< T >::addVector(), Feel::element_product(), Feel::MatrixPetsc< T >::energy(), Feel::MatrixGmm< T, LayoutType >::energy(), Feel::inner_product(), and Feel::VectorUblas< T, Storage >::localize().

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::VectorPetsc< T >, and Feel::VectorUblas< T, Storage >.

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::VectorPetsc< T >, and Feel::VectorUblas< T, Storage >.

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::VectorPetsc< T >, and Feel::VectorUblas< T, Storage >.

Referenced by Feel::MatrixSparse< T >::multVector(), and Feel::Vector< T >::setZero().


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

Referenced by Feel::VectorPetsc< T >::close(), Feel::Vector< T >::closed(), and Feel::VectorUblas< T, Storage >::localize().

template<typename T>
bool Feel::Vector< T >::M_is_initialized [protected]
template<typename T>
DataMap Feel::Vector< T >::M_map [protected]