From: wolf Date: Thu, 10 May 2001 14:35:21 +0000 (+0000) Subject: Implement a function copy_from. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d806f63b2809afa6e4de997086b85659f6fdb9a3;p=dealii-svn.git Implement a function copy_from. git-svn-id: https://svn.dealii.org/trunk@4590 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 2d718610df..6133d3602f 100644 --- a/deal.II/lac/include/lac/sparse_matrix.h +++ b/deal.II/lac/include/lac/sparse_matrix.h @@ -311,6 +311,42 @@ class SparseMatrix : public Subscriptor SparseMatrix & copy_from (const SparseMatrix &source); + /** + * This function is complete + * analogous to the + * @ref{SparsityPattern}@p{::copy_from} + * function in that it allows to + * initialize a whole matrix in + * one step. See there for more + * information on argument types + * and their meaning. You can + * also find a small example on + * how to use this function + * there. + * + * The only difference to the + * cited function is that the + * objects which the inner + * iterator points to need to be + * of type @p{std::pair + void copy_from (const ForwardIterator begin, + const ForwardIterator end); + /** * Add @p{matrix} scaled by * @p{factor} to this matrix. The @@ -773,6 +809,13 @@ class SparseMatrix : public Subscriptor * Exception */ DeclException0 (ExcInvalidConstructorCall); + /** + * Exception + */ + DeclException2 (ExcIteratorRange, + int, int, + << "The iterators denote a range of " << arg1 + << " elements, but the given number of rows was " << arg2); private: /** @@ -994,6 +1037,7 @@ number SparseMatrix::diag_element (const unsigned int i) const }; + template inline number & SparseMatrix::diag_element (const unsigned int i) @@ -1009,6 +1053,7 @@ number & SparseMatrix::diag_element (const unsigned int i) }; + template inline number @@ -1023,6 +1068,7 @@ SparseMatrix::raw_entry (const unsigned int row, }; + template inline number SparseMatrix::global_entry (const unsigned int j) const @@ -1035,6 +1081,7 @@ number SparseMatrix::global_entry (const unsigned int j) const }; + template inline number & SparseMatrix::global_entry (const unsigned int j) @@ -1047,6 +1094,32 @@ number & SparseMatrix::global_entry (const unsigned int j) }; + +template +template +void +SparseMatrix::copy_from (const ForwardIterator begin, + const ForwardIterator end) +{ + Assert (static_cast(std::distance (begin, end)) == m(), + ExcIteratorRange (std::distance (begin, end), m())); + + // for use in the inner loop, we + // define a typedef to the type of + // the inner iterators + typedef typename std::iterator_traits::value_type::const_iterator inner_iterator; + unsigned int row=0; + for (ForwardIterator i=begin; i!=end; ++i, ++row) + { + const inner_iterator end_of_row = i->end(); + for (inner_iterator j=i->begin(); j!=end_of_row; ++j) + // write entries + set (row, j->first, j->second); + }; +}; + + + /*---------------------------- sparse_matrix.h ---------------------------*/ #endif