ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new-templateless/OOPSE/libmdtools/NPT.cpp
(Generate patch)

Comparing:
trunk/OOPSE/libmdtools/NPT.cpp (file contents), Revision 829 by gezelter, Tue Oct 28 16:03:37 2003 UTC vs.
branches/new-templateless/OOPSE/libmdtools/NPT.cpp (file contents), Revision 850 by mmeineke, Mon Nov 3 22:07:17 2003 UTC

# Line 1 | Line 1
1 + #include <stdlib.h>
2   #include <math.h>
3 +
4   #include "Atom.hpp"
5   #include "SRI.hpp"
6   #include "AbstractClasses.hpp"
# Line 7 | Line 9
9   #include "Thermo.hpp"
10   #include "ReadWrite.hpp"
11   #include "Integrator.hpp"
12 < #include "simError.h"
12 > #include "simError.h"
13  
14   #ifdef IS_MPI
15   #include "mpiSimulation.hpp"
# Line 18 | Line 20
20   // modification of the Hoover algorithm:
21   //
22   //    Melchionna, S., Ciccotti, G., and Holian, B. L., 1993,
23 < //       Molec. Phys., 78, 533.
23 > //       Molec. Phys., 78, 533.
24   //
25   //           and
26 < //
26 > //
27   //    Hoover, W. G., 1986, Phys. Rev. A, 34, 2499.
28  
29 < template<typename T> NPT<T>::NPT ( SimInfo *theInfo, ForceFields* the_ff):
30 <  T( theInfo, the_ff )
29 > NPT::NPT ( SimInfo *theInfo, ForceFields* the_ff):
30 >  Integrator( theInfo, the_ff )
31   {
32 +  GenericData* data;
33 +  
34    chi = 0.0;
35    integralOfChidt = 0.0;
36    have_tau_thermostat = 0;
# Line 37 | Line 41 | template<typename T> NPT<T>::NPT ( SimInfo *theInfo, F
41    have_eta_tolerance = 0;
42    have_pos_iter_tolerance = 0;
43  
44 +  // retrieve chi and integralOfChidt from simInfo
45 +  data = info->getProperty(CHIVALUE_ID);
46 +  if(data != NULL ){
47 +    chi = data->getDval();
48 +  }
49 +
50 +  data = info->getProperty(INTEGRALOFCHIDT_ID);
51 +  if(data != NULL ){
52 +    integralOfChidt = data->getDval();
53 +  }
54 +
55    oldPos = new double[3*nAtoms];
56    oldVel = new double[3*nAtoms];
57    oldJi = new double[3*nAtoms];
# Line 48 | Line 63 | template<typename T> NPT<T>::NPT ( SimInfo *theInfo, F
63  
64   }
65  
66 < template<typename T> NPT<T>::~NPT() {
66 > NPT::~NPT() {
67    delete[] oldPos;
68    delete[] oldVel;
69    delete[] oldJi;
70   }
71  
72 < template<typename T> void NPT<T>::moveA() {
73 <
72 > void NPT::moveA() {
73 >
74    //new version of NPT
75    int i, j, k;
76    DirectionalAtom* dAtom;
# Line 69 | Line 84 | template<typename T> void NPT<T>::moveA() {
84    tStats->getPressureTensor( press );
85    instaPress = p_convert * (press[0][0] + press[1][1] + press[2][2]) / 3.0;
86    instaVol = tStats->getVolume();
87 <  
87 >
88    tStats->getCOM(COM);
89 <  
89 >
90    //evolve velocity half step
91    for( i=0; i<nAtoms; i++ ){
92  
# Line 83 | Line 98 | template<typename T> void NPT<T>::moveA() {
98      getVelScaleA( sc, vel );
99  
100      for (j=0; j < 3; j++) {
101 <      
101 >
102        // velocity half step  (use chi from previous step here):
103        vel[j] += dt2 * ((frc[j] / mass ) * eConvert - sc[j]);
104 <  
104 >
105      }
106  
107      atoms[i]->setVel( vel );
108 <  
108 >
109      if( atoms[i]->isDirectional() ){
110  
111        dAtom = (DirectionalAtom *)atoms[i];
112  
113        // get and convert the torque to body frame
114 <      
114 >
115        dAtom->getTrq( Tb );
116        dAtom->lab2Body( Tb );
117 <      
117 >
118        // get the angular momentum, and propagate a half step
119  
120        dAtom->getJ( ji );
121  
122 <      for (j=0; j < 3; j++)
122 >      for (j=0; j < 3; j++)
123          ji[j] += dt2 * (Tb[j] * eConvert - ji[j]*chi);
124 <      
124 >
125        this->rotationPropagation( dAtom, ji );
126 <      
126 >
127        dAtom->setJ( ji );
128 <    }    
128 >    }
129    }
130  
131    // evolve chi and eta  half step
132 <  
132 >
133    evolveChiA();
134    evolveEtaA();
135  
# Line 127 | Line 142 | template<typename T> void NPT<T>::moveA() {
142      for(j = 0; j < 3; j++)
143        oldPos[i*3 + j] = pos[j];
144    }
145 <  
146 <  //the first estimation of r(t+dt) is equal to  r(t)
147 <    
145 >
146 >  //the first estimation of r(t+dt) is equal to  r(t)
147 >
148    for(k = 0; k < 5; k ++){
149  
150      for(i =0 ; i < nAtoms; i++){
# Line 138 | Line 153 | template<typename T> void NPT<T>::moveA() {
153        atoms[i]->getPos(pos);
154  
155        this->getPosScale( pos, COM, i, sc );
156 <  
156 >
157        for(j = 0; j < 3; j++)
158          pos[j] = oldPos[i*3 + j] + dt*(vel[j] + sc[j]);
159  
160        atoms[i]->setPos( pos );
161      }
162 <    
162 >
163      if (nConstrained){
164        constrainA();
165      }
166    }
152    
167  
168 +
169    // Scale the box after all the positions have been moved:
170 <  
170 >
171    this->scaleSimBox();
172   }
173  
174 < template<typename T> void NPT<T>::moveB( void ){
175 <  
174 > void NPT::moveB( void ){
175 >
176    //new version of NPT
177    int i, j, k;
178    DirectionalAtom* dAtom;
179    double Tb[3], ji[3], sc[3];
180    double vel[3], frc[3];
181    double mass;
182 <  
182 >
183    // Set things up for the iteration:
184  
185    for( i=0; i<nAtoms; i++ ){
# Line 189 | Line 204 | template<typename T> void NPT<T>::moveB( void ){
204    // do the iteration:
205  
206    instaVol = tStats->getVolume();
207 <  
207 >
208    for (k=0; k < 4; k++) {
209 <    
209 >
210      instaTemp = tStats->getTemperature();
211      instaPress = tStats->getPressure();
212  
# Line 199 | Line 214 | template<typename T> void NPT<T>::moveB( void ){
214  
215      this->evolveChiB();
216      this->evolveEtaB();
217 <    
217 >
218      for( i=0; i<nAtoms; i++ ){
219  
220        atoms[i]->getFrc( frc );
221        atoms[i]->getVel(vel);
222 <      
222 >
223        mass = atoms[i]->getMass();
224 <      
224 >
225        getVelScaleB( sc, i );
226  
227        // velocity half step
228 <      for (j=0; j < 3; j++)
228 >      for (j=0; j < 3; j++)
229          vel[j] = oldVel[3*i+j] + dt2 * ((frc[j] / mass ) * eConvert - sc[j]);
230 <      
230 >
231        atoms[i]->setVel( vel );
232 <      
232 >
233        if( atoms[i]->isDirectional() ){
234  
235          dAtom = (DirectionalAtom *)atoms[i];
236 <  
237 <        // get and convert the torque to body frame      
238 <  
236 >
237 >        // get and convert the torque to body frame
238 >
239          dAtom->getTrq( Tb );
240 <        dAtom->lab2Body( Tb );      
241 <            
242 <        for (j=0; j < 3; j++)
240 >        dAtom->lab2Body( Tb );
241 >
242 >        for (j=0; j < 3; j++)
243            ji[j] = oldJi[3*i + j] + dt2 * (Tb[j] * eConvert - oldJi[3*i+j]*chi);
244 <      
244 >
245            dAtom->setJ( ji );
246        }
247      }
248 <    
248 >
249      if (nConstrained){
250        constrainB();
251 <    }    
252 <    
251 >    }
252 >
253      if ( this->chiConverged() && this->etaConverged() ) break;
254    }
255  
# Line 244 | Line 259 | template<typename T> void NPT<T>::moveB( void ){
259  
260   }
261  
262 < template<typename T> void NPT<T>::resetIntegrator() {
262 > void NPT::resetIntegrator() {
263    chi = 0.0;
264 <  T::resetIntegrator();
264 >  Integrator::resetIntegrator();
265   }
266  
267 < template<typename T> void NPT<T>::evolveChiA() {
267 > void NPT::evolveChiA() {
268    chi += dt2 * ( instaTemp / targetTemp - 1.0) / tt2;
269    oldChi = chi;
270   }
271  
272 < template<typename T> void NPT<T>::evolveChiB() {
273 <  
272 > void NPT::evolveChiB() {
273 >
274    prevChi = chi;
275    chi = oldChi + dt2 * ( instaTemp / targetTemp - 1.0) / tt2;
276   }
277  
278 < template<typename T> bool NPT<T>::chiConverged() {
279 <  
280 <  return ( fabs( prevChi - chi ) <= chiTolerance );  
278 > bool NPT::chiConverged() {
279 >
280 >  return ( fabs( prevChi - chi ) <= chiTolerance );
281   }
282  
283 < template<typename T> int NPT<T>::readyCheck() {
283 > int NPT::readyCheck() {
284  
285    //check parent's readyCheck() first
286 <  if (T::readyCheck() == -1)
286 >  if (Integrator::readyCheck() == -1)
287      return -1;
288 <
289 <  // First check to see if we have a target temperature.
290 <  // Not having one is fatal.
291 <  
288 >
289 >  // First check to see if we have a target temperature.
290 >  // Not having one is fatal.
291 >
292    if (!have_target_temp) {
293      sprintf( painCave.errMsg,
294               "NPT error: You can't use the NPT integrator\n"
# Line 293 | Line 308 | template<typename T> int NPT<T>::readyCheck() {
308      simError();
309      return -1;
310    }
311 <  
311 >
312    // We must set tauThermostat.
313 <  
313 >
314    if (!have_tau_thermostat) {
315      sprintf( painCave.errMsg,
316               "NPT error: If you use the NPT\n"
# Line 303 | Line 318 | template<typename T> int NPT<T>::readyCheck() {
318      painCave.isFatal = 1;
319      simError();
320      return -1;
321 <  }    
321 >  }
322  
323    // We must set tauBarostat.
324 <  
324 >
325    if (!have_tau_barostat) {
326      sprintf( painCave.errMsg,
327               "NPT error: If you use the NPT\n"
# Line 314 | Line 329 | template<typename T> int NPT<T>::readyCheck() {
329      painCave.isFatal = 1;
330      simError();
331      return -1;
332 <  }    
332 >  }
333  
334    if (!have_chi_tolerance) {
335      sprintf( painCave.errMsg,
# Line 323 | Line 338 | template<typename T> int NPT<T>::readyCheck() {
338      have_chi_tolerance = 1;
339      painCave.isFatal = 0;
340      simError();
341 <  }
341 >  }
342  
343    if (!have_eta_tolerance) {
344      sprintf( painCave.errMsg,
# Line 332 | Line 347 | template<typename T> int NPT<T>::readyCheck() {
347      have_eta_tolerance = 1;
348      painCave.isFatal = 0;
349      simError();
350 <  }
351 <  
350 >  }
351 >
352    // We need NkBT a lot, so just set it here: This is the RAW number
353    // of particles, so no subtraction or addition of constraints or
354    // orientational degrees of freedom:
355 <  
355 >
356    NkBT = (double)Nparticles * kB * targetTemp;
357 <  
357 >
358    // fkBT is used because the thermostat operates on more degrees of freedom
359    // than the barostat (when there are particles with orientational degrees
360    // of freedom).  ndf = 3 * (n_atoms + n_oriented -1) - n_constraint - nZcons
361 <  
361 >
362    fkBT = (double)info->ndf * kB * targetTemp;
363  
364    tt2 = tauThermostat * tauThermostat;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines