]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Can simplify collective set and add functions a little bit.
authorMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Thu, 1 Oct 2009 17:07:55 +0000 (17:07 +0000)
committerMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Thu, 1 Oct 2009 17:07:55 +0000 (17:07 +0000)
git-svn-id: https://svn.dealii.org/trunk@19641 0785d39b-7218-0410-832d-ea1e28bc413d

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

index 90afcc5e5a6852952f232558d029dfc604f286cd..f59371ec4e69c5179a2d551f20a79d50821ac387 100644 (file)
@@ -499,8 +499,13 @@ SparseMatrix<number>::add (const unsigned int  row,
              ExcMessage("The given value is not finite but either "
                         "infinite or Not A Number (NaN)"));
 
-      if (value == 0 && elide_zero_values == true)
+#ifdef DEBUG
+      if (elide_zero_values==true && value == 0)
+       continue;
+#else
+      if (value == 0)
        continue;
+#endif
 
                                   // check whether the next index to add is
                                   // the next present index in the sparsity
@@ -517,9 +522,7 @@ SparseMatrix<number>::add (const unsigned int  row,
                                   // value we add is zero
       if (index == SparsityPattern::invalid_entry)
        {
-         Assert ((index != SparsityPattern::invalid_entry) ||
-                 (value == 0.),
-                 ExcInvalidIndex(row,col_indices[j]));
+         Assert (value == 0., ExcInvalidIndex(row,col_indices[j]));
          continue;
        }
 
@@ -550,39 +553,69 @@ SparseMatrix<number>::set (const unsigned int  row,
   std::size_t index = cols->get_rowstart_indices()[row], next_index = index;
   const std::size_t next_row_index = cols->get_rowstart_indices()[row+1];
 
-  for (unsigned int j=0; j<n_cols; ++j)
+  if (elide_zero_values == true)
     {
-      const number value = values[j];
-      Assert (numbers::is_finite(value),
-             ExcMessage("The given value is not finite but either "
-                        "infinite or Not A Number (NaN)"));
+      for (unsigned int j=0; j<n_cols; ++j)
+       {
+         const number value = values[j];
+         Assert (numbers::is_finite(value),
+                 ExcMessage("The given value is not finite but either "
+                            "infinite or Not A Number (NaN)"));
 
-      if (value == 0 && elide_zero_values == true)
-       continue;
+         if (value == 0)
+           continue;
 
                                   // check whether the next index to set is
                                   // the next present index in the sparsity
                                   // pattern (otherwise, do a binary
                                   // search)
-      if (index != next_row_index && my_cols[index] == col_indices[j])
-       goto set_value;
+         if (index != next_row_index && my_cols[index] == col_indices[j])
+           goto set_value;
 
-      next_index = cols->operator()(row, col_indices[j]);
+         next_index = cols->operator()(row, col_indices[j]);
 
                                   // it is allowed to set elements in
                                   // the matrix that are not part of
                                   // the sparsity pattern, if the
                                   // value to which we set it is zero
-      if (next_index == SparsityPattern::invalid_entry)
-       {
-         Assert (value == 0., ExcInvalidIndex(row,col_indices[j]));
-         continue;
+         if (next_index == SparsityPattern::invalid_entry)
+           {
+             Assert (false, ExcInvalidIndex(row,col_indices[j]));
+             continue;
+           }
+         index = next_index;
+
+       set_value:
+         val[index] = value;
+         ++index;
        }
-      index = next_index;
+    }
+  else
+    {
+                               // same code as above, but now check for zeros
+      for (unsigned int j=0; j<n_cols; ++j)
+       {
+         const number value = values[j];
+         Assert (numbers::is_finite(value),
+                 ExcMessage("The given value is not finite but either "
+                            "infinite or Not A Number (NaN)"));
 
-    set_value:
-      val[index] = value;
-      ++index;
+         if (index != next_row_index && my_cols[index] == col_indices[j])
+           goto set_value_checked;
+
+         next_index = cols->operator()(row, col_indices[j]);
+
+         if (next_index == SparsityPattern::invalid_entry)
+           {
+             Assert (value == 0., ExcInvalidIndex(row,col_indices[j]));
+             continue;
+           }
+         index = next_index;
+
+       set_value_checked:
+         val[index] = value;
+         ++index;
+       }
     }
 }
 

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.