ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/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.
Revision 1615 by gezelter, Fri Aug 26 17:55:44 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]  Vardeman & Gezelter, in progress (2009).                        
40   */
41  
42   /**
# Line 53 | Line 53
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  
# 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 +    /**
288       * Sets the value of this vector to the scalar division of itself  (*this /= s ).
289       * @param s the scalar value
290       */            
# Line 288 | Line 303 | namespace oopse {
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);
# Line 313 | Line 343 | namespace oopse {
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       */
# Line 334 | Line 388 | namespace oopse {
388  
389        len = length();
390                  
391 <      //if (len < oopse:epsilon)
391 >      //if (len < OpenMD::NumericConstant::epsilon)
392        //  throw();
393                  
394        *this /= len;
# Line 345 | Line 399 | namespace oopse {
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 <            
404 >
405 >    unsigned int size() {return Dim;}
406    protected:
407      Real data_[Dim];
408          
# Line 444 | Line 499 | namespace oopse {
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

Comparing trunk/src/math/Vector.hpp (property svn:keywords):
Revision 507 by gezelter, Fri Apr 15 22:04:00 2005 UTC vs.
Revision 1615 by gezelter, Fri Aug 26 17:55:44 2011 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines