]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
New function scalar_product.
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 20 Aug 2008 12:41:11 +0000 (12:41 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 20 Aug 2008 12:41:11 +0000 (12:41 +0000)
git-svn-id: https://svn.dealii.org/trunk@16605 0785d39b-7218-0410-832d-ea1e28bc413d

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

index a1b8ed62c706b26d9cf56f65b266c4f7ac9e7aa7..59c192e4b379e068a6b985469a5941eaecfba51c 100644 (file)
@@ -2,7 +2,7 @@
 //    $Id$
 //    Version: $Name$
 //
-//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 by the deal.II authors
+//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008 by the deal.II authors
 //
 //    This file is subject to QPL and may not be  distributed
 //    without copyright and license information. Please refer
@@ -1294,6 +1294,31 @@ cross_product (Tensor<1,dim>       &dst,
 
 
 
+/**
+ * Compute the scalar product $a:b=\sum_{i,j} a_{ij}b_{ij}$ between two
+ * tensors $a,b$ of rank 2. We don't use <code>operator*</code> for this
+ * operation since the product between two tensors is usually assumed to be
+ * the contraction over the last index of the first tensor and the first index
+ * of the second tensor, for example $(a\cdot b)_{ij}=\sum_k a_{ik}b_{kj}$.
+ *
+ * @relates Tensor
+ * @author Wolfgang Bangerth, 2008
+ */
+template <int dim>
+inline
+double
+scalar_product (const Tensor<2,dim> &t1,
+               const Tensor<2,dim> &t2)
+{
+  double s = 0;
+  for (unsigned int i=0; i<dim; ++i)
+    for (unsigned int j=0; j<dim; ++j)
+      s += t1[i][j] * t2[i][j];
+  return s;
+}
+
+
+
 /**
  * Compute the determinant of a tensor of arbitrary rank and dimension
  * one. Since this is a number, the return value is, of course, the
index 466cf75fd6164a1730c5cba43291a264a0e210d2..ee5bee6ff8e8efbf08ec38fd489574c9012eec06 100644 (file)
@@ -134,10 +134,19 @@ inconvenience this causes.
 <h3>base</h3>
 
 <ol>
+  <li>
+  <p>
+  New: There is a new function scalar_product(const Tensor<2,dim> &,
+  const Tensor<2,dim> &) that computes the scalar product
+  $a:b=\sum_{i,j} a_{ij}b_{ij}$ between two tensors of rank 2.
+  <br> 
+  (WB 2008/08/15)
+  </p>
+
   <li>
   <p>
   New: If the compiler allows to do <code>\#include @<mpi.h@></code>, then
-  the flag <code>DEAL_II_COMPILER_SUPPORTS_MPI</code> is now set in
+  the preprocessor flag <code>DEAL_II_COMPILER_SUPPORTS_MPI</code> is now set in
   <code>base/include/base/config.h</code>. This also fixes a problem in
   <code>base/include/base/utilities.h</code> if a compiler capable of
   including <code>mpi.h</code> was used but not PETSc.

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.