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 708 by tim, Wed Aug 20 22:23:34 2003 UTC vs.
Revision 1113 by tim, Thu Apr 15 16:18:26 2004 UTC

# Line 1 | Line 1
1 < #include <cmath>
1 > #include <math.h>
2   #include <iostream>
3   using namespace std;
4  
# Line 35 | Line 35 | double Thermo::getKinetic(){
35    double aVel[3], aJ[3], I[3][3];
36    int j, 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 <      
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        for (j=0; j<3; j++)
57          kinetic += aJ[j]*aJ[j] / I[j][j];
58        
# Line 104 | Line 95 | double Thermo::getPotential(){
95    potential = potential_local;
96   #endif // is_mpi
97  
107 #ifdef IS_MPI
108  /*
109  std::cerr << "node " << worldRank << ": after pot = " << potential << "\n";
110  */
111 #endif
112
98    return potential;
99   }
100  
# Line 123 | Line 108 | double Thermo::getTemperature(){
108  
109   double Thermo::getTemperature(){
110  
111 <  const double kb = 1.9872179E-3; // boltzman's constant in kcal/(mol K)
111 >  const double kb = 1.9872156E-3; // boltzman's constant in kcal/(mol K)
112    double temperature;
113 <  
113 >
114    temperature = ( 2.0 * this->getKinetic() ) / ((double)info->ndf * kb );
115    return temperature;
116   }
117  
118 < double Thermo::getEnthalpy() {
118 > double Thermo::getVolume() {
119  
120 <  const double e_convert = 4.184E-4; // convert kcal/mol -> (amu A^2)/fs^2
121 <  double u, p, v;
137 <  double press[3][3];
120 >  return info->boxVol;
121 > }
122  
123 <  u = this->getTotalE();
123 > double Thermo::getPressure() {
124  
125 +  // Relies on the calculation of the full molecular pressure tensor
126 +  
127 +  const double p_convert = 1.63882576e8;
128 +  double press[3][3];
129 +  double pressure;
130 +
131    this->getPressureTensor(press);
142  p = (press[0][0] + press[1][1] + press[2][2]) / 3.0;
132  
133 <  v = this->getVolume();
133 >  pressure = p_convert * (press[0][0] + press[1][1] + press[2][2]) / 3.0;
134  
135 <  return (u + (p*v)/e_convert);
135 >  return pressure;
136   }
137  
138 < double Thermo::getVolume() {
138 > double Thermo::getPressureX() {
139  
140 <  return info->boxVol;
140 >  // Relies on the calculation of the full molecular pressure tensor
141 >  
142 >  const double p_convert = 1.63882576e8;
143 >  double press[3][3];
144 >  double pressureX;
145 >
146 >  this->getPressureTensor(press);
147 >
148 >  pressureX = p_convert * press[0][0];
149 >
150 >  return pressureX;
151   }
152  
153 < double Thermo::getPressure() {
153 > double Thermo::getPressureY() {
154  
155    // Relies on the calculation of the full molecular pressure tensor
156    
157    const double p_convert = 1.63882576e8;
158    double press[3][3];
159 <  double pressure;
159 >  double pressureY;
160  
161    this->getPressureTensor(press);
162  
163 <  pressure = p_convert * (press[0][0] + press[1][1] + press[2][2]) / 3.0;
163 >  pressureY = p_convert * press[1][1];
164  
165 <  return pressure;
165 >  return pressureY;
166   }
167  
168 + double Thermo::getPressureZ() {
169  
170 +  // Relies on the calculation of the full molecular pressure tensor
171 +  
172 +  const double p_convert = 1.63882576e8;
173 +  double press[3][3];
174 +  double pressureZ;
175 +
176 +  this->getPressureTensor(press);
177 +
178 +  pressureZ = p_convert * press[2][2];
179 +
180 +  return pressureZ;
181 + }
182 +
183 +
184   void Thermo::getPressureTensor(double press[3][3]){
185    // returns pressure tensor in units amu*fs^-2*Ang^-1
186    // routine derived via viral theorem description in:
# Line 227 | Line 241 | void Thermo::velocitize() {
241  
242   void Thermo::velocitize() {
243    
230  double x,y;
244    double aVel[3], aJ[3], I[3][3];
245    int i, j, vr, vd; // velocity randomizer loop counters
246    double vdrift[3];
# Line 248 | Line 261 | void Thermo::velocitize() {
261    n_oriented    = info->n_oriented;
262    n_constraints = info->n_constraints;
263    
264 <  kebar = kb * temperature * (double)info->ndf /
265 <    ( 2.0 * (double)info->ndfRaw );
264 >  kebar = kb * temperature * (double)info->ndfRaw /
265 >    ( 2.0 * (double)info->ndf );
266    
267    for(vr = 0; vr < n_atoms; vr++){
268      
# Line 257 | Line 270 | void Thermo::velocitize() {
270  
271      av2 = 2.0 * kebar / atoms[vr]->getMass();
272      vbar = sqrt( av2 );
273 <
261 < //     vbar = sqrt( 8.31451e-7 * temperature / atoms[vr]->getMass() );
262 <    
273 >
274      // picks random velocities from a gaussian distribution
275      // centered on vbar
276  
# Line 355 | Line 366 | void Thermo::getCOMVel(double vdrift[3]){
366    
367   }
368  
369 + void Thermo::getCOM(double COM[3]){
370 +
371 +  double mtot, mtot_local;
372 +  double aPos[3], amass;
373 +  double COM_local[3];
374 +  int i, n_atoms, j;
375 +  Atom** atoms;
376 +
377 +  // We are very careless here with the distinction between n_atoms and n_local
378 +  // We should really fix this before someone pokes an eye out.
379 +
380 +  n_atoms = info->n_atoms;  
381 +  atoms   = info->atoms;
382 +
383 +  mtot_local = 0.0;
384 +  COM_local[0] = 0.0;
385 +  COM_local[1] = 0.0;
386 +  COM_local[2] = 0.0;
387 +  
388 +  for(i = 0; i < n_atoms; i++){
389 +    
390 +    amass = atoms[i]->getMass();
391 +    atoms[i]->getPos( aPos );
392 +
393 +    for(j = 0; j < 3; j++)
394 +      COM_local[j] += aPos[j] * amass;
395 +    
396 +    mtot_local += amass;
397 +  }
398 +
399 + #ifdef IS_MPI
400 +  MPI_Allreduce(&mtot_local,&mtot,1,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
401 +  MPI_Allreduce(COM_local,COM,3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
402 + #else
403 +  mtot = mtot_local;
404 +  for(i = 0; i < 3; i++) {
405 +    COM[i] = COM_local[i];
406 +  }
407 + #endif
408 +    
409 +  for (i = 0; i < 3; i++) {
410 +    COM[i] = COM[i] / mtot;
411 +  }
412 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines