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

Comparing trunk/OOPSE/libmdtools/Molecule.cpp (file contents):
Revision 1104 by gezelter, Tue Apr 13 16:26:03 2004 UTC vs.
Revision 1136 by tim, Tue Apr 27 16:26:44 2004 UTC

# Line 42 | Line 42 | void Molecule::initialize( molInit &theInit ){
42  
43  
44   void Molecule::initialize( molInit &theInit ){
45 <
45 >  double totMass;
46 >  
47    nAtoms = theInit.nAtoms;
48    nMembers = nAtoms;
49    nBonds = theInit.nBonds;
# Line 58 | Line 59 | void Molecule::initialize( molInit &theInit ){
59    myRigidBodies = theInit.myRigidBodies;
60  
61    myIntegrableObjects = theInit.myIntegrableObjects;
62 <    
62 >
63 >  for (int i = 0; i < myRigidBodies.size(); i++)
64 >      myRigidBodies[i]->calcRefCoords();
65 >
66 >
67 >  //the mass ratio will never change during the simulation. Thus, we could
68 >  //just calculate it at the begining of the simulation
69 >  totMass = getTotalMass();
70 >  for(int i = 0; i < nAtoms; i ++)
71 >    myAtoms[i]->setMassRatio(myAtoms[i]->getMass()/totMass);  
72   }
73  
74   void Molecule::calcForces( void ){
75    
76    int i;
77 +  double com[3];
78  
79    for(i=0; i<myRigidBodies.size(); i++) {
80      myRigidBodies[i]->updateAtoms();
81    }
82  
83 +  //calculate the center of mass of the molecule
84 +  getCOM(com);  
85 +  for(int i = 0; i < nAtoms; i ++)
86 +    myAtoms[i]->setRc(com);  
87 +  
88 +
89    for(i=0; i<nBonds; i++){
90      myBonds[i]->calc_forces();
91    }
# Line 90 | Line 107 | double Molecule::getPotential( void ){
107    
108    int i;
109    double myPot = 0.0;
110 +
111 +  for(i=0; i<myRigidBodies.size(); i++) {
112 +    myRigidBodies[i]->updateAtoms();
113 +  }
114    
115    for(i=0; i<nBonds; i++){
116      myPot += myBonds[i]->get_potential();
# Line 128 | Line 149 | void Molecule::moveCOM(double delta[3]){
149    double aPos[3];
150    int i, j;
151  
152 <  for(i=0; i<nAtoms; i++) {
153 <    if(myAtoms[i] != NULL ) {
152 >  for(i=0; i<myIntegrableObjects.size(); i++) {
153 >    if(myIntegrableObjects[i] != NULL ) {
154        
155 <      myAtoms[i]->getPos( aPos );
155 >      myIntegrableObjects[i]->getPos( aPos );
156        
157        for (j=0; j< 3; j++)
158          aPos[j] += delta[j];
159  
160 <      myAtoms[i]->setPos( aPos );
160 >      myIntegrableObjects[i]->setPos( aPos );
161      }
162    }
163  
# Line 169 | Line 190 | void Molecule::getCOM( double COM[3] ) {
190  
191    mtot   = 0.0;
192  
193 <  for (i=0; i < nAtoms; i++) {
194 <    if (myAtoms[i] != NULL) {
193 >  for (i=0; i < myIntegrableObjects.size(); i++) {
194 >    if (myIntegrableObjects[i] != NULL) {
195  
196 <      mass = myAtoms[i]->getMass();
196 >      mass = myIntegrableObjects[i]->getMass();
197        mtot   += mass;
198        
199 <      myAtoms[i]->getPos( aPos );
199 >      myIntegrableObjects[i]->getPos( aPos );
200  
201        for( j = 0; j < 3; j++)
202          COM[j] += aPos[j] * mass;
# Line 199 | Line 220 | double Molecule::getCOMvel( double COMvel[3] ) {
220  
221    mtot   = 0.0;
222  
223 <  for (i=0; i < nAtoms; i++) {
224 <    if (myAtoms[i] != NULL) {
223 >  for (i=0; i < myIntegrableObjects.size(); i++) {
224 >    if (myIntegrableObjects[i] != NULL) {
225  
226 <      mass = myAtoms[i]->getMass();
226 >      mass = myIntegrableObjects[i]->getMass();
227        mtot   += mass;
228  
229 <      myAtoms[i]->getVel(aVel);
229 >      myIntegrableObjects[i]->getVel(aVel);
230  
231        for (j=0; j<3; j++)
232          COMvel[j] += aVel[j]*mass;
# Line 222 | Line 243 | double Molecule::getTotalMass()
243  
244   double Molecule::getTotalMass()
245   {
246 <  int natoms;
226 <  Atom** atoms;
246 >
247    double totalMass;
248    
229  natoms = getNAtoms();
230  atoms = getMyAtoms();
249    totalMass = 0;
250 <  for(int i =0; i < natoms; i++){
251 <    totalMass += atoms[i]->getMass();
250 >  for(int i =0; i < myIntegrableObjects.size(); i++){
251 >    totalMass += myIntegrableObjects[i]->getMass();
252    }
253  
254    return totalMass;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines