From: Wolfgang Bangerth Date: Wed, 6 Apr 2005 15:24:33 +0000 (+0000) Subject: Add norm() and norm_square() X-Git-Tag: v8.0.0~14159 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=23a6e612065c899352d1d9d7e33b0fe10fada2bc;p=dealii.git Add norm() and norm_square() git-svn-id: https://svn.dealii.org/trunk@10388 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/include/base/tensor.h b/deal.II/base/include/base/tensor.h index 05898ca5cc..9e1fca1fc6 100644 --- a/deal.II/base/include/base/tensor.h +++ b/deal.II/base/include/base/tensor.h @@ -157,6 +157,27 @@ class Tensor * entries of a tensor. */ Tensor operator - () const; + + /** + * Return the Frobenius-norm of a tensor, + * i.e. the square root of the sum of + * squares of all entries. + */ + double norm () const; + + /** + * Return the square of the + * Frobenius-norm of a tensor, + * i.e. the square root of the + * sum of squares of all entries. + * + * This function mainly exists + * because it makes computing the + * norm simpler recursively, but + * may also be useful in other + * contexts. + */ + double norm_square () const; /** * Fill a vector with all tensor elements. @@ -167,7 +188,7 @@ class Tensor * usual in C++, the rightmost * index of the tensor marches fastest. */ - void unroll(Vector & result) const; + void unroll (Vector & result) const; /** @@ -394,6 +415,29 @@ Tensor::operator - () const } + +template +inline +double Tensor::norm () const +{ + return std::sqrt (norm_square()); +} + + + +template +inline +double Tensor::norm_square () const +{ + double s = 0; + for (unsigned int i=0; i inline void Tensor::clear () diff --git a/deal.II/base/include/base/tensor_base.h b/deal.II/base/include/base/tensor_base.h index b66ce4be3e..fe2078e8c3 100644 --- a/deal.II/base/include/base/tensor_base.h +++ b/deal.II/base/include/base/tensor_base.h @@ -220,6 +220,32 @@ class Tensor<1,dim> */ Tensor<1,dim> operator - () const; + /** + * Return the Frobenius-norm of a + * tensor, i.e. the square root + * of the sum of squares of all + * entries. For the present case + * of rank-1 tensors, this equals + * the usual + * l2 norm of + * the vector. + */ + double norm () const; + + /** + * Return the square of the + * Frobenius-norm of a tensor, + * i.e. the square root of the + * sum of squares of all entries. + * + * This function mainly exists + * because it makes computing the + * norm simpler recursively, but + * may also be useful in other + * contexts. + */ + double norm_square () const; + /** * Reset all values to zero. * @@ -637,6 +663,28 @@ Tensor<1,dim> Tensor<1,dim>::operator - () const +template +inline +double Tensor<1,dim>::norm () const +{ + return std::sqrt (norm_square()); +} + + + +template +inline +double Tensor<1,dim>::norm_square () const +{ + double s = 0; + for (unsigned int i=0; i inline void Tensor<1,dim>::clear () diff --git a/deal.II/doc/news/changes.html b/deal.II/doc/news/changes.html index 9ef311e67f..edb0f4d40a 100644 --- a/deal.II/doc/news/changes.html +++ b/deal.II/doc/news/changes.html @@ -159,6 +159,14 @@ inconvenience this causes.

base

    +
  1. + New: The Tensor classes now + have member functions that compute the Frobenius norm and its + square. +
    + (WB, 2005/04/06) +

    +
  2. New: The DataOutBase class now allows to write data in a new intermediate format that