42 |
|
|
43 |
|
|
44 |
|
void Molecule::initialize( molInit &theInit ){ |
45 |
< |
|
45 |
> |
double totMass; |
46 |
> |
|
47 |
|
nAtoms = theInit.nAtoms; |
48 |
|
nMembers = nAtoms; |
49 |
|
nBonds = theInit.nBonds; |
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 |
|
} |
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 |
|
|
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; |
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; |
243 |
|
|
244 |
|
double Molecule::getTotalMass() |
245 |
|
{ |
246 |
< |
int natoms; |
230 |
< |
Atom** atoms; |
246 |
> |
|
247 |
|
double totalMass; |
248 |
|
|
233 |
– |
natoms = getNAtoms(); |
234 |
– |
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; |