]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Improved tests. And some more tests. Should now test everything.
authorkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 8 Sep 2010 16:17:16 +0000 (16:17 +0000)
committerkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 8 Sep 2010 16:17:16 +0000 (16:17 +0000)
git-svn-id: https://svn.dealii.org/trunk@21893 0785d39b-7218-0410-832d-ea1e28bc413d

tests/bits/sparse_matrix_add_entries_01.cc
tests/bits/sparse_matrix_add_entries_02.cc
tests/bits/sparse_matrix_add_entries_03.cc
tests/bits/sparse_matrix_add_entries_04.cc [new file with mode: 0644]
tests/bits/sparse_matrix_add_entries_04/cmp/generic [new file with mode: 0644]
tests/bits/sparse_matrix_add_entries_05.cc [new file with mode: 0644]
tests/bits/sparse_matrix_add_entries_05/cmp/generic [new file with mode: 0644]
tests/bits/sparse_matrix_add_entries_06.cc [new file with mode: 0644]
tests/bits/sparse_matrix_add_entries_06/cmp/generic [new file with mode: 0644]

index 8a90d59830b57e628f664575eb7da5849bc396cc..08e4f44972ae68fd7b8d3098e7a7ab723245aa89 100644 (file)
@@ -27,8 +27,8 @@ void test ()
 {
                                // set up sparse matrix
   SparsityPattern sp (5,5,3);
-  for (unsigned int i=0; i<5; ++i)
-    for (unsigned int j=0; j<5; ++j)
+  for (unsigned int i=0; i<sp.n_rows(); ++i)
+    for (unsigned int j=0; j<sp.n_cols(); ++j)
       if ((i+2*j+1) % 3 == 0)
         sp.add (i,j);
   sp.compress ();
@@ -36,10 +36,10 @@ void test ()
   SparseMatrix<double> m(sp);
 
                                // prepare structure with indices and values
-  std::vector<unsigned int> indices (m.m());
-  for (unsigned int i=0; i<m.m(); ++i)
-    indices[i] = i;
-  std::vector<double> values (5);
+  std::vector<unsigned int> indices (m.n());
+  for (unsigned int j=0; j<m.n(); ++j)
+    indices[j] = j;
+  std::vector<double> values (m.n());
 
                                    // try to add entries from the list. Zeros
                                    // should be filtered out. list is sorted
index 9a01f44394ad2ef07d4d9726049ca959d91b889e..a5d8eea5eb9d1470ab425512bd693f5bbc44e2c8 100644 (file)
@@ -27,8 +27,8 @@ void test ()
 {
                                // set up sparse matrix
   SparsityPattern sp (5,5,3);
-  for (unsigned int i=0; i<5; ++i)
-    for (unsigned int j=0; j<5; ++j)
+  for (unsigned int i=0; i<sp.n_rows(); ++i)
+    for (unsigned int j=0; j<sp.n_cols(); ++j)
       if ((i+2*j+1) % 3 == 0)
         sp.add (i,j);
   sp.compress ();
@@ -36,10 +36,10 @@ void test ()
   SparseMatrix<double> m(sp);
 
                                // prepare structure with indices and values
-  std::vector<unsigned int> indices (m.m());
-  for (unsigned int i=0; i<m.m(); ++i)
-    indices[i] = i;
-  std::vector<double> values (5);
+  std::vector<unsigned int> indices (m.n());
+  for (unsigned int j=0; j<m.n(); ++j)
+    indices[j] = j;
+  std::vector<double> values (m.n());
 
                                    // try to add entries from the list. Zeros
                                    // should be filtered out. list is sorted
index d0bd800ab8162e8aeab3ea320bebe6ef3078d2b4..acb2b78c011224860d5272868b0a86d55c400792 100644 (file)
@@ -27,8 +27,8 @@ void test ()
 {
                                // set up sparse matrix
   SparsityPattern sp (5,5,3);
-  for (unsigned int i=0; i<5; ++i)
-    for (unsigned int j=0; j<5; ++j)
+  for (unsigned int i=0; i<sp.n_rows(); ++i)
+    for (unsigned int j=0; j<sp.n_cols(); ++j)
       if ((i+2*j+1) % 3 == 0)
         sp.add (i,j);
   sp.compress ();
@@ -36,10 +36,10 @@ void test ()
   SparseMatrix<double> m(sp);
 
                                // prepare structure with indices and values
-  std::vector<unsigned int> indices (m.m());
-  for (unsigned int i=0; i<m.m(); ++i)
-    indices[i] = m.m()-1-i;
-  std::vector<double> values (5);
+  std::vector<unsigned int> indices (m.n());
+  for (unsigned int j=0; j<m.n(); ++j)
+    indices[j] = m.n()-1-j;
+  std::vector<double> values (m.n());
 
                                    // try to add entries from the list. Zeros
                                    // need to be filtered out. list is not
diff --git a/tests/bits/sparse_matrix_add_entries_04.cc b/tests/bits/sparse_matrix_add_entries_04.cc
new file mode 100644 (file)
index 0000000..cc3aeb3
--- /dev/null
@@ -0,0 +1,107 @@
+//----------------------------  sparse_matrix_entries_04.cc  -----------------
+//    $Id$
+//    Version: $Name$
+//
+//    Copyright (C) 2010 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.
+//
+//----------------------------  sparse_matrix_add_entries_04.cc  -------------
+
+
+// check adding elements into a matrix using
+// SparseMatrix::add(row, n_cols, col_indices, values, elide_zero_values,
+//                   col_indices_are_sorted)
+// rectangular case, sorted
+
+#include "../tests.h"
+#include <lac/sparse_matrix.h>
+#include <fstream>
+
+
+void test ()
+{
+                               // set up sparse matrix
+  SparsityPattern sp (5,7,3);
+  for (unsigned int i=0; i<sp.n_rows(); ++i)
+    for (unsigned int j=0; j<sp.n_cols(); ++j)
+      if ((i+2*j+1) % 3 == 0)
+        sp.add (i,j);
+  sp.compress ();
+
+  SparseMatrix<double> m(sp);
+
+                               // prepare structure with indices and values
+  std::vector<unsigned int> indices (m.n());
+  for (unsigned int j=0; j<m.n(); ++j)
+    indices[j] = j;
+  std::vector<double> values (m.n());
+
+                                   // try to add entries from the list. Zeros
+                                   // should be filtered out. list is sorted
+  for (unsigned int i=0; i<m.m(); ++i)
+    {
+      for (unsigned int j=0; j<m.n(); ++j)
+       if ((i+2*j+1) % 3 == 0)
+         values[j] = i*j*.5+.5;
+       else
+         values[j] = 0;
+      m.add(i,m.n(),&indices[0], &values[0], false, true);
+    }
+
+                                   // then make sure we retrieve the same ones
+  for (unsigned int i=0; i<m.m(); ++i)
+    for (unsigned int j=0; j<m.n(); ++j)
+      if ((i+2*j+1) % 3 == 0)
+       {
+         Assert (m(i,j) == i*j*.5+.5, ExcInternalError());
+       }
+      else
+       {
+         Assert (m.el(i,j) == 0, ExcInternalError());
+       }
+
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main ()
+{
+  std::ofstream logfile("sparse_matrix_add_entries_04/output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  try
+    {
+      test ();
+    }
+  catch (std::exception &exc)
+    {
+      deallog << std::endl << std::endl
+             << "----------------------------------------------------"
+             << std::endl;
+      deallog << "Exception on processing: " << std::endl
+             << exc.what() << std::endl
+             << "Aborting!" << std::endl
+             << "----------------------------------------------------"
+             << std::endl;
+
+      return 1;
+    }
+  catch (...)
+    {
+      deallog << std::endl << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      deallog << "Unknown exception!" << std::endl
+               << "Aborting!" << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      return 1;
+    };
+}
diff --git a/tests/bits/sparse_matrix_add_entries_04/cmp/generic b/tests/bits/sparse_matrix_add_entries_04/cmp/generic
new file mode 100644 (file)
index 0000000..0fd8fc1
--- /dev/null
@@ -0,0 +1,2 @@
+
+DEAL::OK
diff --git a/tests/bits/sparse_matrix_add_entries_05.cc b/tests/bits/sparse_matrix_add_entries_05.cc
new file mode 100644 (file)
index 0000000..7a319a4
--- /dev/null
@@ -0,0 +1,107 @@
+//----------------------------  sparse_matrix_entries_05.cc  -----------------
+//    $Id$
+//    Version: $Name$
+//
+//    Copyright (C) 2010 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.
+//
+//----------------------------  sparse_matrix_add_entries_05.cc  -------------
+
+
+// check adding elements into a matrix using
+// SparseMatrix::add(row, n_cols, col_indices, values, elide_zero_values,
+//                   col_indices_are_sorted)
+// rectangular case, not sorted
+
+#include "../tests.h"
+#include <lac/sparse_matrix.h>
+#include <fstream>
+
+
+void test ()
+{
+                               // set up sparse matrix
+  SparsityPattern sp (5,7,3);
+  for (unsigned int i=0; i<sp.n_rows(); ++i)
+    for (unsigned int j=0; j<sp.n_cols(); ++j)
+      if ((i+2*j+1) % 3 == 0)
+        sp.add (i,j);
+  sp.compress ();
+
+  SparseMatrix<double> m(sp);
+
+                               // prepare structure with indices and values
+  std::vector<unsigned int> indices (m.n());
+  for (unsigned int i=0; i<m.n(); ++i)
+    indices[i] = m.n()-1-i;
+  std::vector<double> values (m.n());
+
+                                   // try to add entries from the list. Zeros
+                                   // should be filtered out. list is sorted
+  for (unsigned int i=0; i<m.m(); ++i)
+    {
+      for (unsigned int j=0; j<m.n(); ++j)
+       if ((i+2*j+1) % 3 == 0)
+         values[m.n()-1-j] = i*j*.5+.5;
+       else
+         values[m.n()-1-j] = 0;
+      m.add(i,m.n(),&indices[0], &values[0], false, false);
+    }
+
+                                   // then make sure we retrieve the same ones
+  for (unsigned int i=0; i<m.m(); ++i)
+    for (unsigned int j=0; j<m.n(); ++j)
+      if ((i+2*j+1) % 3 == 0)
+       {
+         Assert (m(i,j) == i*j*.5+.5, ExcInternalError());
+       }
+      else
+       {
+         Assert (m.el(i,j) == 0, ExcInternalError());
+       }
+
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main ()
+{
+  std::ofstream logfile("sparse_matrix_add_entries_05/output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  try
+    {
+      test ();
+    }
+  catch (std::exception &exc)
+    {
+      deallog << std::endl << std::endl
+             << "----------------------------------------------------"
+             << std::endl;
+      deallog << "Exception on processing: " << std::endl
+             << exc.what() << std::endl
+             << "Aborting!" << std::endl
+             << "----------------------------------------------------"
+             << std::endl;
+
+      return 1;
+    }
+  catch (...)
+    {
+      deallog << std::endl << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      deallog << "Unknown exception!" << std::endl
+               << "Aborting!" << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      return 1;
+    };
+}
diff --git a/tests/bits/sparse_matrix_add_entries_05/cmp/generic b/tests/bits/sparse_matrix_add_entries_05/cmp/generic
new file mode 100644 (file)
index 0000000..0fd8fc1
--- /dev/null
@@ -0,0 +1,2 @@
+
+DEAL::OK
diff --git a/tests/bits/sparse_matrix_add_entries_06.cc b/tests/bits/sparse_matrix_add_entries_06.cc
new file mode 100644 (file)
index 0000000..c2e280f
--- /dev/null
@@ -0,0 +1,112 @@
+//----------------------------  sparse_matrix_entries_06.cc  -----------------
+//    $Id$
+//    Version: $Name$
+//
+//    Copyright (C) 2010 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.
+//
+//----------------------------  sparse_matrix_add_entries_06.cc  -------------
+
+
+// check adding elements into a matrix using
+// SparseMatrix::add(row, n_cols, col_indices, values, elide_zero_values,
+//                   col_indices_are_sorted)
+// need to filter out zeros, indices are sorted and zero values should
+// not be elided
+
+#include "../tests.h"
+#include <lac/sparse_matrix.h>
+#include <fstream>
+
+
+void test ()
+{
+                               // set up sparse matrix
+  SparsityPattern sp (5,5,3);
+  for (unsigned int i=0; i<sp.n_rows(); ++i)
+    for (unsigned int j=0; j<sp.n_cols(); ++j)
+      if ((i+2*j+1) % 3 == 0)
+        sp.add (i,j);
+  sp.compress ();
+
+  SparseMatrix<double> m(sp);
+
+                               // prepare structure with indices and values
+  std::vector<unsigned int> indices (m.n());
+  for (unsigned int j=0; j<m.n(); ++j)
+    indices[j] = j;
+  std::vector<double> values (m.n());
+
+                                   // try to add entries from the list. No
+                                   // zeros to be filtered. But less than 3
+                                   // elements, so the program takes another
+                                   // path
+  for (unsigned int i=0; i<m.m(); ++i)
+    {
+      unsigned int n_added = 0;
+      for (unsigned int j=0; j<m.n(); ++j)
+       if ((i+2*j+1) % 3 == 0)
+         {
+           indices[n_added] = j;
+           values[n_added++] = i*j*.5+.5;
+         }
+      m.add(i,n_added,&indices[0], &values[0], false, true);
+    }
+
+                                   // then make sure we retrieve the same ones
+  for (unsigned int i=0; i<m.m(); ++i)
+    for (unsigned int j=0; j<m.n(); ++j)
+      if ((i+2*j+1) % 3 == 0)
+       {
+         Assert (m(i,j) == i*j*.5+.5, ExcInternalError());
+       }
+      else
+       {
+         Assert (m.el(i,j) == 0, ExcInternalError());
+       }
+
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main ()
+{
+  std::ofstream logfile("sparse_matrix_add_entries_06/output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  try
+    {
+      test ();
+    }
+  catch (std::exception &exc)
+    {
+      deallog << std::endl << std::endl
+             << "----------------------------------------------------"
+             << std::endl;
+      deallog << "Exception on processing: " << std::endl
+             << exc.what() << std::endl
+             << "Aborting!" << std::endl
+             << "----------------------------------------------------"
+             << std::endl;
+
+      return 1;
+    }
+  catch (...)
+    {
+      deallog << std::endl << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      deallog << "Unknown exception!" << std::endl
+               << "Aborting!" << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      return 1;
+    };
+}
diff --git a/tests/bits/sparse_matrix_add_entries_06/cmp/generic b/tests/bits/sparse_matrix_add_entries_06/cmp/generic
new file mode 100644 (file)
index 0000000..0fd8fc1
--- /dev/null
@@ -0,0 +1,2 @@
+
+DEAL::OK

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.