From: Stefano Zampini Date: Mon, 17 Oct 2022 10:23:52 +0000 (+0300) Subject: PETScWrappers::MatrixBase: add default getter for mpi comm and constructor from Mat X-Git-Tag: v9.5.0-rc1~715^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=97911ba3839d7a06c3fb0cd06f7574ea0849103b;p=dealii.git PETScWrappers::MatrixBase: add default getter for mpi comm and constructor from Mat --- diff --git a/include/deal.II/lac/petsc_matrix_base.h b/include/deal.II/lac/petsc_matrix_base.h index e6c7121485..dea9e730cb 100644 --- a/include/deal.II/lac/petsc_matrix_base.h +++ b/include/deal.II/lac/petsc_matrix_base.h @@ -304,6 +304,12 @@ namespace PETScWrappers */ MatrixBase(); + /** + * Initialize a Matrix from a PETSc Mat object. Note that we do not copy + * the matrix. + */ + explicit MatrixBase(const Mat &); + /** * Copy constructor. It is deleted as copying this base class * without knowing the concrete kind of matrix stored may both @@ -335,6 +341,7 @@ namespace PETScWrappers */ MatrixBase & operator=(const value_type d); + /** * Release all memory and return to a state just like after having called * the default constructor. @@ -643,10 +650,11 @@ namespace PETScWrappers /** * Return a reference to the MPI communicator object in use with this - * matrix. This function has to be implemented in derived classes. + * matrix. If not implemented, it returns the communicator used by the + * PETSc Mat. */ virtual const MPI_Comm & - get_mpi_communicator() const = 0; + get_mpi_communicator() const; /** * Return the number of nonzero elements of this matrix. Actually, it @@ -1610,6 +1618,14 @@ namespace PETScWrappers prepare_action(VectorOperation::insert); } + inline const MPI_Comm & + MatrixBase::get_mpi_communicator() const + { + static MPI_Comm comm; + PetscObjectGetComm(reinterpret_cast(matrix), &comm); + return comm; + } + # endif // DOXYGEN } // namespace PETScWrappers diff --git a/source/lac/petsc_matrix_base.cc b/source/lac/petsc_matrix_base.cc index c8a26155b8..185fbf9997 100644 --- a/source/lac/petsc_matrix_base.cc +++ b/source/lac/petsc_matrix_base.cc @@ -80,6 +80,16 @@ namespace PETScWrappers {} + MatrixBase::MatrixBase(const Mat &A) + : matrix(A) + , last_action(VectorOperation::unknown) + { + const PetscErrorCode ierr = + PetscObjectReference(reinterpret_cast(matrix)); + AssertNothrow(ierr == 0, ExcPETScError(ierr)); + (void)ierr; + } + MatrixBase::~MatrixBase() {