From: guido Date: Fri, 25 Oct 2002 11:44:33 +0000 (+0000) Subject: Iterators that cannot work added X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2ff507688e5d91b88148680e627124986a05dcdc;p=dealii-svn.git Iterators that cannot work added git-svn-id: https://svn.dealii.org/trunk@6724 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/lac/include/lac/block_matrix_array.h b/deal.II/lac/include/lac/block_matrix_array.h index 33a6123bdb..5e754b725c 100644 --- a/deal.II/lac/include/lac/block_matrix_array.h +++ b/deal.II/lac/include/lac/block_matrix_array.h @@ -51,8 +51,7 @@ template class Vector; * The template argument @p{MATRIX} is a class providing the the * matrix-vector multiplication functions @p{vmult} etc. defined in * this class, but with arguments of type @p{VECTOR} instead of - * @p{BlockVector}. @ref{SparseMatrix} is a possible entry - * type. + * @p{BlockVector}. * * @author Guido Kanschat, 2000, 2001 */ @@ -60,6 +59,148 @@ template class BlockMatrixArray : public Subscriptor { public: + /** + * Type of matrix entries. In analogy to + * the STL container classes. + */ + typedef typename MATRIX::value_type value_type; + + /** + * Accessor class for iterators + */ + class Accessor + { + public: + /** + * Constructor. Since we use + * accessors only for read + * access, a const matrix + * pointer is sufficient. + */ + Accessor (const BlockMatrixArray*, + unsigned int row, + unsigned short index); + + /** + * Row number of the element + * represented by this + * object. + */ + unsigned int row() const; + + /** + * Index in row of the element + * represented by this + * object. + */ + unsigned short index() const; + + /** + * Column number of the + * element represented by + * this object. + */ + unsigned int column() const; + + /** + * Value of this matrix entry. + */ + typename MATRIX::value_type value() const; + + protected: + /** + * The matrix accessed. + */ + const BlockMatrixArray* matrix; + + /** + * Iterator of the underlying matrix class. + */ + typename MATRIX::const_iterator base_iterator; + + /** + * Number of block where row lies in. + */ + unsigned int block_row; + + /** + * First row of block. + */ + unsigned int row_start; + + /** + * Number of block column where column lies in. + */ + unsigned int block_col; + + /** + * First column of block. + */ + unsigned int col_start; + + /** + * Index in whole row. + */ + unsigned int a_index; + }; + + /** + * STL conforming iterator. + */ + class const_iterator : private Accessor + { + public: + /** + * Constructor. + */ + const_iterator(const BlockMatrixArray*, + unsigned int row, + unsigned short index); + + /** + * Prefix increment. + */ + const_iterator& operator++ (); + + /** + * Postfix increment. + */ + const_iterator& operator++ (int); + + /** + * Dereferencing operator. + */ + const Accessor& operator* () const; + + /** + * Dereferencing operator. + */ + const Accessor* operator-> () const; + + /** + * Comparison. True, if + * both iterators point to + * the same matrix + * position. + */ + bool operator == (const const_iterator&) const; + /** + * Inverse of @p{==}. + */ + bool operator != (const const_iterator&) const; + + /** + * Comparison + * operator. Result is true + * if either the first row + * number is smaller or if + * the row numbers are + * equal and the first + * index is smaller. + */ + bool operator < (const const_iterator&) const; + }; + /** * Constructor fixing the * dimensions. @@ -335,6 +476,223 @@ BlockMatrixArray::Entry::Entry (const MATRIX& matrix, {} +//----------------------------------------------------------------------// + + +template +inline +BlockMatrixArray::Accessor::Accessor ( + const BlockMatrixArray* matrix, + unsigned int r, + unsigned short i) + : matrix(matrix), + block_row(0), + row_start(0), + block_col(0), + col_start(0), + a_index(0) +{ + Assert (i==0, ExcNotImplemented()); + while (block_row < matrix->n_block_rows()) + { + const unsigned int block_size = matrix->block(block_row, 0).m(); + row_start += block_size; + if (rblock(block_row, 0).begin(r); + else + base_iterator = matrix->block(0, 0).begin(); +} + + +template +inline +unsigned int +BlockMatrixArray::Accessor::row() const +{ + return row_start + base_iterator->row(); +} + + +template +inline +short unsigned int +BlockMatrixArray::Accessor::index() const +{ + return a_index; +} + + +template +inline +unsigned int +BlockMatrixArray::Accessor::column() const +{ + return col_start + base_iterator->column(); +} + + +template +inline +typename MATRIX::value_type +BlockMatrixArray::Accessor::value () const +{ + return base_iterator->value(); +} + + +//----------------------------------------------------------------------// + + +template +inline +BlockMatrixArray::const_iterator::const_iterator( + const BlockMatrixArray* m, + unsigned int r, + unsigned short i) + : BlockMatrixArray::Accessor(m, r, i) +{} + + + +template +inline +typename BlockMatrixArray::const_iterator& +BlockMatrixArray::const_iterator::operator++ () +{ + Assert (block_rowrow(); + // Advance inside block + ++base_iterator; + ++a_index; + // If end of row inside block, + // advance to next block + if (base_iterator == matrix->block(block_row, block_col).end(local_row)) + { + if (block_col=matrix->block(block_row,0).m()) + { + // If final row in + // block, go to next + // block row + local_row = 0; + ++block_row; + } + } + // Finally, set base_iterator + // to start of row determined + // above + if (block_rowblock(block_row, block_col).begin(local_row); + else + // Set base_iterator to a + // defined state for + // comparison. This is the + // end() state. + base_iterator = matrix->block(0, 0).begin(); + } + return *this; +} + + + +// template +// inline +// const_iterator& +// BlockMatrixArray::const_iterator::operator++ (int) +// { +// Assert (false, ExcNotImplemented()); +// } + + + + +template +inline +const typename BlockMatrixArray::Accessor& +BlockMatrixArray::const_iterator::operator* () const +{ + return *this; +} + + +template +inline +const typename BlockMatrixArray::Accessor* +BlockMatrixArray::const_iterator::operator-> () const +{ + return this; +} + + + +template +inline +bool +BlockMatrixArray::const_iterator::operator == (const const_iterator& i) const +{ + if (matrix != i->matrix) + return false; + + if (block_row == i->block_row + && block_col == i->block_col + && base_iterator == i->base_iterator) + return true; + return false; +} + + + +template +inline +bool +BlockMatrixArray::const_iterator::operator != (const const_iterator& i) const +{ + return !(*this == i); +} + + + +template +inline +bool +BlockMatrixArray::const_iterator::operator < (const const_iterator& i) const +{ + if (block_rowblock_row) + return true; + if (block_row == i->block_row) + { + if (base_iterator->row() < i->base_iterator->row()) + return true; + if (base_iterator->row() == i->base_iterator->row()) + { + if (a_index < i->a_index) + return true; + } + } + return false; +} + +//----------------------------------------------------------------------// + template inline