From 470a1f460fdd636dd96a0fac304e04c11f320c2d Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Thu, 28 Dec 2017 12:56:39 -0700 Subject: [PATCH] Add a couple of tests for TrilinosWrappers::SparseMatrix::n_nonzero_entries(). --- tests/trilinos/n_nonzeros_01.cc | 75 ++++++++++++++++++++++ tests/trilinos/n_nonzeros_01.output | 2 + tests/trilinos/n_nonzeros_02.cc | 96 +++++++++++++++++++++++++++++ tests/trilinos/n_nonzeros_02.output | 2 + 4 files changed, 175 insertions(+) create mode 100644 tests/trilinos/n_nonzeros_01.cc create mode 100644 tests/trilinos/n_nonzeros_01.output create mode 100644 tests/trilinos/n_nonzeros_02.cc create mode 100644 tests/trilinos/n_nonzeros_02.output diff --git a/tests/trilinos/n_nonzeros_01.cc b/tests/trilinos/n_nonzeros_01.cc new file mode 100644 index 0000000000..93d2c80aef --- /dev/null +++ b/tests/trilinos/n_nonzeros_01.cc @@ -0,0 +1,75 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 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 at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + + +// check n_nonzero_elements() for an empty matrix + +#include "../tests.h" +#include +#include +#include + + +void test () +{ + // create an empty sparsity pattern + TrilinosWrappers::SparsityPattern sparsity(4,5,1); + sparsity.compress (); + + // attach a sparse matrix to it + TrilinosWrappers::SparseMatrix A(sparsity); + + // see how many nonzero elements it reports + deallog << A.n_nonzero_elements() << std::endl; +} + + + +int main (int argc, char **argv) +{ + initlog(); + + 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/n_nonzeros_01.output b/tests/trilinos/n_nonzeros_01.output new file mode 100644 index 0000000000..199228a5ad --- /dev/null +++ b/tests/trilinos/n_nonzeros_01.output @@ -0,0 +1,2 @@ + +DEAL::0 diff --git a/tests/trilinos/n_nonzeros_02.cc b/tests/trilinos/n_nonzeros_02.cc new file mode 100644 index 0000000000..4a5c780737 --- /dev/null +++ b/tests/trilinos/n_nonzeros_02.cc @@ -0,0 +1,96 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 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 at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + + +// check n_nonzero_elements() for an empty matrix + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include + + +void test () +{ + Triangulation<2> tria; + GridGenerator::hyper_cube (tria); + + FE_Q<2> fe(1); + DoFHandler<2> dof_handler (tria); + dof_handler.distribute_dofs(fe); + + Table<2,DoFTools::Coupling> coupling (1,1); + coupling.fill (DoFTools::none); + + // create an empty sparsity pattern + TrilinosWrappers::SparsityPattern sparsity; + sparsity.reinit (dof_handler.n_dofs(), dof_handler.n_dofs()); + DoFTools::make_sparsity_pattern (dof_handler, + coupling, sparsity, + ConstraintMatrix(), false, + Utilities::MPI:: + this_mpi_process(MPI_COMM_WORLD)); + sparsity.compress (); + + // attach a sparse matrix to it + TrilinosWrappers::SparseMatrix A; + A.reinit(sparsity); + + // see how many nonzero elements it reports + deallog << A.n_nonzero_elements() << std::endl; +} + + + +int main (int argc, char **argv) +{ + initlog(); + + 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/n_nonzeros_02.output b/tests/trilinos/n_nonzeros_02.output new file mode 100644 index 0000000000..199228a5ad --- /dev/null +++ b/tests/trilinos/n_nonzeros_02.output @@ -0,0 +1,2 @@ + +DEAL::0 -- 2.39.5