]> https://gitweb.dealii.org/ - dealii.git/commitdiff
New tests.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Mon, 29 Mar 2004 19:45:48 +0000 (19:45 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Mon, 29 Mar 2004 19:45:48 +0000 (19:45 +0000)
git-svn-id: https://svn.dealii.org/trunk@8891 0785d39b-7218-0410-832d-ea1e28bc413d

tests/bits/sparse_matrix_iterator_02.cc [new file with mode: 0644]
tests/bits/sparse_matrix_iterator_03.cc [new file with mode: 0644]
tests/bits/sparse_matrix_iterator_04.cc [new file with mode: 0644]
tests/bits/sparse_matrix_iterator_05.cc [new file with mode: 0644]
tests/bits/sparse_matrix_iterator_06.cc [new file with mode: 0644]
tests/bits/sparse_matrix_iterator_07.cc [new file with mode: 0644]
tests/bits/sparse_matrix_iterator_08.cc [new file with mode: 0644]

diff --git a/tests/bits/sparse_matrix_iterator_02.cc b/tests/bits/sparse_matrix_iterator_02.cc
new file mode 100644 (file)
index 0000000..a78f878
--- /dev/null
@@ -0,0 +1,91 @@
+//----------------------------  sparse_matrix_iterator_02.cc  ---------------------------
+//    $Id$
+//    Version: $Name$ 
+//
+//    Copyright (C) 2004 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_iterator_02.cc  ---------------------------
+
+
+// test setting some elements and reading them back from a const matrix
+// iterator
+
+#include "../tests.h"
+#include <lac/sparse_matrix.h>    
+#include <fstream>
+#include <iostream>
+
+
+void test ()
+{
+  SparsityPattern sp (5,5,3);
+  for (unsigned int i=0; i<5; ++i)
+    for (unsigned int j=0; j<5; ++j)
+      if (((i+2*j+1) % 3 == 0)
+          ||
+          (i==j))
+        sp.add (i,j);
+  sp.compress ();
+
+  SparseMatrix<double> m(sp);
+  for (unsigned int i=0; i<5; ++i)
+    for (unsigned int j=0; j<5; ++j)
+      if (((i+2*j+1) % 3 == 0)
+          ||
+          (i==j))
+        m.set (i,j, i*j);
+  
+  SparseMatrix<double>::const_iterator i = m.begin();
+  for (; i!=m.end(); ++i)
+    {
+      deallog << i->row() << ' ' << i->column() << ' '
+              << i->value() << std::endl;
+      Assert (std::fabs(i->value() - i->row()*i->column()) < 1e-14,
+              ExcInternalError());
+    }
+
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main ()
+{
+  std::ofstream logfile("sparse_matrix_iterator_02.output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  try
+    {
+      test ();
+    }
+  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/sparse_matrix_iterator_03.cc b/tests/bits/sparse_matrix_iterator_03.cc
new file mode 100644 (file)
index 0000000..0a41458
--- /dev/null
@@ -0,0 +1,91 @@
+//----------------------------  sparse_matrix_iterator_03.cc  ---------------------------
+//    $Id$
+//    Version: $Name$ 
+//
+//    Copyright (C) 2004 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_iterator_03.cc  ---------------------------
+
+
+// test setting some elements and reading them back from a non-const matrix
+// iterator
+
+#include "../tests.h"
+#include <lac/sparse_matrix.h>    
+#include <fstream>
+#include <iostream>
+
+
+void test ()
+{
+  SparsityPattern sp (5,5,3);
+  for (unsigned int i=0; i<5; ++i)
+    for (unsigned int j=0; j<5; ++j)
+      if (((i+2*j+1) % 3 == 0)
+          ||
+          (i==j))
+        sp.add (i,j);
+  sp.compress ();
+
+  SparseMatrix<double> m(sp);
+  for (unsigned int i=0; i<5; ++i)
+    for (unsigned int j=0; j<5; ++j)
+      if (((i+2*j+1) % 3 == 0)
+          ||
+          (i==j))
+        m.set (i,j, i*j);
+  
+  SparseMatrix<double>::iterator i = m.begin();
+  for (; i!=m.end(); ++i)
+    {
+      deallog << i->row() << ' ' << i->column() << ' '
+              << i->value() << std::endl;
+      Assert (std::fabs(i->value() - i->row()*i->column()) < 1e-14,
+              ExcInternalError());
+    }
+
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main ()
+{
+  std::ofstream logfile("sparse_matrix_iterator_03.output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  try
+    {
+      test ();
+    }
+  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/sparse_matrix_iterator_04.cc b/tests/bits/sparse_matrix_iterator_04.cc
new file mode 100644 (file)
index 0000000..bb20ceb
--- /dev/null
@@ -0,0 +1,90 @@
+//----------------------------  sparse_matrix_iterator_04.cc  ---------------------------
+//    $Id$
+//    Version: $Name$ 
+//
+//    Copyright (C) 2004 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_iterator_04.cc  ---------------------------
+
+// test setting some elements using a non-const matrix iterator and operator=,
+// and reading them back through the matrix itself
+
+#include "../tests.h"
+#include <lac/sparse_matrix.h>    
+#include <fstream>
+#include <iostream>
+
+
+void test ()
+{
+  SparsityPattern sp (5,5,3);
+  for (unsigned int i=0; i<5; ++i)
+    for (unsigned int j=0; j<5; ++j)
+      if (((i+2*j+1) % 3 == 0)
+          ||
+          (i==j))
+        sp.add (i,j);
+  sp.compress ();
+  SparseMatrix<double> m(sp);
+
+  SparseMatrix<double>::iterator i = m.begin();
+  for (; i!=m.end(); ++i)
+    i->value() = i->row()*i->column();
+  
+  for (unsigned int i=0; i<5; ++i)
+    for (unsigned int j=0; j<5; ++j)
+      if (((i+2*j+1) % 3 == 0)
+          ||
+          (i==j))
+        {
+          deallog << i << ' ' << j << ' ' << m.el(i,j)
+                  << std::endl;
+          Assert (std::fabs(m.el(i,j)-i*j) < 1e-14,
+                  ExcInternalError());
+        }
+  
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main ()
+{
+  std::ofstream logfile("sparse_matrix_iterator_04.output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  try
+    {
+      test ();
+    }
+  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/sparse_matrix_iterator_05.cc b/tests/bits/sparse_matrix_iterator_05.cc
new file mode 100644 (file)
index 0000000..2030ac6
--- /dev/null
@@ -0,0 +1,97 @@
+//----------------------------  sparse_matrix_iterator_05.cc  ---------------------------
+//    $Id$
+//    Version: $Name$ 
+//
+//    Copyright (C) 2004 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_iterator_05.cc  ---------------------------
+
+// test setting some elements using a non-const matrix iterator and operator+=,
+// and reading them back through the matrix itself
+
+#include "../tests.h"
+#include <lac/sparse_matrix.h>    
+#include <fstream>
+#include <iostream>
+
+
+void test ()
+{
+  SparsityPattern sp (5,5,3);
+  for (unsigned int i=0; i<5; ++i)
+    for (unsigned int j=0; j<5; ++j)
+      if (((i+2*j+1) % 3 == 0)
+          ||
+          (i==j))
+        sp.add (i,j);
+  sp.compress ();
+
+  SparseMatrix<double> m(sp);
+  for (unsigned int i=0; i<5; ++i)
+    for (unsigned int j=0; j<5; ++j)
+      if (((i+2*j+1) % 3 == 0)
+          ||
+          (i==j))
+        m.set(i,j,1.);
+
+  SparseMatrix<double>::iterator i = m.begin();
+  for (; i!=m.end(); ++i)
+    i->value() += i->row()*i->column();
+  
+  for (unsigned int i=0; i<5; ++i)
+    for (unsigned int j=0; j<5; ++j)
+      if (((i+2*j+1) % 3 == 0)
+          ||
+          (i==j))
+        {
+          deallog << i << ' ' << j << ' ' << m.el(i,j)
+                  << std::endl;
+          Assert (std::fabs(m.el(i,j)-(1.+i*j)) < 1e-14,
+                  ExcInternalError());
+        }
+  
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main ()
+{
+  std::ofstream logfile("sparse_matrix_iterator_05.output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  try
+    {
+      test ();
+    }
+  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/sparse_matrix_iterator_06.cc b/tests/bits/sparse_matrix_iterator_06.cc
new file mode 100644 (file)
index 0000000..6dffa4d
--- /dev/null
@@ -0,0 +1,97 @@
+//----------------------------  sparse_matrix_iterator_06.cc  ---------------------------
+//    $Id$
+//    Version: $Name$ 
+//
+//    Copyright (C) 2004 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_iterator_06.cc  ---------------------------
+
+// test setting some elements using a non-const matrix iterator and operator-=,
+// and reading them back through the matrix itself
+
+#include "../tests.h"
+#include <lac/sparse_matrix.h>    
+#include <fstream>
+#include <iostream>
+
+
+void test ()
+{
+  SparsityPattern sp (5,5,3);
+  for (unsigned int i=0; i<5; ++i)
+    for (unsigned int j=0; j<5; ++j)
+      if (((i+2*j+1) % 3 == 0)
+          ||
+          (i==j))
+        sp.add (i,j);
+  sp.compress ();
+
+  SparseMatrix<double> m(sp);
+  for (unsigned int i=0; i<5; ++i)
+    for (unsigned int j=0; j<5; ++j)
+      if (((i+2*j+1) % 3 == 0)
+          ||
+          (i==j))
+        m.set(i,j,1.);
+
+  SparseMatrix<double>::iterator i = m.begin();
+  for (; i!=m.end(); ++i)
+    i->value() -= i->row()*i->column();
+  
+  for (unsigned int i=0; i<5; ++i)
+    for (unsigned int j=0; j<5; ++j)
+      if (((i+2*j+1) % 3 == 0)
+          ||
+          (i==j))
+        {
+          deallog << i << ' ' << j << ' ' << m.el(i,j)
+                  << std::endl;
+          Assert (std::fabs(m.el(i,j)-(1.-i*j)) < 1e-14,
+                  ExcInternalError());
+        }
+  
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main ()
+{
+  std::ofstream logfile("sparse_matrix_iterator_06.output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  try
+    {
+      test ();
+    }
+  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/sparse_matrix_iterator_07.cc b/tests/bits/sparse_matrix_iterator_07.cc
new file mode 100644 (file)
index 0000000..a0963b0
--- /dev/null
@@ -0,0 +1,97 @@
+//----------------------------  sparse_matrix_iterator_07.cc  ---------------------------
+//    $Id$
+//    Version: $Name$ 
+//
+//    Copyright (C) 2004 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_iterator_07.cc  ---------------------------
+
+// test setting some elements using a non-const matrix iterator and operator*=,
+// and reading them back through the matrix itself
+
+#include "../tests.h"
+#include <lac/sparse_matrix.h>    
+#include <fstream>
+#include <iostream>
+
+
+void test ()
+{
+  SparsityPattern sp (5,5,3);
+  for (unsigned int i=0; i<5; ++i)
+    for (unsigned int j=0; j<5; ++j)
+      if (((i+2*j+1) % 3 == 0)
+          ||
+          (i==j))
+        sp.add (i,j);
+  sp.compress ();
+
+  SparseMatrix<double> m(sp);
+  for (unsigned int i=0; i<5; ++i)
+    for (unsigned int j=0; j<5; ++j)
+      if (((i+2*j+1) % 3 == 0)
+          ||
+          (i==j))
+        m.set(i,j,i*j);
+
+  SparseMatrix<double>::iterator i = m.begin();
+  for (; i!=m.end(); ++i)
+    i->value() *= 2;
+  
+  for (unsigned int i=0; i<5; ++i)
+    for (unsigned int j=0; j<5; ++j)
+      if (((i+2*j+1) % 3 == 0)
+          ||
+          (i==j))
+        {
+          deallog << i << ' ' << j << ' ' << m.el(i,j)
+                  << std::endl;
+          Assert (std::fabs(m.el(i,j)-(2.*i*j)) < 1e-14,
+                  ExcInternalError());
+        }
+  
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main ()
+{
+  std::ofstream logfile("sparse_matrix_iterator_07.output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  try
+    {
+      test ();
+    }
+  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/sparse_matrix_iterator_08.cc b/tests/bits/sparse_matrix_iterator_08.cc
new file mode 100644 (file)
index 0000000..7767c4e
--- /dev/null
@@ -0,0 +1,97 @@
+//----------------------------  sparse_matrix_iterator_08.cc  ---------------------------
+//    $Id$
+//    Version: $Name$ 
+//
+//    Copyright (C) 2004 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_iterator_08.cc  ---------------------------
+
+// test setting some elements using a non-const matrix iterator and operator/=,
+// and reading them back through the matrix itself
+
+#include "../tests.h"
+#include <lac/sparse_matrix.h>    
+#include <fstream>
+#include <iostream>
+
+
+void test ()
+{
+  SparsityPattern sp (5,5,3);
+  for (unsigned int i=0; i<5; ++i)
+    for (unsigned int j=0; j<5; ++j)
+      if (((i+2*j+1) % 3 == 0)
+          ||
+          (i==j))
+        sp.add (i,j);
+  sp.compress ();
+
+  SparseMatrix<double> m(sp);
+  for (unsigned int i=0; i<5; ++i)
+    for (unsigned int j=0; j<5; ++j)
+      if (((i+2*j+1) % 3 == 0)
+          ||
+          (i==j))
+        m.set(i,j,i*j);
+
+  SparseMatrix<double>::iterator i = m.begin();
+  for (; i!=m.end(); ++i)
+    i->value() /= 2;
+  
+  for (unsigned int i=0; i<5; ++i)
+    for (unsigned int j=0; j<5; ++j)
+      if (((i+2*j+1) % 3 == 0)
+          ||
+          (i==j))
+        {
+          deallog << i << ' ' << j << ' ' << m.el(i,j)
+                  << std::endl;
+          Assert (std::fabs(m.el(i,j)-(i*j/2.)) < 1e-14,
+                  ExcInternalError());
+        }
+  
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main ()
+{
+  std::ofstream logfile("sparse_matrix_iterator_08.output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  try
+    {
+      test ();
+    }
+  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.