#ifdef DEAL_II_WITH_PETSC
#include <petscconf.h>
+#include <petscmat.h>
#include <petscpc.h>
#include <string>
PetscOptionsSetValue (NULL, name.c_str (), value.c_str ());
#endif
}
+
+
+
+ /**
+ * Destroy a PETSc matrix. This function wraps MatDestroy with a version
+ * check (the signature of this function changed in PETSc 3.2.0).
+ *
+ * @warning Since the primary intent of this function is to enable RAII
+ * semantics in the PETSc wrappers, this function will not throw an
+ * exception if an error occurs, but instead just returns the error code
+ * given by MatDestroy.
+ *
+ */
+ inline PetscErrorCode destroy_matrix (Mat &matrix)
+ {
+ // PETSc will check whether or not matrix is NULL.
+#if DEAL_II_PETSC_VERSION_LT(3, 2, 0)
+ return MatDestroy (matrix);
+#else
+ return MatDestroy (&matrix);
+#endif
+ }
}
DEAL_II_NAMESPACE_CLOSE
#ifdef DEAL_II_WITH_PETSC
+#include <deal.II/lac/petsc_compatibility.h>
#include <deal.II/lac/exceptions.h>
DEAL_II_NAMESPACE_OPEN
{
// 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));
+ const PetscErrorCode ierr = destroy_matrix(matrix);
+ AssertThrow(ierr == 0, ExcPETScError(ierr));
do_reinit (m, n);
}
MatrixBase::~MatrixBase ()
{
-#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));
+ destroy_matrix (matrix);
}
MatrixBase::clear ()
{
// destroy the matrix...
-#if DEAL_II_PETSC_VERSION_LT(3,2,0)
- int ierr = MatDestroy (matrix);
-#else
- int ierr = MatDestroy (&matrix);
-#endif
- AssertThrow (ierr == 0, ExcPETScError(ierr));
+ {
+ const PetscErrorCode ierr = destroy_matrix (matrix);
+ AssertThrow(ierr == 0, ExcPETScError(ierr));
+ }
+
// ...and replace it by an empty
// sequential matrix
const int m=0, n=0, n_nonzero_per_row=0;
- ierr = MatCreateSeqAIJ(PETSC_COMM_SELF, m, n, n_nonzero_per_row,
- 0, &matrix);
+ const int ierr = MatCreateSeqAIJ(PETSC_COMM_SELF, m, n, n_nonzero_per_row,
+ 0, &matrix);
AssertThrow (ierr == 0, ExcPETScError(ierr));
}
#ifdef DEAL_II_WITH_PETSC
#include <deal.II/lac/exceptions.h>
+#include <deal.II/lac/petsc_compatibility.h>
DEAL_II_NAMESPACE_OPEN
{
this->communicator = communicator;
- // destroy the matrix and
- // generate a new one
-#if DEAL_II_PETSC_VERSION_LT(3,2,0)
- int ierr = MatDestroy (matrix);
-#else
- int ierr = MatDestroy (&matrix);
-#endif
- AssertThrow (ierr == 0, ExcPETScError(ierr));
+ // destroy the matrix and generate a new one
+ const PetscErrorCode ierr = destroy_matrix (matrix);
+ AssertThrow (ierr == 0, ExcPETScError (ierr));
do_reinit (m, n, local_rows, local_columns);
}
ExcInternalError());
this->communicator = communicator;
-
-#if DEAL_II_PETSC_VERSION_LT(3,2,0)
- int ierr = MatDestroy (matrix);
-#else
- int ierr = MatDestroy (&matrix);
-#endif
- AssertThrow (ierr == 0, ExcPETScError(ierr));
+ const PetscErrorCode ierr = destroy_matrix (matrix);
+ AssertThrow (ierr != 0, ExcPETScError (ierr));
do_reinit (m, n,
local_rows_per_process[this_process],
void MatrixFree::clear ()
{
-#if DEAL_II_PETSC_VERSION_LT(3,2,0)
- int ierr = MatDestroy (matrix);
-#else
- int ierr = MatDestroy (&matrix);
-#endif
- AssertThrow (ierr == 0, ExcPETScError(ierr));
+ const PetscErrorCode ierr = destroy_matrix (matrix);
+ AssertThrow (ierr == 0, ExcPETScError (ierr));
const int m=0;
do_reinit (m, m, m, m);
# include <deal.II/base/mpi.h>
# include <deal.II/lac/exceptions.h>
+# include <deal.II/lac/petsc_compatibility.h>
# include <deal.II/lac/petsc_vector.h>
# include <deal.II/lac/sparsity_pattern.h>
# include <deal.II/lac/dynamic_sparsity_pattern.h>
SparseMatrix::~SparseMatrix ()
{
- int ierr;
-
-#if DEAL_II_PETSC_VERSION_LT(3,2,0)
- ierr = MatDestroy (matrix);
-#else
- ierr = MatDestroy (&matrix);
-#endif
- AssertThrow (ierr == 0, ExcPETScError(ierr));
+ destroy_matrix (matrix);
}
SparseMatrix::SparseMatrix (const MPI_Comm &communicator,
this->communicator = other.communicator;
- int ierr;
-#if DEAL_II_PETSC_VERSION_LT(3,2,0)
- ierr = MatDestroy (matrix);
-#else
- ierr = MatDestroy (&matrix);
-#endif
+ PetscErrorCode ierr = destroy_matrix (matrix);
AssertThrow (ierr == 0, ExcPETScError(ierr));
- ierr = MatDuplicate(other.matrix, MAT_DO_NOT_COPY_VALUES, &matrix);
+ ierr = MatDuplicate (other.matrix, MAT_DO_NOT_COPY_VALUES, &matrix);
AssertThrow (ierr == 0, ExcPETScError(ierr));
}
{
this->communicator = communicator;
- // 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));
+ // get rid of old matrix and generate a new one
+ const PetscErrorCode ierr = destroy_matrix (matrix);
+ AssertThrow (ierr == 0, ExcPETScError (ierr));
do_reinit (m, n, local_rows, local_columns,
n_nonzero_per_row, is_symmetric,
// 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));
+ const PetscErrorCode ierr = destroy_matrix (matrix);
+ AssertThrow (ierr == 0, ExcPETScError (ierr));
do_reinit (m, n, local_rows, local_columns,
row_lengths, is_symmetric, offdiag_row_lengths);
{
this->communicator = communicator;
- // 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));
+ // get rid of old matrix and generate a new one
+ destroy_matrix (matrix);
+ const PetscErrorCode ierr = destroy_matrix (matrix);
+ AssertThrow (ierr == 0, ExcPETScError (ierr));
+
do_reinit (sparsity_pattern, local_rows_per_process,
local_columns_per_process, this_process,
{
this->communicator = communicator;
- // 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));
+ // get rid of old matrix and generate a new one
+ const PetscErrorCode ierr = destroy_matrix (matrix);
+ AssertThrow(ierr == 0, ExcPETScError (ierr));
do_reinit (local_rows, local_columns, sparsity_pattern);
}
#ifdef DEAL_II_WITH_PETSC
# include <deal.II/lac/exceptions.h>
+# include <deal.II/lac/petsc_compatibility.h>
# include <deal.II/lac/petsc_vector.h>
# include <deal.II/lac/sparsity_pattern.h>
# include <deal.II/lac/dynamic_sparsity_pattern.h>
{
// 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));
+ const PetscErrorCode ierr = destroy_matrix (matrix);
+ AssertThrow (ierr == 0, ExcPETScError (ierr));
do_reinit (m, n, n_nonzero_per_row, is_symmetric);
}
{
// 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));
+ const PetscErrorCode ierr = destroy_matrix (matrix);
+ AssertThrow (ierr == 0, ExcPETScError (ierr));
do_reinit (m, n, row_lengths, is_symmetric);
}
{
// 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));
+ const PetscErrorCode ierr = destroy_matrix (matrix);
+ AssertThrow (ierr == 0, ExcPETScError (ierr));
do_reinit (sparsity_pattern, preset_nonzero_locations);
}