28 #ifndef __PETSC_MATRIX_H 29 #define __PETSC_MATRIX_H 40 #include "GenericMatrix.h" 41 #include "PETScBaseMatrix.h" 48 class VectorSpaceBasis;
87 std::size_t
size(std::size_t dim)
const 91 std::pair<std::int64_t, std::int64_t>
local_range(std::size_t dim)
const 95 std::size_t
nnz()
const;
106 virtual void apply(std::string mode);
112 virtual std::string
str(
bool verbose)
const;
117 virtual std::shared_ptr<GenericMatrix>
copy()
const;
131 virtual void get(
double* block,
136 virtual void set(
const double* block,
141 virtual void set_local(
const double* block,
146 virtual void add(
const double* block,
151 virtual void add_local(
const double* block,
157 bool same_nonzero_pattern);
160 double norm(std::string norm_type)
const;
163 virtual void getrow(std::size_t row,
164 std::vector<std::size_t>& columns,
165 std::vector<double>& values)
const;
168 virtual void setrow(std::size_t row,
169 const std::vector<std::size_t>& columns,
170 const std::vector<double>& values);
243 MatNullSpace create_petsc_nullspace(
const VectorSpaceBasis& nullspace)
const;
246 static const std::map<std::string, NormType> norm_types;
virtual void ident_local(std::size_t m, const dolfin::la_index *rows)
Set given rows (local row indices) to identity matrix.
Definition: PETScMatrix.cpp:400
std::string get_options_prefix() const
Definition: PETScMatrix.cpp:623
virtual void set_diagonal(const GenericVector &x)
Set diagonal of a matrix.
Definition: PETScMatrix.cpp:492
virtual std::shared_ptr< GenericMatrix > copy() const
Return copy of matrix.
Definition: PETScMatrix.cpp:94
virtual void zero_local(std::size_t m, const dolfin::la_index *rows)
Set given rows (local row indices) to zero.
Definition: PETScMatrix.cpp:372
virtual void apply(std::string mode)
Definition: PETScMatrix.cpp:528
virtual void axpy(double a, const GenericMatrix &A, bool same_nonzero_pattern)
Add multiple of given matrix (AXPY operation)
Definition: PETScMatrix.cpp:277
virtual const PETScMatrix & operator/=(double a)
Divide matrix by given number.
Definition: PETScMatrix.cpp:590
void set_from_options()
Call PETSc function MatSetFromOptions on the PETSc Mat object.
Definition: PETScMatrix.cpp:631
Definition: PETScMatrix.h:58
virtual 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.
Definition: PETScMatrix.cpp:247
virtual bool is_symmetric(double tol) const
Test if matrix is symmetric.
Definition: PETScMatrix.cpp:603
std::size_t size(std::size_t dim) const
Return size of given dimension.
Definition: PETScMatrix.h:87
virtual void init_vector(GenericVector &z, std::size_t dim) const
Definition: PETScMatrix.h:127
bool empty() const
Return true if empty.
Definition: PETScMatrix.cpp:220
Definition: VectorSpaceBasis.h:33
virtual const GenericMatrix & operator=(const GenericMatrix &A)
Assignment operator.
Definition: PETScMatrix.cpp:597
virtual 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.
Definition: PETScMatrix.cpp:267
Definition: TensorLayout.h:41
Base class for LinearAlgebra factories.
Definition: GenericLinearAlgebraFactory.h:46
std::pair< std::int64_t, std::int64_t > local_range(std::size_t dim) const
Return local ownership range.
Definition: PETScMatrix.h:91
void binary_dump(std::string file_name) const
Dump matrix to PETSc binary format.
Definition: PETScMatrix.cpp:704
virtual std::string str(bool verbose) const
Return informal string representation (pretty-print)
Definition: PETScMatrix.cpp:720
std::size_t nnz() const
Return number of non-zero entries in matrix (collective)
Definition: PETScMatrix.cpp:568
virtual GenericLinearAlgebraFactory & factory() const
Return linear algebra backend factory.
Definition: PETScMatrix.cpp:612
virtual void ident(std::size_t m, const dolfin::la_index *rows)
Set given rows (global row indices) to identity matrix.
Definition: PETScMatrix.cpp:383
virtual 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.
Definition: PETScMatrix.cpp:257
virtual ~PETScMatrix()
Destructor.
Definition: PETScMatrix.cpp:89
double norm(std::string norm_type) const
Return norm of matrix.
Definition: PETScMatrix.cpp:509
void set_near_nullspace(const VectorSpaceBasis &nullspace)
Definition: PETScMatrix.cpp:690
void init(const TensorLayout &tensor_layout)
Initialize zero tensor using tensor layout.
Definition: PETScMatrix.cpp:99
Definition: PETScBaseMatrix.h:49
virtual const PETScMatrix & operator*=(double a)
Multiply matrix by given number.
Definition: PETScMatrix.cpp:582
This class defines a common interface for matrices.
Definition: GenericMatrix.h:46
PetscInt la_index
Index type for compatibility with linear algebra backend(s)
Definition: types.h:32
virtual void setrow(std::size_t row, const std::vector< std::size_t > &columns, const std::vector< double > &values)
Set values for given row.
Definition: PETScMatrix.cpp:337
MPI_Comm mpi_comm() const
Return MPI communicator.
Definition: PETScMatrix.cpp:563
virtual void get_diagonal(GenericVector &x) const
Get diagonal of a matrix.
Definition: PETScMatrix.cpp:475
virtual void mult(const GenericVector &x, GenericVector &y) const
Compute matrix-vector product y = Ax.
Definition: PETScMatrix.cpp:417
void init_vector(GenericVector &z, std::size_t dim) const
Definition: PETScBaseMatrix.cpp:106
std::pair< std::int64_t, std::int64_t > size() const
Definition: PETScBaseMatrix.cpp:79
virtual void getrow(std::size_t row, std::vector< std::size_t > &columns, std::vector< double > &values) const
Get non-zero values of given row.
Definition: PETScMatrix.cpp:317
This class defines a common interface for vectors.
Definition: GenericVector.h:47
virtual void zero()
Set all entries to zero and keep any sparse structure.
Definition: PETScMatrix.cpp:575
std::pair< std::int64_t, std::int64_t > local_range(std::size_t dim) const
Return local range along dimension dim.
Definition: PETScBaseMatrix.cpp:89
void set_nullspace(const VectorSpaceBasis &nullspace)
Definition: PETScMatrix.cpp:676
void set_options_prefix(std::string options_prefix)
Definition: PETScMatrix.cpp:617
PETScMatrix()
Create empty matrix (on MPI_COMM_WORLD)
Definition: PETScMatrix.cpp:56
virtual void transpmult(const GenericVector &x, GenericVector &y) const
Definition: PETScMatrix.cpp:446