Feel++ 0.91.0
Feel::MatrixPetsc< T > Class Template Reference

Wrapper for petsc matrices. More...

#include <matrixpetsc.hpp>

Inheritance diagram for Feel::MatrixPetsc< T >:
Feel::MatrixSparse< T >

List of all members.

Public Member Functions

Constructors, destructor
 MatrixPetsc ()
 MatrixPetsc (Mat m)
 ~MatrixPetsc ()
Operator overloads
value_type operator() (const size_type i, const size_type j) const
MatrixPetscoperator= (MatrixSparse< value_type > const &M)
Accessors
size_type size1 () const
size_type size2 () const
size_type rowStart () const
size_type rowStop () const
Methods
void init (const size_type m, const size_type n, const size_type m_l, const size_type n_l, const size_type nnz=30, const size_type noz=10)
void init (const size_type m, const size_type n, const size_type m_l, const size_type n_l, graph_ptrtype const &graph)
void resize (size_type m, size_type n, bool)
void fill (pattern_type const &patt)
void clear ()
void zero ()
void zero (size_type start1, size_type stop1, size_type start2, size_type stop2)
void close () const
bool closed () const
real_type l1Norm () const
real_type linftyNorm () const
void set (const size_type i, const size_type j, const value_type &value)
void add (const size_type i, const size_type j, const value_type &value)
void addMatrix (const ublas::matrix< value_type > &dm, const std::vector< size_type > &rows, const std::vector< size_type > &cols)
void addMatrix (int *rows, int nrows, int *cols, int ncols, value_type *data)
void addMatrix (const ublas::matrix< value_type > &dm, const std::vector< size_type > &dof_indices)
void addMatrix (const T a, MatrixSparse< T > &X)
void scale (T const a)
void transpose (MatrixSparse< value_type > &Mt) const
virtual void symmetricPart (MatrixSparse< value_type > &Ms) const
Mat mat () const
void printMatlab (const std::string name="NULL") const
value_type energy (Vector< value_type > const &__v, Vector< value_type > const &__u, bool transpose=false) const
void zeroRows (std::vector< int > const &rows, std::vector< value_type > const &values, Vector< value_type > &rhs, Context const &on_context)
void updateBlockMat (boost::shared_ptr< MatrixSparse< T > > m, size_type start_i, size_type start_j)

Typedefs

typedef super::value_type value_type
typedef super::real_type real_type
typedef std::vector< std::set
< size_type > > 
pattern_type
typedef super::graph_type graph_type
typedef super::graph_ptrtype graph_ptrtype
static const bool is_row_major = true

Detailed Description

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

Wrapper for petsc matrices.

Petsc matrix. 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::MatrixPetsc< T >::MatrixPetsc ( ) [inline]

Constructor; initializes the matrix to be empty, without any structure, i.e. the matrix is not usable at all. This constructor is therefore only useful for matrices which are members of a class. All other matrices should be created at a point in the data flow where all necessary information is available.

You have to initialize the matrix before usage with init(...).

template<typename T >
Feel::MatrixPetsc< T >::MatrixPetsc ( Mat  m) [inline]

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

References Feel::MatrixSparse< T >::setInitialized().

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

Destructor. Free all memory, but do not release the memory of the sparsity structure.


Member Function Documentation

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

Add value to the element (i,j). Throws an error if the entry does not exist. Still, it is allowed to store zero values in non-existent fields.

Implements Feel::MatrixSparse< T >.

template<typename T >
void Feel::MatrixPetsc< T >::addMatrix ( const ublas::matrix< value_type > &  dm,
const std::vector< size_type > &  rows,
const std::vector< size_type > &  cols 
) [virtual]

Add the full matrix to the Petsc matrix. This is useful for adding an element matrix at assembly time

Implements Feel::MatrixSparse< T >.

Referenced by Feel::MatrixPetsc< T >::addMatrix().

template<typename T >
void Feel::MatrixPetsc< T >::addMatrix ( int *  rows,
int  nrows,
int *  cols,
int  ncols,
value_type *  data 
) [virtual]

Add the full matrix to the Petsc matrix. This is useful for adding an element matrix at assembly time

Implements Feel::MatrixSparse< T >.

template<typename T>
void Feel::MatrixPetsc< T >::addMatrix ( const ublas::matrix< value_type > &  dm,
const std::vector< size_type > &  dof_indices 
) [inline, virtual]

Same, but assumes the row and column maps are the same. Thus the matrix dm must be square.

Implements Feel::MatrixSparse< T >.

References Feel::MatrixPetsc< T >::addMatrix().

template<typename T>
void Feel::MatrixPetsc< T >::addMatrix ( const T  a,
MatrixSparse< T > &  X 
) [inline, virtual]

Add a Sparse matrix X, scaled with a, to this, stores the result in this: $\texttt{this} = a*X + \texttt{this} $. Use this with caution, the sparse matrices need to have the same nonzero pattern, otherwise PETSc will crash! It is advisable to not only allocate appropriate memory with init() , but also explicitly zero the terms of this whenever you add a non-zero value to X. Note: X will be closed, if not already done, before performing any work.

Implements Feel::MatrixSparse< T >.

References Feel::MatrixPetsc< T >::close(), Feel::MatrixSparse< T >::size1(), and Feel::MatrixSparse< T >::size2().

template<typename T >
void Feel::MatrixPetsc< T >::clear ( ) [virtual]

Release all memory and return to a state just like after having called the default constructor.

Implements Feel::MatrixSparse< T >.

template<typename T >
void Feel::MatrixPetsc< T >::close ( ) const [inline, virtual]

Call the Petsc assemble routines. sends necessary messages to other processors

Implements Feel::MatrixSparse< T >.

Referenced by Feel::MatrixPetsc< T >::addMatrix(), and Feel::SolverLinearPetsc< T >::solve().

template<typename T >
bool Feel::MatrixPetsc< T >::closed ( ) const [inline, virtual]

see if Petsc matrix has been closed and fully assembled yet

Implements Feel::MatrixSparse< T >.

template<typename T >
MatrixPetsc< T >::value_type Feel::MatrixPetsc< T >::energy ( Vector< value_type > const &  __v,
Vector< value_type > const &  __u,
bool  transpose = false 
) const
template<typename T >
void Feel::MatrixPetsc< T >::init ( const size_type  m,
const size_type  n,
const size_type  m_l,
const size_type  n_l,
const size_type  nnz = 30,
const size_type  noz = 10 
) [virtual]

Initialize a Petsc matrix that is of global dimension $ m \times n $ with local dimensions $ m_l \times n_l $. nnz is the number of on-processor nonzeros per row (defaults to 30). noz is the number of on-processor nonzeros per row (defaults to 30).

n_nz, PETSC_NULL, n_oz, PETSC_NULL, &_M_mat);

Implements Feel::MatrixSparse< T >.

Referenced by Feel::MatrixPetsc< T >::resize().

template<typename T >
void Feel::MatrixPetsc< T >::init ( const size_type  m,
const size_type  n,
const size_type  m_l,
const size_type  n_l,
graph_ptrtype const &  graph 
) [virtual]

Initialize using sparsity structure computed by dof_map.

Implements Feel::MatrixSparse< T >.

template<typename T >
MatrixPetsc< T >::real_type Feel::MatrixPetsc< T >::l1Norm ( ) const [inline, virtual]

Return the l1-norm of the matrix, that is $|M|_1=max_{all columns j}\sum_{all rows i} |M_ij|$, (max. sum of columns).

This is the natural matrix norm that is compatible to the l1-norm for vectors, i.e. $|Mv|_1\leq |M|_1 |v|_1$.

Implements Feel::MatrixSparse< T >.

template<typename T >
MatrixPetsc< T >::real_type Feel::MatrixPetsc< T >::linftyNorm ( ) const [inline, virtual]

Return the linfty-norm of the matrix, that is

$|M|_\infty=max_{all rows i}\sum_{all columns j} |M_ij|$,

(max. sum of rows). This is the natural matrix norm that is compatible to the linfty-norm of vectors, i.e. $|Mv|_\infty \leq |M|_\infty |v|_\infty$.

Implements Feel::MatrixSparse< T >.

template<typename T>
Mat Feel::MatrixPetsc< T >::mat ( ) const [inline]

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

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

template<typename T >
MatrixPetsc< T >::value_type Feel::MatrixPetsc< T >::operator() ( const size_type  i,
const size_type  j 
) const [inline, virtual]

Return the value of the entry (i,j). This may be an expensive operation and you should always take care where to call this function. In order to avoid abuse, this function throws an exception if the required element does not exist in the matrix.

In case you want a function that returns zero instead (for entries that are not in the sparsity pattern of the matrix), use the el function.

Implements Feel::MatrixSparse< T >.

template<typename T >
MatrixPetsc< T > & Feel::MatrixPetsc< T >::operator= ( MatrixSparse< value_type > const &  M) [virtual]

create a PETSc matrix which is a copy of M

Parameters:
Mthe matrix to copy

Implements Feel::MatrixSparse< T >.

References Feel::MatrixPetsc< T >::mat().

template<typename T >
void Feel::MatrixPetsc< T >::printMatlab ( const std::string  name = "NULL") const [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.

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::MatrixSparse< T >.

template<typename T>
void Feel::MatrixPetsc< T >::resize ( size_type  m,
size_type  n,
bool   
) [inline]
template<typename T >
size_type Feel::MatrixPetsc< T >::rowStart ( ) const [inline, virtual]

return row_start, the index of the first matrix row stored on this processor

Implements Feel::MatrixSparse< T >.

template<typename T >
size_type Feel::MatrixPetsc< T >::rowStop ( ) const [inline, virtual]

return row_stop, the index of the last matrix row (+1) stored on this processor

Implements Feel::MatrixSparse< T >.

template<typename T>
void Feel::MatrixPetsc< T >::scale ( T const  a) [virtual]

scale the matrix by the factor a

Parameters:
ascaling factor

Implements Feel::MatrixSparse< T >.

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

Set the element (i,j) to value. Throws an error if the entry does not exist. Still, it is allowed to store zero values in non-existent fields.

Implements Feel::MatrixSparse< T >.

template<typename T >
size_type Feel::MatrixPetsc< T >::size1 ( ) const [inline, virtual]
Returns:
m, the row-dimension of the matrix where the marix is $ M \times N $.

Implements Feel::MatrixSparse< T >.

Referenced by Feel::MatrixPetsc< T >::updateBlockMat().

template<typename T >
size_type Feel::MatrixPetsc< T >::size2 ( ) const [inline, virtual]
Returns:
n, the column-dimension of the matrix where the marix is $ M \times N $.

Implements Feel::MatrixSparse< T >.

template<typename T >
void Feel::MatrixPetsc< T >::symmetricPart ( MatrixSparse< value_type > &  Ms) const [virtual]

Returns the symmetric part of the matrix

Reimplemented from Feel::MatrixSparse< T >.

template<typename T >
void Feel::MatrixPetsc< T >::transpose ( MatrixSparse< value_type > &  Mt) const [virtual]

Returns the transpose of a matrix

Parameters:
Mthe matrix to transpose
Mtthe matrix transposed

Implements Feel::MatrixSparse< T >.

template<typename T>
void Feel::MatrixPetsc< T >::updateBlockMat ( boost::shared_ptr< MatrixSparse< T > >  m,
size_type  start_i,
size_type  start_j 
) [virtual]

update a block matrix

Implements Feel::MatrixSparse< T >.

References Feel::MatrixPetsc< T >::size1().

template<typename T >
void Feel::MatrixPetsc< T >::zero ( ) [virtual]

Set all entries to 0. This method retains sparsity structure.

Implements Feel::MatrixSparse< T >.

template<typename T >
void Feel::MatrixPetsc< T >::zero ( size_type  start1,
size_type  stop1,
size_type  start2,
size_type  stop2 
) [virtual]

Set all entries to 0 in the range [start1-stop1,start2-stop2]. This method retains sparsity structure.

Implements Feel::MatrixSparse< T >.

template<typename T >
void Feel::MatrixPetsc< T >::zeroRows ( std::vector< int > const &  rows,
std::vector< value_type > const &  values,
Vector< value_type > &  rhs,
Context const &  on_context 
) [virtual]

eliminate row without change pattern, and put 1 on the diagonal entry

Warning:
if the matrix was symmetric before this operation, it won't be afterwards. So use the proper solver (nonsymmetric)

Implements Feel::MatrixSparse< T >.

References Feel::Vector< T >::add(), Feel::ON_ELIMINATION_KEEP_DIAGONAL, Feel::Vector< T >::set(), and Feel::VectorPetsc< T >::vec().