]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
New tests.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 6 Feb 2004 19:19:57 +0000 (19:19 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 6 Feb 2004 19:19:57 +0000 (19:19 +0000)
git-svn-id: https://svn.dealii.org/trunk@8408 0785d39b-7218-0410-832d-ea1e28bc413d

tests/bits/petsc_01.cc [new file with mode: 0644]
tests/bits/petsc_02.cc [new file with mode: 0644]
tests/bits/petsc_03.cc [new file with mode: 0644]
tests/bits/petsc_04.cc [new file with mode: 0644]
tests/bits/petsc_05.cc [new file with mode: 0644]
tests/bits/petsc_06.cc [new file with mode: 0644]
tests/bits/petsc_07.cc [new file with mode: 0644]
tests/bits/petsc_08.cc [new file with mode: 0644]

diff --git a/tests/bits/petsc_01.cc b/tests/bits/petsc_01.cc
new file mode 100644 (file)
index 0000000..ac4b0dd
--- /dev/null
@@ -0,0 +1,91 @@
+//----------------------------  petsc_01.cc  ---------------------------
+//    petsc_01.cc,v 1.4 2003/07/03 10:31:46 guido Exp
+//    Version: 
+//
+//    Copyright (C) 2004 by the deal.II authors and Anna Schneebeli
+//
+//    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.
+//
+//----------------------------  petsc_01.cc  ---------------------------
+
+
+// check setting elements in a petsc matrix using set()
+
+#include "../tests.h"
+#include <lac/petsc_sparse_matrix.h>    
+#include <fstream>
+#include <iostream>
+
+
+void test (petsc_wrappers::SparseMatrix &m)
+{
+                                   // first set a few entries
+  for (unsigned int i=0; i<m.m(); ++i)
+    for (unsigned int j=0; j<m.m(); ++j)
+      if ((i+2*j+1) % 3 == 0)
+        m.set (i,j, i*j*.5+.5);
+
+  m.compress ();
+  
+                                   // then make sure we retrieve the same ones
+  for (unsigned int i=0; i<m.m(); ++i)
+    for (unsigned int j=0; j<m.m(); ++j)
+      if ((i+2*j+1) % 3 == 0)
+        {
+          Assert (m(i,j) == i*j*.5+.5, ExcInternalError());
+          Assert (m.el(i,j) == i*j*.5+.5, ExcInternalError());
+        }
+      else
+        {
+          Assert (m(i,j) == 0, ExcInternalError());
+          Assert (m.el(i,j) == 0, ExcInternalError());
+        }
+
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main (int argc,char **argv) 
+{
+  std::ofstream logfile("petsc_01.output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  try
+    {
+      PetscInitialize(&argc,&argv,0,0);
+      {
+        petsc_wrappers::SparseMatrix m (5,5,3);
+        test (m);
+      }
+      PetscFinalize();
+    }
+  catch (std::exception &exc)
+    {
+      std::cerr << std::endl << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      std::cerr << "Exception on processing: " << std::endl
+               << exc.what() << std::endl
+               << "Aborting!" << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      
+      return 1;
+    }
+  catch (...) 
+    {
+      std::cerr << std::endl << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      std::cerr << "Unknown exception!" << std::endl
+               << "Aborting!" << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      return 1;
+    };
+}
diff --git a/tests/bits/petsc_02.cc b/tests/bits/petsc_02.cc
new file mode 100644 (file)
index 0000000..6e0ec65
--- /dev/null
@@ -0,0 +1,91 @@
+//----------------------------  petsc_02.cc  ---------------------------
+//    petsc_02.cc,v 1.4 2003/07/03 10:31:46 guido Exp
+//    Version: 
+//
+//    Copyright (C) 2004 by the deal.II authors and Anna Schneebeli
+//
+//    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.
+//
+//----------------------------  petsc_02.cc  ---------------------------
+
+
+// check setting elements in a petsc matrix using add()
+
+#include "../tests.h"
+#include <lac/petsc_sparse_matrix.h>    
+#include <fstream>
+#include <iostream>
+
+
+void test (petsc_wrappers::SparseMatrix &m)
+{
+                                   // first set a few entries
+  for (unsigned int i=0; i<m.m(); ++i)
+    for (unsigned int j=0; j<m.m(); ++j)
+      if ((i+2*j+1) % 3 == 0)
+        m.add (i,j, i*j*.5+.5);
+
+  m.compress ();
+  
+                                   // then make sure we retrieve the same ones
+  for (unsigned int i=0; i<m.m(); ++i)
+    for (unsigned int j=0; j<m.m(); ++j)
+      if ((i+2*j+1) % 3 == 0)
+        {
+          Assert (m(i,j) == i*j*.5+.5, ExcInternalError());
+          Assert (m.el(i,j) == i*j*.5+.5, ExcInternalError());
+        }
+      else
+        {
+          Assert (m(i,j) == 0, ExcInternalError());
+          Assert (m.el(i,j) == 0, ExcInternalError());
+        }
+
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main (int argc,char **argv) 
+{
+  std::ofstream logfile("petsc_02.output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  try
+    {
+      PetscInitialize(&argc,&argv,0,0);
+      {
+        petsc_wrappers::SparseMatrix m (5,5,3);
+        test (m);
+      }
+      PetscFinalize();
+    }
+  catch (std::exception &exc)
+    {
+      std::cerr << std::endl << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      std::cerr << "Exception on processing: " << std::endl
+               << exc.what() << std::endl
+               << "Aborting!" << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      
+      return 1;
+    }
+  catch (...) 
+    {
+      std::cerr << std::endl << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      std::cerr << "Unknown exception!" << std::endl
+               << "Aborting!" << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      return 1;
+    };
+}
diff --git a/tests/bits/petsc_03.cc b/tests/bits/petsc_03.cc
new file mode 100644 (file)
index 0000000..c3dc81b
--- /dev/null
@@ -0,0 +1,98 @@
+//----------------------------  petsc_03.cc  ---------------------------
+//    petsc_03.cc,v 1.4 2003/07/03 10:31:46 guido Exp
+//    Version: 
+//
+//    Copyright (C) 2004 by the deal.II authors and Anna Schneebeli
+//
+//    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.
+//
+//----------------------------  petsc_03.cc  ---------------------------
+
+
+// check setting elements in a petsc matrix using set() and add()
+// intermixed. this poses PETSc some problems, since one has to flush some
+// buffer in between these two types of operations
+
+#include "../tests.h"
+#include <lac/petsc_sparse_matrix.h>    
+#include <fstream>
+#include <iostream>
+
+
+void test (petsc_wrappers::SparseMatrix &m)
+{
+                                   // first set a few entries
+  for (unsigned int i=0; i<m.m(); ++i)
+    for (unsigned int j=0; j<m.m(); ++j)
+      if ((i+2*j+1) % 3 == 0)
+        {
+          if (i*j % 2 == 0)
+            m.set (i,j, i*j*.5+.5);
+          else
+            m.add (i,j, i*j*.5+.5);
+        }
+  
+  m.compress ();
+  
+                                   // then make sure we retrieve the same ones
+  for (unsigned int i=0; i<m.m(); ++i)
+    for (unsigned int j=0; j<m.m(); ++j)
+      if ((i+2*j+1) % 3 == 0)
+        {
+          Assert (m(i,j) == i*j*.5+.5, ExcInternalError());
+          Assert (m.el(i,j) == i*j*.5+.5, ExcInternalError());
+        }
+      else
+        {
+          Assert (m(i,j) == 0, ExcInternalError());
+          Assert (m.el(i,j) == 0, ExcInternalError());
+        }
+
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main (int argc,char **argv) 
+{
+  std::ofstream logfile("petsc_03.output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  try
+    {
+      PetscInitialize(&argc,&argv,0,0);
+      {
+        petsc_wrappers::SparseMatrix m (5,5,3);
+        test (m);
+      }
+      PetscFinalize();
+    }
+  catch (std::exception &exc)
+    {
+      std::cerr << std::endl << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      std::cerr << "Exception on processing: " << std::endl
+               << exc.what() << std::endl
+               << "Aborting!" << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      
+      return 1;
+    }
+  catch (...) 
+    {
+      std::cerr << std::endl << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      std::cerr << "Unknown exception!" << std::endl
+               << "Aborting!" << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      return 1;
+    };
+}
diff --git a/tests/bits/petsc_04.cc b/tests/bits/petsc_04.cc
new file mode 100644 (file)
index 0000000..aa59cb8
--- /dev/null
@@ -0,0 +1,72 @@
+//----------------------------  petsc_04.cc  ---------------------------
+//    petsc_04.cc,v 1.4 2003/07/03 10:31:46 guido Exp
+//    Version: 
+//
+//    Copyright (C) 2004 by the deal.II authors and Anna Schneebeli
+//
+//    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.
+//
+//----------------------------  petsc_04.cc  ---------------------------
+
+
+// check querying matrix sizes
+
+#include "../tests.h"
+#include <lac/petsc_sparse_matrix.h>    
+#include <fstream>
+#include <iostream>
+
+
+void test (petsc_wrappers::SparseMatrix &m)
+{
+  Assert (m.m() == 5, ExcInternalError());
+  Assert (m.n() == 5, ExcInternalError());
+
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main (int argc,char **argv) 
+{
+  std::ofstream logfile("petsc_04.output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  try
+    {
+      PetscInitialize(&argc,&argv,0,0);
+      {
+        petsc_wrappers::SparseMatrix m (5,5,3);
+        test (m);
+      }
+      PetscFinalize();
+    }
+  catch (std::exception &exc)
+    {
+      std::cerr << std::endl << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      std::cerr << "Exception on processing: " << std::endl
+               << exc.what() << std::endl
+               << "Aborting!" << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      
+      return 1;
+    }
+  catch (...) 
+    {
+      std::cerr << std::endl << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      std::cerr << "Unknown exception!" << std::endl
+               << "Aborting!" << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      return 1;
+    };
+}
diff --git a/tests/bits/petsc_05.cc b/tests/bits/petsc_05.cc
new file mode 100644 (file)
index 0000000..26d0b16
--- /dev/null
@@ -0,0 +1,86 @@
+//----------------------------  petsc_05.cc  ---------------------------
+//    petsc_05.cc,v 1.4 2003/07/03 10:31:46 guido Exp
+//    Version: 
+//
+//    Copyright (C) 2004 by the deal.II authors and Anna Schneebeli
+//
+//    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.
+//
+//----------------------------  petsc_05.cc  ---------------------------
+
+
+// check querying the number of nonzero elements
+
+#include "../tests.h"
+#include <lac/petsc_sparse_matrix.h>    
+#include <fstream>
+#include <iostream>
+
+
+void test (petsc_wrappers::SparseMatrix &m)
+{
+                                   // first set a few entries. count how many
+                                   // entries we have
+  unsigned int counter = 0;
+  for (unsigned int i=0; i<m.m(); ++i)
+    for (unsigned int j=0; j<m.m(); ++j)
+      if ((i+2*j+1) % 3 == 0)
+        {
+          m.set (i,j, i*j*.5+.5);
+          ++counter;
+        }
+
+  m.compress ();
+
+  deallog << m.n_nonzero_elements() << std::endl;
+  Assert (m.n_nonzero_elements() == counter,
+          ExcInternalError());
+  
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main (int argc,char **argv) 
+{
+  std::ofstream logfile("petsc_05.output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  try
+    {
+      PetscInitialize(&argc,&argv,0,0);
+      {
+        petsc_wrappers::SparseMatrix m (5,5,3);
+        test (m);
+      }
+      PetscFinalize();
+    }
+  catch (std::exception &exc)
+    {
+      std::cerr << std::endl << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      std::cerr << "Exception on processing: " << std::endl
+               << exc.what() << std::endl
+               << "Aborting!" << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      
+      return 1;
+    }
+  catch (...) 
+    {
+      std::cerr << std::endl << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      std::cerr << "Unknown exception!" << std::endl
+               << "Aborting!" << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      return 1;
+    };
+}
diff --git a/tests/bits/petsc_06.cc b/tests/bits/petsc_06.cc
new file mode 100644 (file)
index 0000000..cefe548
--- /dev/null
@@ -0,0 +1,83 @@
+//----------------------------  petsc_06.cc  ---------------------------
+//    petsc_06.cc,v 1.4 2003/07/03 10:31:46 guido Exp
+//    Version: 
+//
+//    Copyright (C) 2004 by the deal.II authors and Anna Schneebeli
+//
+//    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.
+//
+//----------------------------  petsc_06.cc  ---------------------------
+
+
+// check l1_norm
+
+#include "../tests.h"
+#include <lac/petsc_sparse_matrix.h>    
+#include <fstream>
+#include <iostream>
+
+
+void test (petsc_wrappers::SparseMatrix &m)
+{
+                                   // first set a few entries. count how many
+                                   // entries we have
+  for (unsigned int i=0; i<m.m(); ++i)
+    for (unsigned int j=0; j<m.m(); ++j)
+      if ((i+2*j+1) % 3 == 0)
+        m.set (i,j, i*j*.5+.5);  
+
+  m.compress ();
+
+                                   // compare against the exact value of the
+                                   // l1-norm (max col-sum)
+  deallog << m.l1_norm() << std::endl;
+  Assert (m.l1_norm() == 7, ExcInternalError());
+  
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main (int argc,char **argv) 
+{
+  std::ofstream logfile("petsc_06.output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  try
+    {
+      PetscInitialize(&argc,&argv,0,0);
+      {
+        petsc_wrappers::SparseMatrix m (5,5,3);
+        test (m);
+      }
+      PetscFinalize();
+    }
+  catch (std::exception &exc)
+    {
+      std::cerr << std::endl << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      std::cerr << "Exception on processing: " << std::endl
+               << exc.what() << std::endl
+               << "Aborting!" << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      
+      return 1;
+    }
+  catch (...) 
+    {
+      std::cerr << std::endl << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      std::cerr << "Unknown exception!" << std::endl
+               << "Aborting!" << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      return 1;
+    };
+}
diff --git a/tests/bits/petsc_07.cc b/tests/bits/petsc_07.cc
new file mode 100644 (file)
index 0000000..e91d8c3
--- /dev/null
@@ -0,0 +1,83 @@
+//----------------------------  petsc_07.cc  ---------------------------
+//    petsc_07.cc,v 1.4 2003/07/03 10:31:46 guido Exp
+//    Version: 
+//
+//    Copyright (C) 2004 by the deal.II authors and Anna Schneebeli
+//
+//    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.
+//
+//----------------------------  petsc_07.cc  ---------------------------
+
+
+// check linfty_norm
+
+#include "../tests.h"
+#include <lac/petsc_sparse_matrix.h>    
+#include <fstream>
+#include <iostream>
+
+
+void test (petsc_wrappers::SparseMatrix &m)
+{
+                                   // first set a few entries. count how many
+                                   // entries we have
+  for (unsigned int i=0; i<m.m(); ++i)
+    for (unsigned int j=0; j<m.m(); ++j)
+      if ((i+2*j+1) % 3 == 0)
+        m.set (i,j, i*j*.5+.5);  
+
+  m.compress ();
+
+                                   // compare against the exact value of the
+                                   // linfty-norm (max row-sum)
+  deallog << m.linfty_norm() << std::endl;
+  Assert (m.linfty_norm() == 8.5, ExcInternalError());
+  
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main (int argc,char **argv) 
+{
+  std::ofstream logfile("petsc_07.output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  try
+    {
+      PetscInitialize(&argc,&argv,0,0);
+      {
+        petsc_wrappers::SparseMatrix m (5,5,3);
+        test (m);
+      }
+      PetscFinalize();
+    }
+  catch (std::exception &exc)
+    {
+      std::cerr << std::endl << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      std::cerr << "Exception on processing: " << std::endl
+               << exc.what() << std::endl
+               << "Aborting!" << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      
+      return 1;
+    }
+  catch (...) 
+    {
+      std::cerr << std::endl << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      std::cerr << "Unknown exception!" << std::endl
+               << "Aborting!" << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      return 1;
+    };
+}
diff --git a/tests/bits/petsc_08.cc b/tests/bits/petsc_08.cc
new file mode 100644 (file)
index 0000000..353a792
--- /dev/null
@@ -0,0 +1,88 @@
+//----------------------------  petsc_08.cc  ---------------------------
+//    petsc_08.cc,v 1.4 2003/07/03 10:31:46 guido Exp
+//    Version: 
+//
+//    Copyright (C) 2004 by the deal.II authors and Anna Schneebeli
+//
+//    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.
+//
+//----------------------------  petsc_08.cc  ---------------------------
+
+
+// check l2_norm
+
+#include "../tests.h"
+#include <lac/petsc_sparse_matrix.h>    
+#include <fstream>
+#include <iostream>
+
+
+void test (petsc_wrappers::SparseMatrix &m)
+{
+                                   // first set a few entries. count how many
+                                   // entries we have
+  double norm = 0;
+  for (unsigned int i=0; i<m.m(); ++i)
+    for (unsigned int j=0; j<m.m(); ++j)
+      if ((i+2*j+1) % 3 == 0)
+        {
+          m.set (i,j, i*j*.5+.5);
+          norm += (i*j*.5+.5)*(i*j*.5+.5);
+        }
+  norm = std::sqrt(norm);
+
+  m.compress ();
+
+                                   // compare against the exact value of the
+                                   // l2-norm (max row-sum)
+  deallog << m.frobenius_norm() << std::endl;
+  Assert (m.frobenius_norm() == norm, ExcInternalError());
+  
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main (int argc,char **argv) 
+{
+  std::ofstream logfile("petsc_08.output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  try
+    {
+      PetscInitialize(&argc,&argv,0,0);
+      {
+        petsc_wrappers::SparseMatrix m (5,5,3);
+        test (m);
+      }
+      PetscFinalize();
+    }
+  catch (std::exception &exc)
+    {
+      std::cerr << std::endl << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      std::cerr << "Exception on processing: " << std::endl
+               << exc.what() << std::endl
+               << "Aborting!" << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      
+      return 1;
+    }
+  catch (...) 
+    {
+      std::cerr << std::endl << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      std::cerr << "Unknown exception!" << std::endl
+               << "Aborting!" << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      return 1;
+    };
+}

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.