]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Tests for n_nonzero_elements of BlockSparseMatrix from third party libraries. 13489/head
authorMarc Fehling <mafehling.git@gmail.com>
Sat, 5 Mar 2022 03:10:57 +0000 (20:10 -0700)
committerMarc Fehling <mafehling.git@gmail.com>
Sun, 6 Mar 2022 22:02:28 +0000 (15:02 -0700)
tests/lac/block_matrices_01.cc [moved from tests/lac/block_matrices.cc with 100% similarity]
tests/lac/block_matrices_01.output [moved from tests/lac/block_matrices.output with 100% similarity]
tests/petsc/block_matrices_01.cc [new file with mode: 0644]
tests/petsc/block_matrices_01.mpirun=1.output [new file with mode: 0644]
tests/trilinos/block_matrices_01.cc [new file with mode: 0644]
tests/trilinos/block_matrices_01.mpirun=1.output [new file with mode: 0644]

diff --git a/tests/petsc/block_matrices_01.cc b/tests/petsc/block_matrices_01.cc
new file mode 100644 (file)
index 0000000..51dc087
--- /dev/null
@@ -0,0 +1,84 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2022 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.
+//
+// ---------------------------------------------------------------------
+
+
+// Verify n_nonzero_elements for PETSc BlockSparseMatrix.
+
+#include <deal.II/base/mpi.h>
+
+#include <deal.II/lac/block_sparsity_pattern.h>
+#include <deal.II/lac/petsc_block_sparse_matrix.h>
+
+#include "../tests.h"
+
+
+
+void
+test()
+{
+  // create block sparsity pattern
+  BlockDynamicSparsityPattern bdsp(2, 2);
+  bdsp.block(0, 0).reinit(2, 2);
+  bdsp.block(0, 1).reinit(2, 3);
+  bdsp.block(1, 0).reinit(3, 2);
+  bdsp.block(1, 1).reinit(3, 3);
+  bdsp.collect_sizes();
+
+  // add triangular sparsity pattern to each block
+  // block (0, 0)
+  for (unsigned int row = 0; row < 2; ++row)
+    for (unsigned int col = 0; col <= row; ++col)
+      bdsp.add(row, col);
+  // block (1, 1)
+  for (unsigned int row = 2; row < 5; ++row)
+    for (unsigned int col = 2; col <= row; ++col)
+      bdsp.add(row, col);
+
+  bdsp.compress();
+  deallog << "nonzeros BlockSparsityPattern: " << bdsp.n_nonzero_elements()
+          << std::endl;
+
+  // create block sparse matrix
+  std::vector<IndexSet> rows(2);
+  rows[0].set_size(2);
+  rows[0].add_range(0, 2);
+  rows[1].set_size(3);
+  rows[1].add_range(0, 3);
+
+  std::vector<IndexSet> cols(2);
+  cols[0].set_size(2);
+  cols[0].add_range(0, 2);
+  cols[1].set_size(3);
+  cols[1].add_range(0, 3);
+
+  PETScWrappers::MPI::BlockSparseMatrix pbsm;
+  pbsm.reinit(rows, cols, bdsp, MPI_COMM_WORLD);
+  deallog << "nonzeros BlockSparseMatrix: " << pbsm.n_nonzero_elements()
+          << std::endl;
+}
+
+
+
+int
+main(int argc, char *argv[])
+{
+  Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
+
+  initlog();
+
+  test();
+
+  return 0;
+}
diff --git a/tests/petsc/block_matrices_01.mpirun=1.output b/tests/petsc/block_matrices_01.mpirun=1.output
new file mode 100644 (file)
index 0000000..a9c5e15
--- /dev/null
@@ -0,0 +1,3 @@
+
+DEAL::nonzeros BlockSparsityPattern: 9
+DEAL::nonzeros BlockSparseMatrix: 9
diff --git a/tests/trilinos/block_matrices_01.cc b/tests/trilinos/block_matrices_01.cc
new file mode 100644 (file)
index 0000000..118d39b
--- /dev/null
@@ -0,0 +1,72 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2022 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.
+//
+// ---------------------------------------------------------------------
+
+
+// Verify n_nonzero_elements for Trilinos BlockSparseMatrix.
+
+#include <deal.II/base/mpi.h>
+
+#include <deal.II/lac/block_sparsity_pattern.h>
+#include <deal.II/lac/trilinos_block_sparse_matrix.h>
+
+#include "../tests.h"
+
+
+
+void
+test()
+{
+  // create block sparsity pattern
+  BlockDynamicSparsityPattern bdsp(2, 2);
+  bdsp.block(0, 0).reinit(2, 2);
+  bdsp.block(0, 1).reinit(2, 3);
+  bdsp.block(1, 0).reinit(3, 2);
+  bdsp.block(1, 1).reinit(3, 3);
+  bdsp.collect_sizes();
+
+  // add triangular sparsity pattern to each block
+  // block (0, 0)
+  for (unsigned int row = 0; row < 2; ++row)
+    for (unsigned int col = 0; col <= row; ++col)
+      bdsp.add(row, col);
+  // block (1, 1)
+  for (unsigned int row = 2; row < 5; ++row)
+    for (unsigned int col = 2; col <= row; ++col)
+      bdsp.add(row, col);
+
+  bdsp.compress();
+  deallog << "nonzeros BlockSparsityPattern: " << bdsp.n_nonzero_elements()
+          << std::endl;
+
+  // create block sparse matrix
+  TrilinosWrappers::BlockSparseMatrix tbsm;
+  tbsm.reinit(bdsp);
+  deallog << "nonzeros BlockSparseMatrix: " << tbsm.n_nonzero_elements()
+          << std::endl;
+}
+
+
+
+int
+main(int argc, char *argv[])
+{
+  Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
+
+  initlog();
+
+  test();
+
+  return 0;
+}
diff --git a/tests/trilinos/block_matrices_01.mpirun=1.output b/tests/trilinos/block_matrices_01.mpirun=1.output
new file mode 100644 (file)
index 0000000..a9c5e15
--- /dev/null
@@ -0,0 +1,3 @@
+
+DEAL::nonzeros BlockSparsityPattern: 9
+DEAL::nonzeros BlockSparseMatrix: 9

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.