From d7cddf0f8e8b4ab8f82494955b0107a748ad6a54 Mon Sep 17 00:00:00 2001 From: young Date: Wed, 30 Apr 2008 16:18:03 +0000 Subject: [PATCH] Helper Functions git-svn-id: https://svn.dealii.org/trunk@16014 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/doc/news/changes.h | 10 +++++ deal.II/lac/include/lac/petsc_matrix_base.h | 27 +++++++++++++ deal.II/lac/source/petsc_matrix_base.cc | 42 +++++++++++++++++++++ 3 files changed, 79 insertions(+) diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index 3b6a97d46b..dc6c0d4f2e 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -30,6 +30,16 @@ inconvenience this causes.

    +
  1. Changed: A few simple PETSc wrappers forhelper functions + MatrixBase::transpose, + MatrixBase::is_symmetric, + MatrixBase::is_hermitian, + MatrixBase::is_hermitian, and + MatrixBase::write_ascii have been added. +
    + (Toby D. Young 2008/04/30) +

    +
  2. Removed: The FullMatrix::add_diag function was removed. It offered functionality of questionable use in the first place, and its implementation was correct only for matrices of size $3 \times 3$, $4 \times 4$ diff --git a/deal.II/lac/include/lac/petsc_matrix_base.h b/deal.II/lac/include/lac/petsc_matrix_base.h index 608e721d84..fe9b86d8e2 100644 --- a/deal.II/lac/include/lac/petsc_matrix_base.h +++ b/deal.II/lac/include/lac/petsc_matrix_base.h @@ -849,6 +849,33 @@ namespace PETScWrappers */ operator const Mat () const; + /** + * Make an in-place transpose of a + * matrix. + */ + void transpose (); + + /** + * Test whether a matrix is symmetric. + * Default tolerance is zero. + */ + PetscTruth is_symmetric (const double tol = 0.0); + + /** + * Test whether a matrix is Hermitian, + * i.e. it is the complex conjugate + * of its transpose. + */ + PetscTruth is_hermitian (); + + /* + * Abstract PETSc object that helps view + * in ASCII other PETSc objects. Currently + * this function simply writes non-zero + * elements of a matrix to the terminal. + */ + void write_ascii (); + /** * Exception */ diff --git a/deal.II/lac/source/petsc_matrix_base.cc b/deal.II/lac/source/petsc_matrix_base.cc index 48cca472d8..6c0f3a51c0 100644 --- a/deal.II/lac/source/petsc_matrix_base.cc +++ b/deal.II/lac/source/petsc_matrix_base.cc @@ -598,6 +598,48 @@ namespace PETScWrappers { return matrix; } + + void + MatrixBase::transpose () + { + int ierr; + ierr = MatTranspose(matrix, PETSC_NULL); + AssertThrow (ierr == 0, ExcPETScError(ierr)); + } + + PetscTruth + MatrixBase::is_symmetric (const double tolerance) + { + PetscTruth truth; + // First flush PETSc caches + compress (); + MatIsSymmetric (matrix, tolerance, &truth); + return truth; + } + + PetscTruth + MatrixBase::is_hermitian () + { + PetscTruth truth; + // First flush PETSc caches + compress (); + MatIsHermitian (matrix, &truth); + return truth; + } + + void + MatrixBase::write_ascii () + { + // First flush PETSc caches + compress (); + + // Write to screen + PetscViewerSetFormat (PETSC_VIEWER_STDOUT_WORLD, + PETSC_VIEWER_ASCII_DEFAULT); + + MatView (matrix,PETSC_VIEWER_STDOUT_WORLD); + } + } DEAL_II_NAMESPACE_CLOSE -- 2.39.5