]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
A few PETSc helper functions
authoryoung <young@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 8 Jan 2009 10:27:05 +0000 (10:27 +0000)
committeryoung <young@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 8 Jan 2009 10:27:05 +0000 (10:27 +0000)
git-svn-id: https://svn.dealii.org/trunk@18131 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/doc/news/changes.h
deal.II/lac/include/lac/petsc_vector_base.h
deal.II/lac/source/petsc_vector_base.cc

index 913d7eb3f15c3629820a593030d4e296280ec556..3f5198c205eb9503bec94a0a67e7d4939cdb3980 100644 (file)
@@ -473,6 +473,15 @@ inconvenience this causes.
 <h3>lac</h3>
 
 <ol>
+  <li>
+  <p>
+  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.
+  <br>
+  (Toby D. Young 2009/01/08)
+  </p>
+
   <li>
   <p>
   New: There is now a class TrilinosWrappers::SparsityPattern that allows to 
index 41cea4e9c6753f0ec974fae27ea3adfe549cb390..1889d575e1eb498c2565ae4d3b963ff3be759496 100644 (file)
@@ -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
index 748809f287dc7c5308a2f7e4f6523a2aab497160..2acb47d53374aed116a866fd7d23434956595d7a 100644 (file)
@@ -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
   {

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.