From: Wolfgang Bangerth Date: Fri, 2 Jun 2000 13:52:45 +0000 (+0000) Subject: Implement the el(i,j) function. X-Git-Tag: v8.0.0~20423 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3e37306f7fd8af65a147a73f0d05219ec645de11;p=dealii.git Implement the el(i,j) function. git-svn-id: https://svn.dealii.org/trunk@2989 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 2d9d7d0eb4..4f8904cede 100644 --- a/deal.II/lac/include/lac/sparse_matrix.h +++ b/deal.II/lac/include/lac/sparse_matrix.h @@ -278,28 +278,59 @@ class SparseMatrix : public Subscriptor const SparseMatrix &matrix); /** - * Return the value of the entry (i,j). - * This may be an expensive operation - * and you should always take care - * where to call this function. - * In order to avoid abuse, this function - * throws an exception if the wanted - * element does not exist in the matrix. - */ - number operator () (const unsigned int i, const unsigned int j) const; + * Return the value of the entry + * (i,j). This may be an + * expensive operation and you + * should always take care where + * to call this function. In + * order to avoid abuse, this + * function throws an exception + * if the required element does + * not exist in the matrix. + * + * In case you want a function + * that returns zero instead (for + * entries that are not in the + * sparsity pattern of the + * matrix), use the #el# + * function. + */ + number operator () (const unsigned int i, + const unsigned int j) const; + + /** + * This function is mostly like + * #operator()# in that it + * returns the value of the + * matrix entry #(i,j)#. The only + * difference is that if this + * entry does not exist in the + * sparsity pattern, then instead + * of raising an exception, zero + * is returned. While this may be + * convenient in some cases, note + * that it is simple to write + * algorithms that are slow + * compared to an optimal + * solution, since the sparsity + * of the matrix is not used. + */ + number el (const unsigned int i, + const unsigned int j) const; /** * Return the main diagonal element in * the #i#th row. This function throws an * error if the matrix is not square. * - * This function is considerably faster - * than the #operator()#, since for - * square matrices, the diagonal entry is - * always the first to be stored in each - * row and access therefore does not - * involve searching for the right column - * number. + * This function is considerably + * faster than the #operator()#, + * since for square matrices, the + * diagonal entry is always the + * first to be stored in each row + * and access therefore does not + * involve searching for the + * right column number. */ number diag_element (const unsigned int i) const; @@ -850,6 +881,23 @@ number SparseMatrix::operator () (const unsigned int i, }; + +template +inline +number SparseMatrix::el (const unsigned int i, + const unsigned int j) const +{ + Assert (cols != 0, ExcMatrixNotInitialized()); + const unsigned int index = cols->operator()(i,j); + + if (index != SparsityPattern::invalid_entry) + return val[index]; + else + return 0; +}; + + + template inline number SparseMatrix::diag_element (const unsigned int i) const