23 #include "DefaultFactory.h" 24 #include "GenericMatrix.h" 62 { matrix->init(tensor_layout); }
66 {
return matrix->empty(); }
69 virtual std::size_t
size(std::size_t dim)
const 70 {
return matrix->size(dim); }
73 virtual std::pair<std::int64_t, std::int64_t>
75 {
return matrix->local_range(dim); }
78 virtual std::size_t
nnz()
const 79 {
return matrix->nnz(); }
86 virtual void apply(std::string mode)
87 { matrix->apply(mode); }
91 {
return matrix->mpi_comm(); }
94 virtual std::string
str(
bool verbose)
const 95 {
return "<Matrix wrapper of " + matrix->str(verbose) +
">"; }
100 virtual std::shared_ptr<GenericMatrix>
copy()
const 102 std::shared_ptr<Matrix> A(
new Matrix(*
this));
110 { matrix->init_vector(y, dim); }
113 virtual void get(
double* block,
116 { matrix->get(block, m, rows, n, cols); }
119 virtual void set(
const double* block,
122 { matrix->set(block, m, rows, n, cols); }
128 { matrix->set_local(block, m, rows, n, cols); }
131 virtual void add(
const double* block,
134 { matrix->add(block, m, rows, n, cols); }
140 { matrix->add_local(block, m, rows, n, cols); }
144 bool same_nonzero_pattern)
145 { matrix->axpy(a, A, same_nonzero_pattern); }
148 virtual double norm(std::string norm_type)
const 149 {
return matrix->norm(norm_type); }
152 virtual void getrow(std::size_t row, std::vector<std::size_t>& columns,
153 std::vector<double>& values)
const 154 { matrix->getrow(row, columns, values); }
158 const std::vector<std::size_t>& columns,
159 const std::vector<double>& values)
160 { matrix->setrow(row, columns, values); }
164 { matrix->zero(m, rows); }
168 { matrix->zero_local(m, rows); }
172 { matrix->ident(m, rows); }
176 { matrix->ident_local(m, rows); }
180 { matrix->mult(x, y); }
184 { matrix->transpmult(x, y); }
188 { matrix->get_diagonal(x); }
192 { matrix->set_diagonal(x); }
196 { *matrix *= a;
return *
this; }
200 { *matrix /= a;
return *
this; }
204 { *matrix = A;
return *
this; }
208 {
return matrix->is_symmetric(tol); }
214 {
return matrix->factory(); }
220 {
return matrix.get() ; }
224 {
return matrix.get(); }
236 { *matrix = *A.matrix;
return *
this; }
241 std::shared_ptr<GenericMatrix> matrix;
virtual void init(const TensorLayout &tensor_layout)
Initialize zero tensor using tensor layout.
Definition: Matrix.h:61
virtual void axpy(double a, const GenericMatrix &A, bool same_nonzero_pattern)
Add multiple of given matrix (AXPY operation)
Definition: Matrix.h:143
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: Matrix.h:125
virtual bool is_symmetric(double tol) const
Test if matrix is symmetric.
Definition: Matrix.h:207
virtual const Matrix & operator/=(double a)
Divide matrix by given number.
Definition: Matrix.h:199
virtual bool empty() const
Return true if matrix is empty.
Definition: Matrix.h:65
virtual void zero(std::size_t m, const dolfin::la_index *rows)
Set given rows to zero.
Definition: Matrix.h:163
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: Matrix.h:157
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: Matrix.h:131
MPI_Comm mpi_comm() const
Return MPI communicator.
Definition: Matrix.h:90
virtual const Matrix & operator*=(double a)
Multiply matrix by given number.
Definition: Matrix.h:195
virtual void set_diagonal(const GenericVector &x)
Set diagonal of a matrix.
Definition: Matrix.h:191
virtual void mult(const GenericVector &x, GenericVector &y) const
Compute matrix-vector product y = Ax.
Definition: Matrix.h:179
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: Matrix.h:152
virtual void ident(std::size_t m, const dolfin::la_index *rows)
Set given rows (global row indices) to identity matrix.
Definition: Matrix.h:171
virtual std::size_t nnz() const
Return number of non-zero entries in matrix (collective)
Definition: Matrix.h:78
virtual void zero()
Set all entries to zero and keep any sparse structure.
Definition: Matrix.h:82
virtual void get_diagonal(GenericVector &x) const
Get diagonal of a matrix.
Definition: Matrix.h:187
virtual std::shared_ptr< GenericMatrix > copy() const
Return copy of matrix.
Definition: Matrix.h:100
Matrix(const GenericMatrix &A)
Create a Vector from a GenericVector.
Definition: Matrix.h:53
virtual GenericMatrix * instance()
Return concrete instance / unwrap (non-const version)
Definition: Matrix.h:223
Definition: TensorLayout.h:41
Base class for LinearAlgebra factories.
Definition: GenericLinearAlgebraFactory.h:46
virtual const GenericMatrix & operator=(const GenericMatrix &A)
Assignment operator.
Definition: Matrix.h:203
virtual void transpmult(const GenericVector &x, GenericVector &y) const
Definition: Matrix.h:183
Matrix(MPI_Comm comm)
Create empty matrix.
Definition: Matrix.h:43
virtual std::size_t size(std::size_t dim) const
Return size of given dimension.
Definition: Matrix.h:69
Matrix()
Create empty matrix.
Definition: Matrix.h:40
virtual std::shared_ptr< LinearAlgebraObject > shared_instance()
Return concrete shared ptr instance / unwrap (non-const version)
Definition: Matrix.h:229
Matrix(const Matrix &A)
Copy constructor.
Definition: Matrix.h:50
virtual void ident_local(std::size_t m, const dolfin::la_index *rows)
Set given rows (local row indices) to identity matrix.
Definition: Matrix.h:175
This class defines a common interface for matrices.
Definition: GenericMatrix.h:46
virtual void apply(std::string mode)
Finalize assembly of tensor.
Definition: Matrix.h:86
PetscInt la_index
Index type for compatibility with linear algebra backend(s)
Definition: types.h:32
virtual const GenericMatrix * instance() const
Return concrete instance / unwrap (const version)
Definition: Matrix.h:219
virtual std::string str(bool verbose) const
Return informal string representation (pretty-print)
Definition: Matrix.h:94
virtual void init_vector(GenericVector &y, std::size_t dim) const
Definition: Matrix.h:109
virtual double norm(std::string norm_type) const
Return norm of matrix.
Definition: Matrix.h:148
virtual std::shared_ptr< const LinearAlgebraObject > shared_instance() const
Return concrete shared ptr instance / unwrap (const version)
Definition: Matrix.h:226
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: Matrix.h:137
virtual GenericLinearAlgebraFactory & factory() const
Return linear algebra backend factory.
Definition: Matrix.h:213
virtual std::pair< std::int64_t, std::int64_t > local_range(std::size_t dim) const
Return local ownership range.
Definition: Matrix.h:74
This class defines a common interface for vectors.
Definition: GenericVector.h:47
virtual std::shared_ptr< GenericMatrix > create_matrix(MPI_Comm comm) const
Create empty matrix.
Definition: DefaultFactory.cpp:32
virtual void zero_local(std::size_t m, const dolfin::la_index *rows)
Set given rows (local row indices) to zero.
Definition: Matrix.h:167
Default linear algebra factory based on global parameter "linear_algebra_backend".
Definition: DefaultFactory.h:35
virtual ~Matrix()
Destructor.
Definition: Matrix.h:56