DUNE PDELab (git)
Stores the nonzero entries for creating a sparse matrix. More...
#include <dune/istl/matrixindexset.hh>
Public Member Functions | |
MatrixIndexSet (size_type maxVectorSize=defaultMaxVectorSize) noexcept | |
Constructor with custom maxVectorSize. More... | |
MatrixIndexSet (size_type rows, size_type cols, size_type maxVectorSize=defaultMaxVectorSize) | |
Constructor setting the matrix size. More... | |
void | resize (size_type rows, size_type cols) |
Reset the size of an index set. | |
void | add (size_type row, size_type col) |
Add an index to the index set. More... | |
size_type | size () const |
Return the number of entries. | |
size_type | rows () const |
Return the number of rows. | |
size_type | cols () const |
Return the number of columns. | |
const auto & | columnIndices (size_type row) const |
Return column indices of entries in given row. More... | |
size_type | rowsize (size_type row) const |
Return the number of entries in a given row. | |
template<class MatrixType > | |
void | import (const MatrixType &m, size_type rowOffset=0, size_type colOffset=0) |
Import all nonzero entries of a sparse matrix into the index set. More... | |
template<class MatrixType > | |
void | exportIdx (MatrixType &matrix) const |
Initializes a BCRSMatrix with the indices contained in this MatrixIndexSet. More... | |
Static Public Attributes | |
static constexpr size_type | defaultMaxVectorSize = 2048 |
Default value for maxVectorSize. More... | |
Detailed Description
Stores the nonzero entries for creating a sparse matrix.
This stores std::set-like container for the column index of each row. A sorted std::vector is used for this container up to a customizable maxVectorSize. If this size is exceeded, storage of the corresponding row is switched to std::set.
The default value for maxVectorSize works well and ensures that the slow std::set fallback is only used for very dense rows.
This class is thread safe in the sense that concurrent calls to all const methods and furthermore to add(row,col) with different rows in each thread are safe.
Constructor & Destructor Documentation
◆ MatrixIndexSet() [1/2]
|
inlinenoexcept |
Constructor with custom maxVectorSize.
- Parameters
-
maxVectorSize Maximal size for stored row vector (default is defaultMaxVectorSize).
◆ MatrixIndexSet() [2/2]
|
inline |
Constructor setting the matrix size.
- Parameters
-
rows Number of matrix rows cols Number of matrix columns maxVectorSize Maximal size for stored row vector (default is defaultMaxVectorSize).
Member Function Documentation
◆ add()
|
inline |
Add an index to the index set.
It is safe to call add(row, col) for different rows in concurrent threads, but it is not safe to do concurrent calls for the same row, even for different columns.
◆ columnIndices()
|
inline |
Return column indices of entries in given row.
This returns a range of all column indices that have been added for the given column. Since there are different internal implementations of this range, the result is stored in a std::variant<...> which has to be accessed using std::visit
.
◆ exportIdx()
|
inline |
Initializes a BCRSMatrix with the indices contained in this MatrixIndexSet.
- Template Parameters
-
MatrixType Needs to be BCRSMatrix<...>
- Parameters
-
matrix reference to the MatrixType object
◆ import()
|
inline |
Import all nonzero entries of a sparse matrix into the index set.
- Template Parameters
-
MatrixType Needs to be BCRSMatrix<...>
- Parameters
-
m reference to the MatrixType object rowOffset don't write to rows<rowOffset colOffset don't write to cols<colOffset
Member Data Documentation
◆ defaultMaxVectorSize
|
staticconstexpr |
Default value for maxVectorSize.
This was selected after benchmarking for the worst case of reverse insertion of column indices. In many applications this works well. There's no need to use a different value unless you have many dense rows with more than defaultMaxVectorSize nonzero entries. Even in this case defaultMaxVectorSize may work well and a finding a better value may require careful benchmarking.
The documentation for this class was generated from the following file:
- dune/istl/matrixindexset.hh