From: young Date: Thu, 8 Jan 2009 10:27:05 +0000 (+0000) Subject: A few PETSc helper functions X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=669183f6bb9eb77f9db5c4462c76c5c78421b0af;p=dealii-svn.git A few PETSc helper functions git-svn-id: https://svn.dealii.org/trunk@18131 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index 913d7eb3f1..3f5198c205 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -473,6 +473,15 @@ inconvenience this causes.

lac

    +
  1. +

    + New: Added a few simple helper functions (to VectorBase) that allow + some manipulation of PETSc vectors. These functions do what they say + in the documentation. +
    + (Toby D. Young 2009/01/08) +

    +
  2. New: There is now a class TrilinosWrappers::SparsityPattern that allows to diff --git a/deal.II/lac/include/lac/petsc_vector_base.h b/deal.II/lac/include/lac/petsc_vector_base.h index 41cea4e9c6..1889d575e1 100644 --- a/deal.II/lac/include/lac/petsc_vector_base.h +++ b/deal.II/lac/include/lac/petsc_vector_base.h @@ -429,6 +429,32 @@ namespace PETScWrappers */ real_type linfty_norm () const; + /** + * Normalize vector by dividing + * by the $l_2$-norm of the + * vector. Return vector norm + * before normalization. + */ + real_type normalize () const; + + /** + * Return vector component with + * the maximal magnitude. + */ + real_type max () const; + + /** + * Replace every element in a + * vector with its absolute + * value. + */ + VectorBase & abs (); + + /** + * Conjugate a vector. + */ + VectorBase & conjugate (); + /** * Return whether the vector contains * only elements with value zero. This diff --git a/deal.II/lac/source/petsc_vector_base.cc b/deal.II/lac/source/petsc_vector_base.cc index 748809f287..2acb47d533 100644 --- a/deal.II/lac/source/petsc_vector_base.cc +++ b/deal.II/lac/source/petsc_vector_base.cc @@ -399,6 +399,55 @@ namespace PETScWrappers + VectorBase::real_type + VectorBase::normalize () const + { + PetscScalar d; + + const int ierr = VecNormalize (vector, &d); + AssertThrow (ierr == 0, ExcPETScError(ierr)); + + return d; + } + + + + VectorBase::real_type + VectorBase::max () const + { + PetscInt p; + PetscScalar d; + + const int ierr = VecMax (vector, &p, &d); + AssertThrow (ierr == 0, ExcPETScError(ierr)); + + return d; + } + + + + VectorBase & + VectorBase::abs () + { + const int ierr = VecAbs (vector); + AssertThrow (ierr == 0, ExcPETScError(ierr)); + + return *this; + } + + + + VectorBase & + VectorBase::conjugate () + { + const int ierr = VecConjugate (vector); + AssertThrow (ierr == 0, ExcPETScError(ierr)); + + return *this; + } + + + bool VectorBase::all_zero () const {