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

Comparing trunk/OOPSE/libmdtools/NPTf.cpp (file contents):
Revision 600 by gezelter, Mon Jul 14 22:38:13 2003 UTC vs.
Revision 763 by tim, Mon Sep 15 16:52:02 2003 UTC

# Line 1 | Line 1
1 + #include <cmath>
2   #include "Atom.hpp"
3   #include "SRI.hpp"
4   #include "AbstractClasses.hpp"
# Line 19 | Line 20 | NPTf::NPTf ( SimInfo *theInfo, ForceFields* the_ff):
20   //
21   //    Hoover, W. G., 1986, Phys. Rev. A, 34, 2499.
22  
23 < NPTf::NPTf ( SimInfo *theInfo, ForceFields* the_ff):
24 <  Integrator( theInfo, the_ff )
23 > template<typename T> NPTf<T>::NPTf ( SimInfo *theInfo, ForceFields* the_ff):
24 >  T( theInfo, the_ff )
25   {
26    int i, j;
27    chi = 0.0;
28 +  integralOfChidt = 0.0;
29  
30    for(i = 0; i < 3; i++)
31      for (j = 0; j < 3; j++)
# Line 35 | Line 37 | void NPTf::moveA() {
37    have_target_pressure = 0;
38   }
39  
40 < void NPTf::moveA() {
40 > template<typename T> void NPTf<T>::moveA() {
41    
42    int i, j, k;
43    DirectionalAtom* dAtom;
# Line 50 | Line 52 | void NPTf::moveA() {
52    double sc[3];
53    double eta2ij;
54    double press[3][3], vScale[3][3], hm[3][3], hmnew[3][3], scaleMat[3][3];
55 +  double bigScale, smallScale, offDiagMax;
56  
57    tt2 = tauThermostat * tauThermostat;
58    tb2 = tauBarostat * tauBarostat;
# Line 70 | Line 73 | void NPTf::moveA() {
73            (press[i][j] - targetPressure/p_convert) / (NkBT*tb2);
74          
75          vScale[i][j] = eta[i][j] + chi;
76 <        
76 >          
77        } else {
78          
79          eta[i][j] += dt2 * instaVol * press[i][j] / (NkBT*tb2);
# Line 108 | Line 111 | void NPTf::moveA() {
111  
112      for (j = 0; j < 3; j++ )
113        pos[j] += dt * (vel[j] + sc[j]);
114 +
115 +    atoms[i]->setPos( pos );
116    
117      if( atoms[i]->isDirectional() ){
118  
# Line 161 | Line 166 | void NPTf::moveA() {
166    // Use a taylor expansion for eta products:  Hmat = Hmat . exp(dt * etaMat)
167    //  Hmat = Hmat . ( Ident + dt * etaMat  + dt^2 * etaMat*etaMat / 2)
168    
169 +  bigScale = 1.0;
170 +  smallScale = 1.0;
171 +  offDiagMax = 0.0;
172    
173    for(i=0; i<3; i++){
174      for(j=0; j<3; j++){
# Line 178 | Line 186 | void NPTf::moveA() {
186        if (i == j) scaleMat[i][j] = 1.0;
187        // Taylor expansion for the exponential truncated at second order:
188        scaleMat[i][j] += dt*eta[i][j]  + 0.5*dt*dt*eta2ij;
189 <      
189 >
190 >      if (i != j)
191 >        if (fabs(scaleMat[i][j]) > offDiagMax)
192 >          offDiagMax = fabs(scaleMat[i][j]);
193      }
194 +
195 +    if (scaleMat[i][i] > bigScale) bigScale = scaleMat[i][i];
196 +    if (scaleMat[i][i] < smallScale) smallScale = scaleMat[i][i];
197    }
198    
199 <  info->getBoxM(hm);
200 <  info->matMul3(hm, scaleMat, hmnew);
201 <  info->setBoxM(hmnew);
199 >  if ((bigScale > 1.1) || (smallScale < 0.9)) {
200 >    sprintf( painCave.errMsg,
201 >             "NPTf error: Attempting a Box scaling of more than 10 percent.\n"
202 >             " Check your tauBarostat, as it is probably too small!\n\n"
203 >             " scaleMat = [%lf\t%lf\t%lf]\n"
204 >             "            [%lf\t%lf\t%lf]\n"
205 >             "            [%lf\t%lf\t%lf]\n",
206 >             scaleMat[0][0],scaleMat[0][1],scaleMat[0][2],
207 >             scaleMat[1][0],scaleMat[1][1],scaleMat[1][2],
208 >             scaleMat[2][0],scaleMat[2][1],scaleMat[2][2]);
209 >    painCave.isFatal = 1;
210 >    simError();
211 >  } else if (offDiagMax > 0.1) {
212 >    sprintf( painCave.errMsg,
213 >             "NPTf error: Attempting an off-diagonal Box scaling of more than 10 percent.\n"
214 >             " Check your tauBarostat, as it is probably too small!\n\n"
215 >             " scaleMat = [%lf\t%lf\t%lf]\n"
216 >             "            [%lf\t%lf\t%lf]\n"
217 >             "            [%lf\t%lf\t%lf]\n",
218 >             scaleMat[0][0],scaleMat[0][1],scaleMat[0][2],
219 >             scaleMat[1][0],scaleMat[1][1],scaleMat[1][2],
220 >             scaleMat[2][0],scaleMat[2][1],scaleMat[2][2]);
221 >    painCave.isFatal = 1;
222 >    simError();
223 >  } else {
224 >    info->getBoxM(hm);
225 >    info->matMul3(hm, scaleMat, hmnew);
226 >    info->setBoxM(hmnew);
227 >  }
228    
229   }
230  
231 < void NPTf::moveB( void ){
231 > template<typename T> void NPTf<T>::moveB( void ){
232  
233    int i, j;
234    DirectionalAtom* dAtom;
# Line 270 | Line 310 | int NPTf::readyCheck() {
310    }
311   }
312  
313 < int NPTf::readyCheck() {
313 > template<typename T> void NPTf<T>::resetIntegrator() {
314 >  int i,j;
315 >  
316 >  chi = 0.0;
317 >
318 >  for(i = 0; i < 3; i++)
319 >    for (j = 0; j < 3; j++)
320 >      eta[i][j] = 0.0;
321 >
322 > }
323 >
324 > template<typename T> int NPTf<T>::readyCheck() {
325 >
326 >  //check parent's readyCheck() first
327 >  if (T::readyCheck() == -1)
328 >    return -1;
329  
330    // First check to see if we have a target temperature.
331    // Not having one is fatal.
# Line 323 | Line 378 | int NPTf::readyCheck() {
378  
379    return 1;
380   }
381 +
382 + template<typename T> double NPTf<T>::getConservedQuantity(void){
383 +
384 +  double conservedQuantity;
385 +  double tb2;
386 +  double eta2[3][3];  
387 +  double trEta;
388 +
389 +  //HNVE
390 +  conservedQuantity = tStats->getTotalE();
391 +
392 +  //HNVT
393 +  conservedQuantity += (info->getNDF() * kB * targetTemp *
394 +    (integralOfChidt + tauThermostat * tauThermostat * chi * chi /2)) / eConvert;
395 +
396 +  //HNPT
397 +  tb2 = tauBarostat *tauBarostat;
398 +
399 +  trEta = info->matTrace3(eta);
400 +  
401 +  conservedQuantity += (targetPressure * tStats->getVolume() / p_convert +
402 +                        3*NkBT/2 * tb2 * trEta * trEta) / eConvert;
403 +  
404 +  return conservedQuantity;
405 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines