]> https://gitweb.dealii.org/ - dealii.git/commitdiff
remove sneaky bug in the SparseMatrix::set function, some small rearrangements
authorRalf Hartmann <Ralf.Hartmann@dlr.de>
Fri, 10 Mar 2000 13:16:38 +0000 (13:16 +0000)
committerRalf Hartmann <Ralf.Hartmann@dlr.de>
Fri, 10 Mar 2000 13:16:38 +0000 (13:16 +0000)
git-svn-id: https://svn.dealii.org/trunk@2574 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/sparse_matrix.h

index 3aa504e119a1446451a21294c016bd3cf3001e7d..3fa840c0fdf09e544c86d635013481139da3a3a7 100644 (file)
@@ -683,29 +683,38 @@ void SparseMatrix<number>::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 <typename number>
 inline
 void SparseMatrix<number>::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 <typename number>
 inline
 number SparseMatrix<number>::operator () (const unsigned int i,

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.