]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add tests.
authorWolfgang Bangerth <bangerth@colostate.edu>
Tue, 15 Nov 2016 14:48:47 +0000 (07:48 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Wed, 16 Nov 2016 01:12:18 +0000 (18:12 -0700)
tests/trilinos/trilinos_sparsity_pattern_iterators_01.cc [new file with mode: 0644]
tests/trilinos/trilinos_sparsity_pattern_iterators_01.output [new file with mode: 0644]
tests/trilinos/trilinos_sparsity_pattern_iterators_02.cc [new file with mode: 0644]
tests/trilinos/trilinos_sparsity_pattern_iterators_02.output [new file with mode: 0644]

diff --git a/tests/trilinos/trilinos_sparsity_pattern_iterators_01.cc b/tests/trilinos/trilinos_sparsity_pattern_iterators_01.cc
new file mode 100644 (file)
index 0000000..34d32d2
--- /dev/null
@@ -0,0 +1,94 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2016 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+
+// Tests Trilinos sparsity iterators, specifically copy construction
+// and assignment operators
+
+#include "../tests.h"
+#include <deal.II/lac/trilinos_sparsity_pattern.h>
+#include <fstream>
+#include <iomanip>
+
+
+void test ()
+{
+  TrilinosWrappers::SparsityPattern sp;
+
+  sp.reinit(5,7,3);
+  for (unsigned int i=0; i<5; ++i)
+    for (unsigned int j=0; j<7; ++j)
+      if ((i+2*j+1) % 3 == 0)
+        {
+          deallog << "Creating sparsity pattern entry "
+                  << i << ' ' << j << std::endl;
+          sp.add (i,j);
+        }
+  sp.compress ();
+
+  for (TrilinosWrappers::SparsityPattern::const_iterator p = sp.begin(); p != sp.end(); ++p)
+    {
+      deallog << p->row() << ' ' << p->column() << std::endl;
+
+      // check copy construction
+      TrilinosWrappers::SparsityPattern::const_iterator q (p);
+      Assert (p == q, ExcInternalError());
+
+      // also check copy operation
+      q = p;
+      Assert (p == q, ExcInternalError());
+    }
+}
+
+
+
+int main (int argc, char **argv)
+{
+  std::ofstream logfile("output");
+  deallog.attach(logfile);
+  deallog.threshold_double(1.e-10);
+
+  Utilities::MPI::MPI_InitFinalize mpi_initialization (argc, argv, testing_max_num_threads());
+
+  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/trilinos/trilinos_sparsity_pattern_iterators_01.output b/tests/trilinos/trilinos_sparsity_pattern_iterators_01.output
new file mode 100644 (file)
index 0000000..b822e74
--- /dev/null
@@ -0,0 +1,23 @@
+
+DEAL::Creating sparsity pattern entry 0 1
+DEAL::Creating sparsity pattern entry 0 4
+DEAL::Creating sparsity pattern entry 1 2
+DEAL::Creating sparsity pattern entry 1 5
+DEAL::Creating sparsity pattern entry 2 0
+DEAL::Creating sparsity pattern entry 2 3
+DEAL::Creating sparsity pattern entry 2 6
+DEAL::Creating sparsity pattern entry 3 1
+DEAL::Creating sparsity pattern entry 3 4
+DEAL::Creating sparsity pattern entry 4 2
+DEAL::Creating sparsity pattern entry 4 5
+DEAL::0 1
+DEAL::0 4
+DEAL::1 2
+DEAL::1 5
+DEAL::2 0
+DEAL::2 3
+DEAL::2 6
+DEAL::3 1
+DEAL::3 4
+DEAL::4 2
+DEAL::4 5
diff --git a/tests/trilinos/trilinos_sparsity_pattern_iterators_02.cc b/tests/trilinos/trilinos_sparsity_pattern_iterators_02.cc
new file mode 100644 (file)
index 0000000..9a4e12b
--- /dev/null
@@ -0,0 +1,118 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2016 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+
+// Tests Trilinos sparsity iterators, specifically copy construction
+// and assignment operators
+//
+// The accessors keep a cache that is administered via a shared
+// pointer. make sure that copying these objects works as expected
+
+#include "../tests.h"
+#include <deal.II/lac/trilinos_sparsity_pattern.h>
+#include <fstream>
+#include <iomanip>
+
+
+void test ()
+{
+  TrilinosWrappers::SparsityPattern sp;
+
+  sp.reinit(5,7,3);
+  for (unsigned int i=0; i<5; ++i)
+    for (unsigned int j=0; j<7; ++j)
+      if ((i+2*j+1) % 3 == 0)
+        {
+          deallog << "Creating sparsity pattern entry "
+                  << i << ' ' << j << std::endl;
+          sp.add (i,j);
+        }
+  sp.compress ();
+
+  // get an iterator to the first row, then copy it
+  TrilinosWrappers::SparsityPattern::const_iterator p = sp.begin(0);
+  TrilinosWrappers::SparsityPattern::const_iterator q (p);
+
+  // now reset 'p' to the second row, and output what elements both
+  // 'p' and 'q' point to
+  p = sp.begin(1);
+
+  for (unsigned int i=0; i<2; ++i, ++p)
+    deallog << "p[" << i << "]: "
+            << p->row() << ' ' << p->column()
+            << std::endl;
+
+  for (unsigned int i=0; i<2; ++i, ++q)
+    deallog << "q[" << i << "]: "
+            << q->row() << ' ' << q->column()
+            << std::endl;
+
+
+  // do the same with copy assignment
+  p = sp.begin(0);
+  q = p;
+  p = sp.begin(1);
+
+  for (unsigned int i=0; i<2; ++i, ++p)
+    deallog << "p[" << i << "]: "
+            << p->row() << ' ' << p->column()
+            << std::endl;
+
+  for (unsigned int i=0; i<2; ++i, ++q)
+    deallog << "q[" << i << "]: "
+            << q->row() << ' ' << q->column()
+            << std::endl;
+}
+
+
+
+int main (int argc, char **argv)
+{
+  std::ofstream logfile("output");
+  deallog.attach(logfile);
+  deallog.threshold_double(1.e-10);
+
+  Utilities::MPI::MPI_InitFinalize mpi_initialization (argc, argv, testing_max_num_threads());
+
+  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/trilinos/trilinos_sparsity_pattern_iterators_02.output b/tests/trilinos/trilinos_sparsity_pattern_iterators_02.output
new file mode 100644 (file)
index 0000000..1d916a1
--- /dev/null
@@ -0,0 +1,20 @@
+
+DEAL::Creating sparsity pattern entry 0 1
+DEAL::Creating sparsity pattern entry 0 4
+DEAL::Creating sparsity pattern entry 1 2
+DEAL::Creating sparsity pattern entry 1 5
+DEAL::Creating sparsity pattern entry 2 0
+DEAL::Creating sparsity pattern entry 2 3
+DEAL::Creating sparsity pattern entry 2 6
+DEAL::Creating sparsity pattern entry 3 1
+DEAL::Creating sparsity pattern entry 3 4
+DEAL::Creating sparsity pattern entry 4 2
+DEAL::Creating sparsity pattern entry 4 5
+DEAL::p[0]: 1 2
+DEAL::p[1]: 1 5
+DEAL::q[0]: 0 1
+DEAL::q[1]: 0 4
+DEAL::p[0]: 1 2
+DEAL::p[1]: 1 5
+DEAL::q[0]: 0 1
+DEAL::q[1]: 0 4

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.