| 3 |
|
#include "Atom.hpp" |
| 4 |
|
|
| 5 |
|
class CutoffGroup{ |
| 6 |
< |
public: |
| 7 |
< |
|
| 8 |
< |
void addAtom(Atom* atom) {cutoffAtomList.push_back(atom);} |
| 9 |
< |
|
| 10 |
< |
Atom* beginAtom(vector<Atom*>::iterator& i){ |
| 11 |
< |
i = cutoffAtomList.begin(); |
| 12 |
< |
return i != cutoffAtomList.end()? *i : NULL; |
| 13 |
< |
} |
| 14 |
< |
|
| 15 |
< |
Atom* nextAtom(vector<Atom*>::iterator& i){ |
| 16 |
< |
i++; |
| 17 |
< |
return i != cutoffAtomList.end()? *i : NULL; |
| 18 |
< |
} |
| 19 |
< |
|
| 20 |
< |
double getMass(){ |
| 21 |
< |
vector<Atom*>::iterator i; |
| 22 |
< |
Atom* atom; |
| 23 |
< |
double totalMass; |
| 24 |
< |
double mass; |
| 6 |
> |
public: |
| 7 |
> |
|
| 8 |
> |
CutoffGroup() { |
| 9 |
> |
haveTotalMass = false; |
| 10 |
> |
totalMass = 0.0; |
| 11 |
> |
} |
| 12 |
> |
|
| 13 |
> |
void addAtom(Atom* atom) {cutoffAtomList.push_back(atom);} |
| 14 |
> |
|
| 15 |
> |
Atom* beginAtom(vector<Atom*>::iterator& i){ |
| 16 |
> |
i = cutoffAtomList.begin(); |
| 17 |
> |
return i != cutoffAtomList.end()? *i : NULL; |
| 18 |
> |
} |
| 19 |
> |
|
| 20 |
> |
Atom* nextAtom(vector<Atom*>::iterator& i){ |
| 21 |
> |
i++; |
| 22 |
> |
return i != cutoffAtomList.end()? *i : NULL; |
| 23 |
> |
} |
| 24 |
> |
|
| 25 |
> |
double getMass(){ |
| 26 |
> |
vector<Atom*>::iterator i; |
| 27 |
> |
Atom* atom; |
| 28 |
> |
double mass; |
| 29 |
|
|
| 30 |
< |
totalMass = 0; |
| 30 |
> |
if (!haveTotalMass) { |
| 31 |
|
|
| 32 |
+ |
totalMass = 0; |
| 33 |
+ |
|
| 34 |
|
for(atom = beginAtom(i); atom != NULL; atom = nextAtom(i)){ |
| 35 |
|
mass = atom->getMass(); |
| 36 |
|
totalMass += mass; |
| 37 |
|
} |
| 38 |
|
|
| 39 |
< |
return totalMass; |
| 39 |
> |
haveTotalMass = true; |
| 40 |
|
} |
| 41 |
|
|
| 42 |
< |
void getCOM(double com[3]){ |
| 43 |
< |
vector<Atom*>::iterator i; |
| 44 |
< |
Atom* atom; |
| 45 |
< |
double pos[3]; |
| 40 |
< |
double totalMass; |
| 41 |
< |
double mass; |
| 42 |
< |
|
| 43 |
< |
com[0] = 0; |
| 44 |
< |
com[1] = 0; |
| 45 |
< |
com[2] = 0; |
| 46 |
< |
totalMass = 0; |
| 42 |
> |
return totalMass; |
| 43 |
> |
} |
| 44 |
> |
|
| 45 |
> |
void getCOM(double com[3]){ |
| 46 |
|
|
| 47 |
+ |
vector<Atom*>::iterator i; |
| 48 |
+ |
Atom* atom; |
| 49 |
+ |
double pos[3]; |
| 50 |
+ |
double mass; |
| 51 |
+ |
|
| 52 |
+ |
com[0] = 0; |
| 53 |
+ |
com[1] = 0; |
| 54 |
+ |
com[2] = 0; |
| 55 |
+ |
totalMass = getMass(); |
| 56 |
+ |
|
| 57 |
+ |
if (cutoffAtomList.size() == 1) { |
| 58 |
+ |
|
| 59 |
+ |
beginAtom(i)->getPos(com); |
| 60 |
+ |
|
| 61 |
+ |
} else { |
| 62 |
+ |
|
| 63 |
|
for(atom = beginAtom(i); atom != NULL; atom = nextAtom(i)){ |
| 64 |
|
mass = atom->getMass(); |
| 50 |
– |
totalMass += mass; |
| 65 |
|
atom->getPos(pos); |
| 66 |
|
com[0] += pos[0] * mass; |
| 67 |
|
com[1] += pos[1] * mass; |
| 68 |
|
com[2] += pos[2] * mass; |
| 69 |
|
} |
| 70 |
< |
|
| 70 |
> |
|
| 71 |
|
com[0] /= totalMass; |
| 72 |
|
com[1] /= totalMass; |
| 73 |
|
com[2] /= totalMass; |
| 60 |
– |
|
| 74 |
|
} |
| 75 |
< |
|
| 76 |
< |
int getNumAtom() {return cutoffAtomList.size();} |
| 75 |
> |
|
| 76 |
> |
} |
| 77 |
> |
|
| 78 |
> |
int getNumAtom() {return cutoffAtomList.size();} |
| 79 |
> |
|
| 80 |
> |
private: |
| 81 |
> |
vector<Atom*> cutoffAtomList; |
| 82 |
> |
bool haveTotalMass; |
| 83 |
> |
double totalMass; |
| 84 |
|
|
| 65 |
– |
private: |
| 66 |
– |
vector<Atom*> cutoffAtomList; |
| 67 |
– |
|
| 85 |
|
}; |
| 86 |
|
|
| 87 |
|
#endif |