3#ifndef DUNE_ISTL_MATRIXINDEXSET_HH
4#define DUNE_ISTL_MATRIXINDEXSET_HH
17 typedef std::size_t size_type;
25 indices_.resize(rows_);
32 indices_.resize(rows_);
36 void add(size_type i, size_type j) {
37 indices_[i].insert(j);
42 size_type entries = 0;
43 for (size_type i=0; i<rows_; i++)
44 entries += indices_[i].
size();
50 size_type
rows()
const {
return rows_;}
54 size_type
rowsize(size_type row)
const {
return indices_[row].size();}
62 template <
class MatrixType>
63 void import(
const MatrixType& m, size_type rowOffset=0, size_type colOffset=0) {
65 typedef typename MatrixType::row_type RowType;
66 typedef typename RowType::ConstIterator ColumnIterator;
68 for (size_type rowIdx=0; rowIdx<m.N(); rowIdx++) {
70 const RowType& row = m[rowIdx];
72 ColumnIterator cIt = row.begin();
73 ColumnIterator cEndIt = row.end();
75 for(; cIt!=cEndIt; ++cIt)
76 add(rowIdx+rowOffset, cIt.index()+colOffset);
87 template <
class MatrixType>
90 matrix.setSize(rows_, cols_);
91 matrix.setBuildMode(MatrixType::random);
93 for (size_type i=0; i<rows_; i++)
94 matrix.setrowsize(i, indices_[i].size());
98 for (size_type i=0; i<rows_; i++) {
100 typename std::set<size_type>::iterator it = indices_[i].begin();
101 for (; it!=indices_[i].end(); ++it)
102 matrix.addindex(i, *it);
112 std::vector<std::set<size_type> > indices_;
114 size_type rows_, cols_;
Stores the nonzero entries in a sparse matrix.
Definition: matrixindexset.hh:14
void resize(size_type rows, size_type cols)
Reset the size of an index set.
Definition: matrixindexset.hh:29
MatrixIndexSet()
Default constructor.
Definition: matrixindexset.hh:20
void add(size_type i, size_type j)
Add an index to the index set.
Definition: matrixindexset.hh:36
size_type rows() const
Return the number of rows.
Definition: matrixindexset.hh:50
void exportIdx(MatrixType &matrix) const
Initializes a BCRSMatrix with the indices contained in this MatrixIndexSet.
Definition: matrixindexset.hh:88
MatrixIndexSet(size_type rows, size_type cols)
Constructor setting the matrix size.
Definition: matrixindexset.hh:24
size_type rowsize(size_type row) const
Return the number of entries in a given row.
Definition: matrixindexset.hh:54
size_type size() const
Return the number of entries.
Definition: matrixindexset.hh:41
Dune namespace.
Definition: alignment.hh:11