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