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

Comparing trunk/src/math/DynamicVector.hpp (file contents):
Revision 891 by tim, Wed Feb 22 20:35:16 2006 UTC vs.
Revision 1879 by gezelter, Sun Jun 16 15:15:42 2013 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, 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   /**
# Line 56 | Line 57
57   #include <algorithm>
58   #include <vector>
59  
60 < namespace oopse {
60 > namespace OpenMD {
61      
62    /**
63     * @class DynamicVector DynamicVector.hpp "math/DynamicVector.hpp"
# Line 93 | Line 94 | namespace oopse {
94         *  @brief  Create a %DynamicVector with copies of an exemplar element.
95         *  @param  n  The number of elements to initially create.
96         *  @param  value  An element to copy.
97 +       *  @param  alloc  The allocator_type to use
98         *
99         *  This constructor fills the %DynamicVector with @a n copies of @a value.
100         */
# Line 126 | Line 128 | namespace oopse {
128          DynamicVector(_InputIterator first, _InputIterator last,
129                 const allocator_type& alloc = allocator_type())
130          : std::vector<Real, Alloc>(first, last, alloc) {}
131 <            
131 >      
132 >    inline Real operator()(unsigned int i) const{
133 >      return (*this)[i];
134 >    }
135 >    
136 >    inline Real& operator()(unsigned int i){
137 >      return (*this)[i];
138 >    }    
139      /**
140       * Tests if this vetor is equal to other vector
141       * @return true if equal, otherwise return false
# Line 218 | Line 227 | namespace oopse {
227       * @param s the scalar value
228       */
229      inline void mul( const DynamicVector<Real>& v1, Real s) {
230 +      this->resize(v1.size());
231        for (unsigned int i = 0; i < this->size(); i++)
232          (*this)[i] = s * v1[i];
233      }
# Line 265 | Line 275 | namespace oopse {
275        return *this;
276      }
277  
278 +    /** zero out the vector */
279 +    inline void setZero( ) {
280 +      for (unsigned int i = 0; i < this->size(); i++)
281 +        (*this)[i] = 0;
282 +    }
283 +
284      /**
285       * Returns the length of this vector.
286       * @return the length of this vector
# Line 287 | Line 303 | namespace oopse {
303  
304        len = length();
305                  
306 <      //if (len < oopse:epsilon)
306 >      //if (len < OpenMD::NumericConstant::epsilon)
307        //  throw();
308                  
309        *this /= len;
# Line 300 | Line 316 | namespace oopse {
316      inline bool isNormalized() {
317        return equal(lengthSquare(), 1.0);
318      }          
319 +
320 +    template<class VectorType>
321 +    void getSubVector(unsigned int beginning, VectorType& v) {
322 +        assert(beginning + v.size() -1 <= this->size());
323 +
324 +        for (unsigned int i = 0; i < v.size(); ++i)
325 +             v(i) = (*this)[beginning+i];
326 +    }
327 +
328      
329    };
330  
# Line 319 | Line 344 | namespace oopse {
344     */  
345    template<typename Real>    
346    inline DynamicVector<Real> operator +(const DynamicVector<Real>& v1, const DynamicVector<Real>& v2) {
347 <    DynamicVector<Real> result;
348 <        
347 >    assert(v1.size() == v2.size());
348 >    DynamicVector<Real>result(v1.size());
349      result.add(v1, v2);
350      return result;        
351    }
# Line 333 | Line 358 | namespace oopse {
358     */  
359    template<typename Real>    
360    DynamicVector<Real> operator -(const DynamicVector<Real>& v1, const DynamicVector<Real>& v2) {
361 <    DynamicVector<Real> result;
361 >    assert(v1.size() == v2.size());
362 >    DynamicVector<Real> result(v1.size());
363      result.sub(v1, v2);
364      return result;        
365    }
# Line 345 | Line 371 | namespace oopse {
371     * @param s the scalar value
372     */
373    template<typename Real>                
374 <  DynamicVector<Real> operator * ( const DynamicVector<Real>& v1, Real s) {      
375 <    DynamicVector<Real> result;
374 >  DynamicVector<Real> operator *( const DynamicVector<Real>& v1, Real s) {      
375 >    DynamicVector<Real> result(v1.size());
376      result.mul(v1,s);
377      return result;          
378    }
# Line 358 | Line 384 | namespace oopse {
384     * @param v1 the source vector
385     */  
386    template<typename Real>
387 <  DynamicVector<Real> operator * ( Real s, const DynamicVector<Real>& v1 ) {
388 <    DynamicVector<Real> result;
387 >  DynamicVector<Real> operator *( Real s, const DynamicVector<Real>& v1 ) {
388 >    DynamicVector<Real> result(v1.size());
389      result.mul(v1, s);
390      return result;          
391    }
# Line 371 | Line 397 | namespace oopse {
397     * @param s the scalar value
398     */
399    template<typename Real>    
400 <  DynamicVector<Real> operator / ( const DynamicVector<Real>& v1, Real s) {      
401 <    DynamicVector<Real> result;
400 >  DynamicVector<Real> operator / ( const DynamicVector<Real>& v1, Real s) {    
401 >    DynamicVector<Real> result(v1.size());
402      result.div( v1,s);
403      return result;          
404    }

Comparing trunk/src/math/DynamicVector.hpp (property svn:keywords):
Revision 891 by tim, Wed Feb 22 20:35:16 2006 UTC vs.
Revision 1879 by gezelter, Sun Jun 16 15:15:42 2013 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines