From c538fb5b486ee9b9c9686dbf9182ca4634780035 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 7 Apr 1998 13:55:28 +0000 Subject: [PATCH] Add some norms to the dVector class. git-svn-id: https://svn.dealii.org/trunk@152 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/include/lac/dvector.h | 22 ++++++++- deal.II/lac/source/dvector.cc | 82 ++++++++++++++++++++++++++++++- 2 files changed, 102 insertions(+), 2 deletions(-) diff --git a/deal.II/lac/include/lac/dvector.h b/deal.II/lac/include/lac/dvector.h index cc78b2cc8d..33a08d319b 100644 --- a/deal.II/lac/include/lac/dvector.h +++ b/deal.II/lac/include/lac/dvector.h @@ -95,9 +95,29 @@ class dVector : public VectorBase double operator* (const dVector& V) const; /** - * Return square of the norm. + * Return square of the l2-norm. */ double norm_sqr () const; + + /** + * Return the mean value of the elements of + * this vector. + */ + double mean_value () const; + + /** + * Return the l1-norm of the vector, i.e. + * the sum of the absolute values. + */ + double l1_norm () const; + + /** + * Return the l2-norm of the vector, i.e. + * the square root of the sum of the + * squares of the elements. + */ + double l2_norm () const; + /** * Change Dimension.

diff --git a/deal.II/lac/source/dvector.cc b/deal.II/lac/source/dvector.cc index d39bb93f53..9ede32ce1b 100644 --- a/deal.II/lac/source/dvector.cc +++ b/deal.II/lac/source/dvector.cc @@ -144,7 +144,87 @@ double dVector::norm_sqr () const sum0 += val[i] * val[i]; return sum0+sum1+sum2+sum3; -} +}; + + + +double dVector::mean_value () const +{ + double sum0 = 0, + sum1 = 0, + sum2 = 0, + sum3 = 0; + + // use modern processors better by + // allowing pipelined commands to be + // executed in parallel + for (unsigned int i=0; i<(dim/4); ++i) + { + sum0 += val[4*i]; + sum1 += val[4*i+1]; + sum2 += val[4*i+2]; + sum3 += val[4*i+3]; + }; + // add up remaining elements + for (unsigned int i=(dim/4)*4; i