From 794983149f32f001fd96da4845af127d8ea9ff34 Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Wed, 19 Sep 2018 12:52:51 -0500 Subject: [PATCH] add a test --- tests/petsc/sparse_matrix_03.cc | 74 +++++++++++++++++++++++++++++ tests/petsc/sparse_matrix_03.output | 14 ++++++ 2 files changed, 88 insertions(+) create mode 100644 tests/petsc/sparse_matrix_03.cc create mode 100644 tests/petsc/sparse_matrix_03.output diff --git a/tests/petsc/sparse_matrix_03.cc b/tests/petsc/sparse_matrix_03.cc new file mode 100644 index 0000000000..d04b25bf15 --- /dev/null +++ b/tests/petsc/sparse_matrix_03.cc @@ -0,0 +1,74 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2004 - 2017 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.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + + + +// check SparseMatrix::transpose + +#include + +#include +#include + +#include "../tests.h" + + +void +test() +{ + const unsigned int s = 3; + PETScWrappers::SparseMatrix m(s, s, s); + + const auto print = [&]() { + for (unsigned int i = 0; i < m.m(); ++i) + { + for (unsigned int j = 0; j < m.n(); ++j) + deallog << m(i, j) << " "; + deallog << std::endl; + } + }; + + for (unsigned int i = 0; i < m.m(); ++i) + for (unsigned int j = 0; j < m.n(); ++j) + m.set(i, j, i + m.m() * j); + + m.compress(VectorOperation::insert); + + deallog << "before: " << std::endl; + print(); + + m.transpose(); + + deallog << "after: " << std::endl; + print(); + + m.transpose(); + + deallog << "back to original: " << std::endl; + print(); + + deallog << "OK" << std::endl; +} + + + +int +main(int argc, char **argv) +{ + initlog(); + + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + test(); +} diff --git a/tests/petsc/sparse_matrix_03.output b/tests/petsc/sparse_matrix_03.output new file mode 100644 index 0000000000..a61e2a5555 --- /dev/null +++ b/tests/petsc/sparse_matrix_03.output @@ -0,0 +1,14 @@ + +DEAL::before: +DEAL::0.00000 3.00000 6.00000 +DEAL::1.00000 4.00000 7.00000 +DEAL::2.00000 5.00000 8.00000 +DEAL::after: +DEAL::0.00000 1.00000 2.00000 +DEAL::3.00000 4.00000 5.00000 +DEAL::6.00000 7.00000 8.00000 +DEAL::back to original: +DEAL::0.00000 3.00000 6.00000 +DEAL::1.00000 4.00000 7.00000 +DEAL::2.00000 5.00000 8.00000 +DEAL::OK -- 2.39.5