From: Toby D. Young Date: Mon, 20 Jan 2014 12:05:00 +0000 (+0000) Subject: Slightly extend full matrix interface. X-Git-Tag: v8.2.0-rc1~999 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=87111c3e3f69edcb84ace9c0ef2000002acee152;p=dealii.git Slightly extend full matrix interface. git-svn-id: https://svn.dealii.org/trunk@32265 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/include/deal.II/lac/petsc_full_matrix.h b/deal.II/include/deal.II/lac/petsc_full_matrix.h index 176e9d5fc3..c800efccd2 100644 --- a/deal.II/include/deal.II/lac/petsc_full_matrix.h +++ b/deal.II/include/deal.II/lac/petsc_full_matrix.h @@ -50,26 +50,52 @@ namespace PETScWrappers class FullMatrix : public MatrixBase { public: + /** * Declare type for container size. */ typedef types::global_dof_index size_type; + + /** + * Default constructor. Create an empty matrix. + */ + FullMatrix (); + + /** - * Create a full matrix of dimensions - * @p m times @p n. + * Create a full matrix of dimensions @p m times @p n. */ FullMatrix (const size_type m, const size_type n); + /** - * Return a reference to the MPI - * communicator object in use with this - * matrix. Since this is a sequential - * matrix, it returns the MPI_COMM_SELF - * communicator. + * Throw away the present matrix and generate one that has the + * same properties as if it were created by the constructor of + * this class with the same argument list as the present function. + */ + void reinit (const size_type m, + const size_type n); + + + /** + * Return a reference to the MPI communicator object in use with + * this matrix. Since this is a sequential matrix, it returns the + * MPI_COMM_SELF communicator. */ virtual const MPI_Comm &get_mpi_communicator () const; + + private: + + /** + * Do the actual work for the respective reinit() function and the + * matching constructor, i.e. create a matrix. Getting rid of the + * previous matrix is left to the caller. + */ + void do_reinit (const size_type m, + const size_type n); + }; /*@}*/ diff --git a/deal.II/source/lac/petsc_full_matrix.cc b/deal.II/source/lac/petsc_full_matrix.cc index 20903076e8..8a35af920a 100644 --- a/deal.II/source/lac/petsc_full_matrix.cc +++ b/deal.II/source/lac/petsc_full_matrix.cc @@ -24,17 +24,54 @@ DEAL_II_NAMESPACE_OPEN namespace PETScWrappers { + + FullMatrix::FullMatrix () + { + const int m=0, n=0; + const int ierr + = MatCreateSeqDense (PETSC_COMM_SELF, m, n, PETSC_NULL, + &matrix); + + AssertThrow (ierr == 0, ExcPETScError(ierr)); + } + FullMatrix::FullMatrix (const size_type m, const size_type n) { + do_reinit (m, n); + } + + void + FullMatrix::reinit (const size_type m, + const size_type n) + { + // get rid of old matrix and generate a + // new one +#if DEAL_II_PETSC_VERSION_LT(3,2,0) + const int ierr = MatDestroy (matrix); +#else + const int ierr = MatDestroy (&matrix); +#endif + AssertThrow (ierr == 0, ExcPETScError(ierr)); + + do_reinit (m, n); + } + + void + FullMatrix::do_reinit (const size_type m, + const size_type n) + { + // use the call sequence indicating only a maximal number of + // elements per row for all rows globally const int ierr - = MatCreateSeqDense(PETSC_COMM_SELF, m, n, PETSC_NULL, - &matrix); + = MatCreateSeqDense (PETSC_COMM_SELF, m, n, PETSC_NULL, + &matrix); AssertThrow (ierr == 0, ExcPETScError(ierr)); } + const MPI_Comm & FullMatrix::get_mpi_communicator () const {