From ab9612f3a4d68582d1ff513db6edcdece449eb37 Mon Sep 17 00:00:00 2001 From: Timo Heister Date: Mon, 12 Jan 2015 11:26:49 -0500 Subject: [PATCH] implement PETScWrappers::MPI::SparseMatrix::reinit --- .../lac/petsc_parallel_sparse_matrix.h | 6 ++++++ source/lac/petsc_parallel_sparse_matrix.cc | 21 +++++++++++++++++++ 2 files changed, 27 insertions(+) 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) -- 2.39.5