--- branches/development/src/math/SquareMatrix.hpp 2011/11/22 20:38:56 1665 +++ branches/development/src/math/SquareMatrix.hpp 2012/10/22 20:42:10 1808 @@ -57,8 +57,8 @@ namespace OpenMD { /** * @class SquareMatrix SquareMatrix.hpp "math/SquareMatrix.hpp" * @brief A square matrix class - * @template Real the element type - * @template Dim the dimension of the square matrix + * \tparam Real the element type + * \tparam Dim the dimension of the square matrix */ template class SquareMatrix : public RectMatrix { @@ -125,7 +125,7 @@ namespace OpenMD { Real det; return det; } - + /** Returns the trace of this matrix. */ Real trace() const { Real tmp = 0; @@ -133,9 +133,28 @@ namespace OpenMD { for (unsigned int i = 0; i < Dim ; i++) tmp += this->data_[i][i]; + return tmp; + } + + /** + * Returns the tensor contraction (double dot product) of two rank 2 + * tensors (or Matrices) + * @param t1 first tensor + * @param t2 second tensor + * @return the tensor contraction (double dot product) of t1 and t2 + */ + Real doubleDot( const SquareMatrix& t1, const SquareMatrix& t2 ) { + Real tmp; + tmp = 0; + + for (unsigned int i = 0; i < Dim; i++) + for (unsigned int j =0; j < Dim; j++) + tmp += t1[i][j] * t2[i][j]; + return tmp; } + /** Tests if this matrix is symmetrix. */ bool isSymmetric() const { for (unsigned int i = 0; i < Dim - 1; i++) @@ -165,6 +184,19 @@ namespace OpenMD { return true; } + /** + * Returns a column vector that contains the elements from the + * diagonal of m in the order R(0) = m(0,0), R(1) = m(1,1), and so + * on. + */ + Vector diagonals() const { + Vector result; + for (unsigned int i = 0; i < Dim; i++) { + result(i) = this->data_[i][i]; + } + return result; + } + /** Tests if this matrix is the unit matrix. */ bool isUnitMatrix() const { if (!isDiagonal()) @@ -200,7 +232,7 @@ namespace OpenMD { * @return true if success, otherwise return false * @param a symmetric matrix whose eigenvectors are to be computed. On return, the matrix is * overwritten - * @param w will contain the eigenvalues of the matrix On return of this function + * @param d will contain the eigenvalues of the matrix On return of this function * @param v the columns of this matrix will contain the eigenvectors. The eigenvectors are * normalized and mutually orthogonal. */