ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/math/Vector.hpp
(Generate patch)

Comparing:
trunk/src/math/Vector.hpp (file contents), Revision 507 by gezelter, Fri Apr 15 22:04:00 2005 UTC vs.
branches/development/src/math/Vector.hpp (file contents), Revision 1665 by gezelter, Tue Nov 22 20:38:56 2011 UTC

# Line 6 | Line 6
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.
# Line 37 | Line 28
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   /**
# Line 53 | Line 54
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    }
76  
# Line 270 | Line 272 | namespace oopse {
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 +    /**
289       * Sets the value of this vector to the scalar division of itself  (*this /= s ).
290       * @param s the scalar value
291       */            
# Line 286 | Line 302 | namespace oopse {
302      inline void div( const Vector<Real, Dim>& v1, Real s ) {
303        for (unsigned int i = 0; i < Dim; i++)
304          this->data_[i] = v1.data_[i] / s;
305 +    }
306 +
307 +    /**
308 +     * Sets the elements of this vector to the division of
309 +     * elements of two other vectors.  Not to be confused with scalar
310 +     * division (div)
311 +     *
312 +     * (*this.data_[i] =  v1.data_[i] / v2.data_[i]).
313 +     * @param v1 the first vector            
314 +     * @param v2 the second vector
315 +     */
316 +    inline void Vdiv( const Vector<Real, Dim>& v1, const Vector<Real, Dim>& v2) {
317 +      for (unsigned int i = 0; i < Dim; i++)
318 +        this->data_[i] = v1.data_[i] / v2.data_[i];
319      }
320  
321 +
322      /** @see #add */
323      inline Vector<Real, Dim>& operator +=( const Vector<Real, Dim>& v1 ) {
324        add(v1);
# Line 313 | Line 344 | namespace oopse {
344      }
345  
346      /**
347 +     * Returns the sum of all elements of this vector.
348 +     * @return the sum of all elements of this vector
349 +     */
350 +    inline Real sum() {
351 +      Real tmp;
352 +      tmp = 0;
353 +      for (unsigned int i = 0; i < Dim; i++)
354 +        tmp += this->data_[i];
355 +      return tmp;  
356 +    }
357 +
358 +    /**
359 +     * Returns the product of all elements of this vector.
360 +     * @return the product of all elements of this vector
361 +     */
362 +    inline Real componentProduct() {
363 +      Real tmp;
364 +      tmp = 1;
365 +      for (unsigned int i = 0; i < Dim; i++)
366 +        tmp *= this->data_[i];
367 +      return tmp;  
368 +    }
369 +            
370 +    /**
371       * Returns the length of this vector.
372       * @return the length of this vector
373       */
# Line 334 | Line 389 | namespace oopse {
389  
390        len = length();
391                  
392 <      //if (len < oopse:epsilon)
392 >      //if (len < OpenMD::NumericConstant::epsilon)
393        //  throw();
394                  
395        *this /= len;
# Line 345 | Line 400 | namespace oopse {
400       * @return true if this vector is normalized, otherwise return false
401       */
402      inline bool isNormalized() {
403 <      return equal(lengthSquare(), 1.0);
403 >      return equal(lengthSquare(), (RealType)1);
404      }          
405 <            
405 >
406 >    unsigned int size() {return Dim;}
407    protected:
408      Real data_[Dim];
409          
# Line 444 | Line 500 | namespace oopse {
500      return tmp;
501    }
502  
503 +
504 +  
505 +
506    /**
507 +   * Returns the wide dot product of three Vectors.  Compare with
508 +   * Rapaport's VWDot function.
509 +   *
510 +   * @param v1 first vector
511 +   * @param v2 second vector
512 +   * @param v3 third vector
513 +   * @return the wide dot product of v1, v2, and v3.
514 +   */
515 +  template<typename Real, unsigned int Dim>    
516 +  inline Real dot( const Vector<Real, Dim>& v1, const Vector<Real, Dim>& v2, const Vector<Real, Dim>& v3 ) {
517 +    Real tmp;
518 +    tmp = 0;
519 +
520 +    for (unsigned int i = 0; i < Dim; i++)
521 +      tmp += v1[i] * v2[i] * v3[i];
522 +
523 +    return tmp;
524 +  }
525 +
526 +
527 +  /**
528     * Returns the distance between  two Vectors
529     * @param v1 first vector
530     * @param v2 second vector

Comparing:
trunk/src/math/Vector.hpp (property svn:keywords), Revision 507 by gezelter, Fri Apr 15 22:04:00 2005 UTC vs.
branches/development/src/math/Vector.hpp (property svn:keywords), Revision 1665 by gezelter, Tue Nov 22 20:38:56 2011 UTC

# Line 0 | Line 1
1 + Author Id Revision Date

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines