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 |
|
/** |
57 |
|
#include <algorithm> |
58 |
|
#include <vector> |
59 |
|
|
60 |
< |
namespace oopse { |
60 |
> |
namespace OpenMD { |
61 |
|
|
62 |
|
/** |
63 |
|
* @class DynamicVector DynamicVector.hpp "math/DynamicVector.hpp" |
127 |
|
DynamicVector(_InputIterator first, _InputIterator last, |
128 |
|
const allocator_type& alloc = allocator_type()) |
129 |
|
: std::vector<Real, Alloc>(first, last, alloc) {} |
130 |
< |
|
130 |
> |
|
131 |
> |
inline Real operator()(unsigned int i) const{ |
132 |
> |
return (*this)[i]; |
133 |
> |
} |
134 |
> |
|
135 |
> |
inline Real& operator()(unsigned int i){ |
136 |
> |
return (*this)[i]; |
137 |
> |
} |
138 |
|
/** |
139 |
|
* Tests if this vetor is equal to other vector |
140 |
|
* @return true if equal, otherwise return false |
226 |
|
* @param s the scalar value |
227 |
|
*/ |
228 |
|
inline void mul( const DynamicVector<Real>& v1, Real s) { |
229 |
+ |
this->resize(v1.size()); |
230 |
|
for (unsigned int i = 0; i < this->size(); i++) |
231 |
|
(*this)[i] = s * v1[i]; |
232 |
|
} |
274 |
|
return *this; |
275 |
|
} |
276 |
|
|
277 |
+ |
/** zero out the vector */ |
278 |
+ |
inline void setZero( ) { |
279 |
+ |
for (unsigned int i = 0; i < this->size(); i++) |
280 |
+ |
(*this)[i] = 0; |
281 |
+ |
} |
282 |
+ |
|
283 |
|
/** |
284 |
|
* Returns the length of this vector. |
285 |
|
* @return the length of this vector |
302 |
|
|
303 |
|
len = length(); |
304 |
|
|
305 |
< |
//if (len < oopse:epsilon) |
305 |
> |
//if (len < OpenMD::NumericConstant::epsilon) |
306 |
|
// throw(); |
307 |
|
|
308 |
|
*this /= len; |
315 |
|
inline bool isNormalized() { |
316 |
|
return equal(lengthSquare(), 1.0); |
317 |
|
} |
318 |
+ |
|
319 |
+ |
template<class VectorType> |
320 |
+ |
void getSubVector(unsigned int beginning, VectorType& v) { |
321 |
+ |
assert(beginning + v.size() -1 <= this->size()); |
322 |
+ |
|
323 |
+ |
for (unsigned int i = 0; i < v.size(); ++i) |
324 |
+ |
v(i) = (*this)[beginning+i]; |
325 |
+ |
} |
326 |
+ |
|
327 |
|
|
328 |
|
}; |
329 |
|
|
343 |
|
*/ |
344 |
|
template<typename Real> |
345 |
|
inline DynamicVector<Real> operator +(const DynamicVector<Real>& v1, const DynamicVector<Real>& v2) { |
346 |
< |
DynamicVector<Real> result; |
347 |
< |
|
346 |
> |
assert(v1.size() == v2.size()); |
347 |
> |
DynamicVector<Real>result(v1.size()); |
348 |
|
result.add(v1, v2); |
349 |
|
return result; |
350 |
|
} |
357 |
|
*/ |
358 |
|
template<typename Real> |
359 |
|
DynamicVector<Real> operator -(const DynamicVector<Real>& v1, const DynamicVector<Real>& v2) { |
360 |
< |
DynamicVector<Real> result; |
360 |
> |
assert(v1.size() == v2.size()); |
361 |
> |
DynamicVector<Real> result(v1.size()); |
362 |
|
result.sub(v1, v2); |
363 |
|
return result; |
364 |
|
} |
370 |
|
* @param s the scalar value |
371 |
|
*/ |
372 |
|
template<typename Real> |
373 |
< |
DynamicVector<Real> operator * ( const DynamicVector<Real>& v1, Real s) { |
374 |
< |
DynamicVector<Real> result; |
373 |
> |
DynamicVector<Real> operator *( const DynamicVector<Real>& v1, Real s) { |
374 |
> |
DynamicVector<Real> result(v1.size()); |
375 |
|
result.mul(v1,s); |
376 |
|
return result; |
377 |
|
} |
383 |
|
* @param v1 the source vector |
384 |
|
*/ |
385 |
|
template<typename Real> |
386 |
< |
DynamicVector<Real> operator * ( Real s, const DynamicVector<Real>& v1 ) { |
387 |
< |
DynamicVector<Real> result; |
386 |
> |
DynamicVector<Real> operator *( Real s, const DynamicVector<Real>& v1 ) { |
387 |
> |
DynamicVector<Real> result(v1.size()); |
388 |
|
result.mul(v1, s); |
389 |
|
return result; |
390 |
|
} |
396 |
|
* @param s the scalar value |
397 |
|
*/ |
398 |
|
template<typename Real> |
399 |
< |
DynamicVector<Real> operator / ( const DynamicVector<Real>& v1, Real s) { |
400 |
< |
DynamicVector<Real> result; |
399 |
> |
DynamicVector<Real> operator / ( const DynamicVector<Real>& v1, Real s) { |
400 |
> |
DynamicVector<Real> result(v1.size()); |
401 |
|
result.div( v1,s); |
402 |
|
return result; |
403 |
|
} |