Go to the documentation of this file.
20 #ifndef LIBMESH_SPARSE_MATRIX_H
21 #define LIBMESH_SPARSE_MATRIX_H
25 #include "libmesh/libmesh.h"
26 #include "libmesh/libmesh_common.h"
27 #include "libmesh/id_types.h"
28 #include "libmesh/reference_counted_object.h"
29 #include "libmesh/parallel_object.h"
41 template <
typename T>
class SparseMatrix;
42 template <
typename T>
class DenseMatrix;
44 namespace SparsityPattern {
class Graph; }
45 template <
typename T>
class NumericVector;
50 std::ostream &
operator << (std::ostream & os,
const SparseMatrix<T> & m);
63 class SparseMatrix :
public ReferenceCountedObject<SparseMatrix<T>>,
95 static std::unique_ptr<SparseMatrix<T>>
96 build(
const Parallel::Communicator &
comm,
153 virtual void init () = 0;
158 virtual void clear () = 0;
163 virtual void zero () = 0;
168 virtual void zero_rows (std::vector<numeric_index_type> & rows, T diag_value = 0.0);
174 virtual void close () = 0;
233 const std::vector<numeric_index_type> & rows,
234 const std::vector<numeric_index_type> & cols) = 0;
241 const std::vector<numeric_index_type> & dof_indices) = 0;
250 const std::vector<numeric_index_type> & brows,
251 const std::vector<numeric_index_type> & bcols);
258 const std::vector<numeric_index_type> & dof_indices)
300 virtual bool closed()
const = 0;
335 friend std::ostream & operator << <>(std::ostream & os,
const SparseMatrix<T> &
m);
350 libmesh_not_implemented();
359 const std::vector<numeric_index_type> & rows,
360 const std::vector<numeric_index_type> & cols)
const
375 const std::vector<numeric_index_type> & rows,
376 const std::vector<numeric_index_type> & cols)
const
417 std::vector<numeric_index_type> & ,
418 std::vector<T> & )
const
420 libmesh_not_implemented();
433 const std::vector<numeric_index_type> & ,
434 const std::vector<numeric_index_type> & ,
437 libmesh_not_implemented();
461 template <
typename T>
472 #endif // LIBMESH_SPARSE_MATRIX_H
SparseMatrix(const Parallel::Communicator &comm)
Constructor; initializes the matrix to be empty, without any structure, i.e.
virtual void close()=0
Calls the SparseMatrix's internal assembly routines, ensuring that the values are consistent across p...
SolverPackage
Defines an enum for various linear solver packages.
virtual T operator()(const numeric_index_type i, const numeric_index_type j) const =0
virtual void get_row(numeric_index_type, std::vector< numeric_index_type > &, std::vector< T > &) const
Get a row from the matrix.
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.
The libMesh namespace provides an interface to certain functionality in the library.
std::ostream & operator<<(std::ostream &os, const OrderWrapper &order)
Overload stream operators.
virtual bool initialized() const
virtual void get_diagonal(NumericVector< T > &dest) const =0
Copies the diagonal part of the matrix into dest.
const Parallel::Communicator & comm() const
Defines a dense matrix for use in Finite Element-type computations.
virtual void print_matlab(const std::string &="") const
Print the contents of the matrix in Matlab's sparse matrix format.
virtual Real linfty_norm() const =0
const DofMap * _dof_map
The DofMap object associated with this object.
SolverPackage default_solver_package()
virtual void clear()=0
Restores the SparseMatrix<T> to a pristine state.
virtual void add_block_matrix(const DenseMatrix< T > &dm, const std::vector< numeric_index_type > &dof_indices)
Same as add_block_matrix(), but assumes the row and column maps are the same.
virtual bool need_full_sparsity_pattern() const
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
virtual void zero_rows(std::vector< numeric_index_type > &rows, T diag_value=0.0)
Sets all row entries to 0 then puts diag_value in the diagonal entry.
virtual void flush()
For PETSc matrix , this function is similar to close but without shrinking memory.
virtual bool closed() const =0
virtual numeric_index_type local_m() const
Get the number of rows owned by this process.
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.
virtual numeric_index_type m() const =0
virtual ~SparseMatrix()=default
virtual void add(const numeric_index_type i, const numeric_index_type j, const T value)=0
Add value to the element (i,j).
dof_id_type numeric_index_type
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.
virtual void add_matrix(const DenseMatrix< T > &dm, const std::vector< numeric_index_type > &rows, const std::vector< numeric_index_type > &cols)=0
Add the full matrix dm to the SparseMatrix.
virtual void update_sparsity_pattern(const SparsityPattern::Graph &)
Updates the matrix sparsity pattern.
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.
virtual void init()=0
Initialize this matrix using the sparsity structure computed by dof_map.
SparseMatrix & operator=(const SparseMatrix &)=default
virtual numeric_index_type row_stop() const =0
This class handles the numbering of degrees of freedom on a mesh.
void attach_dof_map(const DofMap &dof_map)
Get a pointer to the DofMap to use.
virtual void print_personal(std::ostream &os=libMesh::out) const =0
Print the contents of the matrix to the screen in a package-personalized style, if available.
virtual Real l1_norm() const =0
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 give...
virtual void set(const numeric_index_type i, const numeric_index_type j, const T value)=0
Set the element (i,j) to value.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void get_transpose(SparseMatrix< T > &dest) const =0
Copies the transpose of the matrix into dest, which may be *this.
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 packag...
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 o...
virtual void zero()=0
Set all entries to 0.
bool _is_initialized
Flag indicating whether or not the matrix has been initialized.
virtual void add_block_matrix(const DenseMatrix< T > &dm, const std::vector< numeric_index_type > &brows, const std::vector< numeric_index_type > &bcols)
Add the full matrix dm to the SparseMatrix.
virtual numeric_index_type row_start() const =0
virtual numeric_index_type n() const =0