ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-3.0/test/brains/Molecule.cpp
(Generate patch)

Comparing trunk/OOPSE-3.0/test/brains/Molecule.cpp (file contents):
Revision 1689 by tim, Fri Oct 29 20:54:04 2004 UTC vs.
Revision 1690 by tim, Fri Oct 29 22:37:59 2004 UTC

# Line 24 | Line 24
24   */
25  
26   /**
27 < * @file Molecule.hpp
27 > * @file Molecule.cpp
28   * @author    tlin
29 < * @date  10/25/2004
29 > * @date  10/28/2004
30   * @version 1.0
31   */
32  
33   #include "primitives/Molecule.hpp"
34 + #include <algorithm>
35  
36   namespace oopse {
37  
# Line 47 | Line 48 | Molecule::~Molecule() {
48      
49   }
50  
51 + void Molecule::addAtom(Atom* atom) {
52 +    if (atoms_.find(atom) == atoms_.end()) {
53 +        atoms_.push_back(atom);
54 +    }
55 + }
56  
57 + void Molecule::addBond(Bond* bond) {
58 +    if (bonds_.find(bond) == bonds_.end()) {
59 +        bonds_.push_back(bond);
60 +    }
61 + }
62 +
63 + void Molecule::addBend(Bend* bend) {
64 +    if (bends_.find(bend) == bends_.end()) {
65 +        bends_.push_back(bend);
66 +    }
67 + }
68 +
69 + void Molecule::addTorsion(Torsion* torsion) {
70 +    if (torsions_.find(torsion) == torsions_.end()) {
71 +        torsions_.push_back(torsion);
72 +    }
73 + }
74 +
75 + void Molecule::addRigidBody(RigidBody *rb) {
76 +    if (rigidBodies_.find(bond) == bonds_.end()) {
77 +        rigidBodies_.push_back(rb);
78 +    }
79 + }
80 +
81 + void Molecule::addCutoffGroup(CutoffGroup* cp) {
82 +    if (cutoffGroups_.find(bond) == bonds_.end()) {
83 +        cutoffGroups_.push_back(cp);
84 +    }
85 +
86 + }
87 +
88 + void Molecule::complete() {
89 +    
90 +    std::set<Atom*> allAtoms;
91 +    allAtoms.insert(atoms_.begin(), atoms_.end());
92 +
93 +    std::set<Atom*> rigidAtoms;
94 +    RigidBody* rb;
95 +    std::vector<RigidBody*> rbIter;
96 +
97 +    
98 +    for (rb = beginRigidBody(rbIter); rb != NULL; rb = nextRigidBody(rbIter)) {
99 +        rigidAtoms.insert(rb->beginAtomIter(), rb->endAtomIter());
100 +    }
101 +
102 +    //find all free atoms (which do not belong to rigid bodies)  
103 +    //performs the "difference" operation from set theory,  the output range contains a copy of every
104 +    //element that is contained in [allAtoms.begin(), allAtoms.end()) and not contained in
105 +    //[rigidAtoms.begin(), rigidAtoms.end()).
106 +    std::set_difference(allAtoms.begin(), allAtoms.end(), rigidAtoms.begin(), rigidAtoms.end(),
107 +                            std::back_inserter(integrableObjects_));
108 +
109 +    if (integrableObjects_.size() != allAtoms.size() - rigidAtoms.size()) {
110 +        //Some atoms in rigidAtoms are not in allAtoms, something must be wrong
111 +    }
112 +
113 +    integrableObjects_.insert(integrableObjects_.end(), rigidBodies_.begin(), rigidBodies_.end());
114 + }
115 +
116   Atom* Molecule::beginAtom(std::vector<Atom*>::iterator& i) {
117      i = atoms_.begin();
118      return (i == atoms_.end()) ? NULL : *i;
# Line 148 | Line 213 | void Molecule::calcForces() {
213      
214   }
215  
216 + double Molecule::getPotential() {
217 +    //RigidBody* rb;
218 +    Bond* bond;
219 +    Bend* bend;
220 +    Torsion* torsion;
221 +    //std::vector<RigidBody*> rbIter;
222 +    std::vector<Bond*> bondIter;;
223 +    std::vector<Bend*> bendIter;
224 +    std::vector<Torsion*> torsionIter;
225 +
226 +    double potential = 0;
227 +    
228 +    //for (rb = beginRigidBody(rbIter); rb != NULL; rb = nextRigidBody(rbIter)) {
229 +    //    rb->updateAtoms();
230 +    //}
231 +
232 +    for (bond = beginBond(bondIter); bond != NULL; bond = nextBond(bondIter)) {
233 +        potential += bond->getPotential();
234 +    }
235 +
236 +    for (bend = beginBend(bendIter); bend != NULL; bend = nextBend(bendIter)) {
237 +        potential += bend->getPotential();
238 +    }
239 +
240 +    for (torsion = beginTorsion(torsionIter); torsion != NULL; torsion = nextTorsion(torsionIter)) {
241 +        potential += torsion->getPotential();
242 +    }
243 +    
244 +    return potential;
245 + }
246 +
247 + Vector3d Molecule::getCom() {
248 +    StuntDouble* sd;
249 +    std::vector<StuntDouble*>::iterator i;
250 +    Vector3d com;
251 +    double totalMass = 0;
252 +    double mass;
253 +    
254 +    for (sd = beginIntegrableObject(i); sd != NULL; sd = nextIntegrableObject(i)){
255 +        mass = sd->getMass();
256 +        totalMass += mass;
257 +        com += sd->getPos() * mass;    
258 +    }
259 +
260 +    com /= totalMass;
261 +
262 +    return com;
263 + }
264 +
265 + void Molecule::moveCom(const Vetor3d& delta) {
266 +    StuntDouble* sd;
267 +    std::vector<StuntDouble*>::iterator i;
268 +    
269 +    for (sd = beginIntegrableObject(i); sd != NULL; sd = nextIntegrableObject(i)){
270 +        s->setPos(sd->getPos() + delta);
271 +    }
272 +
273 + }
274 +
275 + Vector3d Molecule::getComVel() {
276 +    StuntDouble* sd;
277 +    std::vector<StuntDouble*>::iterator i;
278 +    Vector3d velCom;
279 +    double totalMass = 0;
280 +    double mass;
281 +    
282 +    for (sd = beginIntegrableObject(i); sd != NULL; sd = nextIntegrableObject(i)){
283 +        mass = sd->getMass();
284 +        totalMass += mass;
285 +        velCom += sd->getVel() * mass;    
286 +    }
287 +
288 +    velCom /= totalMass;
289 +
290 +    return velCom;
291 + }
292 +
293 + std::ostream& operator <<(std::ostream& o, const Molecule& mol) {
294 +    o << std::endl;
295 +    o << "Molecule " << mol.getGlobalIndex() << "has: " << std::endl;
296 +    o << mol.getNAtoms() << " atoms" << std::endl;
297 +    o << mol.getNBonds() << " bonds" << std::endl;
298 +    o << mol.getNBends() << " bends" << std::endl;
299 +    o << mol.getNTorsions() << " torsions" << std::endl;
300 +    o << mol.getNRigidBodies() << " rigid bodies" << std::endl;
301 +    o << mol.getNIntegrableObjects() << "integrable objects" << std::endl;
302 +    o << mol.getNCutoffGroups() << "cutoff groups" << std::endl;
303 +
304 +    return o;
305 + }
306 +
307   }//end namespace oopse

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines