From: guido Date: Fri, 2 Aug 2002 19:54:28 +0000 (+0000) Subject: Lp-norms X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1042d41c8d96e84678c233472c8e7011f5e10559;p=dealii-svn.git Lp-norms git-svn-id: https://svn.dealii.org/trunk@6316 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/doc/news/2002/c-3-4.html b/deal.II/doc/news/2002/c-3-4.html index d410b92319..9b90c33a9c 100644 --- a/deal.II/doc/news/2002/c-3-4.html +++ b/deal.II/doc/news/2002/c-3-4.html @@ -153,6 +153,15 @@ contributor's names are abbreviated by WB (Wolfgang Bangerth), GK

deal.II

    +
  1. Improved: VectorTools::integrate_difference can compute Lp + and W1,p norms for arbitrary p. The function + receives an additional optional argument p for this. All previous + fuctionality remains unchanged, although the code has been cleaned up a bit. +
    + (GK 2002/08/01) +

    +
  2. New: The GridTools class now offers functions to apply general transformations to all vertices of a triangulation, and also more specialized diff --git a/deal.II/lac/include/lac/vector.h b/deal.II/lac/include/lac/vector.h index 5fd37c96f6..54a50402b5 100644 --- a/deal.II/lac/include/lac/vector.h +++ b/deal.II/lac/include/lac/vector.h @@ -229,28 +229,35 @@ class Vector Number norm_sqr () const; /** - * Return the mean value of the elements of + * Mean value of the elements of * this vector. */ Number mean_value () const; /** - * Return the $l_1$-norm of the vector, i.e. - * the sum of the absolute values. + * $l_1$-norm of the vector. + * The sum of the absolute values. */ Number l1_norm () const; /** - * Return the $l_2$-norm of the vector, i.e. - * the square root of the sum of the + * $l_2$-norm of the vector. The + * square root of the sum of the * squares of the elements. */ Number l2_norm () const; /** - * Return the maximum absolute value of the - * elements of this vector, which is the - * $l_\infty$-norm of a vector. + * $l_p$-norm of the vector. The + * pth root of the sum of the pth + * powers of the absolute values + * of the elements. + */ + Number lp_norm (double p) const; + + /** + * Maximum absolute value of the + * elements. */ Number linfty_norm () const; diff --git a/deal.II/lac/include/lac/vector.templates.h b/deal.II/lac/include/lac/vector.templates.h index 36f400ec2f..793ee1690a 100644 --- a/deal.II/lac/include/lac/vector.templates.h +++ b/deal.II/lac/include/lac/vector.templates.h @@ -239,6 +239,36 @@ Number Vector::l2_norm () const }; +template +Number Vector::lp_norm (double p) const +{ + Assert (dim!=0, ExcEmptyVector()); + + Number sum0 = 0, + sum1 = 0, + sum2 = 0, + sum3 = 0; + + // use modern processors better by + // allowing pipelined commands to be + // executed in parallel + const_iterator ptr = begin(), + eptr = ptr + (dim/4)*4; + while (ptr!=eptr) + { + sum0 += std::pow(std::fabs(*ptr++), p); + sum1 += std::pow(std::fabs(*ptr++), p); + sum2 += std::pow(std::fabs(*ptr++), p); + sum3 += std::pow(std::fabs(*ptr++), p); + }; + // add up remaining elements + while (ptr != end()) + sum0 += pow(std::fabs(*ptr++), p); + + return pow(sum0+sum1+sum2+sum3, 1./p); +}; + + template Number Vector::linfty_norm () const { Assert (dim!=0, ExcEmptyVector());