From 01f1ef02d3a2717c7aaff12eacfbc4f75ceb8236 Mon Sep 17 00:00:00 2001 From: Stefano Zampini Date: Mon, 16 Jan 2023 16:27:34 +0300 Subject: [PATCH] rename assign_petsc_matrix/vector to reinit --- .../deal.II/lac/petsc_block_sparse_matrix.h | 21 ++++++++----------- include/deal.II/lac/petsc_block_vector.h | 13 +++++------- include/deal.II/lac/petsc_matrix_base.h | 8 ++++--- include/deal.II/lac/petsc_vector.h | 2 ++ include/deal.II/lac/petsc_vector_base.h | 8 +++---- source/lac/petsc_matrix_base.cc | 2 +- .../lac/petsc_parallel_block_sparse_matrix.cc | 2 +- source/lac/petsc_parallel_block_vector.cc | 4 ++-- source/lac/petsc_vector_base.cc | 2 +- 9 files changed, 30 insertions(+), 32 deletions(-) diff --git a/include/deal.II/lac/petsc_block_sparse_matrix.h b/include/deal.II/lac/petsc_block_sparse_matrix.h index 5fdf6d4173..11aced3b74 100644 --- a/include/deal.II/lac/petsc_block_sparse_matrix.h +++ b/include/deal.II/lac/petsc_block_sparse_matrix.h @@ -173,6 +173,14 @@ namespace PETScWrappers const MPI_Comm & com); + /** + * This method associates the PETSc Mat to the instance of the class. + * Infers the number of blocks from A if it is of type MATNEST, otherwise + * the block operator will only have a single block. + */ + void + reinit(Mat A); + /** * Matrix-vector multiplication: let $dst = M*src$ with $M$ being this @@ -299,17 +307,6 @@ namespace PETScWrappers Mat & petsc_matrix(); - /** - * This method assigns the PETSc Mat to the instance of the class. - * - * Note that the matrix is not copied: instead, the instance of this class - * is initialized to use the given matrix. This is useful if you want to - * interpret a PETSc Mat object as a deal.II BlockMatrix, and you already - * have a BlockMatrix object that you want to use for this purpose. - */ - void - assign_petsc_matrix(Mat A); - private: /** * A PETSc Mat object that describes the entire block matrix. @@ -329,7 +326,7 @@ namespace PETScWrappers inline BlockSparseMatrix::BlockSparseMatrix(const Mat &A) : BlockSparseMatrix() { - this->assign_petsc_matrix(A); + this->reinit(A); } inline BlockSparseMatrix & diff --git a/include/deal.II/lac/petsc_block_vector.h b/include/deal.II/lac/petsc_block_vector.h index 670f2061d4..b441defa8d 100644 --- a/include/deal.II/lac/petsc_block_vector.h +++ b/include/deal.II/lac/petsc_block_vector.h @@ -155,15 +155,12 @@ namespace PETScWrappers operator=(const BlockVector &V); /** - * This method assigns the given PETSc Vec to the instance of the class. - * - * Note that the vector is not copied: instead, the instance of this class - * is initialized to use the given vector. This is useful if you want to - * interpret a PETSc vector as a deal.II vector, and you already have a - * BlockVector that you want to use for this purpose. + * This method associates the PETSc Vec to the instance of the class. + * Infers the number of blocks from v if it is of type VECNEST, otherwise + * the block vector will only have a single block. */ void - assign_petsc_vector(Vec v); + reinit(Vec v); /** * Reinitialize the BlockVector to contain @p n_blocks of size @p @@ -399,7 +396,7 @@ namespace PETScWrappers : BlockVectorBase() , petsc_nest_vector(nullptr) { - this->assign_petsc_vector(v); + this->reinit(v); } inline BlockVector & diff --git a/include/deal.II/lac/petsc_matrix_base.h b/include/deal.II/lac/petsc_matrix_base.h index 7afc7db09e..99363019e9 100644 --- a/include/deal.II/lac/petsc_matrix_base.h +++ b/include/deal.II/lac/petsc_matrix_base.h @@ -345,11 +345,13 @@ namespace PETScWrappers virtual ~MatrixBase() override; /** - * This method assigns the PETSc Mat to the instance of the class. - * + * This method associates the PETSc Mat to the instance of the class. + * This is particularly useful when performing PETSc to Deal.II operations + * since it allows to reuse the Deal.II MatrixBase and the PETSc Mat + * without incurring in memory copies. */ void - assign_petsc_matrix(Mat A); + reinit(Mat A); /** * This operator assigns a scalar to a matrix. Since this does usually not diff --git a/include/deal.II/lac/petsc_vector.h b/include/deal.II/lac/petsc_vector.h index fbfa3d0ba5..bad7777a8c 100644 --- a/include/deal.II/lac/petsc_vector.h +++ b/include/deal.II/lac/petsc_vector.h @@ -289,6 +289,8 @@ namespace PETScWrappers Vector & operator=(const dealii::Vector &v); + using VectorBase::reinit; + /** * Change the dimension of the vector to @p N. It is unspecified how * resizing the vector affects the memory allocation of this object; diff --git a/include/deal.II/lac/petsc_vector_base.h b/include/deal.II/lac/petsc_vector_base.h index 4e69a3a3f4..5f583d8241 100644 --- a/include/deal.II/lac/petsc_vector_base.h +++ b/include/deal.II/lac/petsc_vector_base.h @@ -328,13 +328,13 @@ namespace PETScWrappers operator=(const PetscScalar s); /** - * This method assigns the PETSc Vec to the instance of the class. - * This is particularly useful when performing PETSc to deal.II operations - * since it allows one to reuse the VectorBase and the PETSc Vec + * This method associates the PETSc Vec to the instance of the class. + * This is particularly useful when performing PETSc to Deal.II operations + * since it allows to reuse the Deal.II VectorBase and the PETSc Vec * without incurring in memory copies. */ void - assign_petsc_vector(Vec v); + reinit(Vec v); /** * Test for equality. This function assumes that the present vector and diff --git a/source/lac/petsc_matrix_base.cc b/source/lac/petsc_matrix_base.cc index 8c475bd9a2..9592822eb0 100644 --- a/source/lac/petsc_matrix_base.cc +++ b/source/lac/petsc_matrix_base.cc @@ -90,7 +90,7 @@ namespace PETScWrappers } void - MatrixBase::assign_petsc_matrix(Mat A) + MatrixBase::reinit(Mat A) { AssertThrow(last_action == ::dealii::VectorOperation::unknown, ExcMessage("Cannot assign a new Mat.")); diff --git a/source/lac/petsc_parallel_block_sparse_matrix.cc b/source/lac/petsc_parallel_block_sparse_matrix.cc index 3e5a6a24c9..5b97e58acb 100644 --- a/source/lac/petsc_parallel_block_sparse_matrix.cc +++ b/source/lac/petsc_parallel_block_sparse_matrix.cc @@ -210,7 +210,7 @@ namespace PETScWrappers } void - BlockSparseMatrix::assign_petsc_matrix(Mat A) + BlockSparseMatrix::reinit(Mat A) { clear(); diff --git a/source/lac/petsc_parallel_block_vector.cc b/source/lac/petsc_parallel_block_vector.cc index 3c7f03831d..3cb802877c 100644 --- a/source/lac/petsc_parallel_block_vector.cc +++ b/source/lac/petsc_parallel_block_vector.cc @@ -46,7 +46,7 @@ namespace PETScWrappers } void - BlockVector::assign_petsc_vector(Vec v) + BlockVector::reinit(Vec v) { PetscBool isnest; @@ -81,7 +81,7 @@ namespace PETScWrappers this->components.resize(nb); for (unsigned int i = 0; i < nb; ++i) { - this->components[i].assign_petsc_vector(sv[i]); + this->components[i].reinit(sv[i]); } this->collect_sizes(); diff --git a/source/lac/petsc_vector_base.cc b/source/lac/petsc_vector_base.cc index 309fb0e361..538374755e 100644 --- a/source/lac/petsc_vector_base.cc +++ b/source/lac/petsc_vector_base.cc @@ -181,7 +181,7 @@ namespace PETScWrappers void - VectorBase::assign_petsc_vector(Vec v) + VectorBase::reinit(Vec v) { /* TODO GHOSTED */ AssertThrow(last_action == ::dealii::VectorOperation::unknown, -- 2.39.5