| 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, 24107 (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 */ |
| 272 |
|
} |
| 273 |
|
|
| 274 |
|
/** |
| 275 |
+ |
* Sets the elements of this vector to the multiplication of |
| 276 |
+ |
* elements of two other vectors. Not to be confused with scalar |
| 277 |
+ |
* multiplication (mul) or dot products. |
| 278 |
+ |
* |
| 279 |
+ |
* (*this.data_[i] = v1.data_[i] * v2.data_[i]). |
| 280 |
+ |
* @param v1 the first vector |
| 281 |
+ |
* @param v2 the second vector |
| 282 |
+ |
*/ |
| 283 |
+ |
inline void Vmul( const Vector<Real, Dim>& v1, const Vector<Real, Dim>& v2) { |
| 284 |
+ |
for (unsigned int i = 0; i < Dim; i++) |
| 285 |
+ |
this->data_[i] = v1.data_[i] * v2.data_[i]; |
| 286 |
+ |
} |
| 287 |
+ |
|
| 288 |
+ |
/* replaces the elements with the absolute values of those elements */ |
| 289 |
+ |
inline Vector<Real, Dim>& abs() { |
| 290 |
+ |
for (unsigned int i = 0; i < Dim; i++) { |
| 291 |
+ |
this->data_[i] = std::abs(this->data_[i]); |
| 292 |
+ |
} |
| 293 |
+ |
return *this; |
| 294 |
+ |
} |
| 295 |
+ |
|
| 296 |
+ |
/* returns the maximum value in this vector */ |
| 297 |
+ |
inline Real max() { |
| 298 |
+ |
Real val = this->data_[0]; |
| 299 |
+ |
for (unsigned int i = 0; i < Dim; i++) { |
| 300 |
+ |
if (this->data_[i] > val) val = this->data_[i]; |
| 301 |
+ |
} |
| 302 |
+ |
return val; |
| 303 |
+ |
} |
| 304 |
+ |
|
| 305 |
+ |
/** |
| 306 |
|
* Sets the value of this vector to the scalar division of itself (*this /= s ). |
| 307 |
|
* @param s the scalar value |
| 308 |
|
*/ |
| 321 |
|
this->data_[i] = v1.data_[i] / s; |
| 322 |
|
} |
| 323 |
|
|
| 324 |
+ |
/** |
| 325 |
+ |
* Sets the elements of this vector to the division of |
| 326 |
+ |
* elements of two other vectors. Not to be confused with scalar |
| 327 |
+ |
* division (div) |
| 328 |
+ |
* |
| 329 |
+ |
* (*this.data_[i] = v1.data_[i] / v2.data_[i]). |
| 330 |
+ |
* @param v1 the first vector |
| 331 |
+ |
* @param v2 the second vector |
| 332 |
+ |
*/ |
| 333 |
+ |
inline void Vdiv( const Vector<Real, Dim>& v1, const Vector<Real, Dim>& v2) { |
| 334 |
+ |
for (unsigned int i = 0; i < Dim; i++) |
| 335 |
+ |
this->data_[i] = v1.data_[i] / v2.data_[i]; |
| 336 |
+ |
} |
| 337 |
+ |
|
| 338 |
+ |
|
| 339 |
|
/** @see #add */ |
| 340 |
|
inline Vector<Real, Dim>& operator +=( const Vector<Real, Dim>& v1 ) { |
| 341 |
|
add(v1); |
| 361 |
|
} |
| 362 |
|
|
| 363 |
|
/** |
| 364 |
+ |
* Returns the sum of all elements of this vector. |
| 365 |
+ |
* @return the sum of all elements of this vector |
| 366 |
+ |
*/ |
| 367 |
+ |
inline Real sum() { |
| 368 |
+ |
Real tmp; |
| 369 |
+ |
tmp = 0; |
| 370 |
+ |
for (unsigned int i = 0; i < Dim; i++) |
| 371 |
+ |
tmp += this->data_[i]; |
| 372 |
+ |
return tmp; |
| 373 |
+ |
} |
| 374 |
+ |
|
| 375 |
+ |
/** |
| 376 |
+ |
* Returns the product of all elements of this vector. |
| 377 |
+ |
* @return the product of all elements of this vector |
| 378 |
+ |
*/ |
| 379 |
+ |
inline Real componentProduct() { |
| 380 |
+ |
Real tmp; |
| 381 |
+ |
tmp = 1; |
| 382 |
+ |
for (unsigned int i = 0; i < Dim; i++) |
| 383 |
+ |
tmp *= this->data_[i]; |
| 384 |
+ |
return tmp; |
| 385 |
+ |
} |
| 386 |
+ |
|
| 387 |
+ |
/** |
| 388 |
|
* Returns the length of this vector. |
| 389 |
|
* @return the length of this vector |
| 390 |
|
*/ |
| 406 |
|
|
| 407 |
|
len = length(); |
| 408 |
|
|
| 409 |
< |
//if (len < oopse:epsilon) |
| 409 |
> |
//if (len < OpenMD::NumericConstant::epsilon) |
| 410 |
|
// throw(); |
| 411 |
|
|
| 412 |
|
*this /= len; |
| 417 |
|
* @return true if this vector is normalized, otherwise return false |
| 418 |
|
*/ |
| 419 |
|
inline bool isNormalized() { |
| 420 |
< |
return equal(lengthSquare(), 1.0); |
| 420 |
> |
return equal(lengthSquare(), (RealType)1); |
| 421 |
|
} |
| 422 |
< |
|
| 422 |
> |
|
| 423 |
> |
unsigned int size() {return Dim;} |
| 424 |
|
protected: |
| 425 |
|
Real data_[Dim]; |
| 426 |
|
|
| 517 |
|
return tmp; |
| 518 |
|
} |
| 519 |
|
|
| 520 |
+ |
|
| 521 |
+ |
|
| 522 |
+ |
|
| 523 |
|
/** |
| 524 |
+ |
* Returns the wide dot product of three Vectors. Compare with |
| 525 |
+ |
* Rapaport's VWDot function. |
| 526 |
+ |
* |
| 527 |
+ |
* @param v1 first vector |
| 528 |
+ |
* @param v2 second vector |
| 529 |
+ |
* @param v3 third vector |
| 530 |
+ |
* @return the wide dot product of v1, v2, and v3. |
| 531 |
+ |
*/ |
| 532 |
+ |
template<typename Real, unsigned int Dim> |
| 533 |
+ |
inline Real dot( const Vector<Real, Dim>& v1, const Vector<Real, Dim>& v2, const Vector<Real, Dim>& v3 ) { |
| 534 |
+ |
Real tmp; |
| 535 |
+ |
tmp = 0; |
| 536 |
+ |
|
| 537 |
+ |
for (unsigned int i = 0; i < Dim; i++) |
| 538 |
+ |
tmp += v1[i] * v2[i] * v3[i]; |
| 539 |
+ |
|
| 540 |
+ |
return tmp; |
| 541 |
+ |
} |
| 542 |
+ |
|
| 543 |
+ |
|
| 544 |
+ |
/** |
| 545 |
|
* Returns the distance between two Vectors |
| 546 |
|
* @param v1 first vector |
| 547 |
|
* @param v2 second vector |