]> https://gitweb.dealii.org/ - dealii.git/commitdiff
New tests.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Mon, 9 Feb 2004 23:02:51 +0000 (23:02 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Mon, 9 Feb 2004 23:02:51 +0000 (23:02 +0000)
git-svn-id: https://svn.dealii.org/trunk@8445 0785d39b-7218-0410-832d-ea1e28bc413d

tests/bits/petsc_sparse_matrix_vector_01.cc [new file with mode: 0644]
tests/bits/petsc_sparse_matrix_vector_02.cc [new file with mode: 0644]
tests/bits/petsc_sparse_matrix_vector_03.cc [new file with mode: 0644]
tests/bits/petsc_sparse_matrix_vector_04.cc [new file with mode: 0644]
tests/bits/petsc_sparse_matrix_vector_05.cc [new file with mode: 0644]
tests/bits/petsc_sparse_matrix_vector_06.cc [new file with mode: 0644]
tests/bits/petsc_sparse_matrix_vector_07.cc [new file with mode: 0644]

diff --git a/tests/bits/petsc_sparse_matrix_vector_01.cc b/tests/bits/petsc_sparse_matrix_vector_01.cc
new file mode 100644 (file)
index 0000000..2adbe04
--- /dev/null
@@ -0,0 +1,99 @@
+//----------------------------  petsc_sparse_matrix_vector_01.cc  ---------------------------
+//    vector_11.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_sparse_matrix_vector_01.cc  ---------------------------
+
+
+// check SparseMatrix::vmult
+
+#include "../tests.h"
+#include <lac/petsc_vector.h>
+#include <lac/petsc_sparse_matrix.h>
+#include <fstream>
+#include <iostream>
+#include <vector>
+
+
+void test (petsc_wrappers::Vector &v,
+           petsc_wrappers::Vector &w)
+{
+  petsc_wrappers::SparseMatrix m(v.size(),v.size(),v.size());
+  for (unsigned int i=0; i<m.m(); ++i)
+    for (unsigned int j=0; j<m.m(); ++j)
+        m.set (i,j, i+2*j);
+
+  for (unsigned int i=0; i<v.size(); ++i)
+    v(i) = i;
+  
+  m.compress ();
+  v.compress ();
+  w.compress ();
+
+                                   // w:=Mv
+  m.vmult (w,v);
+
+                                   // make sure we get the expected result
+  for (unsigned int i=0; i<v.size(); ++i)
+    {
+      Assert (v(i) == i, ExcInternalError());
+
+      double result = 0;
+      for (unsigned int j=0; j<m.m(); ++j)
+        result += (i+2*j)*j;
+      Assert (w(i) == result, ExcInternalError());
+    }
+
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main (int argc, char **argv)
+{
+  std::ofstream logfile("petsc_sparse_matrix_vector_01.output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  try
+    {
+      PetscInitialize(&argc,&argv,0,0);
+      {
+        petsc_wrappers::Vector v (100);
+        petsc_wrappers::Vector w (100);
+        test (v,w);
+      }
+      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_sparse_matrix_vector_02.cc b/tests/bits/petsc_sparse_matrix_vector_02.cc
new file mode 100644 (file)
index 0000000..fd3f255
--- /dev/null
@@ -0,0 +1,99 @@
+//----------------------------  petsc_sparse_matrix_vector_02.cc  ---------------------------
+//    vector_11.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_sparse_matrix_vector_02.cc  ---------------------------
+
+
+// check SparseMatrix::Tvmult
+
+#include "../tests.h"
+#include <lac/petsc_vector.h>
+#include <lac/petsc_sparse_matrix.h>
+#include <fstream>
+#include <iostream>
+#include <vector>
+
+
+void test (petsc_wrappers::Vector &v,
+           petsc_wrappers::Vector &w)
+{
+  petsc_wrappers::SparseMatrix m(v.size(),v.size(),v.size());
+  for (unsigned int i=0; i<m.m(); ++i)
+    for (unsigned int j=0; j<m.m(); ++j)
+        m.set (i,j, i+2*j);
+
+  for (unsigned int i=0; i<v.size(); ++i)
+    v(i) = i;
+  
+  m.compress ();
+  v.compress ();
+  w.compress ();
+
+                                   // w:=Mv
+  m.Tvmult (w,v);
+
+                                   // make sure we get the expected result
+  for (unsigned int i=0; i<v.size(); ++i)
+    {
+      Assert (v(i) == i, ExcInternalError());
+
+      double result = 0;
+      for (unsigned int j=0; j<m.m(); ++j)
+        result += (j+2*i)*j;
+      Assert (w(i) == result, ExcInternalError());
+    }
+
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main (int argc, char **argv)
+{
+  std::ofstream logfile("petsc_sparse_matrix_vector_02.output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  try
+    {
+      PetscInitialize(&argc,&argv,0,0);
+      {
+        petsc_wrappers::Vector v (100);
+        petsc_wrappers::Vector w (100);
+        test (v,w);
+      }
+      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_sparse_matrix_vector_03.cc b/tests/bits/petsc_sparse_matrix_vector_03.cc
new file mode 100644 (file)
index 0000000..0fa5d90
--- /dev/null
@@ -0,0 +1,102 @@
+//----------------------------  petsc_sparse_matrix_vector_03.cc  ---------------------------
+//    vector_11.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_sparse_matrix_vector_03.cc  ---------------------------
+
+
+// check SparseMatrix::vmult_add
+
+#include "../tests.h"
+#include <lac/petsc_vector.h>
+#include <lac/petsc_sparse_matrix.h>
+#include <fstream>
+#include <iostream>
+#include <vector>
+
+
+void test (petsc_wrappers::Vector &v,
+           petsc_wrappers::Vector &w)
+{
+  petsc_wrappers::SparseMatrix m(v.size(),v.size(),v.size());
+  for (unsigned int i=0; i<m.m(); ++i)
+    for (unsigned int j=0; j<m.m(); ++j)
+        m.set (i,j, i+2*j);
+
+  for (unsigned int i=0; i<v.size(); ++i)
+    {
+      v(i) = i;
+      w(i) = i;
+    }
+  
+  m.compress ();
+  v.compress ();
+  w.compress ();
+
+                                   // w:=Mv
+  m.vmult_add (w,v);
+
+                                   // make sure we get the expected result
+  for (unsigned int i=0; i<v.size(); ++i)
+    {
+      Assert (v(i) == i, ExcInternalError());
+
+      double result = 0;
+      for (unsigned int j=0; j<m.m(); ++j)
+        result += (i+2*j)*j;
+      Assert (w(i) == i+result, ExcInternalError());
+    }
+
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main (int argc, char **argv)
+{
+  std::ofstream logfile("petsc_sparse_matrix_vector_03.output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  try
+    {
+      PetscInitialize(&argc,&argv,0,0);
+      {
+        petsc_wrappers::Vector v (100);
+        petsc_wrappers::Vector w (100);
+        test (v,w);
+      }
+      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_sparse_matrix_vector_04.cc b/tests/bits/petsc_sparse_matrix_vector_04.cc
new file mode 100644 (file)
index 0000000..20126c7
--- /dev/null
@@ -0,0 +1,102 @@
+//----------------------------  petsc_sparse_matrix_vector_04.cc  ---------------------------
+//    vector_11.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_sparse_matrix_vector_04.cc  ---------------------------
+
+
+// check SparseMatrix::Tvmult_add
+
+#include "../tests.h"
+#include <lac/petsc_vector.h>
+#include <lac/petsc_sparse_matrix.h>
+#include <fstream>
+#include <iostream>
+#include <vector>
+
+
+void test (petsc_wrappers::Vector &v,
+           petsc_wrappers::Vector &w)
+{
+  petsc_wrappers::SparseMatrix m(v.size(),v.size(),v.size());
+  for (unsigned int i=0; i<m.m(); ++i)
+    for (unsigned int j=0; j<m.m(); ++j)
+        m.set (i,j, i+2*j);
+
+  for (unsigned int i=0; i<v.size(); ++i)
+    {
+      v(i) = i;
+      w(i) = i;
+    }
+  
+  m.compress ();
+  v.compress ();
+  w.compress ();
+
+                                   // w:=Mv
+  m.Tvmult_add (w,v);
+
+                                   // make sure we get the expected result
+  for (unsigned int i=0; i<v.size(); ++i)
+    {
+      Assert (v(i) == i, ExcInternalError());
+
+      double result = 0;
+      for (unsigned int j=0; j<m.m(); ++j)
+        result += (j+2*i)*j;
+      Assert (w(i) == i+result, ExcInternalError());
+    }
+
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main (int argc, char **argv)
+{
+  std::ofstream logfile("petsc_sparse_matrix_vector_04.output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  try
+    {
+      PetscInitialize(&argc,&argv,0,0);
+      {
+        petsc_wrappers::Vector v (100);
+        petsc_wrappers::Vector w (100);
+        test (v,w);
+      }
+      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_sparse_matrix_vector_05.cc b/tests/bits/petsc_sparse_matrix_vector_05.cc
new file mode 100644 (file)
index 0000000..0b0cedf
--- /dev/null
@@ -0,0 +1,105 @@
+//----------------------------  petsc_sparse_matrix_vector_05.cc  ---------------------------
+//    vector_11.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_sparse_matrix_vector_05.cc  ---------------------------
+
+
+// check SparseMatrix::matrix_scalar_product
+
+#include "../tests.h"
+#include <lac/petsc_vector.h>
+#include <lac/petsc_sparse_matrix.h>
+#include <fstream>
+#include <iostream>
+#include <vector>
+
+
+void test (petsc_wrappers::Vector &v,
+           petsc_wrappers::Vector &w)
+{
+  petsc_wrappers::SparseMatrix m(v.size(),v.size(),v.size());
+  for (unsigned int i=0; i<m.m(); ++i)
+    for (unsigned int j=0; j<m.m(); ++j)
+        m.set (i,j, i+2*j);
+
+  for (unsigned int i=0; i<v.size(); ++i)
+    {
+      v(i) = i;
+      w(i) = i+1;
+    }
+  
+  m.compress ();
+  v.compress ();
+  w.compress ();
+
+                                   // <w,Mv>
+  const double s = m.matrix_scalar_product (w,v);
+
+                                   // make sure we get the expected result
+  for (unsigned int i=0; i<v.size(); ++i)
+    {
+      Assert (v(i) == i, ExcInternalError());
+      Assert (w(i) == i+1, ExcInternalError());
+    }
+
+  double result = 0;
+  for (unsigned int i=0; i<m.m(); ++i)
+    for (unsigned int j=0; j<m.m(); ++j)
+      result += (i+2*j)*j*(i+1);
+
+  Assert (s == result, ExcInternalError());
+
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main (int argc, char **argv)
+{
+  std::ofstream logfile("petsc_sparse_matrix_vector_05.output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  try
+    {
+      PetscInitialize(&argc,&argv,0,0);
+      {
+        petsc_wrappers::Vector v (100);
+        petsc_wrappers::Vector w (100);
+        test (v,w);
+      }
+      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_sparse_matrix_vector_06.cc b/tests/bits/petsc_sparse_matrix_vector_06.cc
new file mode 100644 (file)
index 0000000..717de20
--- /dev/null
@@ -0,0 +1,96 @@
+//----------------------------  petsc_sparse_matrix_vector_06.cc  ---------------------------
+//    vector_11.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_sparse_matrix_vector_06.cc  ---------------------------
+
+
+// check SparseMatrix::matrix_norm_square
+
+#include "../tests.h"
+#include <lac/petsc_vector.h>
+#include <lac/petsc_sparse_matrix.h>
+#include <fstream>
+#include <iostream>
+#include <vector>
+
+
+void test (petsc_wrappers::Vector &v)
+{
+  petsc_wrappers::SparseMatrix m(v.size(),v.size(),v.size());
+  for (unsigned int i=0; i<m.m(); ++i)
+    for (unsigned int j=0; j<m.m(); ++j)
+        m.set (i,j, i+2*j);
+
+  for (unsigned int i=0; i<v.size(); ++i)
+    v(i) = i;
+  
+  m.compress ();
+  v.compress ();
+
+                                   // <w,Mv>
+  const double s = m.matrix_norm_square (v);
+
+                                   // make sure we get the expected result
+  for (unsigned int i=0; i<v.size(); ++i)
+    Assert (v(i) == i, ExcInternalError());
+
+  double result = 0;
+  for (unsigned int i=0; i<m.m(); ++i)
+    for (unsigned int j=0; j<m.m(); ++j)
+      result += (i+2*j)*j*i;
+
+  Assert (s == result, ExcInternalError());
+
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main (int argc, char **argv)
+{
+  std::ofstream logfile("petsc_sparse_matrix_vector_06.output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  try
+    {
+      PetscInitialize(&argc,&argv,0,0);
+      {
+        petsc_wrappers::Vector v (100);
+        test (v);
+      }
+      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_sparse_matrix_vector_07.cc b/tests/bits/petsc_sparse_matrix_vector_07.cc
new file mode 100644 (file)
index 0000000..e2d7957
--- /dev/null
@@ -0,0 +1,108 @@
+//----------------------------  petsc_sparse_matrix_vector_07.cc  ---------------------------
+//    vector_11.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_sparse_matrix_vector_07.cc  ---------------------------
+
+
+// check SparseMatrix::matrix_norm_square
+
+#include "../tests.h"
+#include <lac/petsc_vector.h>
+#include <lac/petsc_sparse_matrix.h>
+#include <fstream>
+#include <iostream>
+#include <vector>
+
+
+void test (petsc_wrappers::Vector &v,
+           petsc_wrappers::Vector &w,
+           petsc_wrappers::Vector &x)
+{
+  petsc_wrappers::SparseMatrix m(v.size(),v.size(),v.size());
+  for (unsigned int i=0; i<m.m(); ++i)
+    for (unsigned int j=0; j<m.m(); ++j)
+        m.set (i,j, i+2*j);
+
+  for (unsigned int i=0; i<v.size(); ++i)
+    {
+      v(i) = i;
+      w(i) = i+1;
+    }
+      
+  m.compress ();
+  v.compress ();
+  w.compress ();
+
+                                   // x=w-Mv
+  const double s = m.residual (x, v, w);
+
+                                   // make sure we get the expected result
+  for (unsigned int i=0; i<v.size(); ++i)
+    {
+      Assert (v(i) == i, ExcInternalError());
+      Assert (w(i) == i+1, ExcInternalError());
+
+      double result = i+1;
+      for (unsigned int j=0; j<m.m(); ++j)
+        result -= (i+2*j)*j;
+
+      Assert (x(i) == result, ExcInternalError());
+    }
+
+  Assert (s == x.l2_norm(), ExcInternalError());
+
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main (int argc, char **argv)
+{
+  std::ofstream logfile("petsc_sparse_matrix_vector_07.output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  try
+    {
+      PetscInitialize(&argc,&argv,0,0);
+      {
+        petsc_wrappers::Vector v (100);
+        petsc_wrappers::Vector w (100);
+        petsc_wrappers::Vector x (100);
+        test (v,w,x);
+      }
+      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.