--- trunk/src/math/RectMatrix.hpp 2013/08/05 16:13:46 1923 +++ trunk/src/math/RectMatrix.hpp 2013/08/05 21:46:11 1924 @@ -555,7 +555,32 @@ namespace OpenMD { return result; } + + /** + * Returns the tensor contraction (double dot product) of two rank 2 + * tensors (or Matrices) + * + * \f[ \mathbf{A} \colon \! \mathbf{B} = \sum_\alpha \sum_\beta \mathbf{A}_{\alpha \beta} B_{\alpha \beta} \f] + * + * @param t1 first tensor + * @param t2 second tensor + * @return the tensor contraction (double dot product) of t1 and t2 + */ + template + inline Real doubleDot( const RectMatrix& t1, + const RectMatrix& t2 ) { + Real tmp; + tmp = 0; + + for (unsigned int i = 0; i < Row; i++) + for (unsigned int j =0; j < Col; j++) + tmp += t1(i,j) * t2(i,j); + + return tmp; + } + + /** * Returns the vector (cross) product of two matrices. This * operation is defined in: