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

Comparing trunk/OOPSE/libmdtools/NPTi.cpp (file contents):
Revision 768 by mmeineke, Wed Sep 17 14:22:15 2003 UTC vs.
Revision 772 by gezelter, Fri Sep 19 16:01:07 2003 UTC

# Line 13 | Line 13
13   #include "mpiSimulation.hpp"
14   #endif
15  
16
16   // Basic isotropic thermostating and barostating via the Melchionna
17   // modification of the Hoover algorithm:
18   //
# Line 88 | Line 87 | template<typename T> void NPTi<T>::moveA() {
87      mass = atoms[i]->getMass();
88  
89      for (j=0; j < 3; j++) {
90 <      // velocity half step  (use chi from previous step here):
90 >      // velocity half step
91        vel[j] += dt2 * ((frc[j] / mass ) * eConvert - vel[j]*(chi + eta));
93  
92      }
93  
94      atoms[i]->setVel( vel );
# Line 142 | Line 140 | template<typename T> void NPTi<T>::moveA() {
140      }    
141    }
142  
143 <  // evolve chi and eta  half step
143 >  // advance chi half step
144    
145    chi += dt2 * ( instaTemp / targetTemp - 1.0) / tt2;
148  eta += dt2 * ( instaVol * (instaPress - targetPressure) / (p_convert*NkBT*tb2));
146  
147 <  //calculate the integral of chidt
147 >  // calculate the integral of chidt
148 >
149    integralOfChidt += dt2*chi;
150  
151 +  // advance eta half step
152 +
153 +  eta += dt2 * ( instaVol * (instaPress - targetPressure) / (p_convert*NkBT*tb2));
154 +
155    //save the old positions
156    for(i = 0; i < nAtoms; i++){
157      atoms[i]->getPos(pos);
# Line 208 | Line 210 | template<typename T> void NPTi<T>::moveB( void ){
210    double vel[3], frc[3];
211    double mass;
212  
213 <  double instTemp, instPress, instVol;
213 >  double instaTemp, instaPress, instaVol;
214    double tt2, tb2;
215    double oldChi, prevChi;
216 <  double oldEta, preEta;
216 >  double oldEta, prevEta;
217    
218    tt2 = tauThermostat * tauThermostat;
219    tb2 = tauBarostat * tauBarostat;
220  
219
221    // Set things up for the iteration:
222  
223    oldChi = chi;
# Line 243 | Line 244 | template<typename T> void NPTi<T>::moveB( void ){
244  
245    // do the iteration:
246  
247 <  instVol = tStats->getVolume();
247 >  instaVol = tStats->getVolume();
248    
249    for (k=0; k < 4; k++) {
250      
251 <    instTemp = tStats->getTemperature();
252 <    instPress = tStats->getPressure();
251 >    instaTemp = tStats->getTemperature();
252 >    instaPress = tStats->getPressure();
253  
254      // evolve chi another half step using the temperature at t + dt/2
255  
256      prevChi = chi;
257 <    chi = oldChi + dt2 * ( instTemp / targetTemp - 1.0) /
257 <      (tauThermostat*tauThermostat);
257 >    chi = oldChi + dt2 * ( instaTemp / targetTemp - 1.0) / tt2;
258  
259 <    preEta = eta;
260 <    eta = oldEta + dt2 * ( instVol * (instPress - targetPressure) /
259 >    prevEta = eta;
260 >
261 >    // advance eta half step and calculate scale factor for velocity
262 >
263 >    eta = oldEta + dt2 * ( instaVol * (instaPress - targetPressure) /
264         (p_convert*NkBT*tb2));
265  
266    
# Line 295 | Line 298 | template<typename T> void NPTi<T>::moveB( void ){
298      }    
299      
300      if (fabs(prevChi - chi) <=
301 <        chiTolerance && fabs(preEta -eta) <= etaTolerance)
301 >        chiTolerance && fabs(prevEta -eta) <= etaTolerance)
302        break;
303    }
304  
305 <  //calculate integral of chida
305 >  //calculate integral of chidt
306    integralOfChidt += dt2*chi;
307  
305
308   }
309  
310   template<typename T> void NPTi<T>::resetIntegrator() {
# Line 370 | Line 372 | template<typename T> int NPTi<T>::readyCheck() {
372      simError();
373    }
374  
375 <    if (!have_eta_tolerance) {
375 >  if (!have_eta_tolerance) {
376      sprintf( painCave.errMsg,
377               "NPTi warning: setting eta tolerance to 1e-6\n");
378      etaTolerance = 1e-6;
# Line 378 | Line 380 | template<typename T> int NPTi<T>::readyCheck() {
380      painCave.isFatal = 0;
381      simError();
382    }
383 <  // We need NkBT a lot, so just set it here:
384 <
383 >  
384 >  
385 >  // We need NkBT a lot, so just set it here: This is the RAW number
386 >  // of particles, so no subtraction or addition of constraints or
387 >  // orientational degrees of freedom:
388 >  
389    NkBT = (double)Nparticles * kB * targetTemp;
390 +  
391 +  // fkBT is used because the thermostat operates on more degrees of freedom
392 +  // than the barostat (when there are particles with orientational degrees
393 +  // of freedom).  ndf = 3 * (n_atoms + n_oriented -1) - n_constraint - nZcons
394 +  
395    fkBT = (double)info->ndf * kB * targetTemp;
396  
397    return 1;
# Line 389 | Line 400 | template<typename T> double NPTi<T>::getConservedQuant
400   template<typename T> double NPTi<T>::getConservedQuantity(void){
401  
402    double conservedQuantity;
403 +  double Three_NkBT;
404 +  double Energy;
405 +  double thermostat_kinetic;
406 +  double thermostat_potential;
407 +  double barostat_kinetic;
408 +  double barostat_potential;
409    double tb2;
410 <  double eta2;  
394 <  double E_NPT;
395 <  double U;
396 <  double TS;
397 <  double PV;
398 <  double extra;
410 >  double eta2;
411  
412 <  U = tStats->getTotalE();
412 >  Energy = tStats->getTotalE();
413  
414 <  TS = fkBT *
415 <    (integralOfChidt + tauThermostat * tauThermostat * chi * chi / 2.0) / eConvert;
414 >  thermostat_kinetic = fkBT* tauThermostat * tauThermostat * chi * chi /
415 >    (2.0 * eConvert);
416  
417 <  PV = (targetPressure * tStats->getVolume() / p_convert) / eConvert;
417 >  thermostat_potential = fkBT* integralOfChidt / eConvert;
418  
407  tb2 = tauBarostat * tauBarostat;
408  eta2 = eta * eta;
419  
420 +  barostat_kinetic = 3.0 * NkBT * tauBarostat * tauBarostat * eta * eta /
421 +    (2.0 * eConvert);
422 +  
423 +  barostat_potential = (targetPressure * tStats->getVolume() / p_convert) /
424 +    eConvert;
425  
426 <  extra = ((double)info->ndfTrans * kB * targetTemp * tb2 * eta2 / 2.0) / eConvert;
427 <
426 >  conservedQuantity = Energy + thermostat_kinetic + thermostat_potential +
427 >    barostat_kinetic + barostat_potential;
428 >  
429    cout.width(8);
430    cout.precision(8);
431  
432 <  
433 < //   cout << info->getTime() << "\t"
434 < //        << chi << "\t"
419 < //        << eta << "\t"
420 < //        << U << "\t"
421 < //        << TS << "\t"
422 < //        << PV << "\t"
423 < //        << extra << "\t"
424 < //        << U+TS+PV+extra << endl;
432 >  cerr << info->getTime() << "\t" << Energy << "\t" << thermostat_kinetic <<
433 >      "\t" << thermostat_potential << "\t" << barostat_kinetic <<
434 >      "\t" << barostat_potential << "\t" << conservedQuantity << endl;
435  
426  conservedQuantity = U+TS+PV+extra;
436    return conservedQuantity;
437   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines