DUNE PDELab (git)

Dune::MatrixIndexSet Class Reference

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]

Dune::MatrixIndexSet::MatrixIndexSet ( size_type  maxVectorSize = defaultMaxVectorSize)
inlinenoexcept

Constructor with custom maxVectorSize.

Parameters
maxVectorSizeMaximal size for stored row vector (default is defaultMaxVectorSize).

◆ MatrixIndexSet() [2/2]

Dune::MatrixIndexSet::MatrixIndexSet ( size_type  rows,
size_type  cols,
size_type  maxVectorSize = defaultMaxVectorSize 
)
inline

Constructor setting the matrix size.

Parameters
rowsNumber of matrix rows
colsNumber of matrix columns
maxVectorSizeMaximal size for stored row vector (default is defaultMaxVectorSize).

Member Function Documentation

◆ add()

void Dune::MatrixIndexSet::add ( size_type  row,
size_type  col 
)
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()

const auto & Dune::MatrixIndexSet::columnIndices ( size_type  row) const
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()

template<class MatrixType >
void Dune::MatrixIndexSet::exportIdx ( MatrixType &  matrix) const
inline

Initializes a BCRSMatrix with the indices contained in this MatrixIndexSet.

Template Parameters
MatrixTypeNeeds to be BCRSMatrix<...>
Parameters
matrixreference to the MatrixType object

◆ import()

template<class MatrixType >
void Dune::MatrixIndexSet::import ( const MatrixType &  m,
size_type  rowOffset = 0,
size_type  colOffset = 0 
)
inline

Import all nonzero entries of a sparse matrix into the index set.

Template Parameters
MatrixTypeNeeds to be BCRSMatrix<...>
Parameters
mreference to the MatrixType object
rowOffsetdon't write to rows<rowOffset
colOffsetdon't write to cols<colOffset

Member Data Documentation

◆ defaultMaxVectorSize

constexpr size_type Dune::MatrixIndexSet::defaultMaxVectorSize = 2048
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:
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 24, 23:30, 2024)