From: Timo Heister Date: Mon, 12 Jan 2015 16:26:49 +0000 (-0500) Subject: implement PETScWrappers::MPI::SparseMatrix::reinit X-Git-Tag: v8.3.0-rc1~553^2~6 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ab9612f3a4d68582d1ff513db6edcdece449eb37;p=dealii.git implement PETScWrappers::MPI::SparseMatrix::reinit --- diff --git a/include/deal.II/lac/petsc_parallel_sparse_matrix.h b/include/deal.II/lac/petsc_parallel_sparse_matrix.h index 1b7df5c61c..8830fc8338 100644 --- a/include/deal.II/lac/petsc_parallel_sparse_matrix.h +++ b/include/deal.II/lac/petsc_parallel_sparse_matrix.h @@ -325,6 +325,12 @@ namespace PETScWrappers const SparsityType &sparsity_pattern, const MPI_Comm &communicator); + /** + * Initialize this matrix to have the same structure as @p other. This will not copy + * the values of the other matrix, but you can use copy_from() for this. + */ + void reinit (const SparseMatrix &other); + /** * Return a reference to the MPI communicator object in use with this * matrix. diff --git a/source/lac/petsc_parallel_sparse_matrix.cc b/source/lac/petsc_parallel_sparse_matrix.cc index d488abb7d1..6ab9194223 100644 --- a/source/lac/petsc_parallel_sparse_matrix.cc +++ b/source/lac/petsc_parallel_sparse_matrix.cc @@ -106,6 +106,27 @@ namespace PETScWrappers } + void + SparseMatrix:: + reinit (const SparseMatrix &other) + { + if (&other == this) + return; + + this->communicator = other.communicator; + + int ierr; +#if DEAL_II_PETSC_VERSION_LT(3,2,0) + ierr = MatDestroy (matrix); +#else + ierr = MatDestroy (&matrix); +#endif + AssertThrow (ierr == 0, ExcPETScError(ierr)); + + ierr = MatDuplicate(other.matrix, MAT_DO_NOT_COPY_VALUES, &matrix); + AssertThrow (ierr == 0, ExcPETScError(ierr)); + } + SparseMatrix & SparseMatrix::operator = (const value_type d)