From: Guido Kanschat Date: Tue, 5 May 2009 16:27:00 +0000 (+0000) Subject: put matrix accessors into public light, so they will be documented and used X-Git-Tag: v8.0.0~7711 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a2667732d6104ff3ace7696f37a9ead9a300090f;p=dealii.git put matrix accessors into public light, so they will be documented and used git-svn-id: https://svn.dealii.org/trunk@18815 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/lac/include/lac/sparse_matrix.h b/deal.II/lac/include/lac/sparse_matrix.h index 9db67c178a..e795fdaaa8 100644 --- a/deal.II/lac/include/lac/sparse_matrix.h +++ b/deal.II/lac/include/lac/sparse_matrix.h @@ -30,399 +30,396 @@ template class FullMatrix; *@{ */ -namespace internals +namespace SparseMatrixIterators { - namespace SparseMatrixIterators + // forward declaration + template + class Iterator; + + /** + * General template for sparse matrix + * accessors. The first template argument + * denotes the underlying numeric type, + * the second the constness of the + * matrix. + * + * The general template is not + * implemented, only the specializations + * for the two possible values of the + * second template argument. + */ + template + class Accessor; + + + /** + * Accessor class for constant matrices, + * used in the const_iterators. This + * class builds on the accessor classes + * used for sparsity patterns to loop + * over all nonzero entries, and only + * adds the accessor functions to gain + * access to the actual value stored at a + * certain location. + */ + template + class Accessor : public SparsityPatternIterators::Accessor { - // forward declaration - template - class Iterator; - - /** - * General template for sparse matrix - * accessors. The first template argument - * denotes the underlying numeric type, - * the second the constness of the - * matrix. - * - * The general template is not - * implemented, only the specializations - * for the two possible values of the - * second template argument. - */ - template - class Accessor; - - - /** - * Accessor class for constant matrices, - * used in the const_iterators. This - * class builds on the accessor classes - * used for sparsity patterns to loop - * over all nonzero entries, and only - * adds the accessor functions to gain - * access to the actual value stored at a - * certain location. - */ - template - class Accessor : public SparsityPatternIterators::Accessor - { - public: - /** - * Typedef for the type (including - * constness) of the matrix to be - * used here. - */ - typedef const SparseMatrix MatrixType; - - /** - * Constructor. - */ - Accessor (MatrixType *matrix, - const unsigned int row, - const unsigned int index); - - /** - * Constructor. Construct the end - * accessor for the given matrix. - */ - Accessor (MatrixType *matrix); - - /** - * Copy constructor to get from a - * non-const accessor to a const - * accessor. - */ - Accessor (const internals::SparseMatrixIterators::Accessor &a); - - /** - * Value of this matrix entry. - */ - number value() const; - - /** - * Return a reference to the matrix - * into which this accessor - * points. Note that in the present - * case, this is a constant - * reference. - */ - MatrixType & get_matrix () const; - - private: - /** - * Pointer to the matrix we use. - */ - MatrixType *matrix; - - /** - * Make the advance function of the - * base class available. - */ - using SparsityPatternIterators::Accessor::advance; - - /** - * Make iterator class a friend. - */ - template - friend class Iterator; - }; - - - /** - * Accessor class for non-constant - * matrices, used in the iterators. This - * class builds on the accessor classes - * used for sparsity patterns to loop - * over all nonzero entries, and only - * adds the accessor functions to gain - * access to the actual value stored at a - * certain location. - */ - template - class Accessor : public SparsityPatternIterators::Accessor - { - private: - /** - * Reference class. This is what the - * accessor class returns when you - * call the value() function. The - * reference acts just as if it were - * a reference to the actual value of - * a matrix entry, i.e. you can read - * and write it, you can add and - * multiply to it, etc, but since the - * matrix does not give away the - * address of this matrix entry, we - * have to go through functions to do - * all this. - * - * The constructor takes a pointer to - * an accessor object that describes - * which element of the matrix it - * points to. This creates an - * ambiguity when one writes code - * like iterator->value()=0 (instead - * of iterator->value()=0.0), since - * the right hand side is an integer - * that can both be converted to a - * number (i.e., most - * commonly a double) or to another - * object of type - * Reference. The compiler - * then complains about not knowing - * which conversion to take. - * - * For some reason, adding another - * overload operator=(int) doesn't - * seem to cure the problem. We avoid - * it, however, by adding a second, - * dummy argument to the Reference - * constructor, that is unused, but - * makes sure there is no second - * matching conversion sequence using - * a one-argument right hand side. - * - * The testcase oliver_01 checks that - * this actually works as intended. - */ - class Reference - { - public: - /** - * Constructor. For the second - * argument, see the general - * class documentation. - */ - Reference (const Accessor *accessor, - const bool dummy); - - /** - * Conversion operator to the - * data type of the matrix. - */ - operator number () const; - - /** - * Set the element of the matrix - * we presently point to to @p n. - */ - const Reference & operator = (const number n) const; - - /** - * Add @p n to the element of the - * matrix we presently point to. - */ - const Reference & operator += (const number n) const; + public: + /** + * Typedef for the type (including + * constness) of the matrix to be + * used here. + */ + typedef const SparseMatrix MatrixType; + + /** + * Constructor. + */ + Accessor (MatrixType *matrix, + const unsigned int row, + const unsigned int index); + + /** + * Constructor. Construct the end + * accessor for the given matrix. + */ + Accessor (MatrixType *matrix); + + /** + * Copy constructor to get from a + * non-const accessor to a const + * accessor. + */ + Accessor (const SparseMatrixIterators::Accessor &a); + + /** + * Value of this matrix entry. + */ + number value() const; + + /** + * Return a reference to the matrix + * into which this accessor + * points. Note that in the present + * case, this is a constant + * reference. + */ + MatrixType & get_matrix () const; + + private: + /** + * Pointer to the matrix we use. + */ + MatrixType *matrix; + + /** + * Make the advance function of the + * base class available. + */ + using SparsityPatternIterators::Accessor::advance; + + /** + * Make iterator class a friend. + */ + template + friend class Iterator; + }; + + + /** + * Accessor class for non-constant + * matrices, used in the iterators. This + * class builds on the accessor classes + * used for sparsity patterns to loop + * over all nonzero entries, and only + * adds the accessor functions to gain + * access to the actual value stored at a + * certain location. + */ + template + class Accessor : public SparsityPatternIterators::Accessor + { + private: + /** + * Reference class. This is what the + * accessor class returns when you + * call the value() function. The + * reference acts just as if it were + * a reference to the actual value of + * a matrix entry, i.e. you can read + * and write it, you can add and + * multiply to it, etc, but since the + * matrix does not give away the + * address of this matrix entry, we + * have to go through functions to do + * all this. + * + * The constructor takes a pointer to + * an accessor object that describes + * which element of the matrix it + * points to. This creates an + * ambiguity when one writes code + * like iterator->value()=0 (instead + * of iterator->value()=0.0), since + * the right hand side is an integer + * that can both be converted to a + * number (i.e., most + * commonly a double) or to another + * object of type + * Reference. The compiler + * then complains about not knowing + * which conversion to take. + * + * For some reason, adding another + * overload operator=(int) doesn't + * seem to cure the problem. We avoid + * it, however, by adding a second, + * dummy argument to the Reference + * constructor, that is unused, but + * makes sure there is no second + * matching conversion sequence using + * a one-argument right hand side. + * + * The testcase oliver_01 checks that + * this actually works as intended. + */ + class Reference + { + public: + /** + * Constructor. For the second + * argument, see the general + * class documentation. + */ + Reference (const Accessor *accessor, + const bool dummy); + + /** + * Conversion operator to the + * data type of the matrix. + */ + operator number () const; + + /** + * Set the element of the matrix + * we presently point to to @p n. + */ + const Reference & operator = (const number n) const; + + /** + * Add @p n to the element of the + * matrix we presently point to. + */ + const Reference & operator += (const number n) const; - /** - * Subtract @p n from the element - * of the matrix we presently - * point to. - */ - const Reference & operator -= (const number n) const; + /** + * Subtract @p n from the element + * of the matrix we presently + * point to. + */ + const Reference & operator -= (const number n) const; - /** - * Multiply the element of the - * matrix we presently point to - * by @p n. - */ - const Reference & operator *= (const number n) const; + /** + * Multiply the element of the + * matrix we presently point to + * by @p n. + */ + const Reference & operator *= (const number n) const; - /** - * Divide the element of the - * matrix we presently point to - * by @p n. - */ - const Reference & operator /= (const number n) const; + /** + * Divide the element of the + * matrix we presently point to + * by @p n. + */ + const Reference & operator /= (const number n) const; - private: - /** - * Pointer to the accessor that - * denotes which element we - * presently point to. - */ - const Accessor *accessor; - }; - - public: - /** - * Typedef for the type (including - * constness) of the matrix to be - * used here. - */ - typedef SparseMatrix MatrixType; + private: + /** + * Pointer to the accessor that + * denotes which element we + * presently point to. + */ + const Accessor *accessor; + }; + + public: + /** + * Typedef for the type (including + * constness) of the matrix to be + * used here. + */ + typedef SparseMatrix MatrixType; - /** - * Constructor. - */ - Accessor (MatrixType *matrix, - const unsigned int row, - const unsigned int index); + /** + * Constructor. + */ + Accessor (MatrixType *matrix, + const unsigned int row, + const unsigned int index); - /** - * Constructor. Construct the end - * accessor for the given matrix. - */ - Accessor (MatrixType *matrix); + /** + * Constructor. Construct the end + * accessor for the given matrix. + */ + Accessor (MatrixType *matrix); - /** - * Value of this matrix entry, - * returned as a read- and writable - * reference. - */ - Reference value() const; + /** + * Value of this matrix entry, + * returned as a read- and writable + * reference. + */ + Reference value() const; - /** - * Return a reference to the matrix - * into which this accessor - * points. Note that in the present - * case, this is a non-constant - * reference. - */ - MatrixType & get_matrix () const; + /** + * Return a reference to the matrix + * into which this accessor + * points. Note that in the present + * case, this is a non-constant + * reference. + */ + MatrixType & get_matrix () const; - private: - /** - * Pointer to the matrix we use. - */ - MatrixType *matrix; - - /** - * Make the advance function of the - * base class available. - */ - using SparsityPatternIterators::Accessor::advance; - - /** - * Make iterator class a friend. - */ - template - friend class Iterator; + private: + /** + * Pointer to the matrix we use. + */ + MatrixType *matrix; + + /** + * Make the advance function of the + * base class available. + */ + using SparsityPatternIterators::Accessor::advance; + + /** + * Make iterator class a friend. + */ + template + friend class Iterator; - /** - * Make the inner reference class a - * friend if the compiler has a bug - * and requires this. - */ + /** + * Make the inner reference class a + * friend if the compiler has a bug + * and requires this. + */ #ifdef DEAL_II_NESTED_CLASS_FRIEND_BUG - friend class Reference; + friend class Reference; #endif - }; + }; - /** - * STL conforming iterator for constant - * and non-constant matrices. - * - * The first template argument - * denotes the underlying numeric type, - * the second the constness of the - * matrix. - * - * Since there is a specialization of - * this class for - * Constness=false, this class - * is for iterators to constant matrices. - */ - template - class Iterator - { - public: - /** - * Typedef for the matrix type - * (including constness) we are to - * operate on. - */ - typedef - typename Accessor::MatrixType - MatrixType; - - /** - * Constructor. Create an iterator - * into the matrix @p matrix for the - * given row and the index within it. - */ - Iterator (MatrixType *matrix, - const unsigned int row, - const unsigned int index); - - /** - * Constructor. Create the end - * iterator for the given matrix. - */ - Iterator (MatrixType *matrix); + /** + * STL conforming iterator for constant + * and non-constant matrices. + * + * The first template argument + * denotes the underlying numeric type, + * the second the constness of the + * matrix. + * + * Since there is a specialization of + * this class for + * Constness=false, this class + * is for iterators to constant matrices. + */ + template + class Iterator + { + public: + /** + * Typedef for the matrix type + * (including constness) we are to + * operate on. + */ + typedef + typename Accessor::MatrixType + MatrixType; + + /** + * Constructor. Create an iterator + * into the matrix @p matrix for the + * given row and the index within it. + */ + Iterator (MatrixType *matrix, + const unsigned int row, + const unsigned int index); + + /** + * Constructor. Create the end + * iterator for the given matrix. + */ + Iterator (MatrixType *matrix); - /** - * Conversion constructor to get from - * a non-const iterator to a const - * iterator. - */ - Iterator (const internals::SparseMatrixIterators::Iterator &i); + /** + * Conversion constructor to get from + * a non-const iterator to a const + * iterator. + */ + Iterator (const SparseMatrixIterators::Iterator &i); - /** - * Prefix increment. - */ - Iterator & operator++ (); - - /** - * Postfix increment. - */ - Iterator operator++ (int); + /** + * Prefix increment. + */ + Iterator & operator++ (); - /** - * Dereferencing operator. - */ - const Accessor & operator* () const; + /** + * Postfix increment. + */ + 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 Iterator &) const; + /** + * Dereferencing operator. + */ + const Accessor * operator-> () const; - /** - * Inverse of ==. - */ - bool operator != (const Iterator &) const; + /** + * Comparison. True, if + * both iterators point to + * the same matrix + * position. + */ + bool operator == (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. - * - * This function is only valid if - * both iterators point into the same - * matrix. - */ - bool operator < (const Iterator &) const; + /** + * Inverse of ==. + */ + bool operator != (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. + * + * This function is only valid if + * both iterators point into the same + * matrix. + */ + bool operator < (const Iterator &) const; - /** - * Comparison operator. Works in the - * same way as above operator, just - * the other way round. - */ - bool operator > (const Iterator &) const; + /** + * Comparison operator. Works in the + * same way as above operator, just + * the other way round. + */ + bool operator > (const Iterator &) const; - private: - /** - * Store an object of the - * accessor class. - */ - Accessor accessor; - }; + private: + /** + * Store an object of the + * accessor class. + */ + Accessor accessor; + }; - } } @@ -482,7 +479,7 @@ class SparseMatrix : public virtual Subscriptor * matrix. */ typedef - internals::SparseMatrixIterators::Iterator + SparseMatrixIterators::Iterator const_iterator; /** @@ -495,7 +492,7 @@ class SparseMatrix : public virtual Subscriptor * a sparse matrix is attached to it. */ typedef - internals::SparseMatrixIterators::Iterator + SparseMatrixIterators::Iterator iterator; /** @@ -2434,314 +2431,312 @@ SparseMatrix::copy_from (const ForwardIterator begin, //--------------------------------------------------------------------------- -namespace internals +namespace SparseMatrixIterators { - namespace SparseMatrixIterators - { - template - inline - Accessor:: - Accessor (const MatrixType *matrix, - const unsigned int row, - const unsigned int index) - : - SparsityPatternIterators::Accessor (&matrix->get_sparsity_pattern(), - row, index), - matrix (matrix) - {} - - - - template - inline - Accessor:: - Accessor (const MatrixType *matrix) - : - SparsityPatternIterators::Accessor (&matrix->get_sparsity_pattern()), - matrix (matrix) - {} + template + inline + Accessor:: + Accessor (const MatrixType *matrix, + const unsigned int row, + const unsigned int index) + : + SparsityPatternIterators::Accessor (&matrix->get_sparsity_pattern(), + row, index), + matrix (matrix) + {} + + + + template + inline + Accessor:: + Accessor (const MatrixType *matrix) + : + SparsityPatternIterators::Accessor (&matrix->get_sparsity_pattern()), + matrix (matrix) + {} - template - inline - Accessor:: - Accessor (const internals::SparseMatrixIterators::Accessor &a) - : - SparsityPatternIterators::Accessor (a), - matrix (&a.get_matrix()) - {} + template + inline + Accessor:: + Accessor (const SparseMatrixIterators::Accessor &a) + : + SparsityPatternIterators::Accessor (a), + matrix (&a.get_matrix()) + {} - template - inline - number - Accessor::value () const - { - return matrix->raw_entry(a_row, a_index); - } + template + inline + number + Accessor::value () const + { + return matrix->raw_entry(a_row, a_index); + } - template - inline - typename Accessor::MatrixType & - Accessor::get_matrix () const - { - return *matrix; - } + template + inline + typename Accessor::MatrixType & + Accessor::get_matrix () const + { + return *matrix; + } - template - inline - Accessor::Reference:: - Reference (const Accessor *accessor, - const bool) - : - accessor (accessor) - {} + template + inline + Accessor::Reference:: + Reference (const Accessor *accessor, + const bool) + : + accessor (accessor) + {} - template - inline - Accessor::Reference::operator number() const - { - return accessor->matrix->raw_entry(accessor->a_row, - accessor->a_index); - } + template + inline + Accessor::Reference::operator number() const + { + return accessor->matrix->raw_entry(accessor->a_row, + accessor->a_index); + } - template - inline - const typename Accessor::Reference & - Accessor::Reference::operator = (const number n) const - { + template + inline + const typename Accessor::Reference & + Accessor::Reference::operator = (const number n) const + { //TODO: one could optimize this by not going again through the mapping from row/col index to global index - accessor->matrix->set (accessor->row(), accessor->column(), n); - return *this; - } + accessor->matrix->set (accessor->row(), accessor->column(), n); + return *this; + } - template - inline - const typename Accessor::Reference & - Accessor::Reference::operator += (const number n) const - { + template + inline + const typename Accessor::Reference & + Accessor::Reference::operator += (const number n) const + { //TODO: one could optimize this by not going again through the mapping from row/col index to global index - accessor->matrix->set (accessor->row(), accessor->column(), - static_cast(*this) + n); - return *this; - } + accessor->matrix->set (accessor->row(), accessor->column(), + static_cast(*this) + n); + return *this; + } - template - inline - const typename Accessor::Reference & - Accessor::Reference::operator -= (const number n) const - { + template + inline + const typename Accessor::Reference & + Accessor::Reference::operator -= (const number n) const + { //TODO: one could optimize this by not going again through the mapping from row/col index to global index - accessor->matrix->set (accessor->row(), accessor->column(), - static_cast(*this) - n); - return *this; - } + accessor->matrix->set (accessor->row(), accessor->column(), + static_cast(*this) - n); + return *this; + } - template - inline - const typename Accessor::Reference & - Accessor::Reference::operator *= (const number n) const - { + template + inline + const typename Accessor::Reference & + Accessor::Reference::operator *= (const number n) const + { //TODO: one could optimize this by not going again through the mapping from row/col index to global index - accessor->matrix->set (accessor->row(), accessor->column(), - static_cast(*this)*n); - return *this; - } + accessor->matrix->set (accessor->row(), accessor->column(), + static_cast(*this)*n); + return *this; + } - template - inline - const typename Accessor::Reference & - Accessor::Reference::operator /= (const number n) const - { + template + inline + const typename Accessor::Reference & + Accessor::Reference::operator /= (const number n) const + { //TODO: one could optimize this by not going again through the mapping from row/col index to global index - accessor->matrix->set (accessor->row(), accessor->column(), - static_cast(*this)/n); - return *this; - } + accessor->matrix->set (accessor->row(), accessor->column(), + static_cast(*this)/n); + return *this; + } - template - inline - Accessor:: - Accessor (MatrixType *matrix, - const unsigned int row, - const unsigned int index) - : - SparsityPatternIterators::Accessor (&matrix->get_sparsity_pattern(), - row, index), - matrix (matrix) - {} - - - - template - inline - Accessor:: - Accessor (MatrixType *matrix) - : - SparsityPatternIterators::Accessor (&matrix->get_sparsity_pattern()), - matrix (matrix) - {} + template + inline + Accessor:: + Accessor (MatrixType *matrix, + const unsigned int row, + const unsigned int index) + : + SparsityPatternIterators::Accessor (&matrix->get_sparsity_pattern(), + row, index), + matrix (matrix) + {} + + + + template + inline + Accessor:: + Accessor (MatrixType *matrix) + : + SparsityPatternIterators::Accessor (&matrix->get_sparsity_pattern()), + matrix (matrix) + {} - template - inline - typename Accessor::Reference - Accessor::value() const - { - return Reference(this,true); - } + template + inline + typename Accessor::Reference + Accessor::value() const + { + return Reference(this,true); + } - template - inline - typename Accessor::MatrixType & - Accessor::get_matrix () const - { - return *matrix; - } + template + inline + typename Accessor::MatrixType & + Accessor::get_matrix () const + { + return *matrix; + } - template - inline - Iterator:: - Iterator (MatrixType *matrix, - const unsigned int r, - const unsigned int i) - : - accessor(matrix, r, i) - {} - - - - template - inline - Iterator:: - Iterator (MatrixType *matrix) - : - accessor(matrix) - {} - - - - template - inline - Iterator:: - Iterator (const internals::SparseMatrixIterators::Iterator &i) - : - accessor(*i) - {} + template + inline + Iterator:: + Iterator (MatrixType *matrix, + const unsigned int r, + const unsigned int i) + : + accessor(matrix, r, i) + {} + + + + template + inline + Iterator:: + Iterator (MatrixType *matrix) + : + accessor(matrix) + {} + + + + template + inline + Iterator:: + Iterator (const SparseMatrixIterators::Iterator &i) + : + accessor(*i) + {} - template - inline - Iterator & - Iterator::operator++ () - { - accessor.advance (); - return *this; - } + template + inline + Iterator & + Iterator::operator++ () + { + accessor.advance (); + return *this; + } - template - inline - Iterator - Iterator::operator++ (int) - { - const Iterator iter = *this; - accessor.advance (); - return iter; - } + template + inline + Iterator + Iterator::operator++ (int) + { + const Iterator iter = *this; + accessor.advance (); + return iter; + } - template - inline - const Accessor & - Iterator::operator* () const - { - return accessor; - } + template + inline + const Accessor & + Iterator::operator* () const + { + return accessor; + } - template - inline - const Accessor * - Iterator::operator-> () const - { - return &accessor; - } + template + inline + const Accessor * + Iterator::operator-> () const + { + return &accessor; + } - template - inline - bool - Iterator:: - operator == (const Iterator& other) const - { - return (accessor == other.accessor); - } + template + inline + bool + Iterator:: + operator == (const Iterator& other) const + { + return (accessor == other.accessor); + } - template - inline - bool - Iterator:: - operator != (const Iterator& other) const - { - return ! (*this == other); - } + template + inline + bool + Iterator:: + operator != (const Iterator& other) const + { + return ! (*this == other); + } - template - inline - bool - Iterator:: - operator < (const Iterator& other) const - { - Assert (&accessor.get_matrix() == &other.accessor.get_matrix(), - ExcInternalError()); + template + inline + bool + Iterator:: + operator < (const Iterator& other) const + { + Assert (&accessor.get_matrix() == &other.accessor.get_matrix(), + ExcInternalError()); - return (accessor < other.accessor); - } + return (accessor < other.accessor); + } - template - inline - bool - Iterator:: - operator > (const Iterator& other) const - { - return (other < *this); - } - + template + inline + bool + Iterator:: + operator > (const Iterator& other) const + { + return (other < *this); } + } + template inline typename SparseMatrix::const_iterator diff --git a/deal.II/lac/include/lac/sparsity_pattern.h b/deal.II/lac/include/lac/sparsity_pattern.h index c946b18591..b4c51d34dd 100644 --- a/deal.II/lac/include/lac/sparsity_pattern.h +++ b/deal.II/lac/include/lac/sparsity_pattern.h @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 by the deal.II authors +// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -188,230 +188,230 @@ namespace internals get_column_index_from_iterator (const std::pair &i); } - +} + - namespace SparsityPatternIterators - { - // forward declaration - class Iterator; +namespace SparsityPatternIterators +{ + // forward declaration + class Iterator; - /** - * Accessor class for iterators into - * sparsity patterns. This class is also - * the base class for both const and - * non-const accessor classes into sparse - * matrices. - * - * Note that this class only allow read - * access to elements, providing their - * row and column number. It does not - * allow to modify the sparsity pattern - * itself. - */ - class Accessor - { - public: - /** - * Constructor. - */ - Accessor (const SparsityPattern *matrix, - const unsigned int row, - const unsigned int index); - - /** - * Constructor. Construct the end - * accessor for the given sparsity - * pattern. - */ - Accessor (const SparsityPattern *matrix); - - /** - * Row number of the element - * represented by this object. This - * function can only be called for - * entries for which is_valid_entry() - * is true. - */ - unsigned int row () const; - - /** - * Index in row of the element - * represented by this object. This - * function can only be called for - * entries for which is_valid_entry() - * is true. - */ - unsigned int index () const; - - /** - * Column number of the element - * represented by this object. This - * function can only be called for - * entries for which is_valid_entry() is - * true. - */ - unsigned int column () const; - - /** - * Return whether the sparsity - * pattern entry pointed to by this - * iterator is valid or not. Note - * that after compressing the - * sparsity pattern, all entries are - * valid. However, before - * compression, the sparsity pattern - * allocated some memory to be used - * while still adding new nonzero - * entries; if you create iterators - * in this phase of the sparsity - * pattern's lifetime, you will - * iterate over elements that are not - * valid. If this is so, then this - * function will return false. - */ - inline bool is_valid_entry () const; - - - /** - * Comparison. True, if - * both iterators point to - * the same matrix - * position. - */ - bool operator == (const Accessor &) 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. - * - * This function is only valid if - * both iterators point into the same - * sparsity pattern. - */ - bool operator < (const Accessor &) const; - - /** @addtogroup Exceptions - * @{ */ + /** + * Accessor class for iterators into + * sparsity patterns. This class is also + * the base class for both const and + * non-const accessor classes into sparse + * matrices. + * + * Note that this class only allow read + * access to elements, providing their + * row and column number. It does not + * allow to modify the sparsity pattern + * itself. + */ + class Accessor + { + public: + /** + * Constructor. + */ + Accessor (const SparsityPattern *matrix, + const unsigned int row, + const unsigned int index); + + /** + * Constructor. Construct the end + * accessor for the given sparsity + * pattern. + */ + Accessor (const SparsityPattern *matrix); + + /** + * Row number of the element + * represented by this object. This + * function can only be called for + * entries for which is_valid_entry() + * is true. + */ + unsigned int row () const; + + /** + * Index in row of the element + * represented by this object. This + * function can only be called for + * entries for which is_valid_entry() + * is true. + */ + unsigned int index () const; + + /** + * Column number of the element + * represented by this object. This + * function can only be called for + * entries for which is_valid_entry() is + * true. + */ + unsigned int column () const; + + /** + * Return whether the sparsity + * pattern entry pointed to by this + * iterator is valid or not. Note + * that after compressing the + * sparsity pattern, all entries are + * valid. However, before + * compression, the sparsity pattern + * allocated some memory to be used + * while still adding new nonzero + * entries; if you create iterators + * in this phase of the sparsity + * pattern's lifetime, you will + * iterate over elements that are not + * valid. If this is so, then this + * function will return false. + */ + inline bool is_valid_entry () const; + + + /** + * Comparison. True, if + * both iterators point to + * the same matrix + * position. + */ + bool operator == (const Accessor &) 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. + * + * This function is only valid if + * both iterators point into the same + * sparsity pattern. + */ + bool operator < (const Accessor &) const; + + /** @addtogroup Exceptions + * @{ */ - /** - * Exception - */ - DeclException0 (ExcInvalidIterator); - //@} - protected: - /** - * The sparsity pattern we operate on - * accessed. - */ - const SparsityPattern * sparsity_pattern; - - /** - * Current row number. - */ - unsigned int a_row; - - /** - * Current index in row. - */ - unsigned int a_index; - - /** - * Move the accessor to the next - * nonzero entry in the matrix. - */ - void advance (); + /** + * Exception + */ + DeclException0 (ExcInvalidIterator); + //@} + protected: + /** + * The sparsity pattern we operate on + * accessed. + */ + const SparsityPattern * sparsity_pattern; + + /** + * Current row number. + */ + unsigned int a_row; + + /** + * Current index in row. + */ + unsigned int a_index; + + /** + * Move the accessor to the next + * nonzero entry in the matrix. + */ + void advance (); - /** - * Grant access to iterator class. - */ - friend class Iterator; - }; + /** + * Grant access to iterator class. + */ + friend class Iterator; + }; - /** - * STL conforming iterator walking over - * the elements of a sparsity pattern. - */ - class Iterator - { - public: - /** - * Constructor. Create an iterator - * into the sparsity pattern @p sp for the - * given row and the index within it. - */ - Iterator (const SparsityPattern *sp, - const unsigned int row, - const unsigned int index); + /** + * STL conforming iterator walking over + * the elements of a sparsity pattern. + */ + class Iterator + { + public: + /** + * Constructor. Create an iterator + * into the sparsity pattern @p sp for the + * given row and the index within it. + */ + Iterator (const SparsityPattern *sp, + const unsigned int row, + const unsigned int index); - /** - * Prefix increment. - */ - Iterator& operator++ (); - - /** - * Postfix increment. - */ - 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 Iterator&) const; - - /** - * Inverse of ==. - */ - bool operator != (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. - * - * This function is only valid if - * both iterators point into the same - * matrix. - */ - bool operator < (const Iterator&) const; - - private: - /** - * Store an object of the - * accessor class. - */ - Accessor accessor; - }; - - } + /** + * Prefix increment. + */ + Iterator& operator++ (); + + /** + * Postfix increment. + */ + 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 Iterator&) const; + + /** + * Inverse of ==. + */ + bool operator != (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. + * + * This function is only valid if + * both iterators point into the same + * matrix. + */ + bool operator < (const Iterator&) const; + + private: + /** + * Store an object of the + * accessor class. + */ + Accessor accessor; + }; } + /** * Structure representing the sparsity pattern of a sparse matrix. * @@ -430,7 +430,7 @@ class SparsityPattern : public Subscriptor * sparsity pattern. */ typedef - internals::SparsityPatternIterators::Iterator + SparsityPatternIterators::Iterator const_iterator; /** @@ -444,7 +444,7 @@ class SparsityPattern : public Subscriptor * const_iterator. */ typedef - internals::SparsityPatternIterators::Iterator + SparsityPatternIterators::Iterator iterator; @@ -1663,204 +1663,200 @@ class SparsityPattern : public Subscriptor #ifndef DOXYGEN -namespace internals -{ - namespace SparsityPatternIterators - { - inline - Accessor:: - Accessor (const SparsityPattern *sparsity_pattern, - const unsigned int r, - const unsigned int i) - : - sparsity_pattern(sparsity_pattern), - a_row(r), - a_index(i) - {} - - - inline - Accessor:: - Accessor (const SparsityPattern *sparsity_pattern) - : - sparsity_pattern(sparsity_pattern), - a_row(sparsity_pattern->n_rows()), - a_index(0) - {} - - - inline - unsigned int - Accessor::row() const - { - Assert (is_valid_entry() == true, ExcInvalidIterator()); +namespace SparsityPatternIterators +{ + inline + Accessor:: + Accessor (const SparsityPattern *sparsity_pattern, + const unsigned int r, + const unsigned int i) + : + sparsity_pattern(sparsity_pattern), + a_row(r), + a_index(i) + {} + + + inline + Accessor:: + Accessor (const SparsityPattern *sparsity_pattern) + : + sparsity_pattern(sparsity_pattern), + a_row(sparsity_pattern->n_rows()), + a_index(0) + {} + + + inline + unsigned int + Accessor::row() const + { + Assert (is_valid_entry() == true, ExcInvalidIterator()); - return a_row; - } + return a_row; + } - inline - unsigned int - Accessor::column() const - { - Assert (is_valid_entry() == true, ExcInvalidIterator()); + inline + unsigned int + Accessor::column() const + { + Assert (is_valid_entry() == true, ExcInvalidIterator()); - return (sparsity_pattern - ->get_column_numbers()[sparsity_pattern - ->get_rowstart_indices()[a_row]+a_index]); - } + return (sparsity_pattern + ->get_column_numbers()[sparsity_pattern + ->get_rowstart_indices()[a_row]+a_index]); + } - inline - unsigned int - Accessor::index() const - { - Assert (is_valid_entry() == true, ExcInvalidIterator()); + inline + unsigned int + Accessor::index() const + { + Assert (is_valid_entry() == true, ExcInvalidIterator()); - return a_index; - } + return a_index; + } - inline - bool - Accessor::is_valid_entry () const - { - return (sparsity_pattern - ->get_column_numbers()[sparsity_pattern - ->get_rowstart_indices()[a_row]+a_index] - != SparsityPattern::invalid_entry); - } + inline + bool + Accessor::is_valid_entry () const + { + return (sparsity_pattern + ->get_column_numbers()[sparsity_pattern + ->get_rowstart_indices()[a_row]+a_index] + != SparsityPattern::invalid_entry); + } - inline - bool - Accessor::operator == (const Accessor& other) const - { - return (sparsity_pattern == other.sparsity_pattern && - a_row == other.a_row && - a_index == other.a_index); - } + inline + bool + Accessor::operator == (const Accessor& other) const + { + return (sparsity_pattern == other.sparsity_pattern && + a_row == other.a_row && + a_index == other.a_index); + } - inline - bool - Accessor::operator < (const Accessor& other) const - { - Assert (sparsity_pattern == other.sparsity_pattern, - ExcInternalError()); + inline + bool + Accessor::operator < (const Accessor& other) const + { + Assert (sparsity_pattern == other.sparsity_pattern, + ExcInternalError()); - return (a_row < other.a_row || - (a_row == other.a_row && - a_index < other.a_index)); - } + return (a_row < other.a_row || + (a_row == other.a_row && + a_index < other.a_index)); + } - inline - void - Accessor::advance () - { - Assert (a_row < sparsity_pattern->n_rows(), ExcIteratorPastEnd()); + inline + void + Accessor::advance () + { + Assert (a_row < sparsity_pattern->n_rows(), ExcIteratorPastEnd()); - ++a_index; - - // if at end of line: cycle until we - // find a row with a nonzero number of - // entries - while (a_index >= sparsity_pattern->row_length(a_row)) - { - a_index = 0; - ++a_row; - - // if we happened to find the end - // of the matrix, then stop here - if (a_row == sparsity_pattern->n_rows()) - break; - } - } + ++a_index; + + // if at end of line: cycle until we + // find a row with a nonzero number of + // entries + while (a_index >= sparsity_pattern->row_length(a_row)) + { + a_index = 0; + ++a_row; + + // if we happened to find the end + // of the matrix, then stop here + if (a_row == sparsity_pattern->n_rows()) + break; + } + } - inline - Iterator::Iterator (const SparsityPattern *sparsity_pattern, - const unsigned int r, - const unsigned int i) - : - accessor(sparsity_pattern, r, i) - {} + inline + Iterator::Iterator (const SparsityPattern *sparsity_pattern, + const unsigned int r, + const unsigned int i) + : + accessor(sparsity_pattern, r, i) + {} - inline - Iterator & - Iterator::operator++ () - { - accessor.advance (); - return *this; - } + inline + Iterator & + Iterator::operator++ () + { + accessor.advance (); + return *this; + } - inline - Iterator - Iterator::operator++ (int) - { - const Iterator iter = *this; - accessor.advance (); - return iter; - } + inline + Iterator + Iterator::operator++ (int) + { + const Iterator iter = *this; + accessor.advance (); + return iter; + } - inline - const Accessor & - Iterator::operator* () const - { - return accessor; - } + inline + const Accessor & + Iterator::operator* () const + { + return accessor; + } - inline - const Accessor * - Iterator::operator-> () const - { - return &accessor; - } + inline + const Accessor * + Iterator::operator-> () const + { + return &accessor; + } - inline - bool - Iterator::operator == (const Iterator& other) const - { - return (accessor == other.accessor); - } + inline + bool + Iterator::operator == (const Iterator& other) const + { + return (accessor == other.accessor); + } - inline - bool - Iterator::operator != (const Iterator& other) const - { - return ! (*this == other); - } + inline + bool + Iterator::operator != (const Iterator& other) const + { + return ! (*this == other); + } - inline - bool - Iterator::operator < (const Iterator& other) const - { - return accessor < other.accessor; - } - + inline + bool + Iterator::operator < (const Iterator& other) const + { + return accessor < other.accessor; } + } - inline SparsityPattern::iterator SparsityPattern::begin () const