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 2065 by gezelter, Thu Mar 5 15:11:00 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 <    
106 <      totalMass = getMass();
111 <      
103 >      DataStorage& data = snapshotMan_->getCurrentSnapshot()->*storage_;
104 >      bool needsVel = false;
105 >      if (data.getStorageLayout() & DataStorage::dslVelocity) needsVel = true;
106 >
107        if (cutoffAtomList.size() == 1) {
108 <        data.position[localIndex_] = beginAtom(i)->getPos();
108 >        data.position[localIndex_] = cutoffAtomList[0]->getPos();
109 >        if (needsVel)
110 >          data.velocity[localIndex_] = cutoffAtomList[0]->getVel();
111        } else {
112 +        std::vector<Atom *>::iterator i;
113 +        Atom * atom;
114 +        RealType totalMass = getMass();
115          data.position[localIndex_] = V3Zero;
116 +        if (needsVel) data.velocity[localIndex_] = V3Zero;
117 +        
118          for(atom = beginAtom(i); atom != NULL; atom = nextAtom(i)) {
119            data.position[localIndex_] += atom->getMass() * atom->getPos();
120 <        }        
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)) {
120 >          if (needsVel)
121              data.velocity[localIndex_] += atom->getMass() * atom->getVel();
122 <          }        
123 <          data.velocity[localIndex_] /= totalMass;
124 <        }
125 <      }
122 >        }    
123 >        data.position[localIndex_] /= totalMass;
124 >        if (needsVel) data.velocity[localIndex_] /= totalMass;          
125 >      }      
126      }
127  
128  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines