]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Avoid a bug with the newly introduced general use of always storing the
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 9 Feb 2013 21:50:29 +0000 (21:50 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 9 Feb 2013 21:50:29 +0000 (21:50 +0000)
diagonal of a square matrix.

git-svn-id: https://svn.dealii.org/trunk@28297 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/source/lac/chunk_sparsity_pattern.cc

index 2983d2b74728c7850e8b574bb1ed1b7e1abe013c..96f6a1238615d44d5a04a5aa93b3eb449c1c3023 100644 (file)
@@ -2,7 +2,7 @@
 //    $Id$
 //    Version: $Name$
 //
-//    Copyright (C) 2008, 2011, 2012 by the deal.II authors
+//    Copyright (C) 2008, 2011, 2012, 2013 by the deal.II authors
 //
 //    This file is subject to QPL and may not be  distributed
 //    without copyright and license information. Please refer
@@ -300,14 +300,22 @@ void ChunkSparsityPattern::copy_from (const FullMatrix<number> &matrix,
 {
   Assert (chunk_size > 0, ExcInvalidNumber (chunk_size));
 
-  // count number of entries per row, then
-  // initialize the underlying sparsity
-  // pattern
+  // count number of entries per row, then initialize the underlying sparsity
+  // pattern. remember to also allocate space for the diagonal entry (if that
+  // hasn't happened yet) if m==n since we always allocate that for diagonal
+  // matrices
   std::vector<unsigned int> entries_per_row (matrix.m(), 0);
   for (unsigned int row=0; row<matrix.m(); ++row)
-    for (unsigned int col=0; col<matrix.n(); ++col)
-      if (matrix(row,col) != 0)
-        ++entries_per_row[row];
+    {
+      for (unsigned int col=0; col<matrix.n(); ++col)
+       if (matrix(row,col) != 0)
+         ++entries_per_row[row];
+
+      if ((matrix.m() == matrix.n())
+         &&
+         (matrix(row,row) == 0))
+       ++entries_per_row[row];
+    }
 
   reinit (matrix.m(), matrix.n(),
           entries_per_row,

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.