LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
|
A temporary data structure for matrix in COO format. More...
#include <lf/assemble/coomatrix.h>
Public Types | |
using | Scalar = SCALAR |
using | Triplet = Eigen::Triplet<SCALAR> |
using | TripletVec = std::vector<Triplet> |
using | Index = Eigen::Index |
Public Member Functions | |
COOMatrix (size_type num_rows, size_type num_cols) | |
COOMatrix (const COOMatrix &)=default | |
COOMatrix (COOMatrix &&) noexcept=default | |
COOMatrix & | operator= (const COOMatrix &)=default |
COOMatrix & | operator= (COOMatrix &&) noexcept=default |
~COOMatrix ()=default | |
Index | rows () const |
return number of rows | |
Index | cols () const |
return number of column | |
void | AddToEntry (gdof_idx_t i, gdof_idx_t j, SCALAR increment) |
Add a value to the specified entry. | |
void | setZero () |
Erase all entries of the matrix. | |
template<typename PREDICATE > | |
void | setZero (PREDICATE &&pred) |
Erase specific entries of the COO matrix, that is, set them to zero. | |
TripletVec & | triplets () |
Gives access to the vector of triplets. | |
const TripletVec & | triplets () const |
template<typename VECTOR > | |
Eigen::Matrix< SCALAR, Eigen::Dynamic, 1 > | MatVecMult (SCALAR alpha, const VECTOR &vec) const |
Computes the product of a (scaled) vector with the matrix in COO format. | |
template<typename VECTOR , typename RESULTVECTOR > | |
void | MatVecMult (SCALAR alpha, const VECTOR &vec, RESULTVECTOR &resvec) const |
In-situ computes the product of a vector with the matrix in COO format. | |
Eigen::SparseMatrix< Scalar > | makeSparse () const |
Create an Eigen::SparseMatrix out of the COO format. | |
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > | makeDense () const |
Create an Eigen::MatrixX from the COO format. | |
void | PrintInfo (std::ostream &o) const |
Ouput of triplet list describing COO matrix. | |
Private Attributes | |
size_type | rows_ |
size_type | cols_ |
TripletVec | triplets_ {} |
Friends | |
template<typename SCALARTYPE > | |
std::ostream & | operator<< (std::ostream &o, const COOMatrix< SCALARTYPE > &mat) |
Output operator for COO matrix. | |
A temporary data structure for matrix in COO format.
SCALAR | basic scalar type for the matrix |
This class provides a container for a matrix in triplet format, also known as COO format see Wikipedia. It essentially manages a vector of Eigen triplets_.
This matrix format allows efficient incremental matrix construction in the context of local assembly.
SCALAR
must be a type that can serve as a scalar type for Eigen::Matrix.
Definition at line 52 of file coomatrix.h.
using lf::assemble::COOMatrix< SCALAR >::Index = Eigen::Index |
Definition at line 57 of file coomatrix.h.
Definition at line 54 of file coomatrix.h.
using lf::assemble::COOMatrix< SCALAR >::Triplet = Eigen::Triplet<SCALAR> |
Definition at line 55 of file coomatrix.h.
using lf::assemble::COOMatrix< SCALAR >::TripletVec = std::vector<Triplet> |
Definition at line 56 of file coomatrix.h.
|
inline |
Set up zero matrix of a given size
Definition at line 60 of file coomatrix.h.
|
default |
|
defaultnoexcept |
|
default |
|
inline |
Add a value to the specified entry.
i | row index |
j | column index |
increment |
Adds another index-value triplet.
Definition at line 87 of file coomatrix.h.
References lf::assemble::AssembleMatrixLocally(), lf::assemble::COOMatrix< SCALAR >::cols_, lf::assemble::COOMatrix< SCALAR >::rows_, and lf::assemble::COOMatrix< SCALAR >::triplets_.
|
inline |
return number of column
Definition at line 72 of file coomatrix.h.
References lf::assemble::COOMatrix< SCALAR >::cols_.
|
inline |
Create an Eigen::MatrixX from the COO format.
This method is mainly meant for debugging
Definition at line 188 of file coomatrix.h.
References lf::assemble::AssembleMatrixLocally(), lf::assemble::COOMatrix< SCALAR >::cols_, lf::assemble::COOMatrix< SCALAR >::rows_, and lf::assemble::COOMatrix< SCALAR >::triplets_.
|
inline |
Create an Eigen::SparseMatrix out of the COO format.
Definition at line 172 of file coomatrix.h.
References lf::assemble::COOMatrix< SCALAR >::cols_, lf::assemble::COOMatrix< SCALAR >::rows_, and lf::assemble::COOMatrix< SCALAR >::triplets_.
Eigen::Matrix< SCALAR, Eigen::Dynamic, 1 > lf::assemble::COOMatrix< SCALAR >::MatVecMult | ( | SCALAR | alpha, |
const VECTOR & | vec ) const |
Computes the product of a (scaled) vector with the matrix in COO format.
VECTOR | a basic vector type for the argument vector |
alpha | scalar with which to multiply the argument vector before the matrix x vector multiplication. |
vec | constant reference to a vector of type VECTOR |
An object of type VECTOR must provide a method Size()
telling the length of the vector and operator []
for read access to vector entries.
Definition at line 236 of file coomatrix.h.
References lf::assemble::AssembleMatrixLocally().
void lf::assemble::COOMatrix< SCALAR >::MatVecMult | ( | SCALAR | alpha, |
const VECTOR & | vec, | ||
RESULTVECTOR & | resvec ) const |
In-situ computes the product of a vector with the matrix in COO format.
VECTOR | a basic vector type for the argument vector |
RESULTVECTOR | another vector type for returning the result |
alpha | scalar with which to multiply the argument vector before the matrix x vector multiplication. |
vec | constant reference to a vector of type VECTOR |
resvec | reference to an object of type RESULTVECTOR. |
result
!An object of type VECTOR or RESULTVECTOR must provide a method Size()
telling the length of the vector and operator []
for read/write access to vector entries.
Definition at line 250 of file coomatrix.h.
References lf::assemble::AssembleMatrixLocally().
|
default |
|
defaultnoexcept |
|
inline |
Ouput of triplet list describing COO matrix.
o | output stream |
Definition at line 205 of file coomatrix.h.
References lf::assemble::AssembleMatrixLocally(), lf::assemble::COOMatrix< SCALAR >::cols_, lf::assemble::COOMatrix< SCALAR >::rows_, and lf::assemble::COOMatrix< SCALAR >::triplets_.
|
inline |
return number of rows
Definition at line 70 of file coomatrix.h.
References lf::assemble::COOMatrix< SCALAR >::rows_.
|
inline |
Erase all entries of the matrix.
This method clears the vector of triplets, effectively setting the matrix to zero. It does not affect the size information about the matrix.
Definition at line 98 of file coomatrix.h.
References lf::assemble::COOMatrix< SCALAR >::triplets_.
|
inline |
Erase specific entries of the COO matrix, that is, set them to zero.
PREDICATE | a predicate type compliant with std::function<bool(gdof_idx_t,gdof_idx_t)> |
pred | selector predicate |
Removes all triplets trp
for which pred(trp.row(),trp.col())
is true
. This amounts to setting the corresponding matrix entries to zero.
Definition at line 109 of file coomatrix.h.
References lf::assemble::AssembleMatrixLocally(), and lf::assemble::COOMatrix< SCALAR >::triplets_.
|
inline |
Gives access to the vector of triplets.
Use of this method is deprecated. Use setZero(pred) and AddToEntry() instead.
Definition at line 124 of file coomatrix.h.
References lf::assemble::COOMatrix< SCALAR >::triplets_.
|
inline |
Definition at line 125 of file coomatrix.h.
References lf::assemble::COOMatrix< SCALAR >::triplets_.
|
friend |
Output operator for COO matrix.
This function prints matrix size and the list of triplets
Definition at line 229 of file coomatrix.h.
|
private |
dimensions of matrix
Definition at line 223 of file coomatrix.h.
Referenced by lf::assemble::COOMatrix< SCALAR >::AddToEntry(), lf::assemble::COOMatrix< SCALAR >::cols(), lf::assemble::COOMatrix< SCALAR >::makeDense(), lf::assemble::COOMatrix< SCALAR >::makeSparse(), and lf::assemble::COOMatrix< SCALAR >::PrintInfo().
|
private |
|
private |
COO format data
Definition at line 224 of file coomatrix.h.
Referenced by lf::assemble::COOMatrix< SCALAR >::AddToEntry(), lf::assemble::COOMatrix< SCALAR >::makeDense(), lf::assemble::COOMatrix< SCALAR >::makeSparse(), lf::assemble::COOMatrix< SCALAR >::PrintInfo(), lf::assemble::COOMatrix< SCALAR >::setZero(), lf::assemble::COOMatrix< SCALAR >::setZero(), lf::assemble::COOMatrix< SCALAR >::triplets(), and lf::assemble::COOMatrix< SCALAR >::triplets().