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). |
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 |
|
/** |
73 |
|
inline bool equal(RealType e1, RealType e2) { |
74 |
|
return fabs(e1 - e2) < epsilon; |
75 |
|
} |
75 |
– |
|
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() { |
275 |
|
inline void mul( const Vector<Real, Dim>& v1, Real s) { |
276 |
|
for (unsigned int i = 0; i < Dim; i++) |
277 |
|
this->data_[i] = s * v1.data_[i]; |
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 |
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); |
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. |
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 |