From a34ed79ac01781fabf0a9c6d2fc490dac8f14cee Mon Sep 17 00:00:00 2001 From: wolf Date: Mon, 15 Mar 2004 16:16:58 +0000 Subject: [PATCH] Have a number of reinit functions, and merge code with the constructors. git-svn-id: https://svn.dealii.org/trunk@8741 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/include/lac/petsc_sparse_matrix.h | 62 ++++++++++++++++ deal.II/lac/source/petsc_sparse_matrix.cc | 73 ++++++++++++++++++- 2 files changed, 131 insertions(+), 4 deletions(-) diff --git a/deal.II/lac/include/lac/petsc_sparse_matrix.h b/deal.II/lac/include/lac/petsc_sparse_matrix.h index 0c4a797eeb..bdfeb53421 100644 --- a/deal.II/lac/include/lac/petsc_sparse_matrix.h +++ b/deal.II/lac/include/lac/petsc_sparse_matrix.h @@ -40,6 +40,12 @@ namespace PETScWrappers class SparseMatrix : public MatrixBase { public: + /** + * Default constructor. Create an empty + * matrix. + */ + SparseMatrix (); + /** * Create a sparse matrix of dimensions * m times n, with an @@ -98,6 +104,62 @@ namespace PETScWrappers const unsigned int n, const std::vector &row_lengths, const bool is_symmetric = false); + + /** + * Set all matrix entries to zero, but + * retain the sparsity pattern. This + * function simply calls the respective + * function of the base class. + */ + void reinit (); + + /** + * 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 unsigned int m, + const unsigned int n, + const unsigned int n_nonzero_per_row, + const bool is_symmetric = false); + + /** + * 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 unsigned int m, + const unsigned int n, + const std::vector &row_lengths, + const bool is_symmetric = false); + + 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 unsigned int m, + const unsigned int n, + const unsigned int n_nonzero_per_row, + const bool is_symmetric = false); + + /** + * Same as previous function. + */ + void do_reinit (const unsigned int m, + const unsigned int n, + const std::vector &row_lengths, + const bool is_symmetric = false); }; } diff --git a/deal.II/lac/source/petsc_sparse_matrix.cc b/deal.II/lac/source/petsc_sparse_matrix.cc index b690583d25..5f13542903 100644 --- a/deal.II/lac/source/petsc_sparse_matrix.cc +++ b/deal.II/lac/source/petsc_sparse_matrix.cc @@ -20,10 +20,74 @@ namespace PETScWrappers { + SparseMatrix::SparseMatrix () + { + const int m=0, n=0, n_nonzero_per_row=0; + const int ierr + = MatCreateSeqAIJ(PETSC_COMM_SELF, m, n, n_nonzero_per_row, + 0, &matrix); + AssertThrow (ierr == 0, ExcPETScError(ierr)); + } + + + SparseMatrix::SparseMatrix (const unsigned int m, const unsigned int n, const unsigned int n_nonzero_per_row, const bool is_symmetric) + { + do_reinit (m, n, n_nonzero_per_row, is_symmetric); + } + + + + SparseMatrix::SparseMatrix (const unsigned int m, + const unsigned int n, + const std::vector &row_lengths, + const bool is_symmetric) + { + do_reinit (m, n, row_lengths, is_symmetric); + } + + + + void + SparseMatrix::reinit (const unsigned int m, + const unsigned int n, + const unsigned int n_nonzero_per_row, + const bool is_symmetric) + { + // get rid of old matrix and generate a + // new one + const int ierr = MatDestroy (matrix); + AssertThrow (ierr == 0, ExcPETScError(ierr)); + + do_reinit (m, n, n_nonzero_per_row, is_symmetric); + } + + + + void + SparseMatrix::reinit (const unsigned int m, + const unsigned int n, + const std::vector &row_lengths, + const bool is_symmetric) + { + // get rid of old matrix and generate a + // new one + const int ierr = MatDestroy (matrix); + AssertThrow (ierr == 0, ExcPETScError(ierr)); + + do_reinit (m, n, row_lengths, is_symmetric); + } + + + + void + SparseMatrix::do_reinit (const unsigned int m, + const unsigned int n, + const unsigned int n_nonzero_per_row, + const bool is_symmetric) { // use the call sequence indicating only // a maximal number of elements per row @@ -44,10 +108,11 @@ namespace PETScWrappers - SparseMatrix::SparseMatrix (const unsigned int m, - const unsigned int n, - const std::vector &row_lengths, - const bool is_symmetric) + void + SparseMatrix::do_reinit (const unsigned int m, + const unsigned int n, + const std::vector &row_lengths, + const bool is_symmetric) { Assert (row_lengths.size() == m, ExcDimensionMismatch (row_lengths.size(), m)); -- 2.39.5