]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Add l1_norm and linfty_norm for Tensor<2,dim>.
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 8 Feb 2012 15:13:40 +0000 (15:13 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 8 Feb 2012 15:13:40 +0000 (15:13 +0000)
git-svn-id: https://svn.dealii.org/trunk@25014 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/doc/news/changes.h
deal.II/include/deal.II/base/tensor.h

index 059568060c416b22eb9273acbbda8a83ead3878d..27efd234fa3f317cf3427491f1a23eb9425f256b 100644 (file)
@@ -87,6 +87,10 @@ enabled due to a missing include file in file
 <h3>Specific improvements</h3>
 
 <ol>
+<li> New: There are now global functions l1_norm() and linfty_norm() that compute
+the respective norms of a rank-2 tensor.
+<br>
+(Wolfgang Bangerth, 2012/02/08)
 
 <li> New: VectorTools::interpolation_to_different_mesh implemented which interpolates between
      DoFHandlers with different triangulations based on a common coarse grid.
index a0280769c1c1b29ec38657ebef59f1b4ca562145..132bebbea14ec88550da6ff5165b9e4afb2b221b 100644 (file)
@@ -1,7 +1,7 @@
 //---------------------------------------------------------------------------
 //    $Id$
 //
-//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008, 2009, 2011 by the deal.II authors
+//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008, 2009, 2011, 2012 by the deal.II authors
 //
 //    This file is subject to QPL and may not be  distributed
 //    without copyright and license information. Please refer
@@ -1798,6 +1798,63 @@ transpose (const Tensor<2,3,Number> &t)
 #endif // DOXYGEN
 
 
+/**
+ * Return the $l_1$ norm of the given rank-2 tensor, where
+ * $||t||_1 = \max_j \sum_i |t_{ij}|$ (maximum of
+ * the sums over columns).
+ *
+ * @relates Tensor
+ * @author Wolfgang Bangerth, 2012
+ */
+template <int dim, typename Number>
+inline
+double
+l1_norm (const Tensor<2,dim,Number> &t)
+{
+  double max = 0;
+  for (unsigned int j=0; j<dim; ++j)
+    {
+      double sum = 0;
+      for (unsigned int i=0; i<dim; ++i)
+       sum += std::fabs(t[i][j]);
+
+      if (sum > max)
+       max = sum;
+    }
+
+  return max;
+}
+
+
+
+/**
+ * Return the $l_\infty$ norm of the given rank-2 tensor, where
+ * $||t||_\infty = \max_i \sum_j |t_{ij}|$ (maximum of
+ * the sums over rows).
+ *
+ * @relates Tensor
+ * @author Wolfgang Bangerth, 2012
+ */
+template <int dim, typename Number>
+inline
+double
+linfty_norm (const Tensor<2,dim,Number> &t)
+{
+  double max = 0;
+  for (unsigned int i=0; i<dim; ++i)
+    {
+      double sum = 0;
+      for (unsigned int j=0; j<dim; ++j)
+       sum += std::fabs(t[i][j]);
+
+      if (sum > max)
+       max = sum;
+    }
+
+  return max;
+}
+
+
 
 /**
  * Multiplication of a tensor of general rank with a scalar Number

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.