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

Comparing trunk/src/primitives/CutoffGroup.hpp (file contents):
Revision 1782 by gezelter, Wed Aug 22 02:28:28 2012 UTC vs.
Revision 2057 by gezelter, Tue Mar 3 15:22:26 2015 UTC

# Line 35 | Line 35
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).          
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   */
# Line 51 | Line 51 | namespace OpenMD {
51    class CutoffGroup {
52    public:
53      
54 <    CutoffGroup() :  snapshotMan_(NULL) {
54 >    CutoffGroup() :  snapshotMan_(NULL), globalIndex(-1), localIndex_(-1) {
55  
56        storage_ = &Snapshot::cgData;
57        haveTotalMass = false;
# Line 82 | Line 82 | namespace OpenMD {
82  
83      std::vector<Atom*> getAtoms() { return cutoffAtomList; }
84      RealType getMass() {
85      std::vector<Atom *>::iterator i;
86      Atom * atom;
87      RealType mass;
85        
86        if (!haveTotalMass) {
87 <        totalMass = 0;
87 >        totalMass = 0.0;
88          
89 <        for(atom = beginAtom(i); atom != NULL; atom = nextAtom(i)) {
90 <          mass = atom->getMass();
89 >        std::vector<Atom *>::iterator i;
90 >        for(Atom* atom = beginAtom(i); atom != NULL; atom = nextAtom(i)) {
91 >          RealType mass = atom->getMass();
92            totalMass += mass;
93          }
94          
# Line 101 | Line 99 | namespace OpenMD {
99      }
100      
101      void updateCOM() {
104      std::vector<Atom *>::iterator i;
105      Atom * atom;
102  
103 <      DataStorage&  data = snapshotMan_->getCurrentSnapshot()->*storage_;
104 <      int storageLayout = data.getStorageLayout();
105 <    
110 <      totalMass = getMass();
111 <      
103 >      DataStorage& data = snapshotMan_->getCurrentSnapshot()->*storage_;
104 >      bool needsVel = (data.getStorageLayout() & DataStorage::dslVelocity);
105 >
106        if (cutoffAtomList.size() == 1) {
107 <        data.position[localIndex_] = beginAtom(i)->getPos();
107 >        data.position[localIndex_] = cutoffAtomList[0]->getPos();
108 >        if (needsVel)
109 >          data.velocity[localIndex_] = cutoffAtomList[0]->getVel();
110        } else {
111 +        std::vector<Atom *>::iterator i;
112 +        Atom * atom;
113 +        RealType totalMass = getMass();
114          data.position[localIndex_] = V3Zero;
115 +        if (needsVel) data.velocity[localIndex_] = V3Zero;
116 +        
117          for(atom = beginAtom(i); atom != NULL; atom = nextAtom(i)) {
118            data.position[localIndex_] += atom->getMass() * atom->getPos();
119 <        }        
119 <        data.position[localIndex_] /= totalMass;
120 <      }
121 <
122 <      if (storageLayout & DataStorage::dslVelocity) {
123 <        if (cutoffAtomList.size() == 1) {
124 <          data.velocity[localIndex_] = beginAtom(i)->getVel();
125 <        } else {
126 <          data.velocity[localIndex_] = V3Zero;
127 <          for(atom = beginAtom(i); atom != NULL; atom = nextAtom(i)) {
119 >          if (needsVel)
120              data.velocity[localIndex_] += atom->getMass() * atom->getVel();
121 <          }        
122 <          data.velocity[localIndex_] /= totalMass;
123 <        }
124 <      }
121 >        }    
122 >        data.position[localIndex_] /= totalMass;
123 >        if (needsVel) data.velocity[localIndex_] /= totalMass;          
124 >      }      
125      }
126  
127  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines