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

Comparing trunk/OOPSE/libmdtools/Thermo.cpp (file contents):
Revision 755 by mmeineke, Tue Sep 9 20:35:25 2003 UTC vs.
Revision 1125 by gezelter, Mon Apr 19 22:13:01 2004 UTC

# Line 1 | Line 1
1 < #include <cmath>
1 > #include <math.h>
2   #include <iostream>
3   using namespace std;
4  
# Line 33 | Line 33 | double Thermo::getKinetic(){
33    double kinetic;
34    double amass;
35    double aVel[3], aJ[3], I[3][3];
36 <  int j, kl;
36 >  int i, j, k, kl;
37  
38  DirectionalAtom *dAtom;
39
40  int n_atoms;
38    double kinetic_global;
39 <  Atom** atoms;
43 <
39 >  vector<StuntDouble *> integrableObjects = info->integrableObjects;
40    
45  n_atoms = info->n_atoms;
46  atoms = info->atoms;
47
41    kinetic = 0.0;
42    kinetic_global = 0.0;
50  for( kl=0; kl < n_atoms; kl++ ){
51    
52    atoms[kl]->getVel(aVel);
53    amass = atoms[kl]->getMass();
54    
55    for (j=0; j < 3; j++)
56      kinetic += amass * aVel[j] * aVel[j];
43  
44 <    if( atoms[kl]->isDirectional() ){
45 <            
46 <      dAtom = (DirectionalAtom *)atoms[kl];
44 >  for (kl=0; kl<integrableObjects.size(); kl++) {
45 >    integrableObjects[kl]->getVel(aVel);
46 >    amass = integrableObjects[kl]->getMass();
47  
48 <      dAtom->getJ( aJ );
49 <      dAtom->getI( I );
50 <      
51 <      for (j=0; j<3; j++)
52 <        kinetic += aJ[j]*aJ[j] / I[j][j];
53 <      
54 <    }
48 >   for(j=0; j<3; j++)
49 >      kinetic += amass*aVel[j]*aVel[j];
50 >
51 >   if (integrableObjects[kl]->isDirectional()){
52 >
53 >      integrableObjects[kl]->getJ( aJ );
54 >      integrableObjects[kl]->getI( I );
55 >
56 >      if (integrableObjects[kl]->isLinear()) {
57 >        i = integrableObjects[kl]->linearAxis();
58 >        j = (i+1)%3;
59 >        k = (i+2)%3;
60 >        kinetic += aJ[j]*aJ[j]/I[j][j] + aJ[k]*aJ[k]/I[k][k];
61 >      } else {
62 >        for (j=0; j<3; j++)
63 >          kinetic += aJ[j]*aJ[j] / I[j][j];
64 >      }
65 >   }
66    }
67   #ifdef IS_MPI
68    MPI_Allreduce(&kinetic,&kinetic_global,1,MPI_DOUBLE,
69                  MPI_SUM, MPI_COMM_WORLD);
70    kinetic = kinetic_global;
71   #endif //is_mpi
72 <
72 >  
73    kinetic = kinetic * 0.5 / e_convert;
74  
75    return kinetic;
# Line 104 | Line 101 | double Thermo::getPotential(){
101    potential = potential_local;
102   #endif // is_mpi
103  
107 #ifdef IS_MPI
108  /*
109  std::cerr << "node " << worldRank << ": after pot = " << potential << "\n";
110  */
111 #endif
112
104    return potential;
105   }
106  
# Line 123 | Line 114 | double Thermo::getTemperature(){
114  
115   double Thermo::getTemperature(){
116  
117 <  const double kb = 1.9872179E-3; // boltzman's constant in kcal/(mol K)
117 >  const double kb = 1.9872156E-3; // boltzman's constant in kcal/(mol K)
118    double temperature;
119 <  
119 >
120    temperature = ( 2.0 * this->getKinetic() ) / ((double)info->ndf * kb );
121    return temperature;
131 }
132
133 double Thermo::getEnthalpy() {
134
135  const double e_convert = 4.184E-4; // convert kcal/mol -> (amu A^2)/fs^2
136  double u, p, v;
137  double press[3][3];
138
139  u = this->getTotalE();
140
141  this->getPressureTensor(press);
142  p = (press[0][0] + press[1][1] + press[2][2]) / 3.0;
143
144  v = this->getVolume();
145
146  return (u + (p*v)/e_convert);
122   }
123  
124   double Thermo::getVolume() {
# Line 272 | Line 247 | void Thermo::velocitize() {
247  
248   void Thermo::velocitize() {
249    
275  double x,y;
250    double aVel[3], aJ[3], I[3][3];
251    int i, j, vr, vd; // velocity randomizer loop counters
252    double vdrift[3];
# Line 293 | Line 267 | void Thermo::velocitize() {
267    n_oriented    = info->n_oriented;
268    n_constraints = info->n_constraints;
269    
270 <  kebar = kb * temperature * (double)info->ndf /
271 <    ( 2.0 * (double)info->ndfRaw );
270 >  kebar = kb * temperature * (double)info->ndfRaw /
271 >    ( 2.0 * (double)info->ndf );
272    
273    for(vr = 0; vr < n_atoms; vr++){
274      
# Line 302 | Line 276 | void Thermo::velocitize() {
276  
277      av2 = 2.0 * kebar / atoms[vr]->getMass();
278      vbar = sqrt( av2 );
279 <
306 < //     vbar = sqrt( 8.31451e-7 * temperature / atoms[vr]->getMass() );
307 <    
279 >
280      // picks random velocities from a gaussian distribution
281      // centered on vbar
282  
# Line 400 | Line 372 | void Thermo::getCOMVel(double vdrift[3]){
372    
373   }
374  
375 + void Thermo::getCOM(double COM[3]){
376 +
377 +  double mtot, mtot_local;
378 +  double aPos[3], amass;
379 +  double COM_local[3];
380 +  int i, n_atoms, j;
381 +  Atom** atoms;
382 +
383 +  // We are very careless here with the distinction between n_atoms and n_local
384 +  // We should really fix this before someone pokes an eye out.
385 +
386 +  n_atoms = info->n_atoms;  
387 +  atoms   = info->atoms;
388 +
389 +  mtot_local = 0.0;
390 +  COM_local[0] = 0.0;
391 +  COM_local[1] = 0.0;
392 +  COM_local[2] = 0.0;
393 +  
394 +  for(i = 0; i < n_atoms; i++){
395 +    
396 +    amass = atoms[i]->getMass();
397 +    atoms[i]->getPos( aPos );
398 +
399 +    for(j = 0; j < 3; j++)
400 +      COM_local[j] += aPos[j] * amass;
401 +    
402 +    mtot_local += amass;
403 +  }
404 +
405 + #ifdef IS_MPI
406 +  MPI_Allreduce(&mtot_local,&mtot,1,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
407 +  MPI_Allreduce(COM_local,COM,3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
408 + #else
409 +  mtot = mtot_local;
410 +  for(i = 0; i < 3; i++) {
411 +    COM[i] = COM_local[i];
412 +  }
413 + #endif
414 +    
415 +  for (i = 0; i < 3; i++) {
416 +    COM[i] = COM[i] / mtot;
417 +  }
418 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines