#ifdef DEAL_II_WITH_PETSC
#include <petscconf.h>
+#include <petscksp.h>
#include <petscmat.h>
#include <petscpc.h>
return MatDestroy (&matrix);
#endif
}
+
+
+
+ /**
+ * Destroy a Krylov Subspace (KSP) PETSc solver. This function wraps
+ * KSPDestroy 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_krylov_solver (KSP &krylov_solver)
+ {
+ // PETSc will check whether or not matrix is NULL.
+#if DEAL_II_PETSC_VERSION_LT(3, 2, 0)
+ return KSPDestroy (krylov_solver);
+#else
+ return KSPDestroy (&krylov_solver);
+#endif
+ }
}
DEAL_II_NAMESPACE_CLOSE
#ifdef DEAL_II_WITH_PETSC
# include <deal.II/lac/exceptions.h>
+# include <deal.II/lac/petsc_compatibility.h>
# include <deal.II/lac/petsc_matrix_base.h>
# include <deal.II/lac/petsc_vector_base.h>
# include <deal.II/lac/petsc_precondition.h>
SolverBase::SolverData::~SolverData ()
{
- if (ksp != NULL)
- {
- // destroy the solver object
-#if DEAL_II_PETSC_VERSION_LT(3,2,0)
- int ierr = KSPDestroy (ksp);
-#else
- int ierr = KSPDestroy (&ksp);
-#endif
-
- AssertThrow (ierr == 0, ExcPETScError(ierr));
- }
+ destroy_krylov_solver (ksp);
}
SparseDirectMUMPS::SolverDataMUMPS::~SolverDataMUMPS ()
{
- // destroy the solver object
-#if DEAL_II_PETSC_VERSION_LT(3,2,0)
- int ierr = KSPDestroy (ksp);
-#else
- int ierr = KSPDestroy (&ksp);
-#endif
-
- AssertThrow (ierr == 0, ExcPETScError(ierr));
+ destroy_krylov_solver (ksp);
}