--- trunk/src/math/Vector.hpp 2010/05/10 17:28:26 1442 +++ trunk/src/math/Vector.hpp 2013/06/16 15:15:42 1879 @@ -35,8 +35,9 @@ * * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). - * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). - * [4] Vardeman & Gezelter, in progress (2009). + * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). + * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). + * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). */ /** @@ -72,7 +73,6 @@ namespace OpenMD { inline bool equal(RealType e1, RealType e2) { return fabs(e1 - e2) < epsilon; } - /** * @class Vector Vector.hpp "math/Vector.hpp" @@ -107,10 +107,11 @@ namespace OpenMD { return *this; } - template - inline Vector(const T& s){ + // template + // inline Vector(const T& s){ + inline Vector(const Real& s) { for (unsigned int i = 0; i < Dim; i++) - this->data_[i] = s; + this->data_[i] = s; } /** Constructs and initializes a Vector from an array */ @@ -195,6 +196,12 @@ namespace OpenMD { inline bool operator !=(const Vector& v) { return !(*this == v); } + + /** Zeros out the values in this vector in place */ + inline void zero() { + for (unsigned int i = 0; i < Dim; i++) + this->data_[i] = 0; + } /** Negates the value of this vector in place. */ inline void negate() { @@ -268,8 +275,39 @@ 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]; } + /* replaces the elements with the absolute values of those elements */ + inline Vector& abs() { + for (unsigned int i = 0; i < Dim; i++) { + this->data_[i] = std::abs(this->data_[i]); + } + return *this; + } + + /* returns the maximum value in this vector */ + inline Real max() { + Real val = this->data_[0]; + for (unsigned int i = 0; i < Dim; i++) { + if (this->data_[i] > val) val = this->data_[i]; + } + return val; + } + /** * Sets the value of this vector to the scalar division of itself (*this /= s ). * @param s the scalar value @@ -289,6 +327,21 @@ namespace OpenMD { 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 +377,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 +523,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