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 1879 by gezelter, Sun Jun 16 15:15:42 2013 UTC vs.
Revision 2065 by gezelter, Thu Mar 5 15:11:00 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 <    
106 <      totalMass = getMass();
109 <      
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 <        }        
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)) {
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