]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add a test for copying PETSc matrix iterators. 3573/head
authorDavid Wells <wellsd2@rpi.edu>
Sat, 12 Nov 2016 03:21:07 +0000 (22:21 -0500)
committerDavid Wells <wellsd2@rpi.edu>
Sat, 12 Nov 2016 03:29:00 +0000 (22:29 -0500)
tests/petsc/sparse_matrix_iterator_02.cc [new file with mode: 0644]
tests/petsc/sparse_matrix_iterator_02.output [new file with mode: 0644]

diff --git a/tests/petsc/sparse_matrix_iterator_02.cc b/tests/petsc/sparse_matrix_iterator_02.cc
new file mode 100644 (file)
index 0000000..307ac32
--- /dev/null
@@ -0,0 +1,92 @@
+// ---------------------------------------------------------------------
+//
+// 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.
+//
+// ---------------------------------------------------------------------
+
+
+
+// test PETScWrappers::MatrixBase::const_iterator::operator=
+
+#include "../tests.h"
+#include <deal.II/lac/petsc_sparse_matrix.h>
+#include <fstream>
+#include <iostream>
+
+
+void test ()
+{
+  const types::global_dof_index n_rows = 5;
+  PETScWrappers::SparseMatrix matrix(n_rows, n_rows, 2);
+  matrix.set(0, 0, 1.0);
+  matrix.set(0, n_rows - 1, -1.0);
+  for (unsigned int row_n = 1; row_n < n_rows; ++row_n)
+    {
+      matrix.set(row_n, row_n, 1.0);
+      matrix.set(row_n, row_n - 1, -1.0);
+    }
+  matrix.compress (VectorOperation::insert);
+
+  for (PETScWrappers::SparseMatrix::const_iterator iterator = matrix.begin();
+       iterator != matrix.end(); ++iterator)
+    {
+      // This is what we want to test.
+      PETScWrappers::SparseMatrix::const_iterator duplicate = iterator;
+      deallog << "row: " << duplicate->row() << std::endl;
+      deallog << "column: " << duplicate->column() << std::endl;
+      deallog << "value: " << duplicate->value() << std::endl;
+    }
+
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main (int argc,char **argv)
+{
+  std::ofstream logfile("output");
+  deallog.attach(logfile);
+  deallog.threshold_double(1.e-10);
+
+  try
+    {
+      Utilities::MPI::MPI_InitFinalize mpi_initialization (argc, argv, 1);
+      {
+        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/petsc/sparse_matrix_iterator_02.output b/tests/petsc/sparse_matrix_iterator_02.output
new file mode 100644 (file)
index 0000000..c638751
--- /dev/null
@@ -0,0 +1,32 @@
+
+DEAL::row: 0
+DEAL::column: 0
+DEAL::value: 1.00000
+DEAL::row: 0
+DEAL::column: 4
+DEAL::value: -1.00000
+DEAL::row: 1
+DEAL::column: 0
+DEAL::value: -1.00000
+DEAL::row: 1
+DEAL::column: 1
+DEAL::value: 1.00000
+DEAL::row: 2
+DEAL::column: 1
+DEAL::value: -1.00000
+DEAL::row: 2
+DEAL::column: 2
+DEAL::value: 1.00000
+DEAL::row: 3
+DEAL::column: 2
+DEAL::value: -1.00000
+DEAL::row: 3
+DEAL::column: 3
+DEAL::value: 1.00000
+DEAL::row: 4
+DEAL::column: 3
+DEAL::value: -1.00000
+DEAL::row: 4
+DEAL::column: 4
+DEAL::value: 1.00000
+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.