| 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] Vardeman & Gezelter, in progress (2009). |
| 40 |
|
*/ |
| 41 |
|
|
| 42 |
|
/** |
| 53 |
|
#include <cmath> |
| 54 |
|
#include <iostream> |
| 55 |
|
#include <math.h> |
| 56 |
< |
namespace oopse { |
| 56 |
> |
#include "config.h" |
| 57 |
> |
namespace OpenMD { |
| 58 |
|
|
| 59 |
< |
static const double epsilon = 0.000001; |
| 59 |
> |
static const RealType epsilon = 0.000001; |
| 60 |
|
|
| 61 |
|
template<typename T> |
| 62 |
|
inline bool equal(T e1, T e2) { |
| 63 |
|
return e1 == e2; |
| 64 |
|
} |
| 65 |
|
|
| 66 |
< |
template<> |
| 67 |
< |
inline bool equal(float e1, float e2) { |
| 68 |
< |
return fabs(e1 - e2) < epsilon; |
| 69 |
< |
} |
| 66 |
> |
//template<> |
| 67 |
> |
//inline bool equal(float e1, float e2) { |
| 68 |
> |
// return fabs(e1 - e2) < epsilon; |
| 69 |
> |
//} |
| 70 |
|
|
| 71 |
|
template<> |
| 72 |
< |
inline bool equal(double e1, double e2) { |
| 72 |
> |
inline bool equal(RealType e1, RealType e2) { |
| 73 |
|
return fabs(e1 - e2) < epsilon; |
| 74 |
|
} |
| 75 |
|
|
| 271 |
|
} |
| 272 |
|
|
| 273 |
|
/** |
| 274 |
+ |
* Sets the elements of this vector to the multiplication of |
| 275 |
+ |
* elements of two other vectors. Not to be confused with scalar |
| 276 |
+ |
* multiplication (mul) or dot products. |
| 277 |
+ |
* |
| 278 |
+ |
* (*this.data_[i] = v1.data_[i] * v2.data_[i]). |
| 279 |
+ |
* @param v1 the first vector |
| 280 |
+ |
* @param v2 the second vector |
| 281 |
+ |
*/ |
| 282 |
+ |
inline void Vmul( const Vector<Real, Dim>& v1, const Vector<Real, Dim>& v2) { |
| 283 |
+ |
for (unsigned int i = 0; i < Dim; i++) |
| 284 |
+ |
this->data_[i] = v1.data_[i] * v2.data_[i]; |
| 285 |
+ |
} |
| 286 |
+ |
|
| 287 |
+ |
/** |
| 288 |
|
* Sets the value of this vector to the scalar division of itself (*this /= s ). |
| 289 |
|
* @param s the scalar value |
| 290 |
|
*/ |
| 301 |
|
inline void div( const Vector<Real, Dim>& v1, Real s ) { |
| 302 |
|
for (unsigned int i = 0; i < Dim; i++) |
| 303 |
|
this->data_[i] = v1.data_[i] / s; |
| 304 |
+ |
} |
| 305 |
+ |
|
| 306 |
+ |
/** |
| 307 |
+ |
* Sets the elements of this vector to the division of |
| 308 |
+ |
* elements of two other vectors. Not to be confused with scalar |
| 309 |
+ |
* division (div) |
| 310 |
+ |
* |
| 311 |
+ |
* (*this.data_[i] = v1.data_[i] / v2.data_[i]). |
| 312 |
+ |
* @param v1 the first vector |
| 313 |
+ |
* @param v2 the second vector |
| 314 |
+ |
*/ |
| 315 |
+ |
inline void Vdiv( const Vector<Real, Dim>& v1, const Vector<Real, Dim>& v2) { |
| 316 |
+ |
for (unsigned int i = 0; i < Dim; i++) |
| 317 |
+ |
this->data_[i] = v1.data_[i] / v2.data_[i]; |
| 318 |
|
} |
| 319 |
|
|
| 320 |
+ |
|
| 321 |
|
/** @see #add */ |
| 322 |
|
inline Vector<Real, Dim>& operator +=( const Vector<Real, Dim>& v1 ) { |
| 323 |
|
add(v1); |
| 343 |
|
} |
| 344 |
|
|
| 345 |
|
/** |
| 346 |
+ |
* Returns the sum of all elements of this vector. |
| 347 |
+ |
* @return the sum of all elements of this vector |
| 348 |
+ |
*/ |
| 349 |
+ |
inline Real sum() { |
| 350 |
+ |
Real tmp; |
| 351 |
+ |
tmp = 0; |
| 352 |
+ |
for (unsigned int i = 0; i < Dim; i++) |
| 353 |
+ |
tmp += this->data_[i]; |
| 354 |
+ |
return tmp; |
| 355 |
+ |
} |
| 356 |
+ |
|
| 357 |
+ |
/** |
| 358 |
+ |
* Returns the product of all elements of this vector. |
| 359 |
+ |
* @return the product of all elements of this vector |
| 360 |
+ |
*/ |
| 361 |
+ |
inline Real componentProduct() { |
| 362 |
+ |
Real tmp; |
| 363 |
+ |
tmp = 1; |
| 364 |
+ |
for (unsigned int i = 0; i < Dim; i++) |
| 365 |
+ |
tmp *= this->data_[i]; |
| 366 |
+ |
return tmp; |
| 367 |
+ |
} |
| 368 |
+ |
|
| 369 |
+ |
/** |
| 370 |
|
* Returns the length of this vector. |
| 371 |
|
* @return the length of this vector |
| 372 |
|
*/ |
| 388 |
|
|
| 389 |
|
len = length(); |
| 390 |
|
|
| 391 |
< |
//if (len < oopse:epsilon) |
| 391 |
> |
//if (len < OpenMD::NumericConstant::epsilon) |
| 392 |
|
// throw(); |
| 393 |
|
|
| 394 |
|
*this /= len; |
| 399 |
|
* @return true if this vector is normalized, otherwise return false |
| 400 |
|
*/ |
| 401 |
|
inline bool isNormalized() { |
| 402 |
< |
return equal(lengthSquare(), 1.0); |
| 402 |
> |
return equal(lengthSquare(), (RealType)1); |
| 403 |
|
} |
| 404 |
|
|
| 405 |
|
unsigned int size() {return Dim;} |
| 499 |
|
return tmp; |
| 500 |
|
} |
| 501 |
|
|
| 502 |
+ |
|
| 503 |
+ |
|
| 504 |
+ |
|
| 505 |
|
/** |
| 506 |
+ |
* Returns the wide dot product of three Vectors. Compare with |
| 507 |
+ |
* Rapaport's VWDot function. |
| 508 |
+ |
* |
| 509 |
+ |
* @param v1 first vector |
| 510 |
+ |
* @param v2 second vector |
| 511 |
+ |
* @param v3 third vector |
| 512 |
+ |
* @return the wide dot product of v1, v2, and v3. |
| 513 |
+ |
*/ |
| 514 |
+ |
template<typename Real, unsigned int Dim> |
| 515 |
+ |
inline Real dot( const Vector<Real, Dim>& v1, const Vector<Real, Dim>& v2, const Vector<Real, Dim>& v3 ) { |
| 516 |
+ |
Real tmp; |
| 517 |
+ |
tmp = 0; |
| 518 |
+ |
|
| 519 |
+ |
for (unsigned int i = 0; i < Dim; i++) |
| 520 |
+ |
tmp += v1[i] * v2[i] * v3[i]; |
| 521 |
+ |
|
| 522 |
+ |
return tmp; |
| 523 |
+ |
} |
| 524 |
+ |
|
| 525 |
+ |
|
| 526 |
+ |
/** |
| 527 |
|
* Returns the distance between two Vectors |
| 528 |
|
* @param v1 first vector |
| 529 |
|
* @param v2 second vector |