class SparseMatrix : public MatrixBase
{
public:
+ /**
+ * Default constructor. Create an empty
+ * matrix.
+ */
+ SparseMatrix ();
+
/**
* Create a sparse matrix of dimensions
* <tt>m</tt> times <tt>n</tt>, with an
const unsigned int n,
const std::vector<unsigned int> &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<unsigned int> &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<unsigned int> &row_lengths,
+ const bool is_symmetric = false);
};
}
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<unsigned int> &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<unsigned int> &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
- SparseMatrix::SparseMatrix (const unsigned int m,
- const unsigned int n,
- const std::vector<unsigned int> &row_lengths,
- const bool is_symmetric)
+ void
+ SparseMatrix::do_reinit (const unsigned int m,
+ const unsigned int n,
+ const std::vector<unsigned int> &row_lengths,
+ const bool is_symmetric)
{
Assert (row_lengths.size() == m,
ExcDimensionMismatch (row_lengths.size(), m));