From 6f7db1baa8ae13d0a0ab23cd8497c26668c51b4c Mon Sep 17 00:00:00 2001 From: Stefano Zampini Date: Tue, 18 Apr 2023 11:18:45 +0300 Subject: [PATCH] PETScWrappers::BlockSparseMatrix unify constructors add missing test --- include/deal.II/lac/petsc_block_sparse_matrix.h | 15 +++++++++++++-- source/lac/petsc_parallel_block_sparse_matrix.cc | 3 +++ tests/petsc/block_matrices_01.cc | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/include/deal.II/lac/petsc_block_sparse_matrix.h b/include/deal.II/lac/petsc_block_sparse_matrix.h index 397725d162..63b9edab52 100644 --- a/include/deal.II/lac/petsc_block_sparse_matrix.h +++ b/include/deal.II/lac/petsc_block_sparse_matrix.h @@ -100,7 +100,7 @@ namespace PETScWrappers * reinit(BlockSparsityPattern). The number of blocks per row and column * are then determined by that function. */ - BlockSparseMatrix() = default; + BlockSparseMatrix(); /** * Create a BlockSparseMatrix with a PETSc Mat that describes the entire @@ -339,7 +339,7 @@ namespace PETScWrappers * a "nested" matrix using PETSc's MATNEST object whose individual * blocks are the blocks of this matrix. */ - Mat petsc_nest_matrix = nullptr; + Mat petsc_nest_matrix; /** * Utility to setup the MATNEST object @@ -361,6 +361,12 @@ namespace PETScWrappers /** @} */ // ------------- inline and template functions ----------------- + inline BlockSparseMatrix::BlockSparseMatrix() + : BaseClass() + , petsc_nest_matrix(nullptr) + {} + + inline BlockSparseMatrix::BlockSparseMatrix(const Mat &A) : BlockSparseMatrix() @@ -368,9 +374,12 @@ namespace PETScWrappers this->reinit(A); } + + template inline BlockSparseMatrix::BlockSparseMatrix( const std::array, block_rows> &arrayA) + : BlockSparseMatrix() { this->reinit(block_rows, block_columns); this->sub_objects.reinit(block_rows, block_columns); @@ -385,6 +394,8 @@ namespace PETScWrappers this->collect_sizes(); } + + inline BlockSparseMatrix & BlockSparseMatrix::operator=(const double d) { diff --git a/source/lac/petsc_parallel_block_sparse_matrix.cc b/source/lac/petsc_parallel_block_sparse_matrix.cc index a8faa324eb..798f2e514d 100644 --- a/source/lac/petsc_parallel_block_sparse_matrix.cc +++ b/source/lac/petsc_parallel_block_sparse_matrix.cc @@ -260,6 +260,9 @@ namespace PETScWrappers ierr = MatCreateNest( comm, m, nullptr, n, nullptr, psub_objects.data(), &petsc_nest_matrix); AssertThrow(ierr == 0, ExcPETScError(ierr)); + + ierr = MatNestSetVecType(petsc_nest_matrix, VECNEST); + AssertThrow(ierr == 0, ExcPETScError(ierr)); } diff --git a/tests/petsc/block_matrices_01.cc b/tests/petsc/block_matrices_01.cc index aca37f1457..9cb37b47a8 100644 --- a/tests/petsc/block_matrices_01.cc +++ b/tests/petsc/block_matrices_01.cc @@ -78,6 +78,7 @@ test() Assert(tmp2.n_block_cols() == pbsm.n_block_cols(), ExcInternalError()); Assert(tmp2.m() == pbsm.m(), ExcInternalError()); Assert(tmp2.n() == pbsm.n(), ExcInternalError()); + Assert(tmp2.petsc_matrix() == pbsm.petsc_matrix(), ExcInternalError()); for (unsigned int blr = 0; blr < 2; ++blr) { for (unsigned int blc = 0; blc < 2; ++blc) -- 2.39.5