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 435 by mmeineke, Fri Mar 28 19:33:37 2003 UTC vs.
Revision 1167 by tim, Wed May 12 16:38:45 2004 UTC

# Line 1 | Line 1
1 < #include <cstdlib>
1 > #include <stdlib.h>
2  
3  
4   #include "Molecule.hpp"
5 + #include "simError.h"
6  
7  
8  
# Line 11 | Line 12 | Molecule::Molecule( void ){
12    myBonds = NULL;
13    myBends = NULL;
14    myTorsions = NULL;
14
15   }
16  
17
18
17   Molecule::~Molecule( void ){
18    int i;
19 +  CutoffGroup* cg;
20 +  vector<CutoffGroup*>::iterator iter;
21    
22    if( myAtoms != NULL ){
23      for(i=0; i<nAtoms; i++) if(myAtoms[i] != NULL ) delete myAtoms[i];
# Line 39 | Line 39 | Molecule::~Molecule( void ){
39      delete[] myTorsions;
40    }
41  
42 <  if( myExcludes != NULL ){
43 <    for(i=0; i<nExcludes; i++) if(myExcludes[i] != NULL ) delete myExcludes[i];
44 <    delete[] myExcludes;
45 <  }
42 >  for(cg = beginCutoffGroup(iter);  cg != NULL; cg = nextCutoffGroup(iter))
43 >    delete cg;
44 >  myCutoffGroups.clear();
45 >  
46   }
47  
48  
49   void Molecule::initialize( molInit &theInit ){
50  
51 +  CutoffGroup* curCutoffGroup;
52 +  vector<CutoffGroup*>::iterator iterCutoff;
53 +  Atom* cutoffAtom;
54 +  vector<Atom*>::iterator iterAtom;
55 +  int atomIndex;
56 +  
57    nAtoms = theInit.nAtoms;
58    nMembers = nAtoms;
59    nBonds = theInit.nBonds;
60    nBends = theInit.nBends;
61    nTorsions = theInit.nTorsions;
62 <  nExcludes = theInit.nExcludes;
62 >  nRigidBodies = theInit.nRigidBodies;
63    nOriented = theInit.nOriented;
64  
65    myAtoms = theInit.myAtoms;
66    myBonds = theInit.myBonds;
67    myBends = theInit.myBends;
68    myTorsions = theInit.myTorsions;
69 <  myExcludes = theInit.myExcludes;
70 <    
69 >  myRigidBodies = theInit.myRigidBodies;
70 >
71 >  myIntegrableObjects = theInit.myIntegrableObjects;
72 >
73 >  for (int i = 0; i < myRigidBodies.size(); i++)
74 >      myRigidBodies[i]->calcRefCoords();
75 >
76 >  myCutoffGroups = theInit.myCutoffGroups;
77 >  nCutoffGroups = myCutoffGroups.size();
78 >  
79   }
80  
81   void Molecule::calcForces( void ){
82    
83    int i;
84 +  double com[3];
85  
86 +  for(i=0; i<myRigidBodies.size(); i++) {
87 +    myRigidBodies[i]->updateAtoms();
88 +  }
89 +
90 +  //calculate the center of mass of the molecule
91 +  //getCOM(com);  
92 +  //for(int i = 0; i < nAtoms; i ++)
93 +  //  myAtoms[i]->setRc(com);  
94 +  
95 +
96    for(i=0; i<nBonds; i++){
97      myBonds[i]->calc_forces();
98    }
# Line 79 | Line 104 | void Molecule::calcForces( void ){
104    for(i=0; i<nTorsions; i++){
105      myTorsions[i]->calc_forces();
106    }
107 +
108 +  // Rigid Body forces and torques are done after the fortran force loop
109 +
110   }
111  
112  
# Line 86 | Line 114 | double Molecule::getPotential( void ){
114    
115    int i;
116    double myPot = 0.0;
117 +
118 +  for(i=0; i<myRigidBodies.size(); i++) {
119 +    myRigidBodies[i]->updateAtoms();
120 +  }
121    
122    for(i=0; i<nBonds; i++){
123      myPot += myBonds[i]->get_potential();
# Line 117 | Line 149 | void Molecule::printMe( void ){
149    for(i=0; i<nTorsions; i++){
150      myTorsions[i]->printMe();
151    }
152 +
153   }
154 +
155 + void Molecule::moveCOM(double delta[3]){
156 +  double aPos[3];
157 +  int i, j;
158 +
159 +  for(i=0; i<myIntegrableObjects.size(); i++) {
160 +    if(myIntegrableObjects[i] != NULL ) {
161 +      
162 +      myIntegrableObjects[i]->getPos( aPos );
163 +      
164 +      for (j=0; j< 3; j++)
165 +        aPos[j] += delta[j];
166 +
167 +      myIntegrableObjects[i]->setPos( aPos );
168 +    }
169 +  }
170 +
171 +  for(i=0; i<myRigidBodies.size(); i++) {
172 +
173 +      myRigidBodies[i]->getPos( aPos );
174 +
175 +      for (j=0; j< 3; j++)
176 +        aPos[j] += delta[j];
177 +      
178 +      myRigidBodies[i]->setPos( aPos );
179 +    }
180 + }
181 +
182 + void Molecule::atoms2rigidBodies( void ) {
183 +  int i;
184 +  for (i = 0; i < myRigidBodies.size(); i++) {
185 +    myRigidBodies[i]->calcForcesAndTorques();  
186 +  }
187 + }
188 +
189 + void Molecule::getCOM( double COM[3] ) {
190 +
191 +  double mass, mtot;
192 +  double aPos[3];
193 +  int i, j;
194 +
195 +  for (j=0; j<3; j++)
196 +    COM[j] = 0.0;
197 +
198 +  mtot   = 0.0;
199 +
200 +  for (i=0; i < myIntegrableObjects.size(); i++) {
201 +    if (myIntegrableObjects[i] != NULL) {
202 +
203 +      mass = myIntegrableObjects[i]->getMass();
204 +      mtot   += mass;
205 +      
206 +      myIntegrableObjects[i]->getPos( aPos );
207 +
208 +      for( j = 0; j < 3; j++)
209 +        COM[j] += aPos[j] * mass;
210 +
211 +    }
212 +  }
213 +
214 +  for (j = 0; j < 3; j++)
215 +    COM[j] /= mtot;
216 + }
217 +
218 + double Molecule::getCOMvel( double COMvel[3] ) {
219 +
220 +  double mass, mtot;
221 +  double aVel[3];
222 +  int i, j;
223 +
224 +
225 +  for (j=0; j<3; j++)
226 +    COMvel[j] = 0.0;
227 +
228 +  mtot   = 0.0;
229 +
230 +  for (i=0; i < myIntegrableObjects.size(); i++) {
231 +    if (myIntegrableObjects[i] != NULL) {
232 +
233 +      mass = myIntegrableObjects[i]->getMass();
234 +      mtot   += mass;
235 +
236 +      myIntegrableObjects[i]->getVel(aVel);
237 +
238 +      for (j=0; j<3; j++)
239 +        COMvel[j] += aVel[j]*mass;
240 +
241 +    }
242 +  }
243 +
244 +  for (j=0; j<3; j++)
245 +    COMvel[j] /= mtot;
246 +
247 +  return mtot;
248 +
249 + }
250 +
251 + double Molecule::getTotalMass()
252 + {
253 +
254 +  double totalMass;
255 +  
256 +  totalMass = 0;
257 +  for(int i =0; i < myIntegrableObjects.size(); i++){
258 +    totalMass += myIntegrableObjects[i]->getMass();
259 +  }
260 +
261 +  return totalMass;
262 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines