From 458d07a1469dc50f9fb157f695711873d1b00885 Mon Sep 17 00:00:00 2001
From: Michael Wild <themiwi@users.sourceforge.net>
Date: Tue, 29 Nov 2011 21:55:57 +0100
Subject: [PATCH] FIX: Dot product of SymmTensor's is not symmetric

The result of the dot product of two symmetric tensors is not symmetric
in general, as the original author assumed. This patch also adds two
lines to applications/test/tensor/Test-tensor.C to verify the fixed
implementation.

Fixes http://www.openfoam.com/mantisbt/view.php?id=348.

Signed-off-by: Michael Wild <themiwi@users.sourceforge.net>
---
 applications/test/tensor/Test-tensor.C           |    4 ++++
 src/OpenFOAM/primitives/SymmTensor/SymmTensorI.H |    8 ++++++--
 src/OpenFOAM/primitives/Tensor/Tensor.H          |    4 +++-
 src/OpenFOAM/primitives/Tensor/TensorI.H         |    2 ++
 4 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/applications/test/tensor/Test-tensor.C b/applications/test/tensor/Test-tensor.C
index efc7824..6da37d3 100644
--- a/applications/test/tensor/Test-tensor.C
+++ b/applications/test/tensor/Test-tensor.C
@@ -50,10 +50,14 @@ int main()
         << (t1 & t7 & t1.T()) << " " << transform(t1, t7) << endl;
 
     symmTensor st1(1, 2, 3, 4, 5, 6);
+    symmTensor st2(7, 8, 9, 10, 11, 12);
 
     Info<< "Check symmetric transformation "
         << transform(t1, st1) << endl;
 
+    Info<< "Check for dot product of symmetric tensors "
+        << (st1 & st2) << endl;
+
     vector v1(1, 2, 3);
 
     Info<< sqr(v1) << endl;
diff --git a/src/OpenFOAM/primitives/SymmTensor/SymmTensorI.H b/src/OpenFOAM/primitives/SymmTensor/SymmTensorI.H
index 5f9fbe9..4566cc7 100644
--- a/src/OpenFOAM/primitives/SymmTensor/SymmTensorI.H
+++ b/src/OpenFOAM/primitives/SymmTensor/SymmTensorI.H
@@ -24,6 +24,7 @@ License
 \*---------------------------------------------------------------------------*/
 
 #include "Vector.H"
+#include "Tensor.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -184,18 +185,21 @@ inline Vector<Cmpt> operator*(const SymmTensor<Cmpt>& st)
 
 //- Inner-product between two symmetric tensors
 template <class Cmpt>
-inline SymmTensor<Cmpt>
+inline Tensor<Cmpt>
 operator&(const SymmTensor<Cmpt>& st1, const SymmTensor<Cmpt>& st2)
 {
-    return SymmTensor<Cmpt>
+    return Tensor<Cmpt>
     (
         st1.xx()*st2.xx() + st1.xy()*st2.xy() + st1.xz()*st2.xz(),
         st1.xx()*st2.xy() + st1.xy()*st2.yy() + st1.xz()*st2.yz(),
         st1.xx()*st2.xz() + st1.xy()*st2.yz() + st1.xz()*st2.zz(),
 
+        st1.xy()*st2.xx() + st1.yy()*st2.xy() + st1.yz()*st2.xz(),
         st1.xy()*st2.xy() + st1.yy()*st2.yy() + st1.yz()*st2.yz(),
         st1.xy()*st2.xz() + st1.yy()*st2.yz() + st1.yz()*st2.zz(),
 
+        st1.xz()*st2.xx() + st1.yz()*st2.xy() + st1.zz()*st2.xz(),
+        st1.xz()*st2.xy() + st1.yz()*st2.yy() + st1.zz()*st2.yz(),
         st1.xz()*st2.xz() + st1.yz()*st2.yz() + st1.zz()*st2.zz()
     );
 }
diff --git a/src/OpenFOAM/primitives/Tensor/Tensor.H b/src/OpenFOAM/primitives/Tensor/Tensor.H
index c3dd522..a1554dc 100644
--- a/src/OpenFOAM/primitives/Tensor/Tensor.H
+++ b/src/OpenFOAM/primitives/Tensor/Tensor.H
@@ -40,13 +40,15 @@ SourceFiles
 
 #include "Vector.H"
 #include "SphericalTensor.H"
-#include "SymmTensor.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 namespace Foam
 {
 
+template<class Cmpt>
+class SymmTensor;
+
 /*---------------------------------------------------------------------------*\
                            Class Tensor Declaration
 \*---------------------------------------------------------------------------*/
diff --git a/src/OpenFOAM/primitives/Tensor/TensorI.H b/src/OpenFOAM/primitives/Tensor/TensorI.H
index cbfe677..237bb6c 100644
--- a/src/OpenFOAM/primitives/Tensor/TensorI.H
+++ b/src/OpenFOAM/primitives/Tensor/TensorI.H
@@ -23,6 +23,8 @@ License
 
 \*---------------------------------------------------------------------------*/
 
+#include "SymmTensor.H"
+
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 namespace Foam
-- 
1.7.5.4

