ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-3.0/src/primitives/CutoffGroup.hpp
(Generate patch)

Comparing branches/new_design/OOPSE-3.0/src/primitives/CutoffGroup.hpp (file contents):
Revision 1683, Thu Oct 28 22:34:02 2004 UTC vs.
Revision 1695 by tim, Mon Nov 1 22:52:57 2004 UTC

# Line 1 | Line 1
1 < #ifndef _CUTOFFGROUP_H_
2 < #define _CUTOFFGROUP_H_
3 < #include "primitives/Atom.hpp"
4 <
5 < class CutoffGroup{
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 <    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 <      haveTotalMass = true;
40 <    }
41 <    
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();
65 <        atom->getPos(pos);
66 <        com[0] += pos[0] * mass;
67 <        com[1] += pos[1] * mass;
68 <        com[2] += pos[2] * mass;
69 <      }
70 <      
71 <      com[0] /= totalMass;
72 <      com[1] /= totalMass;
73 <      com[2] /= totalMass;
74 <    }
75 <    
76 <  }
77 <  
78 <  int getNumAtom() {return cutoffAtomList.size();}
79 <
80 <  int getGlobalIndex() {return globalIndex;}
81 <  void setGlobalIndex(int id) {this->globalIndex = id;}
82 < private:
83 <  vector<Atom*> cutoffAtomList;
84 <  bool haveTotalMass;
85 <  double totalMass;
86 <  int globalIndex;
87 <
88 < };
89 <
90 < #endif
1 > #ifndef PRIMITIVES_CUTOFFGROUP_HPP
2 > #define PRIMITIVES_CUTOFFGROUP_HPP
3 >
4 > #include "primitives/Atom.hpp"
5 > #include "math/Vector3.hpp"
6 >
7 > namespace oopse {
8 >
9 > 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 >  Atom* beginAtom(std::vector<Atom*>::iterator& i){
20 >    i = cutoffAtomList.begin();
21 >    return i != cutoffAtomList.end()? *i : NULL;
22 >  }
23 >  
24 >  Atom* nextAtom(std::vector<Atom*>::iterator& i){
25 >    i++;
26 >    return i != cutoffAtomList.end()? *i : NULL;
27 >  }
28 >  
29 >  double getMass(){
30 >    std::vector<Atom*>::iterator i;
31 >    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 >  void getCOM(Vector3d& com){
50 >
51 >    std::vector<Atom*>::iterator i;
52 >    Atom* atom;
53 >    Vector3d pos;
54 >    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 >  std::vector<Atom*> cutoffAtomList;
88 >  bool haveTotalMass;
89 >  double totalMass;
90 >  int globalIndex;
91 >
92 > };
93 >
94 > }//end namespace oopse
95 > #endif //PRIMITIVES_CUTOFFGROUP_HPP

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines