]> https://gitweb.dealii.org/ - dealii.git/commitdiff
scalar product of tensors
authorGuido Kanschat <dr.guido.kanschat@gmail.com>
Mon, 15 Jan 2001 09:57:34 +0000 (09:57 +0000)
committerGuido Kanschat <dr.guido.kanschat@gmail.com>
Mon, 15 Jan 2001 09:57:34 +0000 (09:57 +0000)
git-svn-id: https://svn.dealii.org/trunk@3656 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/tensor.h

index 750bfc1b0ae797805dbf124cd7ad9f203f8b80a3..92486dabe623dafcff32bc28ede461fb4b640758 100644 (file)
@@ -397,6 +397,25 @@ DeclException1 (ExcInvalidTensorIndex,
                << "Invalid tensor index " << arg1);
 
 
+/**
+ * Contract a tensor of rank 1 with a tensor of rank 1. The result is
+ * @p{sum_j src1[j] src2[j]}.
+ *
+ * @author Guido Kanschat, 2000
+ */
+template <int dim>
+inline
+double contract (const Tensor<1,dim> &src1,
+                const Tensor<1,dim> &src2)
+{
+  double res = 0.;
+  for (unsigned int i=0; i<dim; ++i)
+    res += src1[i] * src2[i];
+
+  return res;
+}
+
+
 /**
  * Contract a tensor of rank 2 with a tensor of rank 1. The result is
  * @p{dest[i] = sum_j src1[i][j] src2[j]}.

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.