]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Add block matrix test.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 5 May 2000 14:04:38 +0000 (14:04 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 5 May 2000 14:04:38 +0000 (14:04 +0000)
git-svn-id: https://svn.dealii.org/trunk@2799 0785d39b-7218-0410-832d-ea1e28bc413d

tests/lac/block_matrices.cc [new file with mode: 0644]
tests/lac/block_matrices.checked [new file with mode: 0644]

diff --git a/tests/lac/block_matrices.cc b/tests/lac/block_matrices.cc
new file mode 100644 (file)
index 0000000..66c7f26
--- /dev/null
@@ -0,0 +1,91 @@
+//----------------------------  solver.cc  ---------------------------
+//    $Id$
+//    Version: $Name$
+//
+//    Copyright (C) 2000 by the deal.II authors
+//
+//    This file is subject to QPL and may not be  distributed
+//    without copyright and license information. Please refer
+//    to the file deal.II/doc/license.html for the  text  and
+//    further information on this license.
+//
+//----------------------------  solver.cc  ---------------------------
+
+
+#include <base/logstream.h>
+#include <lac/block_sparsity_pattern.h>
+#include <fstream>
+#include <algorithm>
+
+
+
+
+int main () 
+{
+  ofstream logfile("block_matrices.output");
+  logfile.setf(ios::fixed);
+  logfile.precision(3);
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  BlockSparsityPattern<3,2> bsp;
+                                  // set sizes
+  bsp.block(0,0).reinit ( 2, 10, 7);
+  bsp.block(0,1).reinit ( 2, 19, 8);
+  bsp.block(1,0).reinit ( 7, 10, 6);
+  bsp.block(1,1).reinit ( 7, 19, 7);
+  bsp.block(2,0).reinit (10, 10, 6);
+  bsp.block(2,1).reinit (10, 19, 12);
+  bsp.collect_sizes ();
+  
+  for (unsigned int row=0; row<19; ++row)
+    for (unsigned int i=0; i<10; ++i)
+      bsp.add (row, (row*5+i*9)%29);
+  bsp.compress ();
+
+                                  // now check whether the elements
+                                  // we inserted are indeed those
+                                  // that are in there. for now, we
+                                  // only check their number, but
+                                  // their places are checked later
+                                  // with the matrix-vector
+                                  // operations.
+  for (unsigned int row=0; row<19; ++row)
+    {
+                                      // first count the number of
+                                      // elements in each row
+      vector<bool> t(29, false);
+      for (unsigned int i=0; i<10; ++i)
+       t[(row*5+i*9)%29] = true;
+                                      // if we are in the third block
+                                      // row, then the first matrix
+                                      // is square, so there may be
+                                      // an additional element
+      if (row>=9)
+       t[row-9] = true;
+
+      deallog << "Row " << row << " sparsity:  ";
+      for (unsigned int i=0; i<29; ++i)
+       deallog << t[i];
+      deallog << endl;
+      
+      const unsigned int c=count(t.begin(), t.end(), true);
+
+                                      // now see how many elements
+                                      // there really are:
+      unsigned int ac=0;
+      for (unsigned int col=0; col<2; ++col)
+       if (row<2)
+         ac += bsp.block(0,col).row_length(row-0);
+       else
+         if (row<9)
+           ac += bsp.block(1,col).row_length(row-2);
+         else
+           ac += bsp.block(2,col).row_length(row-9);
+      deallog << "Row=" << row
+             << ": expected length=" << c
+             << ", actual length=" << ac
+             << endl;
+      Assert (c==ac, ExcInternalError());
+    };
+};
diff --git a/tests/lac/block_matrices.checked b/tests/lac/block_matrices.checked
new file mode 100644 (file)
index 0000000..a5fa48c
--- /dev/null
@@ -0,0 +1,39 @@
+
+DEAL::Row 0 sparsity:  10000101010000101010000101010
+DEAL::Row=0: expected length=10, actual length=10
+DEAL::Row 1 sparsity:  01010100001010100001010100001
+DEAL::Row=1: expected length=10, actual length=10
+DEAL::Row 2 sparsity:  00001010101000010101000010101
+DEAL::Row=2: expected length=10, actual length=10
+DEAL::Row 3 sparsity:  10101000010101010000101010000
+DEAL::Row=3: expected length=10, actual length=10
+DEAL::Row 4 sparsity:  10000101010000101010100001010
+DEAL::Row=4: expected length=10, actual length=10
+DEAL::Row 5 sparsity:  01010100001010100001010101000
+DEAL::Row=5: expected length=10, actual length=10
+DEAL::Row 6 sparsity:  01000010101000010101000010101
+DEAL::Row=6: expected length=10, actual length=10
+DEAL::Row 7 sparsity:  10101010000101010000101010000
+DEAL::Row=7: expected length=10, actual length=10
+DEAL::Row 8 sparsity:  10000101010100001010100001010
+DEAL::Row=8: expected length=10, actual length=10
+DEAL::Row 9 sparsity:  11010100001010101000010101000
+DEAL::Row=9: expected length=11, actual length=11
+DEAL::Row 10 sparsity:  01000010101000010101010000101
+DEAL::Row=10: expected length=10, actual length=10
+DEAL::Row 11 sparsity:  00101010000101010000101010100
+DEAL::Row=11: expected length=10, actual length=10
+DEAL::Row 12 sparsity:  10110001010100001010100001010
+DEAL::Row=12: expected length=11, actual length=11
+DEAL::Row 13 sparsity:  01011101000010101000010101000
+DEAL::Row=13: expected length=11, actual length=11
+DEAL::Row 14 sparsity:  01000110101010000101010000101
+DEAL::Row=14: expected length=11, actual length=11
+DEAL::Row 15 sparsity:  00101010000101010100001010100
+DEAL::Row=15: expected length=10, actual length=10
+DEAL::Row 16 sparsity:  10100001010100001010101000010
+DEAL::Row=16: expected length=10, actual length=10
+DEAL::Row 17 sparsity:  00010101100010101000010101010
+DEAL::Row=17: expected length=11, actual length=11
+DEAL::Row 18 sparsity:  01010000111010000101010000101
+DEAL::Row=18: expected length=11, actual length=11

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.