PETScMatrix.h¶
Note
The documentation on this page was automatically extracted from the DOLFIN C++ code and may need to be edited or expanded.
-
class
PETScMatrix
¶ Parent class(es)
This class provides a simple matrix class based on PETSc. It is a wrapper for a PETSc matrix pointer (Mat) implementing the GenericMatrix interface.
The interface is intentionally simple. For advanced usage, access the PETSc Mat pointer using the function mat() and use the standard PETSc interface.
-
PETScMatrix
()¶ Create empty matrix
-
explicit
PETScMatrix
(Mat A)¶ Create a wrapper around a PETSc Mat pointer
-
PETScMatrix
(const PETScMatrix &A)¶ Copy constructor
-
void
init
(const TensorLayout &tensor_layout)¶ Initialize zero tensor using tensor layout
-
bool
empty
() const¶ Return true if empty
-
std::size_t
size
(std::size_t dim) const¶ Return size of given dimension
-
std::pair<std::size_t, std::size_t>
local_range
(std::size_t dim) const¶ Return local ownership range
-
std::size_t
nnz
() const¶ Return number of non-zero entries in matrix (collective)
-
void
zero
()¶ Set all entries to zero and keep any sparse structure
-
void
apply
(std::string mode)¶ Finalize assembly of tensor. The following values are recognized for the mode parameter:
add - corresponds to PETSc MatAssemblyBegin+End(MAT_FINAL_ASSEMBLY) insert - corresponds to PETSc MatAssemblyBegin+End(MAT_FINAL_ASSEMBLY) flush - corresponds to PETSc MatAssemblyBegin+End(MAT_FLUSH_ASSEMBLY)
-
MPI_Comm
mpi_comm
() const¶ Return MPI communicator
-
std::string
str
(bool verbose) const¶ Return informal string representation (pretty-print)
-
std::shared_ptr<GenericMatrix>
copy
() const¶ Return copy of matrix
-
void
init_vector
(GenericVector &z, std::size_t dim) const¶ Initialize vector z to be compatible with the matrix-vector product y = Ax. In the parallel case, both size and layout are important.
- Arguments
- dim (std::size_t)
- The dimension (axis): dim = 0 –> z = y, dim = 1 –> z = x
-
void
get
(double *block, std::size_t m, const dolfin::la_index *rows, std::size_t n, const dolfin::la_index *cols) const¶ Get block of values
-
void
set
(const double *block, std::size_t m, const dolfin::la_index *rows, std::size_t n, const dolfin::la_index *cols)¶ Set block of values using global indices
-
void
set_local
(const double *block, std::size_t m, const dolfin::la_index *rows, std::size_t n, const dolfin::la_index *cols)¶ Set block of values using local indices
-
void
add
(const double *block, std::size_t m, const dolfin::la_index *rows, std::size_t n, const dolfin::la_index *cols)¶ Add block of values using global indices
-
void
add_local
(const double *block, std::size_t m, const dolfin::la_index *rows, std::size_t n, const dolfin::la_index *cols)¶ Add block of values using local indices
-
void
axpy
(double a, const GenericMatrix &A, bool same_nonzero_pattern)¶ Add multiple of given matrix (AXPY operation)
-
double
norm
(std::string norm_type) const¶ Return norm of matrix
-
void
getrow
(std::size_t row, std::vector<std::size_t> &columns, std::vector<double> &values) const¶ Get non-zero values of given row
-
void
setrow
(std::size_t row, const std::vector<std::size_t> &columns, const std::vector<double> &values)¶ Set values for given row
-
void
zero
(std::size_t m, const dolfin::la_index *rows)¶ Set given rows (global row indices) to zero
-
void
zero_local
(std::size_t m, const dolfin::la_index *rows)¶ Set given rows (local row indices) to zero
-
void
ident
(std::size_t m, const dolfin::la_index *rows)¶ Set given rows (global row indices) to identity matrix
-
void
ident_local
(std::size_t m, const dolfin::la_index *rows)¶ Set given rows (local row indices) to identity matrix
-
void
get_diagonal
(GenericVector &x) const¶ Get diagonal of a matrix
-
void
set_diagonal
(const GenericVector &x)¶ Set diagonal of a matrix
-
const PETScMatrix &
operator*=
(double a)¶ Multiply matrix by given number
-
const PETScMatrix &
operator/=
(double a)¶ Divide matrix by given number
-
const GenericMatrix &
operator=
(const GenericMatrix &A)¶ Assignment operator
-
bool
is_symmetric
(double tol) const¶ Test if matrix is symmetric
-
GenericLinearAlgebraFactory &
factory
() const¶ Return linear algebra backend factory
-
void
set_options_prefix
(std::string options_prefix)¶ Sets the prefix used by PETSc when searching the options database
-
std::string
get_options_prefix
() const¶ Returns the prefix used by PETSc when searching the options database
-
const PETScMatrix &
operator=
(const PETScMatrix &A)¶ Assignment operator
-
void
set_nullspace
(const VectorSpaceBasis &nullspace)¶ Attach nullspace to matrix
-
void
binary_dump
(std::string file_name) const¶ Dump matrix to PETSc binary format
-