--- branches/development/src/math/DynamicRectMatrix.hpp 2010/07/09 23:08:25 1465 +++ branches/development/src/math/DynamicRectMatrix.hpp 2013/05/15 15:09:35 1874 @@ -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). */ /** @@ -108,7 +109,7 @@ namespace OpenMD { ~DynamicRectMatrix() { deallocate();} /** copy assignment operator */ - DynamicRectMatrix operator =(const DynamicRectMatrix m) { + DynamicRectMatrix operator =(const DynamicRectMatrix &m) { if (this == &m) return *this; if (nrow_ != m.getNRow() || ncol_ != m.getNCol()) { @@ -232,11 +233,11 @@ namespace OpenMD { /** * Tests if this matrix is identical to matrix m * @return true if this matrix is equal to the matrix m, return false otherwise - * @m matrix to be compared + * @param m matrix to be compared * * @todo replace operator == by template function equal */ - bool operator ==(const DynamicRectMatrix m) { + bool operator ==(const DynamicRectMatrix &m) { assert(nrow_ == m.getNRow() && ncol_ == m.getNCol()); for (unsigned int i = 0; i < nrow_; i++) for (unsigned int j = 0; j < ncol_; j++) @@ -249,9 +250,9 @@ namespace OpenMD { /** * Tests if this matrix is not equal to matrix m * @return true if this matrix is not equal to the matrix m, return false otherwise - * @m matrix to be compared + * @param m matrix to be compared */ - bool operator !=(const DynamicRectMatrix m) { + bool operator !=(const DynamicRectMatrix &m) { return !(*this == m); } @@ -266,7 +267,7 @@ namespace OpenMD { * Sets the value of this matrix to the negation of matrix m. * @param m the source matrix */ - inline void negate(const DynamicRectMatrix m) { + inline void negate(const DynamicRectMatrix &m) { for (unsigned int i = 0; i < nrow_; i++) for (unsigned int j = 0; j < ncol_; j++) this->data_[i][j] = -m.data_[i][j]; @@ -276,7 +277,7 @@ namespace OpenMD { * Sets the value of this matrix to the sum of itself and m (*this += m). * @param m the other matrix */ - inline void add( const DynamicRectMatrix m ) { + inline void add( const DynamicRectMatrix &m ) { assert(nrow_ == m.getNRow() && ncol_ == m.getNCol()); for (unsigned int i = 0; i < nrow_; i++) for (unsigned int j = 0; j < ncol_; j++) @@ -288,7 +289,7 @@ namespace OpenMD { * @param m1 the first matrix * @param m2 the second matrix */ - inline void add( const DynamicRectMatrix m1, const DynamicRectMatrix m2 ) { + inline void add( const DynamicRectMatrix &m1, const DynamicRectMatrix &m2 ) { assert(m1.getNRow() == m2.getNRow() && m1.getNCol() == m2.getNCol()); for (unsigned int i = 0; i < nrow_; i++) for (unsigned int j = 0; j < ncol_; j++) @@ -299,7 +300,7 @@ namespace OpenMD { * Sets the value of this matrix to the difference of itself and m (*this -= m). * @param m the other matrix */ - inline void sub( const DynamicRectMatrix m ) { + inline void sub( const DynamicRectMatrix &m ) { assert(nrow_ == m.getNRow() && ncol_ == m.getNCol()); for (unsigned int i = 0; i < nrow_; i++) for (unsigned int j = 0; j < ncol_; j++) @@ -311,7 +312,7 @@ namespace OpenMD { * @param m1 the first matrix * @param m2 the second matrix */ - inline void sub( const DynamicRectMatrix m1, const DynamicRectMatrix m2){ + inline void sub( const DynamicRectMatrix &m1, const DynamicRectMatrix &m2){ assert(m1.getNRow() == m2.getNRow() && m1.getNCol() == m2.getNCol()); for (unsigned int i = 0; i < nrow_; i++) for (unsigned int j = 0; j < ncol_; j++) @@ -333,7 +334,7 @@ namespace OpenMD { * @param s the scalar value * @param m the matrix */ - inline void mul( Real s, const DynamicRectMatrix m ) { + inline void mul( Real s, const DynamicRectMatrix &m ) { assert(nrow_ == m.getNRow() && ncol_ == m.getNCol()); for (unsigned int i = 0; i < nrow_; i++) for (unsigned int j = 0; j < ncol_; j++) @@ -355,7 +356,7 @@ namespace OpenMD { * @param s the scalar value * @param m the matrix */ - inline void div( Real s, const DynamicRectMatrix m ) { + inline void div( Real s, const DynamicRectMatrix &m ) { assert(nrow_ == m.getNRow() && ncol_ == m.getNCol()); for (unsigned int i = 0; i < nrow_; i++) for (unsigned int j = 0; j < ncol_; j++) @@ -439,19 +440,19 @@ namespace OpenMD { unsigned int nrow_; unsigned int ncol_; private: - void allocate(int nrow, int ncol) { - nrow_ = nrow; - ncol_ = ncol; - data_ = new Real*[nrow_]; - for (int i = 0; i < nrow_; ++i) - data_[i] = new Real[ncol_]; + void allocate( int nrow, int ncol ) { + nrow_ = (unsigned int) nrow; + ncol_ = (unsigned int) ncol; + data_ = new Real*[nrow_]; + for (unsigned int i = 0; i < nrow_; ++i) + data_[i] = new Real[ncol_]; } - + void deallocate() { - for (int i = 0; i < nrow_; ++i) + for (unsigned int i = 0; i < nrow_; ++i) delete data_[i]; delete []data_; - + nrow_ = 0; ncol_ = 0; data_ = NULL; @@ -461,7 +462,7 @@ namespace OpenMD { /** Negate the value of every element of this matrix. */ template - inline DynamicRectMatrix operator -(const DynamicRectMatrix m) { + inline DynamicRectMatrix operator -(const DynamicRectMatrix &m) { DynamicRectMatrix result(m); result.negate(); @@ -476,7 +477,7 @@ namespace OpenMD { * @param m2 the second matrix */ template - inline DynamicRectMatrix operator + (const DynamicRectMatrix m1,const DynamicRectMatrix m2) { + inline DynamicRectMatrix operator + (const DynamicRectMatrix &m1, const DynamicRectMatrix &m2) { DynamicRectMatrix result(m1.getNRow(), m1.getNCol()); @@ -492,7 +493,7 @@ namespace OpenMD { * @param m2 the second matrix */ template - inline DynamicRectMatrix operator - (const DynamicRectMatrix m1, const DynamicRectMatrix m2) { + inline DynamicRectMatrix operator - (const DynamicRectMatrix &m1, const DynamicRectMatrix &m2) { DynamicRectMatrix result(m1.getNRow(), m1.getNCol()); result.sub(m1, m2); @@ -507,7 +508,7 @@ namespace OpenMD { * @param s the scalar */ template - inline DynamicRectMatrix operator *(const DynamicRectMatrix m, Real s) { + inline DynamicRectMatrix operator *(const DynamicRectMatrix &m, Real s) { DynamicRectMatrix result(m.getNRow(), m.getNCol()); result.mul(s, m); @@ -522,7 +523,7 @@ namespace OpenMD { * @param m the matrix */ template - inline DynamicRectMatrix operator *(Real s, const DynamicRectMatrix m) { + inline DynamicRectMatrix operator *(Real s, const DynamicRectMatrix &m) { DynamicRectMatrix result(m.getNRow(), m.getNCol()); result.mul(s, m); @@ -558,10 +559,10 @@ namespace OpenMD { * @param v the vector */ template - inline DynamicVector operator *(const DynamicRectMatrix m, const DynamicVector& v) { + inline DynamicVector operator *(const DynamicRectMatrix &m, const DynamicVector &v) { int nrow = m.getNRow(); int ncol = m.getNCol(); - assert(ncol = v.size()); + assert(ncol == v.size()); DynamicVector result(nrow); for (unsigned int i = 0; i < nrow ; i++) @@ -578,7 +579,7 @@ namespace OpenMD { * @param s the scalar */ template - inline DynamicRectMatrix operator /(const DynamicRectMatrix m, Real s) { + inline DynamicRectMatrix operator /(const DynamicRectMatrix &m, Real s) { DynamicRectMatrix result(m.getNRow(), m.getNCol()); result.div(s, m); @@ -590,7 +591,7 @@ namespace OpenMD { * Write to an output stream */ template - std::ostream &operator<< ( std::ostream& o, const DynamicRectMatrix m) { + std::ostream &operator<< ( std::ostream& o, const DynamicRectMatrix &m) { for (unsigned int i = 0; i < m.getNRow() ; i++) { o << "("; for (unsigned int j = 0; j < m.getNCol() ; j++) {