--- trunk/src/math/Vector.hpp 2010/05/10 17:28:26 1442 +++ trunk/src/math/Vector.hpp 2011/08/26 17:55:44 1615 @@ -268,6 +268,20 @@ namespace OpenMD { inline void mul( const Vector& v1, Real s) { for (unsigned int i = 0; i < Dim; i++) this->data_[i] = s * v1.data_[i]; + } + + /** + * Sets the elements of this vector to the multiplication of + * elements of two other vectors. Not to be confused with scalar + * multiplication (mul) or dot products. + * + * (*this.data_[i] = v1.data_[i] * v2.data_[i]). + * @param v1 the first vector + * @param v2 the second vector + */ + inline void Vmul( const Vector& v1, const Vector& v2) { + for (unsigned int i = 0; i < Dim; i++) + this->data_[i] = v1.data_[i] * v2.data_[i]; } /** @@ -287,8 +301,23 @@ namespace OpenMD { inline void div( const Vector& v1, Real s ) { for (unsigned int i = 0; i < Dim; i++) this->data_[i] = v1.data_[i] / s; + } + + /** + * Sets the elements of this vector to the division of + * elements of two other vectors. Not to be confused with scalar + * division (div) + * + * (*this.data_[i] = v1.data_[i] / v2.data_[i]). + * @param v1 the first vector + * @param v2 the second vector + */ + inline void Vdiv( const Vector& v1, const Vector& v2) { + for (unsigned int i = 0; i < Dim; i++) + this->data_[i] = v1.data_[i] / v2.data_[i]; } + /** @see #add */ inline Vector& operator +=( const Vector& v1 ) { add(v1); @@ -324,6 +353,18 @@ namespace OpenMD { tmp += this->data_[i]; return tmp; } + + /** + * Returns the product of all elements of this vector. + * @return the product of all elements of this vector + */ + inline Real componentProduct() { + Real tmp; + tmp = 1; + for (unsigned int i = 0; i < Dim; i++) + tmp *= this->data_[i]; + return tmp; + } /** * Returns the length of this vector. @@ -458,7 +499,31 @@ namespace OpenMD { return tmp; } + + + /** + * Returns the wide dot product of three Vectors. Compare with + * Rapaport's VWDot function. + * + * @param v1 first vector + * @param v2 second vector + * @param v3 third vector + * @return the wide dot product of v1, v2, and v3. + */ + template + inline Real dot( const Vector& v1, const Vector& v2, const Vector& v3 ) { + Real tmp; + tmp = 0; + + for (unsigned int i = 0; i < Dim; i++) + tmp += v1[i] * v2[i] * v3[i]; + + return tmp; + } + + + /** * Returns the distance between two Vectors * @param v1 first vector * @param v2 second vector