]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix: explicitly instantiate BlockSparseMatrix::reinit(vector<IndexSet>, BlockDynamicS... 18393/head
authorQingyuan Shi <shiqy21@mails.tsinghua.edu.cn>
Sun, 27 Apr 2025 10:56:54 +0000 (18:56 +0800)
committerQingyuan Shi <shiqy21@mails.tsinghua.edu.cn>
Sun, 27 Apr 2025 10:56:54 +0000 (18:56 +0800)
doc/news/changes/minor/20250427Shi [new file with mode: 0644]
source/lac/trilinos_tpetra_block_sparse_matrix.cc
tests/trilinos_tpetra/block_matrices_01.cc [new file with mode: 0644]
tests/trilinos_tpetra/block_matrices_01.output [new file with mode: 0644]

diff --git a/doc/news/changes/minor/20250427Shi b/doc/news/changes/minor/20250427Shi
new file mode 100644 (file)
index 0000000..d881958
--- /dev/null
@@ -0,0 +1,6 @@
+Fix: Add explicit instantiation for TpetraWrappers::BlockSparseMatrix::reinit
+(std::vector<IndexSet>, BlockDynamicSparsityPattern, MPI_Comm, bool) to fix
+missing symbol error when initializing Tpetra block matrices from
+distributed sparsity patterns.
+<br>
+(Qingyuan Shi, 2025/04/27)
index a51c197ce96df43d8dcb45ce0d28653c60eaf261..87c37f192507f535f86527f541324ca0b38df90d 100644 (file)
@@ -32,6 +32,14 @@ namespace LinearAlgebra
     BlockSparseMatrix<double, MemorySpace::Host>::reinit(
       const ::dealii::BlockDynamicSparsityPattern &);
 
+    template void
+    BlockSparseMatrix<double, MemorySpace::Host>::reinit<
+      ::dealii::BlockDynamicSparsityPattern>(
+      const std::vector<dealii::IndexSet> &,
+      const ::dealii::BlockDynamicSparsityPattern &,
+      MPI_Comm,
+      bool);
+
     template void
     BlockSparseMatrix<double, MemorySpace::Host>::vmult(
       TpetraWrappers::Vector<double, MemorySpace::Host> &,
diff --git a/tests/trilinos_tpetra/block_matrices_01.cc b/tests/trilinos_tpetra/block_matrices_01.cc
new file mode 100644 (file)
index 0000000..183d094
--- /dev/null
@@ -0,0 +1,91 @@
+// ------------------------------------------------------------------------
+//
+// SPDX-License-Identifier: LGPL-2.1-or-later
+// Copyright (C) 2022 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// Part of the source code is dual licensed under Apache-2.0 WITH
+// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
+// governing the source code and code contributions can be found in
+// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
+//
+// ------------------------------------------------------------------------
+
+
+// Verify n_nonzero_elements and reinit() for Tpetra 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;
+
+
+
+  // create partitioning
+  std::vector<dealii::IndexSet> partitioning(2);
+  partitioning[0] = dealii::IndexSet(2); // 2 dofs
+  partitioning[1] = dealii::IndexSet(3); // 3 dofs
+
+  partitioning[0].add_range(0, 2);
+  partitioning[1].add_range(0, 3);
+
+  for (auto &set : partitioning)
+    set.compress();
+
+  // create block sparse matrix using another reinit() function
+  TrilinosWrappers::BlockSparseMatrix tbsm2;
+  tbsm2.reinit(partitioning, bdsp, MPI_COMM_SELF, false);
+
+  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_tpetra/block_matrices_01.output b/tests/trilinos_tpetra/block_matrices_01.output
new file mode 100644 (file)
index 0000000..bdea249
--- /dev/null
@@ -0,0 +1,4 @@
+
+DEAL::nonzeros BlockSparsityPattern: 9
+DEAL::nonzeros BlockSparseMatrix: 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.