Loading...
Searching...
No Matches
Dune::MatrixIndexSet Class Reference

Stores the nonzero entries for creating a sparse matrix. More...

`#include <dune/istl/matrixindexset.hh>`

## Public Types

using | size_type = typename Impl::RowIndexSet::size_type

## Public Member Functions

| MatrixIndexSet (size_type maxVectorSize=defaultMaxVectorSize) noexcept
| Constructor with custom maxVectorSize.
| MatrixIndexSet (size_type rows, size_type cols, size_type maxVectorSize=defaultMaxVectorSize)
| Constructor setting the matrix size.
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.
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.
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.
template<class MatrixType>
void | exportIdx (MatrixType &matrix) const
| Initializes a BCRSMatrix with the indices contained in this MatrixIndexSet.

## Static Public Attributes

static constexpr size_type | defaultMaxVectorSize = Impl::RowIndexSet::defaultMaxVectorSize
| Default value for maxVectorSize.

## 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.

## Member Typedef Documentation

## size_type

using Dune::MatrixIndexSet::size_type = typename Impl::RowIndexSet::size_type

## Constructor & Destructor Documentation

## MatrixIndexSet() [1/2]

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

inline noexcept

Constructor with custom maxVectorSize.

Parameters

  maxVectorSize | Maximal 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

  rows | Number of matrix rows
  cols | Number of matrix columns
  maxVectorSize | Maximal 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.

## cols()

size_type Dune::MatrixIndexSet::cols | ( |  | ) | const

inline

Return the number of 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

  MatrixType | Needs to be BCRSMatrix<...>

Parameters

  matrix | reference 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

  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

## resize()

void Dune::MatrixIndexSet::resize | ( | size_type | rows,
|  | size_type | cols )

inline

Reset the size of an index set.

## rows()

size_type Dune::MatrixIndexSet::rows | ( |  | ) | const

inline

Return the number of rows.

## rowsize()

size_type Dune::MatrixIndexSet::rowsize | ( | size_type | row | ) | const

inline

Return the number of entries in a given row.

## size()

size_type Dune::MatrixIndexSet::size | ( |  | ) | const

inline

Return the number of entries.

## Member Data Documentation

## defaultMaxVectorSize

size_type Dune::MatrixIndexSet::defaultMaxVectorSize = Impl::RowIndexSet::defaultMaxVectorSize

static constexpr

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:

- matrixindexset.hh