From 18217543347216a7befa82cc80b8dee593d86b9e Mon Sep 17 00:00:00 2001 From: Ralf Hartmann Date: Fri, 10 Mar 2000 13:16:38 +0000 Subject: [PATCH] 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 --- deal.II/lac/include/lac/sparse_matrix.h | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) 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, -- 2.39.5