5#ifndef DUNE_ISTL_MATRIXINDEXSET_HH
6#define DUNE_ISTL_MATRIXINDEXSET_HH
19 typedef std::size_t size_type;
27 indices_.resize(rows_);
34 indices_.resize(rows_);
38 void add(size_type i, size_type j) {
39 indices_[i].insert(j);
44 size_type entries = 0;
45 for (size_type i=0; i<rows_; i++)
46 entries += indices_[i].
size();
52 size_type
rows()
const {
return rows_;}
56 size_type
rowsize(size_type row)
const {
return indices_[row].size();}
64 template <
class MatrixType>
65 void import(
const MatrixType& m, size_type rowOffset=0, size_type colOffset=0) {
67 typedef typename MatrixType::row_type RowType;
68 typedef typename RowType::ConstIterator ColumnIterator;
70 for (size_type rowIdx=0; rowIdx<m.N(); rowIdx++) {
72 const RowType& row = m[rowIdx];
74 ColumnIterator cIt = row.begin();
75 ColumnIterator cEndIt = row.end();
77 for(; cIt!=cEndIt; ++cIt)
78 add(rowIdx+rowOffset, cIt.index()+colOffset);
89 template <
class MatrixType>
92 matrix.setSize(rows_, cols_);
93 matrix.setBuildMode(MatrixType::random);
95 for (size_type i=0; i<rows_; i++)
96 matrix.setrowsize(i, indices_[i].size());
100 for (size_type i=0; i<rows_; i++) {
102 typename std::set<size_type>::iterator it = indices_[i].begin();
103 for (; it!=indices_[i].end(); ++it)
104 matrix.addindex(i, *it);
114 std::vector<std::set<size_type> > indices_;
116 size_type rows_, cols_;
Stores the nonzero entries in a sparse matrix.
Definition: matrixindexset.hh:16
void resize(size_type rows, size_type cols)
Reset the size of an index set.
Definition: matrixindexset.hh:31
MatrixIndexSet()
Default constructor.
Definition: matrixindexset.hh:22
void add(size_type i, size_type j)
Add an index to the index set.
Definition: matrixindexset.hh:38
size_type rows() const
Return the number of rows.
Definition: matrixindexset.hh:52
void exportIdx(MatrixType &matrix) const
Initializes a BCRSMatrix with the indices contained in this MatrixIndexSet.
Definition: matrixindexset.hh:90
MatrixIndexSet(size_type rows, size_type cols)
Constructor setting the matrix size.
Definition: matrixindexset.hh:26
size_type rowsize(size_type row) const
Return the number of entries in a given row.
Definition: matrixindexset.hh:56
size_type size() const
Return the number of entries.
Definition: matrixindexset.hh:43
Dune namespace.
Definition: alignedallocator.hh:13