From: hartmann Date: Fri, 10 Mar 2000 13:16:38 +0000 (+0000) Subject: remove sneaky bug in the SparseMatrix::set function, some small rearrangements X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6a422cb6827ee8ee8470696fb4d68b7197508e1a;p=dealii-svn.git remove sneaky bug in the SparseMatrix::set function, some small rearrangements git-svn-id: https://svn.dealii.org/trunk@2574 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 3aa504e119..3fa840c0fd 100644 --- a/deal.II/lac/include/lac/sparse_matrix.h +++ b/deal.II/lac/include/lac/sparse_matrix.h @@ -683,29 +683,38 @@ void SparseMatrix::set (const unsigned int i, const number value) { Assert (cols != 0, ExcMatrixNotInitialized()); - Assert ((cols->operator()(i,j) != SparsityPattern::invalid_entry) || + // it is allowed to set elements of + // the matrix that are not part of + // the sparsity pattern, if the + // value to which we set it is zero + const unsigned int index = cols->operator()(i,j); + Assert ((index != SparsityPattern::invalid_entry) || (value == 0.), ExcInvalidIndex(i,j)); - if (value != 0.) - val[cols->operator()(i,j)] = value; + if (index != SparsityPattern::invalid_entry) + val[index] = value; }; + template inline void SparseMatrix::add (const unsigned int i, const unsigned int j, const number value) { Assert (cols != 0, ExcMatrixNotInitialized()); - Assert ((cols->operator()(i,j) != SparsityPattern::invalid_entry) || + + const unsigned int index = cols->operator()(i,j); + Assert ((index != SparsityPattern::invalid_entry) || (value == 0.), ExcInvalidIndex(i,j)); if (value != 0.) - val[cols->operator()(i,j)] += value; + val[index] += value; }; + template inline number SparseMatrix::operator () (const unsigned int i,