Feel++ 0.91.0
Public Member Functions

Feel::VectorPetsc< T > Class Template Reference

Wrapper for petsc matrices. More...

#include <vectorpetsc.hpp>

Inheritance diagram for Feel::VectorPetsc< T >:
Feel::Vector< T >

List of all members.

Public Types

Typedefs
typedef super::value_type value_type
typedef super::real_type real_type
typedef super::clone_ptrtype clone_ptrtype

Public Member Functions

 VectorPetsc (VectorPetsc const &v)
template<>
void localize (std::vector< double > &v_local) const
template<>
void localizeToOneProcessor (std::vector< Real > &v_local, const size_type pid) const
Constructors, destructor
 VectorPetsc ()
 VectorPetsc (const size_type n)
 VectorPetsc (const size_type n, const size_type n_local)
 VectorPetsc (Vec v)
 ~VectorPetsc ()
clone_ptrtype clone () const
void init (const size_type N, const size_type n_local, const bool fast=false)
void init (const size_type N, const bool fast=false)
Operator overloads
value_type operator() (const size_type i) const
Vector< T > & operator+= (const Vector< value_type > &V)
Vector< T > & operator-= (const Vector< value_type > &V)
Accessors
size_type size () const
size_type localSize () const
Vec vec () const
Methods
void close ()
void zero ()
void zero (size_type, size_type)
void setConstant (value_type v)
FEEL_DONT_INLINE void clear ()
void set (const value_type &value)
void set (size_type i, const value_type &value)
void add (size_type i, const value_type &value)
void addVector (int *i, int n, value_type *v)
void addVector (const std::vector< value_type > &v, const std::vector< size_type > &dof_indices)
void addVector (const Vector< value_type > &V, const std::vector< size_type > &dof_indices)
void addVector (const Vector< value_type > &V_in, const MatrixSparse< value_type > &A_in)
void addVector (const ublas::vector< value_type > &V, const std::vector< size_type > &dof_indices)
void insert (const std::vector< T > &, const std::vector< size_type > &)
void insert (const Vector< T > &V, const std::vector< size_type > &dof_indices)
void insert (const ublas::vector< T > &V, const std::vector< size_type > &dof_indices)
void scale (const T factor)
void add (const value_type &v_in)
void add (const Vector< value_type > &v)
void add (const value_type &a_in, const Vector< value_type > &v_in)
real_type min () const
real_type max () const
real_type l1Norm () const
real_type l2Norm () const
value_type sum () const
real_type linftyNorm () const
size_type firstLocalIndex () const
size_type lastLocalIndex () const
void localize (std::vector< T > &v_local) const
void localize (Vector< T > &v_local) const
void localize (Vector< T > &v_local, const std::vector< size_type > &send_list) const
void localize (const size_type first_local_idx, const size_type last_local_idx, const std::vector< size_type > &send_list)
void localizeToOneProcessor (std::vector< T > &v_local, const size_type proc_id=0) const
void printMatlab (const std::string name="NULL") const

Detailed Description

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

Wrapper for petsc matrices.

Petsc vector. Provides a nice interface to the Petsc C-based data structures for parallel, sparse matrices.

Author:
Benjamin S. Kirk, 2002
Christophe Prud'homme
See also:

Constructor & Destructor Documentation

template<typename T>
Feel::VectorPetsc< T >::VectorPetsc ( ) [inline]

Dummy-Constructor. Dimension=0

template<typename T>
Feel::VectorPetsc< T >::VectorPetsc ( const size_type  n) [inline]

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

References Feel::VectorPetsc< T >::init().

template<typename T>
Feel::VectorPetsc< T >::VectorPetsc ( const size_type  n,
const size_type  n_local 
) [inline]

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

References Feel::VectorPetsc< T >::init().

template<typename T>
Feel::VectorPetsc< T >::VectorPetsc ( Vec  v) [inline]

Constructor. Creates a VectorPetsc assuming you already have a valid PETSc Vec object. In this case, v is NOT destroyed by the VectorPetsc constructor when this object goes out of scope. This allows ownership of v to remain with the original creator, and to simply provide additional functionality with the VectorPetsc.

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

template<typename T>
Feel::VectorPetsc< T >::~VectorPetsc ( ) [inline]

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

References Feel::VectorPetsc< T >::clear().


Member Function Documentation

template<typename T >
void Feel::VectorPetsc< T >::add ( size_type  i,
const value_type &  value 
) [virtual]
template<typename T >
void Feel::VectorPetsc< T >::add ( const value_type &  v_in) [virtual]

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

Implements Feel::Vector< T >.

template<typename T >
void Feel::VectorPetsc< T >::add ( const Vector< value_type > &  v) [virtual]

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

Implements Feel::Vector< T >.

template<typename T >
void Feel::VectorPetsc< T >::add ( const value_type &  a_in,
const Vector< value_type > &  v_in 
) [virtual]

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

Implements Feel::Vector< T >.

References Feel::VectorPetsc< T >::size().

template<typename T >
void Feel::VectorPetsc< T >::addVector ( int *  i,
int  n,
value_type *  v 
) [virtual]

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

Implements Feel::Vector< T >.

template<typename T>
void Feel::VectorPetsc< T >::addVector ( const std::vector< value_type > &  v,
const std::vector< size_type > &  dof_indices 
) [inline, virtual]

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

Implements Feel::Vector< T >.

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

template<typename T>
void Feel::VectorPetsc< T >::addVector ( const Vector< value_type > &  V,
const std::vector< size_type > &  dof_indices 
) [inline, virtual]

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

Implements Feel::Vector< T >.

References Feel::VectorPetsc< T >::add(), and Feel::Vector< T >::size().

template<typename T>
void Feel::VectorPetsc< T >::addVector ( const Vector< value_type > &  V_in,
const MatrixSparse< value_type > &  A_in 
) [inline, virtual]

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

Implements Feel::Vector< T >.

References Feel::VectorPetsc< T >::close().

template<typename T>
void Feel::VectorPetsc< T >::addVector ( const ublas::vector< value_type > &  V,
const std::vector< size_type > &  dof_indices 
) [inline]

$U+=V $ where U and V are type uvlas::vector<T> and you want to specify WHERE to add the DenseVector<T> V

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

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

Reimplemented from Feel::Vector< T >.

Referenced by Feel::VectorPetsc< T >::~VectorPetsc().

template<typename T>
clone_ptrtype Feel::VectorPetsc< T >::clone ( ) const [inline, virtual]

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

Implements Feel::Vector< T >.

template<typename T>
void Feel::VectorPetsc< T >::close ( ) [inline, virtual]
template<typename T>
size_type Feel::VectorPetsc< T >::firstLocalIndex ( ) const [inline, virtual]
Returns:
the index of the first vector element actually stored on this processor

Reimplemented from Feel::Vector< T >.

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

Referenced by Feel::VectorPetsc< T >::operator()().

template<typename T >
void Feel::VectorPetsc< T >::init ( const size_type  N,
const size_type  n_local,
const bool  fast = false 
) [inline, 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 from Feel::Vector< T >.

Referenced by Feel::VectorPetsc< T >::init(), Feel::VectorPetsc< T >::localize(), and Feel::VectorPetsc< T >::VectorPetsc().

template<typename T>
void Feel::VectorPetsc< T >::init ( const size_type  N,
const bool  fast = false 
) [inline, virtual]

call init with n_local = N,

Reimplemented from Feel::Vector< T >.

References Feel::VectorPetsc< T >::init().

template<typename T>
void Feel::VectorPetsc< T >::insert ( const std::vector< T > &  ,
const std::vector< size_type > &   
) [inline, virtual]

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

Implements Feel::Vector< T >.

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

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

Implements Feel::Vector< T >.

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

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

Implements Feel::Vector< T >.

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

Implements Feel::Vector< T >.

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

Implements Feel::Vector< T >.

template<typename T>
size_type Feel::VectorPetsc< T >::lastLocalIndex ( ) const [inline, virtual]
Returns:
the index of the last vector element actually stored on this processor

Reimplemented from Feel::Vector< T >.

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

Referenced by Feel::VectorPetsc< T >::operator()().

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

Implements Feel::Vector< T >.

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

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

Implements Feel::Vector< T >.

Referenced by Feel::VectorPetsc< T >::localize().

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

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

Implements Feel::Vector< T >.

References Feel::iota(), and Feel::VectorPetsc< T >::localSize().

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

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

Implements Feel::Vector< T >.

References Feel::VectorPetsc< T >::localSize(), and Feel::VectorPetsc< T >::size().

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

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

Implements Feel::Vector< T >.

References Feel::VectorPetsc< T >::close(), Feel::VectorPetsc< T >::init(), Feel::iota(), and Feel::VectorPetsc< T >::localize().

template<typename T>
void Feel::VectorPetsc< T >::localizeToOneProcessor ( std::vector< T > &  v_local,
const size_type  proc_id = 0 
) const [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.

Implements Feel::Vector< T >.

template<typename T>
size_type Feel::VectorPetsc< T >::localSize ( ) const [inline, virtual]
Returns:
the local size of the vector (index_stop-index_start)

Reimplemented from Feel::Vector< T >.

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

Referenced by Feel::MatrixPetsc< T >::energy(), and Feel::VectorPetsc< T >::localize().

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

Implements Feel::Vector< T >.

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

Implements Feel::Vector< T >.

template<typename T>
value_type Feel::VectorPetsc< T >::operator() ( const size_type  i) const [inline, virtual]
template<typename T>
Vector<T>& Feel::VectorPetsc< T >::operator+= ( const Vector< value_type > &  V) [inline, virtual]

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

Implements Feel::Vector< T >.

References Feel::VectorPetsc< T >::add(), and Feel::Vector< T >::closed().

template<typename T>
Vector<T>& Feel::VectorPetsc< T >::operator-= ( const Vector< value_type > &  V) [inline, virtual]

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

Implements Feel::Vector< T >.

References Feel::VectorPetsc< T >::add(), and Feel::Vector< T >::closed().

template<typename T >
void Feel::VectorPetsc< T >::printMatlab ( const std::string  name = "NULL") const [virtual]

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

Create an ASCII file containing the matrix if a filename was provided.

Otherwise the matrix will be dumped to the screen.

Destroy the viewer.

Reimplemented from Feel::Vector< T >.

template<typename T>
void Feel::VectorPetsc< T >::scale ( const T  factor) [virtual]

Scale each element of the vector by the given factor.

Implements Feel::Vector< T >.

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

v(i) = value

Implements Feel::Vector< T >.

template<typename T >
void Feel::VectorPetsc< T >::set ( const value_type &  value)

$ v(i) = \mathrm{value} \forall i$

template<typename T>
void Feel::VectorPetsc< T >::setConstant ( value_type  v) [inline, virtual]

set the entries to the constant v

Implements Feel::Vector< T >.

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

Reimplemented from Feel::Vector< T >.

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

Referenced by Feel::VectorPetsc< T >::add(), and Feel::VectorPetsc< T >::localize().

template<typename T >
VectorPetsc< T >::value_type Feel::VectorPetsc< T >::sum ( ) const [virtual]
Returns:
the sum of the vector components, i.e. the sum of the values.

Implements Feel::Vector< T >.

template<typename T>
Vec Feel::VectorPetsc< T >::vec ( ) const [inline]

Returns the raw PETSc vector context pointer. Note this is generally not required in user-level code. Just don't do anything crazy like calling VecDestroy()!

Referenced by Feel::MatrixPetsc< T >::energy(), Feel::BackendPetsc< T >::prod(), Feel::SolverNonLinearPetsc< T >::solve(), Feel::SolverLinearPetsc< T >::solve(), and Feel::MatrixPetsc< T >::zeroRows().

template<typename T>
void Feel::VectorPetsc< T >::zero ( ) [inline, virtual]

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

Implements Feel::Vector< T >.

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

Referenced by Feel::VectorPetsc< T >::zero().

template<typename T>
void Feel::VectorPetsc< T >::zero ( size_type  ,
size_type   
) [inline, virtual]

Set entries to zero between start and stop

Implements Feel::Vector< T >.

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