libMesh
Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Attributes | List of all members
libMesh::PetscMatrix< T > Class Template Referencefinal

This class provides a nice interface to the PETSc C-based data structures for parallel, sparse matrices. More...

#include <petsc_matrix.h>

Inheritance diagram for libMesh::PetscMatrix< T >:
[legend]

Public Member Functions

 PetscMatrix (const Parallel::Communicator &comm_in)
 Constructor; initializes the matrix to be empty, without any structure, i.e. More...
 
 PetscMatrix (Mat m, const Parallel::Communicator &comm_in)
 Constructor. More...
 
 PetscMatrix (PetscMatrix &&)=delete
 This class manages a C-style struct (Mat) manually, so we don't want to allow any automatic copy/move functions to be generated, and we can't default the destructor. More...
 
 PetscMatrix (const PetscMatrix &)=delete
 
PetscMatrixoperator= (const PetscMatrix &)=delete
 
PetscMatrixoperator= (PetscMatrix &&)=delete
 
virtual ~PetscMatrix ()
 
void set_matrix_type (PetscMatrixType mat_type)
 
virtual void init (const numeric_index_type m, const numeric_index_type n, const numeric_index_type m_l, const numeric_index_type n_l, const numeric_index_type nnz=30, const numeric_index_type noz=10, const numeric_index_type blocksize=1) override
 Initialize SparseMatrix with the specified sizes. More...
 
void init (const numeric_index_type m, const numeric_index_type n, const numeric_index_type m_l, const numeric_index_type n_l, const std::vector< numeric_index_type > &n_nz, const std::vector< numeric_index_type > &n_oz, const numeric_index_type blocksize=1)
 Initialize a PETSc matrix. More...
 
virtual void init () override
 Initialize this matrix using the sparsity structure computed by dof_map. More...
 
void update_preallocation_and_zero ()
 Update the sparsity pattern based on dof_map, and set the matrix to zero. More...
 
virtual void clear () override
 Restores the SparseMatrix<T> to a pristine state. More...
 
virtual void zero () override
 Set all entries to 0. More...
 
virtual void zero_rows (std::vector< numeric_index_type > &rows, T diag_value=0.0) override
 Sets all row entries to 0 then puts diag_value in the diagonal entry. More...
 
virtual void close () override
 Calls the SparseMatrix's internal assembly routines, ensuring that the values are consistent across processors. More...
 
virtual void flush () override
 For PETSc matrix , this function is similar to close but without shrinking memory. More...
 
virtual numeric_index_type m () const override
 
virtual numeric_index_type n () const override
 
virtual numeric_index_type row_start () const override
 
virtual numeric_index_type row_stop () const override
 
virtual void set (const numeric_index_type i, const numeric_index_type j, const T value) override
 Set the element (i,j) to value. More...
 
virtual void add (const numeric_index_type i, const numeric_index_type j, const T value) override
 Add value to the element (i,j). More...
 
virtual void add_matrix (const DenseMatrix< T > &dm, const std::vector< numeric_index_type > &rows, const std::vector< numeric_index_type > &cols) override
 Add the full matrix dm to the SparseMatrix. More...
 
virtual void add_matrix (const DenseMatrix< T > &dm, const std::vector< numeric_index_type > &dof_indices) override
 Same as add_matrix, but assumes the row and column maps are the same. More...
 
virtual void add_block_matrix (const DenseMatrix< T > &dm, const std::vector< numeric_index_type > &brows, const std::vector< numeric_index_type > &bcols) override
 Add the full matrix dm to the SparseMatrix. More...
 
virtual void add_block_matrix (const DenseMatrix< T > &dm, const std::vector< numeric_index_type > &dof_indices) override
 Same as add_block_matrix(), but assumes the row and column maps are the same. More...
 
virtual void add (const T a, const SparseMatrix< T > &X) override
 Compute A += a*X for scalar a, matrix X. More...
 
virtual T operator() (const numeric_index_type i, const numeric_index_type j) const override
 
virtual Real l1_norm () const override
 
virtual Real linfty_norm () const override
 
virtual bool closed () const override
 
virtual void print_personal (std::ostream &os=libMesh::out) const override
 Print the contents of the matrix to the screen with the PETSc viewer. More...
 
virtual void print_matlab (const std::string &name="") const override
 Print the contents of the matrix in Matlab's sparse matrix format. More...
 
virtual void get_diagonal (NumericVector< T > &dest) const override
 Copies the diagonal part of the matrix into dest. More...
 
virtual void get_transpose (SparseMatrix< T > &dest) const override
 Copies the transpose of the matrix into dest, which may be *this. More...
 
void swap (PetscMatrix< T > &)
 Swaps the internal data pointers of two PetscMatrices, no actual values are swapped. More...
 
Mat mat ()
 
virtual bool initialized () const
 
void attach_dof_map (const DofMap &dof_map)
 Get a pointer to the DofMap to use. More...
 
virtual bool need_full_sparsity_pattern () const
 
virtual void update_sparsity_pattern (const SparsityPattern::Graph &)
 Updates the matrix sparsity pattern. More...
 
void print (std::ostream &os=libMesh::out, const bool sparse=false) const
 Print the contents of the matrix to the screen in a uniform style, regardless of matrix/solver package being used. More...
 
virtual void create_submatrix (SparseMatrix< T > &submatrix, const std::vector< numeric_index_type > &rows, const std::vector< numeric_index_type > &cols) const
 This function creates a matrix called "submatrix" which is defined by the row and column indices given in the "rows" and "cols" entries. More...
 
virtual void reinit_submatrix (SparseMatrix< T > &submatrix, const std::vector< numeric_index_type > &rows, const std::vector< numeric_index_type > &cols) const
 This function is similar to the one above, but it allows you to reuse the existing sparsity pattern of "submatrix" instead of reallocating it again. More...
 
void vector_mult (NumericVector< T > &dest, const NumericVector< T > &arg) const
 Multiplies the matrix by the NumericVector arg and stores the result in NumericVector dest. More...
 
void vector_mult_add (NumericVector< T > &dest, const NumericVector< T > &arg) const
 Multiplies the matrix by the NumericVector arg and adds the result to the NumericVector dest. More...
 
const Parallel::Communicatorcomm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Static Public Member Functions

static std::unique_ptr< SparseMatrix< T > > build (const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
 Builds a SparseMatrix<T> using the linear solver package specified by solver_package. More...
 
static std::string get_info ()
 Gets a string containing the reference information. More...
 
static void print_info (std::ostream &out=libMesh::out)
 Prints the reference information, by default to libMesh::out. More...
 
static unsigned int n_objects ()
 Prints the number of outstanding (created, but not yet destroyed) objects. More...
 
static void enable_print_counter_info ()
 Methods to enable/disable the reference counter output from print_info() More...
 
static void disable_print_counter_info ()
 

Protected Types

typedef std::map< std::string, std::pair< unsigned int, unsigned int > > Counts
 Data structure to log the information. More...
 

Protected Member Functions

virtual void _get_submatrix (SparseMatrix< T > &submatrix, const std::vector< numeric_index_type > &rows, const std::vector< numeric_index_type > &cols, const bool reuse_submatrix) const override
 This function either creates or re-initializes a matrix called submatrix which is defined by the indices given in the rows and cols vectors. More...
 
void increment_constructor_count (const std::string &name)
 Increments the construction counter. More...
 
void increment_destructor_count (const std::string &name)
 Increments the destruction counter. More...
 

Protected Attributes

DofMap const * _dof_map
 The DofMap object associated with this object. More...
 
bool _is_initialized
 Flag indicating whether or not the matrix has been initialized. More...
 
const Parallel::Communicator_communicator
 

Static Protected Attributes

static Counts _counts
 Actually holds the data. More...
 
static Threads::atomic< unsigned int > _n_objects
 The number of objects. More...
 
static Threads::spin_mutex _mutex
 Mutual exclusion object to enable thread-safe reference counting. More...
 
static bool _enable_print_counter
 Flag to control whether reference count information is printed when print_info is called. More...
 

Private Attributes

Mat _mat
 PETSc matrix datatype to store values. More...
 
bool _destroy_mat_on_exit
 This boolean value should only be set to false for the constructor which takes a PETSc Mat object. More...
 
PetscMatrixType _mat_type
 

Detailed Description

template<typename T>
class libMesh::PetscMatrix< T >

This class provides a nice interface to the PETSc C-based data structures for parallel, sparse matrices.

All overridden virtual functions are documented in sparse_matrix.h.

Author
Benjamin S. Kirk
Date
2002 SparseMatrix interface to PETSc Mat.

Definition at line 78 of file petsc_matrix.h.

Member Typedef Documentation

◆ Counts

typedef std::map<std::string, std::pair<unsigned int, unsigned int> > libMesh::ReferenceCounter::Counts
protectedinherited

Data structure to log the information.

The log is identified by the class name.

Definition at line 117 of file reference_counter.h.

Constructor & Destructor Documentation

◆ PetscMatrix() [1/4]

template<typename T>
libMesh::PetscMatrix< T >::PetscMatrix ( const Parallel::Communicator comm_in)
explicit

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

◆ PetscMatrix() [2/4]

template<typename T>
libMesh::PetscMatrix< T >::PetscMatrix ( Mat  m,
const Parallel::Communicator comm_in 
)
explicit

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.

◆ PetscMatrix() [3/4]

template<typename T>
libMesh::PetscMatrix< T >::PetscMatrix ( PetscMatrix< T > &&  )
delete

This class manages a C-style struct (Mat) manually, so we don't want to allow any automatic copy/move functions to be generated, and we can't default the destructor.

◆ PetscMatrix() [4/4]

template<typename T>
libMesh::PetscMatrix< T >::PetscMatrix ( const PetscMatrix< T > &  )
delete

◆ ~PetscMatrix()

template<typename T>
virtual libMesh::PetscMatrix< T >::~PetscMatrix ( )
virtual

Member Function Documentation

◆ _get_submatrix()

template<typename T>
virtual void libMesh::PetscMatrix< T >::_get_submatrix ( SparseMatrix< T > &  submatrix,
const std::vector< numeric_index_type > &  rows,
const std::vector< numeric_index_type > &  cols,
const bool  reuse_submatrix 
) const
overrideprotectedvirtual

This function either creates or re-initializes a matrix called submatrix which is defined by the indices given in the rows and cols vectors.

This function is implemented in terms of MatGetSubMatrix(). The reuse_submatrix parameter determines whether or not PETSc will treat submatrix as one which has already been used (had memory allocated) or as a new matrix.

Reimplemented from libMesh::SparseMatrix< T >.

◆ add() [1/2]

template<typename T>
virtual void libMesh::PetscMatrix< T >::add ( const numeric_index_type  i,
const numeric_index_type  j,
const T  value 
)
overridevirtual

Add value to the element (i,j).

Throws an error if the entry does not exist. Zero values can be "added" to non-existent entries.

Implements libMesh::SparseMatrix< T >.

◆ add() [2/2]

template<typename T>
virtual void libMesh::PetscMatrix< T >::add ( const T  a,
const SparseMatrix< T > &  X 
)
overridevirtual

Compute A += a*X for scalar a, matrix X.

Note
The matrices A and X 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.
X will be closed, if not already done, before performing any work.

Implements libMesh::SparseMatrix< T >.

◆ add_block_matrix() [1/2]

template<typename T>
virtual void libMesh::PetscMatrix< T >::add_block_matrix ( const DenseMatrix< T > &  dm,
const std::vector< numeric_index_type > &  brows,
const std::vector< numeric_index_type > &  bcols 
)
overridevirtual

Add the full matrix dm to the SparseMatrix.

This is useful for adding an element matrix at assembly time. The matrix is assumed blocked, and brow, bcol correspond to the block row and column indices.

Reimplemented from libMesh::SparseMatrix< T >.

Referenced by libMesh::PetscMatrix< T >::add_block_matrix().

◆ add_block_matrix() [2/2]

template<typename T>
virtual void libMesh::PetscMatrix< T >::add_block_matrix ( const DenseMatrix< T > &  dm,
const std::vector< numeric_index_type > &  dof_indices 
)
overridevirtual

Same as add_block_matrix(), but assumes the row and column maps are the same.

Thus the matrix dm must be square.

Reimplemented from libMesh::SparseMatrix< T >.

Definition at line 191 of file petsc_matrix.h.

References libMesh::PetscMatrix< T >::add_block_matrix().

193  { this->add_block_matrix (dm, dof_indices, dof_indices); }
virtual void add_block_matrix(const DenseMatrix< T > &dm, const std::vector< numeric_index_type > &brows, const std::vector< numeric_index_type > &bcols) override
Add the full matrix dm to the SparseMatrix.

◆ add_matrix() [1/2]

template<typename T>
virtual void libMesh::PetscMatrix< T >::add_matrix ( const DenseMatrix< T > &  dm,
const std::vector< numeric_index_type > &  rows,
const std::vector< numeric_index_type > &  cols 
)
overridevirtual

Add the full matrix dm to the SparseMatrix.

This is useful for adding an element matrix at assembly time.

Implements libMesh::SparseMatrix< T >.

◆ add_matrix() [2/2]

template<typename T>
virtual void libMesh::PetscMatrix< T >::add_matrix ( const DenseMatrix< T > &  dm,
const std::vector< numeric_index_type > &  dof_indices 
)
overridevirtual

Same as add_matrix, but assumes the row and column maps are the same.

Thus the matrix dm must be square.

Implements libMesh::SparseMatrix< T >.

◆ attach_dof_map()

template<typename T>
void libMesh::SparseMatrix< T >::attach_dof_map ( const DofMap dof_map)
inherited

Get a pointer to the DofMap to use.

Definition at line 109 of file sparse_matrix.h.

110  { _dof_map = &dof_map; }
DofMap const * _dof_map
The DofMap object associated with this object.

◆ build()

template<typename T>
static std::unique_ptr<SparseMatrix<T> > libMesh::SparseMatrix< T >::build ( const Parallel::Communicator comm,
const SolverPackage  solver_package = libMesh::default_solver_package() 
)
staticinherited

Builds a SparseMatrix<T> using the linear solver package specified by solver_package.

◆ clear()

template<typename T>
virtual void libMesh::PetscMatrix< T >::clear ( )
overridevirtual

Restores the SparseMatrix<T> to a pristine state.

Implements libMesh::SparseMatrix< T >.

◆ close()

template<typename T>
virtual void libMesh::PetscMatrix< T >::close ( )
overridevirtual

Calls the SparseMatrix's internal assembly routines, ensuring that the values are consistent across processors.

Implements libMesh::SparseMatrix< T >.

◆ closed()

template<typename T>
virtual bool libMesh::PetscMatrix< T >::closed ( ) const
overridevirtual
Returns
true if the matrix has been assembled.

Implements libMesh::SparseMatrix< T >.

◆ comm()

const Parallel::Communicator& libMesh::ParallelObject::comm ( ) const
inherited

◆ create_submatrix()

template<typename T>
virtual void libMesh::SparseMatrix< T >::create_submatrix ( SparseMatrix< T > &  submatrix,
const std::vector< numeric_index_type > &  rows,
const std::vector< numeric_index_type > &  cols 
) const
virtualinherited

This function creates a matrix called "submatrix" which is defined by the row and column indices given in the "rows" and "cols" entries.

Currently this operation is only defined for the PetscMatrix type.

Definition at line 354 of file sparse_matrix.h.

357  {
358  this->_get_submatrix(submatrix,
359  rows,
360  cols,
361  false); // false means DO NOT REUSE submatrix
362  }
virtual void _get_submatrix(SparseMatrix< T > &, const std::vector< numeric_index_type > &, const std::vector< numeric_index_type > &, const bool) const
Protected implementation of the create_submatrix and reinit_submatrix routines.

◆ disable_print_counter_info()

static void libMesh::ReferenceCounter::disable_print_counter_info ( )
staticinherited

◆ enable_print_counter_info()

static void libMesh::ReferenceCounter::enable_print_counter_info ( )
staticinherited

Methods to enable/disable the reference counter output from print_info()

◆ flush()

template<typename T>
virtual void libMesh::PetscMatrix< T >::flush ( )
overridevirtual

For PETSc matrix , this function is similar to close but without shrinking memory.

This is useful when we want to switch between ADD_VALUES and INSERT_VALUES. close should be called before using the matrix.

Reimplemented from libMesh::SparseMatrix< T >.

◆ get_diagonal()

template<typename T>
virtual void libMesh::PetscMatrix< T >::get_diagonal ( NumericVector< T > &  dest) const
overridevirtual

Copies the diagonal part of the matrix into dest.

Implements libMesh::SparseMatrix< T >.

◆ get_info()

static std::string libMesh::ReferenceCounter::get_info ( )
staticinherited

Gets a string containing the reference information.

◆ get_transpose()

template<typename T>
virtual void libMesh::PetscMatrix< T >::get_transpose ( SparseMatrix< T > &  dest) const
overridevirtual

Copies the transpose of the matrix into dest, which may be *this.

Implements libMesh::SparseMatrix< T >.

◆ increment_constructor_count()

void libMesh::ReferenceCounter::increment_constructor_count ( const std::string &  name)
protectedinherited

Increments the construction counter.

Should be called in the constructor of any derived class that will be reference counted.

Definition at line 181 of file reference_counter.h.

References libMesh::ReferenceCounter::_counts, libMesh::Quality::name(), and libMesh::Threads::spin_mtx.

Referenced by libMesh::ReferenceCountedObject< RBParametrized >::ReferenceCountedObject().

182 {
183  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
184  std::pair<unsigned int, unsigned int> & p = _counts[name];
185 
186  p.first++;
187 }
std::string name(const ElemQuality q)
static Counts _counts
Actually holds the data.
spin_mutex spin_mtx
A convenient spin mutex object which can be used for obtaining locks.

◆ increment_destructor_count()

void libMesh::ReferenceCounter::increment_destructor_count ( const std::string &  name)
protectedinherited

Increments the destruction counter.

Should be called in the destructor of any derived class that will be reference counted.

Definition at line 194 of file reference_counter.h.

References libMesh::ReferenceCounter::_counts, libMesh::Quality::name(), and libMesh::Threads::spin_mtx.

Referenced by libMesh::ReferenceCountedObject< RBParametrized >::~ReferenceCountedObject().

195 {
196  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
197  std::pair<unsigned int, unsigned int> & p = _counts[name];
198 
199  p.second++;
200 }
std::string name(const ElemQuality q)
static Counts _counts
Actually holds the data.
spin_mutex spin_mtx
A convenient spin mutex object which can be used for obtaining locks.

◆ init() [1/3]

template<typename T>
virtual void libMesh::PetscMatrix< T >::init ( const numeric_index_type  m,
const numeric_index_type  n,
const numeric_index_type  m_l,
const numeric_index_type  n_l,
const numeric_index_type  nnz = 30,
const numeric_index_type  noz = 10,
const numeric_index_type  blocksize = 1 
)
overridevirtual

Initialize SparseMatrix with the specified sizes.

Parameters
mThe global number of rows.
nThe global number of columns.
m_lThe local number of rows.
n_lThe local number of columns.
nnzThe number of on-diagonal nonzeros per row (defaults to 30).
nozThe number of off-diagonal nonzeros per row (defaults to 10).
blocksizeOptional value indicating dense coupled blocks for systems with multiple variables all of the same type.

Implements libMesh::SparseMatrix< T >.

◆ init() [2/3]

template<typename T>
void libMesh::PetscMatrix< T >::init ( const numeric_index_type  m,
const numeric_index_type  n,
const numeric_index_type  m_l,
const numeric_index_type  n_l,
const std::vector< numeric_index_type > &  n_nz,
const std::vector< numeric_index_type > &  n_oz,
const numeric_index_type  blocksize = 1 
)

Initialize a PETSc matrix.

Parameters
mThe global number of rows.
nThe global number of columns.
m_lThe local number of rows.
n_lThe local number of columns.
n_nzarray containing the number of nonzeros in each row of the DIAGONAL portion of the local submatrix.
n_ozArray containing the number of nonzeros in each row of the OFF-DIAGONAL portion of the local submatrix.
blocksizeOptional value indicating dense coupled blocks for systems with multiple variables all of the same type.

◆ init() [3/3]

template<typename T>
virtual void libMesh::PetscMatrix< T >::init ( )
overridevirtual

Initialize this matrix using the sparsity structure computed by dof_map.

Implements libMesh::SparseMatrix< T >.

◆ initialized()

template<typename T>
virtual bool libMesh::SparseMatrix< T >::initialized ( ) const
virtualinherited
Returns
true if the matrix has been initialized, false otherwise.

Definition at line 104 of file sparse_matrix.h.

104 { return _is_initialized; }
bool _is_initialized
Flag indicating whether or not the matrix has been initialized.

◆ l1_norm()

template<typename T>
virtual Real libMesh::PetscMatrix< T >::l1_norm ( ) const
overridevirtual
Returns
The $ \ell_1 $-norm of the matrix, that is the max column sum: $ |M|_1 = \max_{j} \sum_{i} |M_{ij}| $

This is the natural matrix norm that is compatible with the $ \ell_1 $-norm for vectors, i.e. $ |Mv|_1 \leq |M|_1 |v|_1 $. (cf. Haemmerlin-Hoffmann : Numerische Mathematik)

Implements libMesh::SparseMatrix< T >.

◆ linfty_norm()

template<typename T>
virtual Real libMesh::PetscMatrix< T >::linfty_norm ( ) const
overridevirtual
Returns
The $ \ell_{\infty} $-norm of the matrix, that is the max row sum:

$ |M|_{\infty} = \max_{i} \sum_{j} |M_{ij}| $

This is the natural matrix norm that is compatible to the $ \ell_{\infty} $-norm of vectors, i.e. $ |Mv|_{\infty} \leq |M|_{\infty} |v|_{\infty} $. (cf. Haemmerlin-Hoffmann : Numerische Mathematik)

Implements libMesh::SparseMatrix< T >.

◆ m()

template<typename T>
virtual numeric_index_type libMesh::PetscMatrix< T >::m ( ) const
overridevirtual
Returns
The row-dimension of the matrix.

Implements libMesh::SparseMatrix< T >.

◆ mat()

template<typename T>
Mat libMesh::PetscMatrix< T >::mat ( )
Returns
The raw PETSc matrix pointer.
Note
This is generally not required in user-level code.
Don't do anything crazy like calling LibMeshMatDestroy() on it, or very bad things will likely happen!

Definition at line 247 of file petsc_matrix.h.

References libMesh::PetscMatrix< T >::_mat.

247 { libmesh_assert (_mat); return _mat; }
Mat _mat
PETSc matrix datatype to store values.
Definition: petsc_matrix.h:271

◆ n()

template<typename T>
virtual numeric_index_type libMesh::PetscMatrix< T >::n ( ) const
overridevirtual
Returns
The column-dimension of the matrix.

Implements libMesh::SparseMatrix< T >.

◆ n_objects()

static unsigned int libMesh::ReferenceCounter::n_objects ( )
staticinherited

Prints the number of outstanding (created, but not yet destroyed) objects.

Definition at line 83 of file reference_counter.h.

References libMesh::ReferenceCounter::_n_objects.

84  { return _n_objects; }
static Threads::atomic< unsigned int > _n_objects
The number of objects.

◆ n_processors()

processor_id_type libMesh::ParallelObject::n_processors ( ) const
inherited
Returns
The number of processors in the group.

Definition at line 93 of file parallel_object.h.

References libMesh::ParallelObject::_communicator, and libMesh::Parallel::Communicator::size().

Referenced by libMesh::MeshBase::partition().

94  { return cast_int<processor_id_type>(_communicator.size()); }
processor_id_type size() const
Definition: communicator.h:175
const Parallel::Communicator & _communicator

◆ need_full_sparsity_pattern()

template<typename T>
virtual bool libMesh::SparseMatrix< T >::need_full_sparsity_pattern ( ) const
virtualinherited
Returns
true if this sparse matrix format needs to be fed the graph of the sparse matrix.

This is true for LaspackMatrix, but not PetscMatrix. In the case where the full graph is not required, we can efficiently approximate it to provide a good estimate of the required size of the sparse matrix.

Reimplemented in libMesh::EpetraMatrix< T >, and libMesh::LaspackMatrix< T >.

Definition at line 121 of file sparse_matrix.h.

122  { return false; }

◆ operator()()

template<typename T>
virtual T libMesh::PetscMatrix< T >::operator() ( const numeric_index_type  i,
const numeric_index_type  j 
) const
overridevirtual
Returns
A copy of matrix entry (i,j).
Note
This may be an expensive operation, and you should always be careful where you call this function.

Implements libMesh::SparseMatrix< T >.

◆ operator=() [1/2]

template<typename T>
PetscMatrix& libMesh::PetscMatrix< T >::operator= ( const PetscMatrix< T > &  )
delete

◆ operator=() [2/2]

template<typename T>
PetscMatrix& libMesh::PetscMatrix< T >::operator= ( PetscMatrix< T > &&  )
delete

◆ print()

template<typename T>
void libMesh::SparseMatrix< T >::print ( std::ostream &  os = libMesh::out,
const bool  sparse = false 
) const
inherited

Print the contents of the matrix to the screen in a uniform style, regardless of matrix/solver package being used.

Referenced by libMesh::EigenSparseMatrix< T >::print_personal(), and libMesh::LaspackMatrix< T >::print_personal().

◆ print_info()

static void libMesh::ReferenceCounter::print_info ( std::ostream &  out = libMesh::out)
staticinherited

Prints the reference information, by default to libMesh::out.

◆ print_matlab()

template<typename T>
virtual void libMesh::PetscMatrix< T >::print_matlab ( const std::string &  = "") const
overridevirtual

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 from libMesh::SparseMatrix< T >.

◆ print_personal()

template<typename T>
virtual void libMesh::PetscMatrix< T >::print_personal ( std::ostream &  os = libMesh::out) const
overridevirtual

Print the contents of the matrix to the screen with the PETSc viewer.

This function only allows printing to standard out since we have limited ourselves to one PETSc implementation for writing.

Implements libMesh::SparseMatrix< T >.

◆ processor_id()

processor_id_type libMesh::ParallelObject::processor_id ( ) const
inherited

◆ reinit_submatrix()

template<typename T>
virtual void libMesh::SparseMatrix< T >::reinit_submatrix ( SparseMatrix< T > &  submatrix,
const std::vector< numeric_index_type > &  rows,
const std::vector< numeric_index_type > &  cols 
) const
virtualinherited

This function is similar to the one above, but it allows you to reuse the existing sparsity pattern of "submatrix" instead of reallocating it again.

This should hopefully be more efficient if you are frequently extracting submatrices of the same size.

Definition at line 370 of file sparse_matrix.h.

373  {
374  this->_get_submatrix(submatrix,
375  rows,
376  cols,
377  true); // true means REUSE submatrix
378  }
virtual void _get_submatrix(SparseMatrix< T > &, const std::vector< numeric_index_type > &, const std::vector< numeric_index_type > &, const bool) const
Protected implementation of the create_submatrix and reinit_submatrix routines.

◆ row_start()

template<typename T>
virtual numeric_index_type libMesh::PetscMatrix< T >::row_start ( ) const
overridevirtual
Returns
The index of the first matrix row stored on this processor.

Implements libMesh::SparseMatrix< T >.

◆ row_stop()

template<typename T>
virtual numeric_index_type libMesh::PetscMatrix< T >::row_stop ( ) const
overridevirtual
Returns
The index of the last matrix row (+1) stored on this processor.

Implements libMesh::SparseMatrix< T >.

◆ set()

template<typename T>
virtual void libMesh::PetscMatrix< T >::set ( const numeric_index_type  i,
const numeric_index_type  j,
const T  value 
)
overridevirtual

Set the element (i,j) to value.

Throws an error if the entry does not exist. Zero values can be "stored" in non-existent fields.

Implements libMesh::SparseMatrix< T >.

◆ set_matrix_type()

template<typename T>
void libMesh::PetscMatrix< T >::set_matrix_type ( PetscMatrixType  mat_type)

◆ swap()

template<typename T>
void libMesh::PetscMatrix< T >::swap ( PetscMatrix< T > &  )

Swaps the internal data pointers of two PetscMatrices, no actual values are swapped.

◆ update_preallocation_and_zero()

template<typename T>
void libMesh::PetscMatrix< T >::update_preallocation_and_zero ( )

Update the sparsity pattern based on dof_map, and set the matrix to zero.

This is useful in cases where the sparsity pattern changes during a computation.

◆ update_sparsity_pattern()

template<typename T>
virtual void libMesh::SparseMatrix< T >::update_sparsity_pattern ( const SparsityPattern::Graph )
virtualinherited

Updates the matrix sparsity pattern.

When your SparseMatrix<T> implementation does not need this data, simply do not override this method.

Reimplemented in libMesh::EpetraMatrix< T >, and libMesh::LaspackMatrix< T >.

Definition at line 129 of file sparse_matrix.h.

129 {}

◆ vector_mult()

template<typename T>
void libMesh::SparseMatrix< T >::vector_mult ( NumericVector< T > &  dest,
const NumericVector< T > &  arg 
) const
inherited

Multiplies the matrix by the NumericVector arg and stores the result in NumericVector dest.

◆ vector_mult_add()

template<typename T>
void libMesh::SparseMatrix< T >::vector_mult_add ( NumericVector< T > &  dest,
const NumericVector< T > &  arg 
) const
inherited

Multiplies the matrix by the NumericVector arg and adds the result to the NumericVector dest.

◆ zero()

template<typename T>
virtual void libMesh::PetscMatrix< T >::zero ( )
overridevirtual

Set all entries to 0.

Implements libMesh::SparseMatrix< T >.

◆ zero_rows()

template<typename T>
virtual void libMesh::PetscMatrix< T >::zero_rows ( std::vector< numeric_index_type > &  rows,
diag_value = 0.0 
)
overridevirtual

Sets all row entries to 0 then puts diag_value in the diagonal entry.

Reimplemented from libMesh::SparseMatrix< T >.

Member Data Documentation

◆ _communicator

const Parallel::Communicator& libMesh::ParallelObject::_communicator
protectedinherited

◆ _counts

Counts libMesh::ReferenceCounter::_counts
staticprotectedinherited

◆ _destroy_mat_on_exit

template<typename T>
bool libMesh::PetscMatrix< T >::_destroy_mat_on_exit
private

This boolean value should only be set to false for the constructor which takes a PETSc Mat object.

Definition at line 277 of file petsc_matrix.h.

◆ _dof_map

template<typename T>
DofMap const* libMesh::SparseMatrix< T >::_dof_map
protectedinherited

The DofMap object associated with this object.

Definition at line 425 of file sparse_matrix.h.

Referenced by libMesh::SparseMatrix< Number >::attach_dof_map().

◆ _enable_print_counter

bool libMesh::ReferenceCounter::_enable_print_counter
staticprotectedinherited

Flag to control whether reference count information is printed when print_info is called.

Definition at line 141 of file reference_counter.h.

◆ _is_initialized

template<typename T>
bool libMesh::SparseMatrix< T >::_is_initialized
protectedinherited

Flag indicating whether or not the matrix has been initialized.

Definition at line 430 of file sparse_matrix.h.

Referenced by libMesh::SparseMatrix< Number >::initialized().

◆ _mat

template<typename T>
Mat libMesh::PetscMatrix< T >::_mat
private

PETSc matrix datatype to store values.

Definition at line 271 of file petsc_matrix.h.

Referenced by libMesh::PetscMatrix< T >::mat().

◆ _mat_type

template<typename T>
PetscMatrixType libMesh::PetscMatrix< T >::_mat_type
private

Definition at line 279 of file petsc_matrix.h.

◆ _mutex

Threads::spin_mutex libMesh::ReferenceCounter::_mutex
staticprotectedinherited

Mutual exclusion object to enable thread-safe reference counting.

Definition at line 135 of file reference_counter.h.

◆ _n_objects

Threads::atomic<unsigned int> libMesh::ReferenceCounter::_n_objects
staticprotectedinherited

The number of objects.

Print the reference count information when the number returns to 0.

Definition at line 130 of file reference_counter.h.

Referenced by libMesh::ReferenceCounter::n_objects(), libMesh::ReferenceCounter::ReferenceCounter(), and libMesh::ReferenceCounter::~ReferenceCounter().


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