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

Comparing trunk/SHAPES/RigidBody.cpp (file contents):
Revision 1276 by chrisfen, Thu Jun 17 21:27:38 2004 UTC vs.
Revision 1283 by gezelter, Mon Jun 21 15:54:27 2004 UTC

# Line 1 | Line 1
1   #include <math.h>
2 + #include <iostream>
3   #include "RigidBody.hpp"
4   #include "VDWAtom.hpp"
5   #include "MatVec3.h"
# Line 47 | Line 48 | void RigidBody::setEuler( double phi, double theta, do
48      A[2][1] = -cos(phi) * sin(theta);
49      A[2][2] = cos(theta);
50  
51 +    printf("A[2][x] = %lf\t%lf\t%lf\n", A[2][0], A[2][1], A[2][2]);
52 +
53   }
54  
55   void RigidBody::getQ( double q[4] ){
# Line 173 | Line 176 | void RigidBody::calcRefCoords( ) {
176  
177   void RigidBody::calcRefCoords( ) {
178  
179 <  int i, j, it, n_linear_coords;
179 >  int i, j, it, n_linear_coords, pAxis, maxAxis, midAxis;
180    double mtmp;
181    vec3 apos;
182    double refCOM[3];
183    vec3 ptmp;
184    double Itmp[3][3];
185 +  double pAxisMat[3][3], pAxisRotMat[3][3];
186    double evals[3];
187    double r, r2, len;
188 <
188 >  double iMat[3][3];
189 >  double test[3];
190 >  
191    // First, find the center of mass:
192    
193    mass = 0.0;
# Line 193 | Line 199 | void RigidBody::calcRefCoords( ) {
199      mass += mtmp;
200  
201      apos = refCoords[i];
196    
202      for(j = 0; j < 3; j++) {
203        refCOM[j] += apos[j]*mtmp;    
204      }    
# Line 257 | Line 262 | void RigidBody::calcRefCoords( ) {
262    if (n_linear_coords > 1) {
263            printf(
264                 "RigidBody error.\n"
265 <               "\tOOPSE found more than one axis in this rigid body with a vanishing \n"
265 >               "\tSHAPES found more than one axis in this rigid body with a vanishing \n"
266                 "\tmoment of inertia.  This can happen in one of three ways:\n"
267                 "\t 1) Only one atom was specified, or \n"
268                 "\t 2) All atoms were specified at the same location, or\n"
# Line 266 | Line 271 | void RigidBody::calcRefCoords( ) {
271                 );
272                 exit(-1);    
273    }
274 <  
274 >
275    // renormalize column vectors:
276    
277    for (i=0; i < 3; i++) {
# Line 279 | Line 284 | void RigidBody::calcRefCoords( ) {
284        sU[i][j] /= len;
285      }
286    }
287 +  
288 +  //sort and reorder the moment axes
289 +
290 +  // The only problem below is for molecules like C60 with 3 nearly identical
291 +  // non-zero moments of inertia.  In this case it doesn't really matter which is
292 +  // the principal axis, so they get assigned nearly randomly depending on the
293 +  // floating point comparison between eigenvalues
294 +  if (! is_linear) {
295 +    pAxis = 0;
296 +    maxAxis = 0;
297 +  
298 +    for (i = 0; i < 3; i++) {
299 +      if (evals[i] < evals[pAxis]) pAxis = i;
300 +      if (evals[i] > evals[maxAxis]) maxAxis = i;
301 +    }
302 +  
303 +    midAxis = 0;
304 +    for (i=0; i < 3; i++) {
305 +      if (pAxis != i && maxAxis != i) midAxis = i;
306 +    }
307 +  } else {
308 +    pAxis = linear_axis;
309 +    // linear molecules have one zero moment of inertia and two identical
310 +    // moments of inertia.  In this case, it doesn't matter which is chosen
311 +    // as mid and which is max, so just permute from the pAxis:
312 +    midAxis = (pAxis + 1)%3;
313 +    maxAxis = (pAxis + 2)%3;
314 +  }
315 +      
316 +  //let z be the smallest and x be the largest eigenvalue axes
317 +  for (i=0; i<3; i++){
318 +    pAxisMat[i][2] = sU[i][pAxis];
319 +    pAxisMat[i][1] = sU[i][midAxis];
320 +    pAxisMat[i][0] = sU[i][maxAxis];
321 +  }
322 +    
323 +  //calculate the proper rotation matrix
324 +  transposeMat3(pAxisMat, pAxisRotMat);
325 +  
326 +  
327 +  for (i=0; i<myAtoms.size(); i++){
328 +    apos = refCoords[i];
329 +    printf("%f\t%f\t%f\n",apos[0],apos[1],apos[2]);
330 +  }
331 +    
332 +  //rotate the rigid body to the principle axis frame
333 +  for (i = 0; i < myAtoms.size(); i++) {
334 +    matVecMul3(pAxisRotMat, refCoords[i].vec, refCoords[i].vec);
335 +    myAtoms[i]->setPos(refCoords[i].vec);
336 +  }
337 +  
338 +  for (i=0; i<myAtoms.size(); i++){
339 +    apos = refCoords[i];
340 +    printf("%f\t%f\t%f\n",apos[0],apos[1],apos[2]);
341 +  }
342 +  
343 +  identityMat3(iMat);
344 +  setA(iMat);
345   }
346  
347   void RigidBody::doEulerToRotMat(double euler[3], double myA[3][3] ){
# Line 473 | Line 536 | void RigidBody::getAtomRefCoor(double pos[3], int inde
536    pos[2] = ref[2];
537    
538   }
539 +
540 + double RigidBody::getAtomRpar(int index){
541 +  
542 +  return myAtoms[index]->getRpar();
543 +  
544 + }
545 +
546 + double RigidBody::getAtomEps(int index){
547 +  
548 +  return myAtoms[index]->getEps();
549 +  
550 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines