| 6 | 
  | 
 * redistribute this software in source and binary code form, provided | 
| 7 | 
  | 
 * that the following conditions are met: | 
| 8 | 
  | 
 * | 
| 9 | 
< | 
 * 1. Acknowledgement of the program authors must be made in any | 
| 10 | 
< | 
 *    publication of scientific results based in part on use of the | 
| 11 | 
< | 
 *    program.  An acceptable form of acknowledgement is citation of | 
| 12 | 
< | 
 *    the article in which the program was described (Matthew | 
| 13 | 
< | 
 *    A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher | 
| 14 | 
< | 
 *    J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented | 
| 15 | 
< | 
 *    Parallel Simulation Engine for Molecular Dynamics," | 
| 16 | 
< | 
 *    J. Comput. Chem. 26, pp. 252-271 (2005)) | 
| 17 | 
< | 
 * | 
| 18 | 
< | 
 * 2. Redistributions of source code must retain the above copyright | 
| 9 | 
> | 
 * 1. Redistributions of source code must retain the above copyright | 
| 10 | 
  | 
 *    notice, this list of conditions and the following disclaimer. | 
| 11 | 
  | 
 * | 
| 12 | 
< | 
 * 3. Redistributions in binary form must reproduce the above copyright | 
| 12 | 
> | 
 * 2. Redistributions in binary form must reproduce the above copyright | 
| 13 | 
  | 
 *    notice, this list of conditions and the following disclaimer in the | 
| 14 | 
  | 
 *    documentation and/or other materials provided with the | 
| 15 | 
  | 
 *    distribution. | 
| 28 | 
  | 
 * arising out of the use of or inability to use software, even if the | 
| 29 | 
  | 
 * University of Notre Dame has been advised of the possibility of | 
| 30 | 
  | 
 * such damages. | 
| 31 | 
+ | 
 * | 
| 32 | 
+ | 
 * SUPPORT OPEN SCIENCE!  If you use OpenMD or its source code in your | 
| 33 | 
+ | 
 * research, please cite the appropriate papers when you publish your | 
| 34 | 
+ | 
 * work.  Good starting points are: | 
| 35 | 
+ | 
 *                                                                       | 
| 36 | 
+ | 
 * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).              | 
| 37 | 
+ | 
 * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).           | 
| 38 | 
+ | 
 * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).           | 
| 39 | 
+ | 
 * [4]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010). | 
| 40 | 
+ | 
 * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). | 
| 41 | 
  | 
 */ | 
| 42 | 
  | 
  | 
| 43 | 
  | 
/** | 
| 53 | 
  | 
#include <cmath> | 
| 54 | 
  | 
#include "math/DynamicVector.hpp" | 
| 55 | 
  | 
 | 
| 56 | 
< | 
namespace oopse { | 
| 56 | 
> | 
namespace OpenMD { | 
| 57 | 
  | 
 | 
| 58 | 
  | 
  /** | 
| 59 | 
  | 
   * @class DynamicRectMatrix DynamicRectMatrix.hpp "math/DynamicRectMatrix.hpp" | 
| 67 | 
  | 
    typedef DynamicRectMatrix<Real> SelfType; | 
| 68 | 
  | 
             | 
| 69 | 
  | 
    /** default constructor */ | 
| 70 | 
+ | 
    DynamicRectMatrix(){ | 
| 71 | 
+ | 
      nrow_ = 0; | 
| 72 | 
+ | 
      ncol_ = 0; | 
| 73 | 
+ | 
      data_ = NULL; | 
| 74 | 
+ | 
    } | 
| 75 | 
+ | 
 | 
| 76 | 
  | 
    DynamicRectMatrix(int nrow, int ncol) { | 
| 77 | 
  | 
      allocate(nrow, ncol); | 
| 78 | 
  | 
 | 
| 109 | 
  | 
    ~DynamicRectMatrix() { deallocate();} | 
| 110 | 
  | 
 | 
| 111 | 
  | 
    /** copy assignment operator */ | 
| 112 | 
< | 
    DynamicRectMatrix<Real> operator =(const DynamicRectMatrix<Real> m) { | 
| 112 | 
> | 
    DynamicRectMatrix<Real> operator =(const DynamicRectMatrix<Real> &m) { | 
| 113 | 
  | 
      if (this == &m) | 
| 114 | 
  | 
          return *this; | 
| 115 | 
  | 
      if (nrow_ != m.getNRow() || ncol_ != m.getNCol()) { | 
| 233 | 
  | 
    /** | 
| 234 | 
  | 
     * Tests if this matrix is identical to matrix m | 
| 235 | 
  | 
     * @return true if this matrix is equal to the matrix m, return false otherwise | 
| 236 | 
< | 
     * @m matrix to be compared | 
| 236 | 
> | 
     * @param m matrix to be compared | 
| 237 | 
  | 
     * | 
| 238 | 
  | 
     * @todo replace operator == by template function equal | 
| 239 | 
  | 
     */ | 
| 240 | 
< | 
    bool operator ==(const DynamicRectMatrix<Real> m) { | 
| 240 | 
> | 
    bool operator ==(const DynamicRectMatrix<Real> &m) { | 
| 241 | 
  | 
      assert(nrow_ == m.getNRow() && ncol_ == m.getNCol()); | 
| 242 | 
  | 
      for (unsigned int i = 0; i < nrow_; i++) | 
| 243 | 
  | 
        for (unsigned int j = 0; j < ncol_; j++) | 
| 250 | 
  | 
    /** | 
| 251 | 
  | 
     * Tests if this matrix is not equal to matrix m | 
| 252 | 
  | 
     * @return true if this matrix is not equal to the matrix m, return false otherwise | 
| 253 | 
< | 
     * @m matrix to be compared | 
| 253 | 
> | 
     * @param m matrix to be compared | 
| 254 | 
  | 
     */ | 
| 255 | 
< | 
    bool operator !=(const DynamicRectMatrix<Real> m) { | 
| 255 | 
> | 
    bool operator !=(const DynamicRectMatrix<Real> &m) { | 
| 256 | 
  | 
      return !(*this == m); | 
| 257 | 
  | 
    } | 
| 258 | 
  | 
 | 
| 267 | 
  | 
     * Sets the value of this matrix to the negation of matrix m. | 
| 268 | 
  | 
     * @param m the source matrix | 
| 269 | 
  | 
     */ | 
| 270 | 
< | 
    inline void negate(const DynamicRectMatrix<Real> m) { | 
| 270 | 
> | 
    inline void negate(const DynamicRectMatrix<Real> &m) { | 
| 271 | 
  | 
      for (unsigned int i = 0; i < nrow_; i++) | 
| 272 | 
  | 
        for (unsigned int j = 0; j < ncol_; j++) | 
| 273 | 
  | 
          this->data_[i][j] = -m.data_[i][j];         | 
| 277 | 
  | 
     * Sets the value of this matrix to the sum of itself and m (*this += m). | 
| 278 | 
  | 
     * @param m the other matrix | 
| 279 | 
  | 
     */ | 
| 280 | 
< | 
    inline void add( const DynamicRectMatrix<Real> m ) { | 
| 280 | 
> | 
    inline void add( const DynamicRectMatrix<Real> &m ) { | 
| 281 | 
  | 
      assert(nrow_ == m.getNRow() && ncol_ == m.getNCol()); | 
| 282 | 
  | 
      for (unsigned int i = 0; i < nrow_; i++) | 
| 283 | 
  | 
        for (unsigned int j = 0; j < ncol_; j++)         | 
| 289 | 
  | 
     * @param m1 the first matrix | 
| 290 | 
  | 
     * @param m2 the second matrix | 
| 291 | 
  | 
     */ | 
| 292 | 
< | 
    inline void add( const DynamicRectMatrix<Real> m1, const DynamicRectMatrix<Real> m2 ) { | 
| 292 | 
> | 
    inline void add( const DynamicRectMatrix<Real> &m1, const DynamicRectMatrix<Real> &m2 ) { | 
| 293 | 
  | 
      assert(m1.getNRow() == m2.getNRow() && m1.getNCol() == m2.getNCol()); | 
| 294 | 
  | 
      for (unsigned int i = 0; i < nrow_; i++) | 
| 295 | 
  | 
        for (unsigned int j = 0; j < ncol_; j++)         | 
| 300 | 
  | 
     * Sets the value of this matrix to the difference  of itself and m (*this -= m). | 
| 301 | 
  | 
     * @param m the other matrix | 
| 302 | 
  | 
     */ | 
| 303 | 
< | 
    inline void sub( const DynamicRectMatrix<Real> m ) { | 
| 303 | 
> | 
    inline void sub( const DynamicRectMatrix<Real> &m ) { | 
| 304 | 
  | 
      assert(nrow_ == m.getNRow() && ncol_ == m.getNCol()); | 
| 305 | 
  | 
      for (unsigned int i = 0; i < nrow_; i++) | 
| 306 | 
  | 
        for (unsigned int j = 0; j < ncol_; j++)         | 
| 312 | 
  | 
     * @param m1 the first matrix | 
| 313 | 
  | 
     * @param m2 the second matrix | 
| 314 | 
  | 
     */ | 
| 315 | 
< | 
    inline void sub( const DynamicRectMatrix<Real> m1, const DynamicRectMatrix<Real> m2){ | 
| 315 | 
> | 
    inline void sub( const DynamicRectMatrix<Real> &m1, const DynamicRectMatrix<Real> &m2){ | 
| 316 | 
  | 
      assert(m1.getNRow() == m2.getNRow() && m1.getNCol() == m2.getNCol()); | 
| 317 | 
  | 
      for (unsigned int i = 0; i < nrow_; i++) | 
| 318 | 
  | 
        for (unsigned int j = 0; j < ncol_; j++)         | 
| 334 | 
  | 
     * @param s the scalar value | 
| 335 | 
  | 
     * @param m the matrix | 
| 336 | 
  | 
     */ | 
| 337 | 
< | 
    inline void mul( Real s, const DynamicRectMatrix<Real> m ) { | 
| 337 | 
> | 
    inline void mul( Real s, const DynamicRectMatrix<Real> &m ) { | 
| 338 | 
  | 
      assert(nrow_ == m.getNRow() && ncol_ == m.getNCol());     | 
| 339 | 
  | 
      for (unsigned int i = 0; i < nrow_; i++) | 
| 340 | 
  | 
        for (unsigned int j = 0; j < ncol_; j++)   | 
| 356 | 
  | 
     * @param s the scalar value | 
| 357 | 
  | 
     * @param m the matrix | 
| 358 | 
  | 
     */ | 
| 359 | 
< | 
    inline void div( Real s, const DynamicRectMatrix<Real> m ) { | 
| 359 | 
> | 
    inline void div( Real s, const DynamicRectMatrix<Real> &m ) { | 
| 360 | 
  | 
      assert(nrow_ == m.getNRow() && ncol_ == m.getNCol()); | 
| 361 | 
  | 
      for (unsigned int i = 0; i < nrow_; i++) | 
| 362 | 
  | 
        for (unsigned int j = 0; j < ncol_; j++)   | 
| 440 | 
  | 
    unsigned int nrow_; | 
| 441 | 
  | 
    unsigned int ncol_; | 
| 442 | 
  | 
  private: | 
| 443 | 
< | 
    void allocate(int nrow, int ncol) { | 
| 444 | 
< | 
        nrow_ = nrow; | 
| 445 | 
< | 
        ncol_ = ncol; | 
| 446 | 
< | 
        data_ = new Real*[nrow_]; | 
| 447 | 
< | 
        for (int i = 0; i < nrow_; ++i) | 
| 448 | 
< | 
            data_[i] = new Real[ncol_]; | 
| 443 | 
> | 
    void allocate( int nrow,  int ncol ) { | 
| 444 | 
> | 
      nrow_ = (unsigned int) nrow; | 
| 445 | 
> | 
      ncol_ = (unsigned int) ncol; | 
| 446 | 
> | 
      data_ = new Real*[nrow_]; | 
| 447 | 
> | 
      for (unsigned int i = 0; i < nrow_; ++i) | 
| 448 | 
> | 
        data_[i] = new Real[ncol_]; | 
| 449 | 
  | 
    } | 
| 450 | 
< | 
 | 
| 450 | 
> | 
     | 
| 451 | 
  | 
    void deallocate() { | 
| 452 | 
< | 
      for (int i = 0; i < nrow_; ++i) | 
| 452 | 
> | 
      for (unsigned int i = 0; i < nrow_; ++i) | 
| 453 | 
  | 
        delete data_[i]; | 
| 454 | 
  | 
      delete []data_; | 
| 455 | 
< | 
 | 
| 455 | 
> | 
       | 
| 456 | 
  | 
      nrow_ = 0; | 
| 457 | 
  | 
      ncol_ = 0; | 
| 458 | 
  | 
      data_ = NULL; | 
| 462 | 
  | 
 | 
| 463 | 
  | 
  /** Negate the value of every element of this matrix. */ | 
| 464 | 
  | 
  template<typename Real>  | 
| 465 | 
< | 
  inline DynamicRectMatrix<Real> operator -(const DynamicRectMatrix<Real> m) { | 
| 465 | 
> | 
  inline DynamicRectMatrix<Real> operator -(const DynamicRectMatrix<Real> &m) { | 
| 466 | 
  | 
    DynamicRectMatrix<Real> result(m); | 
| 467 | 
  | 
 | 
| 468 | 
  | 
    result.negate(); | 
| 477 | 
  | 
   * @param m2 the second matrix | 
| 478 | 
  | 
   */  | 
| 479 | 
  | 
  template<typename Real>  | 
| 480 | 
< | 
  inline DynamicRectMatrix<Real> operator + (const DynamicRectMatrix<Real> m1,const DynamicRectMatrix<Real> m2) { | 
| 480 | 
> | 
  inline DynamicRectMatrix<Real> operator + (const DynamicRectMatrix<Real> &m1, const DynamicRectMatrix<Real> &m2) { | 
| 481 | 
  | 
     | 
| 482 | 
  | 
    DynamicRectMatrix<Real> result(m1.getNRow(), m1.getNCol()); | 
| 483 | 
  | 
 | 
| 493 | 
  | 
   * @param m2 the second matrix | 
| 494 | 
  | 
   */ | 
| 495 | 
  | 
  template<typename Real>  | 
| 496 | 
< | 
  inline DynamicRectMatrix<Real> operator - (const DynamicRectMatrix<Real> m1, const DynamicRectMatrix<Real> m2) { | 
| 496 | 
> | 
  inline DynamicRectMatrix<Real> operator - (const DynamicRectMatrix<Real> &m1, const DynamicRectMatrix<Real> &m2) { | 
| 497 | 
  | 
    DynamicRectMatrix<Real> result(m1.getNRow(), m1.getNCol()); | 
| 498 | 
  | 
 | 
| 499 | 
  | 
    result.sub(m1, m2); | 
| 508 | 
  | 
   * @param s the scalar | 
| 509 | 
  | 
   */ | 
| 510 | 
  | 
  template<typename Real>  | 
| 511 | 
< | 
  inline DynamicRectMatrix<Real> operator *(const DynamicRectMatrix<Real> m, Real s) { | 
| 511 | 
> | 
  inline DynamicRectMatrix<Real> operator *(const DynamicRectMatrix<Real> &m, Real s) { | 
| 512 | 
  | 
    DynamicRectMatrix<Real> result(m.getNRow(), m.getNCol()); | 
| 513 | 
  | 
 | 
| 514 | 
  | 
    result.mul(s, m); | 
| 523 | 
  | 
   * @param m the matrix | 
| 524 | 
  | 
   */ | 
| 525 | 
  | 
  template<typename Real>  | 
| 526 | 
< | 
  inline DynamicRectMatrix<Real> operator *(Real s, const DynamicRectMatrix<Real> m) { | 
| 526 | 
> | 
  inline DynamicRectMatrix<Real> operator *(Real s, const DynamicRectMatrix<Real> &m) { | 
| 527 | 
  | 
    DynamicRectMatrix<Real> result(m.getNRow(), m.getNCol()); | 
| 528 | 
  | 
 | 
| 529 | 
  | 
    result.mul(s, m); | 
| 559 | 
  | 
   * @param v the vector | 
| 560 | 
  | 
   */ | 
| 561 | 
  | 
  template<typename Real> | 
| 562 | 
< | 
  inline DynamicVector<Real> operator *(const DynamicRectMatrix<Real> m, const DynamicVector<Real>& v) { | 
| 562 | 
> | 
  inline DynamicVector<Real> operator *(const DynamicRectMatrix<Real> &m, const DynamicVector<Real> &v) { | 
| 563 | 
  | 
    int nrow = m.getNRow(); | 
| 564 | 
  | 
    int ncol = m.getNCol(); | 
| 565 | 
< | 
    assert(ncol = v.size()); | 
| 565 | 
> | 
    assert(ncol == v.size()); | 
| 566 | 
  | 
    DynamicVector<Real> result(nrow); | 
| 567 | 
  | 
     | 
| 568 | 
  | 
    for (unsigned int i = 0; i < nrow ; i++) | 
| 579 | 
  | 
   * @param s the scalar | 
| 580 | 
  | 
   */ | 
| 581 | 
  | 
  template<typename Real>  | 
| 582 | 
< | 
  inline DynamicRectMatrix<Real> operator /(const DynamicRectMatrix<Real> m, Real s) { | 
| 582 | 
> | 
  inline DynamicRectMatrix<Real> operator /(const DynamicRectMatrix<Real> &m, Real s) { | 
| 583 | 
  | 
    DynamicRectMatrix<Real> result(m.getNRow(), m.getNCol()); | 
| 584 | 
  | 
 | 
| 585 | 
  | 
    result.div(s, m); | 
| 591 | 
  | 
   * Write to an output stream | 
| 592 | 
  | 
   */ | 
| 593 | 
  | 
  template<typename Real> | 
| 594 | 
< | 
  std::ostream &operator<< ( std::ostream& o, const DynamicRectMatrix<Real> m) { | 
| 594 | 
> | 
  std::ostream &operator<< ( std::ostream& o, const DynamicRectMatrix<Real> &m) { | 
| 595 | 
  | 
    for (unsigned int i = 0; i < m.getNRow() ; i++) { | 
| 596 | 
  | 
      o << "("; | 
| 597 | 
  | 
      for (unsigned int j = 0; j < m.getNCol() ; j++) { |