| 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 |  | /** | 
| 54 |  | #include <cmath> | 
| 55 |  | #include <iostream> | 
| 56 |  | #include <math.h> | 
| 57 | < | namespace oopse { | 
| 57 | > | #include "config.h" | 
| 58 | > | namespace OpenMD { | 
| 59 |  |  | 
| 60 | < | static const double epsilon = 0.000001; | 
| 60 | > | static const RealType epsilon = 0.000001; | 
| 61 |  |  | 
| 62 |  | template<typename T> | 
| 63 |  | inline bool equal(T e1, T e2) { | 
| 64 |  | return e1 == e2; | 
| 65 |  | } | 
| 66 |  |  | 
| 67 | < | template<> | 
| 68 | < | inline bool equal(float e1, float e2) { | 
| 69 | < | return fabs(e1 - e2) < epsilon; | 
| 70 | < | } | 
| 67 | > | //template<> | 
| 68 | > | //inline bool equal(float e1, float e2) { | 
| 69 | > | //  return fabs(e1 - e2) < epsilon; | 
| 70 | > | //} | 
| 71 |  |  | 
| 72 |  | template<> | 
| 73 | < | inline bool equal(double e1, double e2) { | 
| 73 | > | inline bool equal(RealType e1, RealType e2) { | 
| 74 |  | return fabs(e1 - e2) < epsilon; | 
| 75 |  | } | 
| 74 | – |  | 
| 76 |  |  | 
| 77 |  | /** | 
| 78 |  | * @class Vector Vector.hpp "math/Vector.hpp" | 
| 107 |  | return *this; | 
| 108 |  | } | 
| 109 |  |  | 
| 110 | < | template<typename T> | 
| 111 | < | inline Vector(const T& s){ | 
| 110 | > | // template<typename T> | 
| 111 | > | // inline Vector(const T& s){ | 
| 112 | > | inline Vector(const Real& s) { | 
| 113 |  | for (unsigned int i = 0; i < Dim; i++) | 
| 114 | < | this->data_[i] = s; | 
| 114 | > | this->data_[i] = s; | 
| 115 |  | } | 
| 116 |  |  | 
| 117 |  | /** Constructs and initializes a Vector from an array */ | 
| 196 |  | inline bool operator !=(const Vector<Real, Dim>& v) { | 
| 197 |  | return !(*this == v); | 
| 198 |  | } | 
| 199 | + |  | 
| 200 | + | /** Zeros out the values in this vector in place */ | 
| 201 | + | inline void zero() { | 
| 202 | + | for (unsigned int i = 0; i < Dim; i++) | 
| 203 | + | this->data_[i] = 0; | 
| 204 | + | } | 
| 205 |  |  | 
| 206 |  | /** Negates the value of this vector in place. */ | 
| 207 |  | inline void negate() { | 
| 278 |  | } | 
| 279 |  |  | 
| 280 |  | /** | 
| 281 | + | * Sets the elements of this vector to the multiplication of | 
| 282 | + | * elements of two other vectors.  Not to be confused with scalar | 
| 283 | + | * multiplication (mul) or dot products. | 
| 284 | + | * | 
| 285 | + | * (*this.data_[i] =  v1.data_[i] * v2.data_[i]). | 
| 286 | + | * @param v1 the first vector | 
| 287 | + | * @param v2 the second vector | 
| 288 | + | */ | 
| 289 | + | inline void Vmul( const Vector<Real, Dim>& v1, const Vector<Real, Dim>& v2) { | 
| 290 | + | for (unsigned int i = 0; i < Dim; i++) | 
| 291 | + | this->data_[i] = v1.data_[i] * v2.data_[i]; | 
| 292 | + | } | 
| 293 | + |  | 
| 294 | + | /* replaces the elements with the absolute values of those elements */ | 
| 295 | + | inline Vector<Real, Dim>& abs() { | 
| 296 | + | for (unsigned int i = 0; i < Dim; i++) { | 
| 297 | + | this->data_[i] = std::abs(this->data_[i]); | 
| 298 | + | } | 
| 299 | + | return *this; | 
| 300 | + | } | 
| 301 | + |  | 
| 302 | + | /* returns the maximum value in this vector */ | 
| 303 | + | inline Real max() { | 
| 304 | + | Real val = this->data_[0]; | 
| 305 | + | for (unsigned int i = 0; i < Dim; i++) { | 
| 306 | + | if (this->data_[i] > val) val = this->data_[i]; | 
| 307 | + | } | 
| 308 | + | return val; | 
| 309 | + | } | 
| 310 | + |  | 
| 311 | + | /** | 
| 312 |  | * Sets the value of this vector to the scalar division of itself  (*this /= s ). | 
| 313 |  | * @param s the scalar value | 
| 314 |  | */ | 
| 327 |  | this->data_[i] = v1.data_[i] / s; | 
| 328 |  | } | 
| 329 |  |  | 
| 330 | + | /** | 
| 331 | + | * Sets the elements of this vector to the division of | 
| 332 | + | * elements of two other vectors.  Not to be confused with scalar | 
| 333 | + | * division (div) | 
| 334 | + | * | 
| 335 | + | * (*this.data_[i] =  v1.data_[i] / v2.data_[i]). | 
| 336 | + | * @param v1 the first vector | 
| 337 | + | * @param v2 the second vector | 
| 338 | + | */ | 
| 339 | + | inline void Vdiv( const Vector<Real, Dim>& v1, const Vector<Real, Dim>& v2) { | 
| 340 | + | for (unsigned int i = 0; i < Dim; i++) | 
| 341 | + | this->data_[i] = v1.data_[i] / v2.data_[i]; | 
| 342 | + | } | 
| 343 | + |  | 
| 344 | + |  | 
| 345 |  | /** @see #add */ | 
| 346 |  | inline Vector<Real, Dim>& operator +=( const Vector<Real, Dim>& v1 ) { | 
| 347 |  | add(v1); | 
| 367 |  | } | 
| 368 |  |  | 
| 369 |  | /** | 
| 370 | + | * Returns the sum of all elements of this vector. | 
| 371 | + | * @return the sum of all elements of this vector | 
| 372 | + | */ | 
| 373 | + | inline Real sum() { | 
| 374 | + | Real tmp; | 
| 375 | + | tmp = 0; | 
| 376 | + | for (unsigned int i = 0; i < Dim; i++) | 
| 377 | + | tmp += this->data_[i]; | 
| 378 | + | return tmp; | 
| 379 | + | } | 
| 380 | + |  | 
| 381 | + | /** | 
| 382 | + | * Returns the product of all elements of this vector. | 
| 383 | + | * @return the product of all elements of this vector | 
| 384 | + | */ | 
| 385 | + | inline Real componentProduct() { | 
| 386 | + | Real tmp; | 
| 387 | + | tmp = 1; | 
| 388 | + | for (unsigned int i = 0; i < Dim; i++) | 
| 389 | + | tmp *= this->data_[i]; | 
| 390 | + | return tmp; | 
| 391 | + | } | 
| 392 | + |  | 
| 393 | + | /** | 
| 394 |  | * Returns the length of this vector. | 
| 395 |  | * @return the length of this vector | 
| 396 |  | */ | 
| 412 |  |  | 
| 413 |  | len = length(); | 
| 414 |  |  | 
| 415 | < | //if (len < oopse:epsilon) | 
| 415 | > | //if (len < OpenMD::NumericConstant::epsilon) | 
| 416 |  | //  throw(); | 
| 417 |  |  | 
| 418 |  | *this /= len; | 
| 423 |  | * @return true if this vector is normalized, otherwise return false | 
| 424 |  | */ | 
| 425 |  | inline bool isNormalized() { | 
| 426 | < | return equal(lengthSquare(), 1.0); | 
| 426 | > | return equal(lengthSquare(), (RealType)1); | 
| 427 |  | } | 
| 428 | < |  | 
| 428 | > |  | 
| 429 | > | unsigned int size() {return Dim;} | 
| 430 |  | protected: | 
| 431 |  | Real data_[Dim]; | 
| 432 |  |  | 
| 523 |  | return tmp; | 
| 524 |  | } | 
| 525 |  |  | 
| 526 | + |  | 
| 527 | + |  | 
| 528 | + |  | 
| 529 |  | /** | 
| 530 | + | * Returns the wide dot product of three Vectors.  Compare with | 
| 531 | + | * Rapaport's VWDot function. | 
| 532 | + | * | 
| 533 | + | * @param v1 first vector | 
| 534 | + | * @param v2 second vector | 
| 535 | + | * @param v3 third vector | 
| 536 | + | * @return the wide dot product of v1, v2, and v3. | 
| 537 | + | */ | 
| 538 | + | template<typename Real, unsigned int Dim> | 
| 539 | + | inline Real dot( const Vector<Real, Dim>& v1, const Vector<Real, Dim>& v2, const Vector<Real, Dim>& v3 ) { | 
| 540 | + | Real tmp; | 
| 541 | + | tmp = 0; | 
| 542 | + |  | 
| 543 | + | for (unsigned int i = 0; i < Dim; i++) | 
| 544 | + | tmp += v1[i] * v2[i] * v3[i]; | 
| 545 | + |  | 
| 546 | + | return tmp; | 
| 547 | + | } | 
| 548 | + |  | 
| 549 | + |  | 
| 550 | + | /** | 
| 551 |  | * Returns the distance between  two Vectors | 
| 552 |  | * @param v1 first vector | 
| 553 |  | * @param v2 second vector |