From dbb6aee0432579ea2957323ca08c7a7045fddcd3 Mon Sep 17 00:00:00 2001 From: David Wells Date: Fri, 11 Nov 2016 22:21:07 -0500 Subject: [PATCH] Add a test for copying PETSc matrix iterators. --- tests/petsc/sparse_matrix_iterator_02.cc | 92 ++++++++++++++++++++ tests/petsc/sparse_matrix_iterator_02.output | 32 +++++++ 2 files changed, 124 insertions(+) create mode 100644 tests/petsc/sparse_matrix_iterator_02.cc create mode 100644 tests/petsc/sparse_matrix_iterator_02.output diff --git a/tests/petsc/sparse_matrix_iterator_02.cc b/tests/petsc/sparse_matrix_iterator_02.cc new file mode 100644 index 0000000000..307ac32b19 --- /dev/null +++ b/tests/petsc/sparse_matrix_iterator_02.cc @@ -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 +#include +#include + + +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 index 0000000000..c638751055 --- /dev/null +++ b/tests/petsc/sparse_matrix_iterator_02.output @@ -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 -- 2.39.5