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 1760 by gezelter, Thu Jun 21 19:26:46 2012 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    }
74
76      
77    /**
78     * @class Vector Vector.hpp "math/Vector.hpp"
# Line 270 | Line 271 | namespace oopse {
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 +    /* replaces the elements with the absolute values of those elements */
288 +    inline Vector<Real, Dim>& abs() {
289 +      for (unsigned int i = 0; i < Dim; i++) {
290 +        this->data_[i] = std::abs(this->data_[i]);
291 +      }
292 +      return *this;
293 +    }
294 +    
295 +    /* returns the maximum value in this vector */
296 +    inline Real max() {
297 +      Real val = this->data_[0];
298 +      for (unsigned int i = 0; i < Dim; i++) {
299 +        if (this->data_[i] > val) val = this->data_[i];
300 +      }
301 +      return val;
302 +    }
303 +    
304 +    /**
305       * Sets the value of this vector to the scalar division of itself  (*this /= s ).
306       * @param s the scalar value
307       */            
# Line 286 | Line 318 | namespace oopse {
318      inline void div( const Vector<Real, Dim>& v1, Real s ) {
319        for (unsigned int i = 0; i < Dim; i++)
320          this->data_[i] = v1.data_[i] / s;
321 +    }
322 +
323 +    /**
324 +     * Sets the elements of this vector to the division of
325 +     * elements of two other vectors.  Not to be confused with scalar
326 +     * division (div)
327 +     *
328 +     * (*this.data_[i] =  v1.data_[i] / v2.data_[i]).
329 +     * @param v1 the first vector            
330 +     * @param v2 the second vector
331 +     */
332 +    inline void Vdiv( const Vector<Real, Dim>& v1, const Vector<Real, Dim>& v2) {
333 +      for (unsigned int i = 0; i < Dim; i++)
334 +        this->data_[i] = v1.data_[i] / v2.data_[i];
335      }
336  
337 +
338      /** @see #add */
339      inline Vector<Real, Dim>& operator +=( const Vector<Real, Dim>& v1 ) {
340        add(v1);
# Line 313 | Line 360 | namespace oopse {
360      }
361  
362      /**
363 +     * Returns the sum of all elements of this vector.
364 +     * @return the sum of all elements of this vector
365 +     */
366 +    inline Real sum() {
367 +      Real tmp;
368 +      tmp = 0;
369 +      for (unsigned int i = 0; i < Dim; i++)
370 +        tmp += this->data_[i];
371 +      return tmp;  
372 +    }
373 +
374 +    /**
375 +     * Returns the product of all elements of this vector.
376 +     * @return the product of all elements of this vector
377 +     */
378 +    inline Real componentProduct() {
379 +      Real tmp;
380 +      tmp = 1;
381 +      for (unsigned int i = 0; i < Dim; i++)
382 +        tmp *= this->data_[i];
383 +      return tmp;  
384 +    }
385 +            
386 +    /**
387       * Returns the length of this vector.
388       * @return the length of this vector
389       */
# Line 334 | Line 405 | namespace oopse {
405  
406        len = length();
407                  
408 <      //if (len < oopse:epsilon)
408 >      //if (len < OpenMD::NumericConstant::epsilon)
409        //  throw();
410                  
411        *this /= len;
# Line 345 | Line 416 | namespace oopse {
416       * @return true if this vector is normalized, otherwise return false
417       */
418      inline bool isNormalized() {
419 <      return equal(lengthSquare(), 1.0);
419 >      return equal(lengthSquare(), (RealType)1);
420      }          
421 <            
421 >
422 >    unsigned int size() {return Dim;}
423    protected:
424      Real data_[Dim];
425          
# Line 444 | Line 516 | namespace oopse {
516      return tmp;
517    }
518  
519 +
520 +  
521 +
522    /**
523 +   * Returns the wide dot product of three Vectors.  Compare with
524 +   * Rapaport's VWDot function.
525 +   *
526 +   * @param v1 first vector
527 +   * @param v2 second vector
528 +   * @param v3 third vector
529 +   * @return the wide dot product of v1, v2, and v3.
530 +   */
531 +  template<typename Real, unsigned int Dim>    
532 +  inline Real dot( const Vector<Real, Dim>& v1, const Vector<Real, Dim>& v2, const Vector<Real, Dim>& v3 ) {
533 +    Real tmp;
534 +    tmp = 0;
535 +
536 +    for (unsigned int i = 0; i < Dim; i++)
537 +      tmp += v1[i] * v2[i] * v3[i];
538 +
539 +    return tmp;
540 +  }
541 +
542 +
543 +  /**
544     * Returns the distance between  two Vectors
545     * @param v1 first vector
546     * @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 1760 by gezelter, Thu Jun 21 19:26:46 2012 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines