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 2056 by gezelter, Sun Jun 16 15:15:42 2013 UTC vs.
Revision 2057 by gezelter, Tue Mar 3 15:22:26 2015 UTC

# Line 82 | Line 82 | namespace OpenMD {
82  
83      std::vector<Atom*> getAtoms() { return cutoffAtomList; }
84      RealType getMass() {
85      std::vector<Atom *>::iterator i;
85        
86        if (!haveTotalMass) {
87 <        totalMass = 0;
87 >        totalMass = 0.0;
88          
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;
# Line 99 | Line 99 | namespace OpenMD {
99      }
100      
101      void updateCOM() {
102      std::vector<Atom *>::iterator i;
103      Atom * atom;
102  
103 <      DataStorage&  data = snapshotMan_->getCurrentSnapshot()->*storage_;
104 <      int storageLayout = data.getStorageLayout();
105 <    
108 <      totalMass = getMass();
109 <      
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 <        }        
117 <        data.position[localIndex_] /= totalMass;
118 <      }
119 <
120 <      if (storageLayout & DataStorage::dslVelocity) {
121 <        if (cutoffAtomList.size() == 1) {
122 <          data.velocity[localIndex_] = beginAtom(i)->getVel();
123 <        } else {
124 <          data.velocity[localIndex_] = V3Zero;
125 <          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