58 CutoffGroup() : globalIndex(-1), localIndex_(-1), snapshotMan_(NULL) {
59 storage_ = &Snapshot::cgData;
60 haveTotalMass =
false;
69 void addAtom(
Atom* atom) { cutoffAtomList.push_back(atom); }
71 Atom* beginAtom(std::vector<Atom*>::iterator& i) {
72 i = cutoffAtomList.begin();
73 return i != cutoffAtomList.end() ? *i : NULL;
76 Atom* nextAtom(std::vector<Atom*>::iterator& i) {
78 return i != cutoffAtomList.end() ? *i : NULL;
81 std::vector<Atom*> getAtoms() {
return cutoffAtomList; }
86 std::vector<Atom*>::iterator i;
87 for (Atom* atom = beginAtom(i); atom != NULL; atom = nextAtom(i)) {
88 RealType mass = atom->
getMass();
99 DataStorage& data = snapshotMan_->getCurrentSnapshot()->*storage_;
100 bool needsVel =
false;
101 if (data.getStorageLayout() & DataStorage::dslVelocity) needsVel =
true;
103 if (cutoffAtomList.size() == 1) {
104 data.position[localIndex_] = cutoffAtomList[0]->getPos();
105 if (needsVel) data.velocity[localIndex_] = cutoffAtomList[0]->getVel();
107 std::vector<Atom*>::iterator i;
109 RealType totalMass = getMass();
110 data.position[localIndex_] = V3Zero;
111 if (needsVel) data.velocity[localIndex_] = V3Zero;
113 for (atom = beginAtom(i); atom != NULL; atom = nextAtom(i)) {
114 data.position[localIndex_] += atom->getMass() * atom->getPos();
116 data.velocity[localIndex_] += atom->getMass() * atom->getVel();
118 data.position[localIndex_] /= totalMass;
119 if (needsVel) data.velocity[localIndex_] /= totalMass;
124 return ((snapshotMan_->getCurrentSnapshot())->*storage_)
125 .position[localIndex_];
128 return ((snapshotMan_->getCurrentSnapshot())->*storage_)
129 .velocity[localIndex_];
132 size_t getNumAtom() {
return cutoffAtomList.size(); }
134 int getGlobalIndex() {
return globalIndex; }
136 void setGlobalIndex(
int id) { this->globalIndex = id; }
151 std::vector<Atom*> cutoffAtomList;
157 DataStoragePointer storage_;