Public Types | Public Member Functions | Public Attributes | Protected Attributes | List of all members
Seldon::PETScVector< T, Allocator > Class Template Reference

PETSc vector class. More...

#include <PetscVector.hxx>

Inheritance diagram for Seldon::PETScVector< T, Allocator >:
Seldon::Vector_Base< T, Allocator > Seldon::Vector< T, PETScPar, Allocator > Seldon::Vector< T, PETScSeq, Allocator >

Public Types

typedef Allocator::value_type value_type
 
typedef Allocator::pointer pointer
 
typedef Allocator::const_pointer const_pointer
 
typedef Allocator::reference reference
 
typedef Allocator::const_reference const_reference
 
typedef Allocator allocator
 

Public Member Functions

 PETScVector ()
 Default constructor. More...
 
 PETScVector (int i, MPI_Comm mpi_communicator=MPI_COMM_WORLD)
 Main constructor. More...
 
 PETScVector (Vec &petsc_vector)
 Copy constructor. More...
 
 PETScVector (const PETScVector< T, Allocator > &A)
 Copy constructor. More...
 
 ~PETScVector ()
 Destructor.
 
Vec & GetPetscVector ()
 Returns a reference on the inner petsc vector. More...
 
const Vec & GetPetscVector () const
 
void SetCommunicator (MPI_Comm mpi_communicator)
 Sets the MPI communicator. More...
 
void Clear ()
 Clears the vector. More...
 
void Resize (int i)
 Changes the length of the vector, and keeps previous values. More...
 
void SetData (int i, pointer data)
 Changes the length of the vector and sets its data array (low level method). More...
 
void Nullify ()
 Clears the vector without releasing memory. More...
 
value_type operator() (int i) const
 Access operator. More...
 
void SetBuffer (int i, T value, InsertMode insert_mode=INSERT_VALUES)
 Inserts or adds values into certain locations of a vector. More...
 
void Flush ()
 Assembles the PETSc vector.
 
void GetProcessorRange (int &i, int &j) const
 Returns the range of indices owned by this processor. More...
 
void Copy (const PETScVector< T, Allocator > &X)
 Duplicates a vector. More...
 
void Copy (const Vec &petsc_vector)
 Duplicates a vector. More...
 
void Append (const T &x)
 Appends an element to the vector. More...
 
int GetDataSize () const
 Returns the number of elements stored. More...
 
int GetLocalM () const
 Returns the number of elements stored. More...
 
void Zero ()
 Sets all elements to zero. More...
 
void Fill ()
 Fills the vector with 0, 1, 2, ...
 
template<class T0 >
void Fill (const T0 &x)
 Fills the vector with a given value. More...
 
void FillRand ()
 Fills the vector randomly. More...
 
value_type GetNormInf () const
 Returns the infinite norm. More...
 
int GetNormInfIndex () const
 Returns the index of the highest absolute value. More...
 
long GetM () const
 Returns the number of elements. More...
 
size_t GetLength () const
 Returns the number of elements. More...
 
size_t GetSize () const
 Returns the number of elements stored. More...
 
size_t GetMemorySize () const
 Returns the memory used by the object in bytes. More...
 
pointer GetData () const
 Returns a pointer to data_ (stored data). More...
 
const_pointer GetDataConst () const
 Returns a const pointer to data_ (stored data). More...
 
void * GetDataVoid () const
 Returns a pointer of type "void*" to the data array (data_). More...
 
const void * GetDataConstVoid () const
 Returns a pointer of type "const void*" to the data array (data_). More...
 

Public Attributes

Vec petsc_vector_
 Encapsulated PETSc vector.
 
MPI_Comm mpi_communicator_
 The MPI communicator to use.
 
bool petsc_vector_deallocated_
 Boolean to indicate if the inner PETSc vector is destroyed or not.
 

Protected Attributes

size_t m_
 
pointer data_
 

Detailed Description

template<class T, class Allocator>
class Seldon::PETScVector< T, Allocator >

PETSc vector class.

PETSc vector class.

Definition at line 41 of file PetscVector.hxx.

Constructor & Destructor Documentation

◆ PETScVector() [1/4]

template<class T , class Allocator >
Seldon::PETScVector< T, Allocator >::PETScVector
inlineexplicit

Default constructor.

On exit, the vector is empty.

Definition at line 41 of file PetscVectorInline.cxx.

◆ PETScVector() [2/4]

template<class T , class Allocator >
Seldon::PETScVector< T, Allocator >::PETScVector ( int  i,
MPI_Comm  mpi_communicator = MPI_COMM_WORLD 
)
inlineexplicit

Main constructor.

Builds a vector of a given size.

Parameters
[in]ilength of the vector.
[in]mpi_communicatorMPI communicator to use.

Definition at line 55 of file PetscVectorInline.cxx.

◆ PETScVector() [3/4]

template<class T , class Allocator >
Seldon::PETScVector< T, Allocator >::PETScVector ( Vec &  petsc_vector)
inline

Copy constructor.

Builds a copy of a vector.

Parameters
[in]petsc_vectorvector to be copied.

Definition at line 69 of file PetscVectorInline.cxx.

◆ PETScVector() [4/4]

template<class T , class Allocator >
Seldon::PETScVector< T, Allocator >::PETScVector ( const PETScVector< T, Allocator > &  V)
inline

Copy constructor.

Builds a copy of a vector.

Parameters
[in]Vvector to be copied.

Definition at line 82 of file PetscVectorInline.cxx.

Member Function Documentation

◆ Append()

template<class T , class Allocator >
void Seldon::PETScVector< T, Allocator >::Append ( const T &  x)
inline

Appends an element to the vector.

Parameters
xelement to be appended.
Warning
This method will only work if the allocator preserves the elements while reallocating.

Definition at line 309 of file PetscVectorInline.cxx.

◆ Clear()

template<class T , class Allocator >
void Seldon::PETScVector< T, Allocator >::Clear
inline

Clears the vector.

Destructs the vector.

Warning
On exit, the vector is an empty vector.

Definition at line 145 of file PetscVectorInline.cxx.

◆ Copy() [1/2]

template<class T , class Allocator >
void Seldon::PETScVector< T, Allocator >::Copy ( const PETScVector< T, Allocator > &  X)
inline

Duplicates a vector.

Parameters
Xvector to be copied.
Note
Memory is duplicated: 'X' is therefore independent from the current instance after the copy.

Definition at line 296 of file PetscVectorInline.cxx.

◆ Copy() [2/2]

template<class T , class Allocator >
void Seldon::PETScVector< T, Allocator >::Copy ( const Vec &  petsc_vector)

Duplicates a vector.

Parameters
petsc_vectorvector to be copied.
Note
Memory is duplicated: 'X' is therefore independent from the current instance after the copy.

Definition at line 38 of file PetscVector.cxx.

◆ Fill()

template<class T , class Allocator >
template<class T0 >
void Seldon::PETScVector< T, Allocator >::Fill ( const T0 &  x)

Fills the vector with a given value.

Parameters
xvalue to fill the vector with.

Definition at line 97 of file PetscVector.cxx.

◆ FillRand()

template<class T , class Allocator >
void Seldon::PETScVector< T, Allocator >::FillRand

Fills the vector randomly.

Note
The random generator is very basic.

Definition at line 111 of file PetscVector.cxx.

◆ GetData()

template<class T , class Allocator >
Vector_Base< T, Allocator >::pointer Seldon::Vector_Base< T, Allocator >::GetData
inlineinherited

Returns a pointer to data_ (stored data).

Returns
A pointer to the data_, i.e. the data array.

Definition at line 177 of file VectorInline.cxx.

◆ GetDataConst()

template<class T , class Allocator >
Vector_Base< T, Allocator >::const_pointer Seldon::Vector_Base< T, Allocator >::GetDataConst
inlineinherited

Returns a const pointer to data_ (stored data).

Returns
A const pointer to the data_, i.e. the data array.

Definition at line 189 of file VectorInline.cxx.

◆ GetDataConstVoid()

template<class T , class Allocator >
const void * Seldon::Vector_Base< T, Allocator >::GetDataConstVoid
inlineinherited

Returns a pointer of type "const void*" to the data array (data_).

Returns
A pointer of type "const void*" to the data array.

Definition at line 212 of file VectorInline.cxx.

◆ GetDataSize()

template<class T , class Allocator >
int Seldon::PETScVector< T, Allocator >::GetDataSize
inline

Returns the number of elements stored.

Returns
The number of elements stored in memory.

Definition at line 325 of file PetscVectorInline.cxx.

◆ GetDataVoid()

template<class T , class Allocator >
void * Seldon::Vector_Base< T, Allocator >::GetDataVoid
inlineinherited

Returns a pointer of type "void*" to the data array (data_).

Returns
A pointer of type "void*" to the data array.

Definition at line 201 of file VectorInline.cxx.

◆ GetLength()

template<class T , class Allocator >
size_t Seldon::Vector_Base< T, Allocator >::GetLength
inlineinherited

Returns the number of elements.

Returns
The length of the vector.

Definition at line 142 of file VectorInline.cxx.

◆ GetLocalM()

template<class T , class Allocator >
int Seldon::PETScVector< T, Allocator >::GetLocalM
inline

Returns the number of elements stored.

Returns
The number of elements stored in memory.

Definition at line 336 of file PetscVectorInline.cxx.

◆ GetM()

template<class T , class Allocator >
long Seldon::Vector_Base< T, Allocator >::GetM
inlineinherited

Returns the number of elements.

Returns
The length of the vector.

Definition at line 131 of file VectorInline.cxx.

◆ GetMemorySize()

template<class T , class Allocator >
size_t Seldon::Vector_Base< T, Allocator >::GetMemorySize
inlineinherited

Returns the memory used by the object in bytes.

In this method, the type T is assumed to be "static" such that sizeof(T) provides the correct size

Definition at line 165 of file VectorInline.cxx.

◆ GetNormInf()

template<class T , class Allocator >
PETScVector< T, Allocator >::value_type Seldon::PETScVector< T, Allocator >::GetNormInf

Returns the infinite norm.

Returns
The infinite norm.

Definition at line 136 of file PetscVector.cxx.

◆ GetNormInfIndex()

template<class T , class Allocator >
int Seldon::PETScVector< T, Allocator >::GetNormInfIndex

Returns the index of the highest absolute value.

Returns
The index of the element that has the highest absolute value.

Definition at line 151 of file PetscVector.cxx.

◆ GetPetscVector()

template<class T , class Allocator >
const Vec & Seldon::PETScVector< T, Allocator >::GetPetscVector
inline

Returns a reference on the inner petsc vector.

Returns a const reference on the inner petsc vector.

Returns
a reference on the inner petsc vector.
a const reference on the inner petsc vector.

Definition at line 106 of file PetscVectorInline.cxx.

◆ GetProcessorRange()

template<class T , class Allocator >
void Seldon::PETScVector< T, Allocator >::GetProcessorRange ( int &  i,
int &  j 
) const
inline

Returns the range of indices owned by this processor.

The vectors are laid out with the first $n_1$ elements on the first processor, next $n_2$ elements on the second, etc. If the current processor is $k$, this method returns $n_k$ in i and $n_{k+1}$ in j. If i is set to PETSC_NULL on entry, it is not modified by this function. Same is true for j.

Parameters
[in,out]ithe index of the first local element.
[in,out]jthe index of the last local element, plus 1.

Definition at line 280 of file PetscVectorInline.cxx.

◆ GetSize()

template<class T , class Allocator >
size_t Seldon::Vector_Base< T, Allocator >::GetSize
inlineinherited

Returns the number of elements stored.

Returns
The length of the vector stored.

Definition at line 153 of file VectorInline.cxx.

◆ Nullify()

template<class T , class Allocator >
void Seldon::PETScVector< T, Allocator >::Nullify
inline

Clears the vector without releasing memory.

On exit, the vector is empty and the memory has not been released. It is useful for low level manipulations on a Vector instance.

Warning
Memory is not released.

Definition at line 198 of file PetscVectorInline.cxx.

◆ operator()()

template<class T , class Allocator >
PETScVector< T, Allocator >::value_type Seldon::PETScVector< T, Allocator >::operator() ( int  i) const
inline

Access operator.

Parameters
iindex.
Returns
The value of the vector at 'i'.

Definition at line 216 of file PetscVectorInline.cxx.

◆ Resize()

template<class T , class Allocator >
void Seldon::PETScVector< T, Allocator >::Resize ( int  n)
inline

Changes the length of the vector, and keeps previous values.

Reallocates the vector to size i. Previous values are kept.

Parameters
[in]nnew length of the vector.

Definition at line 162 of file PetscVectorInline.cxx.

◆ SetBuffer()

template<class T , class Allocator >
void Seldon::PETScVector< T, Allocator >::SetBuffer ( int  i,
value,
InsertMode  insert_mode = INSERT_VALUES 
)
inline

Inserts or adds values into certain locations of a vector.

Warning
These values may be cached, so 'Flush' must be called after all calls to SetBuffer() have been completed.
Parameters
[in]iindex where to insert the value.
[in]valuethe value to insert.
[in]insert_modeeither INSERT_VALUES or ADD_VALUES, where ADD_VALUES adds the value to the entry, and INSERT_VALUES replaces existing entry with new value.

Definition at line 245 of file PetscVectorInline.cxx.

◆ SetCommunicator()

template<class T , class Allocator >
void Seldon::PETScVector< T, Allocator >::SetCommunicator ( MPI_Comm  mpi_communicator)
inline

Sets the MPI communicator.

Parameters
[in]mpi_communicatorthe mpi communicator to be set.

Definition at line 128 of file PetscVectorInline.cxx.

◆ SetData()

template<class T , class Allocator >
void Seldon::PETScVector< T, Allocator >::SetData ( int  i,
pointer  data 
)
inline

Changes the length of the vector and sets its data array (low level method).

Reallocates a vector and sets the new data array. It is useful to create a vector from pre-existing data.

Parameters
[in]inew length of the vector.
[in]datathe new data array. 'data' contains the new elements of the vector and must therefore contain 'i' elements.
Warning
'data' has to be used carefully outside the object. Unless you use 'Nullify', 'data' will be freed by the destructor, which means that 'data' must have been allocated carefully. The vector allocator should be compatible.
Note
This method should only be used by advanced users.

Definition at line 184 of file PetscVectorInline.cxx.

◆ Zero()

template<class T , class Allocator >
void Seldon::PETScVector< T, Allocator >::Zero

Sets all elements to zero.

Warning
It fills the memory with zeros. If the vector stores complex structures, use 'Fill' instead.

Definition at line 67 of file PetscVector.cxx.


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