ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-4/src/integrators/NPTf.cpp
(Generate patch)

Comparing branches/new_design/OOPSE-4/src/integrators/NPTf.cpp (file contents):
Revision 1773 by tim, Wed Nov 3 16:08:43 2004 UTC vs.
Revision 1774 by tim, Tue Nov 23 23:12:23 2004 UTC

# Line 25 | Line 25 | template<typename T> NPTf<T>::NPTf ( SimInfo *theInfo,
25   //
26   //    Hoover, W. G., 1986, Phys. Rev. A, 34, 2499.
27  
28 < template<typename T> NPTf<T>::NPTf ( SimInfo *theInfo, ForceFields* the_ff):
29 <  T( theInfo, the_ff )
30 < {
28 > NPTf::NPTf (SimInfo* info): NPT(info){
29    GenericData* data;
30    DoubleVectorGenericData * etaValue;
31    int i,j;
# Line 35 | Line 33 | template<typename T> NPTf<T>::NPTf ( SimInfo *theInfo,
33    for(i = 0; i < 3; i++){
34      for (j = 0; j < 3; j++){
35  
36 <      eta[i][j] = 0.0;
37 <      oldEta[i][j] = 0.0;
36 >      eta(i, j) = 0.0;
37 >      oldEta(i, j) = 0.0;
38      }
39    }
40  
# Line 51 | Line 49 | template<typename T> NPTf<T>::NPTf ( SimInfo *theInfo,
49          
50          for(i = 0; i < 3; i++){
51            for (j = 0; j < 3; j++){
52 <            eta[i][j] = (*etaValue)[3*i+j];
53 <            oldEta[i][j] = eta[i][j];
52 >            eta(i, j) = (*etaValue)[3*i+j];
53 >            oldEta(i, j) = eta(i, j);
54            }
55          }
56        }
# Line 61 | Line 59 | template<typename T> NPTf<T>::~NPTf() {
59  
60   }
61  
62 < template<typename T> NPTf<T>::~NPTf() {
62 > NPTf::~NPTf() {
63  
64    // empty for now
65   }
66  
67 < template<typename T> void NPTf<T>::resetIntegrator() {
67 > void NPTf::evolveEtaA() {
68  
69    int i, j;
70  
71 <  for(i = 0; i < 3; i++)
72 <    for (j = 0; j < 3; j++)
73 <      eta[i][j] = 0.0;
74 <
75 <  T::resetIntegrator();
76 < }
77 <
78 < template<typename T> void NPTf<T>::evolveEtaA() {
81 <
82 <  int i, j;
83 <
84 <  for(i = 0; i < 3; i ++){
85 <    for(j = 0; j < 3; j++){
86 <      if( i == j)
87 <        eta[i][j] += dt2 *  instaVol *
88 <          (press[i][j] - targetPressure/p_convert) / (NkBT*tb2);
89 <      else
90 <        eta[i][j] += dt2 * instaVol * press[i][j] / (NkBT*tb2);
71 >    for(i = 0; i < 3; i ++){
72 >        for(j = 0; j < 3; j++){
73 >            if( i == j) {
74 >                eta(i, j) += dt2 *  instaVol * (press(i, j) - targetPressure/p_convert) / (NkBT*tb2);
75 >            } else {
76 >                eta(i, j) += dt2 * instaVol * press(i, j) / (NkBT*tb2);
77 >            }
78 >        }
79      }
92  }
80    
81 <  for(i = 0; i < 3; i++)
82 <    for (j = 0; j < 3; j++)
83 <      oldEta[i][j] = eta[i][j];
81 >    for(i = 0; i < 3; i++) {
82 >        for (j = 0; j < 3; j++) {
83 >        oldEta(i, j) = eta(i, j);
84 >        }
85 >    }
86 >  
87   }
88  
89 < template<typename T> void NPTf<T>::evolveEtaB() {
89 > void NPTf::evolveEtaB() {
90  
91 <  int i,j;
91 >    int i;
92 >    int j;
93  
94 <  for(i = 0; i < 3; i++)
95 <    for (j = 0; j < 3; j++)
96 <      prevEta[i][j] = eta[i][j];
94 >    for(i = 0; i < 3; i++) {
95 >        for (j = 0; j < 3; j++) {
96 >            prevEta(i, j) = eta(i, j);
97 >        }
98 >    }
99  
100 <  for(i = 0; i < 3; i ++){
101 <    for(j = 0; j < 3; j++){
102 <      if( i == j) {
103 <        eta[i][j] = oldEta[i][j] + dt2 *  instaVol *
104 <          (press[i][j] - targetPressure/p_convert) / (NkBT*tb2);
105 <      } else {
106 <        eta[i][j] = oldEta[i][j] + dt2 * instaVol * press[i][j] / (NkBT*tb2);
107 <      }
100 >    for(i = 0; i < 3; i ++){
101 >        for(j = 0; j < 3; j++){
102 >            if( i == j) {
103 >                eta(i, j) = oldEta(i, j) + dt2 *  instaVol *
104 >                (press(i, j) - targetPressure/p_convert) / (NkBT*tb2);
105 >            } else {
106 >                eta(i, j) = oldEta(i, j) + dt2 * instaVol * press(i, j) / (NkBT*tb2);
107 >            }
108 >        }
109      }
110 <  }
110 >
111 >  
112   }
113  
114 < template<typename T> void NPTf<T>::calcVelScale(void){
120 <  int i,j;
114 > void NPTf::calcVelScale(){
115  
116 <  for (i = 0; i < 3; i++ ) {
117 <    for (j = 0; j < 3; j++ ) {
118 <      vScale[i][j] = eta[i][j];
116 >  for (int i = 0; i < 3; i++ ) {
117 >    for (int j = 0; j < 3; j++ ) {
118 >      vScale(i, j) = eta(i, j);
119  
120        if (i == j) {
121 <        vScale[i][j] += chi;
121 >        vScale(i, j) += chi;
122        }
123      }
124    }
125   }
126  
127 < template<typename T> void NPTf<T>::getVelScaleA(double sc[3], double vel[3]) {
128 <
135 <  matVecMul3( vScale, vel, sc );
127 > void NPTf::getVelScaleA(Vector3d& sc, const Vector3d& vel);{
128 >    sc = vScale * vel;
129   }
130  
131 < template<typename T> void NPTf<T>::getVelScaleB(double sc[3], int index ){
132 <  int j;
140 <  double myVel[3];
141 <
142 <  for (j = 0; j < 3; j++)
143 <    myVel[j] = oldVel[3*index + j];
144 <  
145 <  matVecMul3( vScale, myVel, sc );
131 > void NPTf::getVelScaleB(Vector3d& sc, int index ) {
132 >  sc = vScale * oldVel[index];
133   }
134  
135 < template<typename T> void NPTf<T>::getPosScale(double pos[3], double COM[3],
136 <                                               int index, double sc[3]){
150 <  int j;
151 <  double rj[3];
135 > void NPTf::getPosScale(const Vector3d& pos, const Vector3d& COM,
136 >                           int index, Vector3d& sc) {
137  
138 <  for(j=0; j<3; j++)
139 <    rj[j] = ( oldPos[index*3+j] + pos[j]) / 2.0 - COM[j];
140 <
156 <  matVecMul3( eta, rj, sc );
138 >    /**@todo */
139 >    Vector3d rj = (oldPos[index] + pos[j])/2.0 -COM;
140 >    sc = eta * rj;
141   }
142  
143 < template<typename T> void NPTf<T>::scaleSimBox( void ){
143 > void NPTf::scaleSimBox(){
144  
145 <  int i,j,k;
146 <  double scaleMat[3][3];
145 >  int i;
146 >  int j;
147 >  int k;
148 >  Mat3x3d scaleMat;
149    double eta2ij;
150    double bigScale, smallScale, offDiagMax;
151 <  double hm[3][3], hmnew[3][3];
151 >  Mat3x3d hm;
152 >  Mat3x3d hmnew;
153  
154  
155  
# Line 183 | Line 170 | template<typename T> void NPTf<T>::scaleSimBox( void )
170  
171        eta2ij = 0.0;
172        for(k=0; k<3; k++){
173 <        eta2ij += eta[i][k] * eta[k][j];
173 >        eta2ij += eta(i, k) * eta(k, j);
174        }
175  
176 <      scaleMat[i][j] = 0.0;
176 >      scaleMat(i, j) = 0.0;
177        // identity matrix (see above):
178 <      if (i == j) scaleMat[i][j] = 1.0;
178 >      if (i == j) scaleMat(i, j) = 1.0;
179        // Taylor expansion for the exponential truncated at second order:
180 <      scaleMat[i][j] += dt*eta[i][j]  + 0.5*dt*dt*eta2ij;
180 >      scaleMat(i, j) += dt*eta(i, j)  + 0.5*dt*dt*eta2ij;
181        
182  
183        if (i != j)
184 <        if (fabs(scaleMat[i][j]) > offDiagMax)
185 <          offDiagMax = fabs(scaleMat[i][j]);
184 >        if (fabs(scaleMat(i, j)) > offDiagMax)
185 >          offDiagMax = fabs(scaleMat(i, j));
186      }
187  
188 <    if (scaleMat[i][i] > bigScale) bigScale = scaleMat[i][i];
189 <    if (scaleMat[i][i] < smallScale) smallScale = scaleMat[i][i];
188 >    if (scaleMat(i, i) > bigScale) bigScale = scaleMat(i, i);
189 >    if (scaleMat(i, i) < smallScale) smallScale = scaleMat(i, i);
190    }
191  
192    if ((bigScale > 1.01) || (smallScale < 0.99)) {
# Line 212 | Line 199 | template<typename T> void NPTf<T>::scaleSimBox( void )
199               "      eta = [%lf\t%lf\t%lf]\n"
200               "            [%lf\t%lf\t%lf]\n"
201               "            [%lf\t%lf\t%lf]\n",
202 <             scaleMat[0][0],scaleMat[0][1],scaleMat[0][2],
203 <             scaleMat[1][0],scaleMat[1][1],scaleMat[1][2],
204 <             scaleMat[2][0],scaleMat[2][1],scaleMat[2][2],
205 <             eta[0][0],eta[0][1],eta[0][2],
206 <             eta[1][0],eta[1][1],eta[1][2],
207 <             eta[2][0],eta[2][1],eta[2][2]);
202 >             scaleMat(0, 0),scaleMat(0, 1),scaleMat(0, 2),
203 >             scaleMat(1, 0),scaleMat(1, 1),scaleMat(1, 2),
204 >             scaleMat(2, 0),scaleMat(2, 1),scaleMat(2, 2),
205 >             eta(0, 0),eta(0, 1),eta(0, 2),
206 >             eta(1, 0),eta(1, 1),eta(1, 2),
207 >             eta(2, 0),eta(2, 1),eta(2, 2));
208      painCave.isFatal = 1;
209      simError();
210    } else if (offDiagMax > 0.01) {
# Line 230 | Line 217 | template<typename T> void NPTf<T>::scaleSimBox( void )
217               "      eta = [%lf\t%lf\t%lf]\n"
218               "            [%lf\t%lf\t%lf]\n"
219               "            [%lf\t%lf\t%lf]\n",
220 <             scaleMat[0][0],scaleMat[0][1],scaleMat[0][2],
221 <             scaleMat[1][0],scaleMat[1][1],scaleMat[1][2],
222 <             scaleMat[2][0],scaleMat[2][1],scaleMat[2][2],
223 <             eta[0][0],eta[0][1],eta[0][2],
224 <             eta[1][0],eta[1][1],eta[1][2],
225 <             eta[2][0],eta[2][1],eta[2][2]);
220 >             scaleMat(0, 0),scaleMat(0, 1),scaleMat(0, 2),
221 >             scaleMat(1, 0),scaleMat(1, 1),scaleMat(1, 2),
222 >             scaleMat(2, 0),scaleMat(2, 1),scaleMat(2, 2),
223 >             eta(0, 0),eta(0, 1),eta(0, 2),
224 >             eta(1, 0),eta(1, 1),eta(1, 2),
225 >             eta(2, 0),eta(2, 1),eta(2, 2));
226      painCave.isFatal = 1;
227      simError();
228    } else {
# Line 245 | Line 232 | template<typename T> bool NPTf<T>::etaConverged() {
232    }
233   }
234  
235 < template<typename T> bool NPTf<T>::etaConverged() {
236 <  int i;
237 <  double diffEta, sumEta;
235 > bool NPTf::etaConverged() {
236 >    int i;
237 >    double diffEta, sumEta;
238  
239 <  sumEta = 0;
240 <  for(i = 0; i < 3; i++)
241 <    sumEta += pow(prevEta[i][i] - eta[i][i], 2);
239 >    sumEta = 0;
240 >    for(i = 0; i < 3; i++) {
241 >        sumEta += pow(prevEta(i, i) - eta(i, i), 2);
242 >    }
243 >    
244 >    diffEta = sqrt( sumEta / 3.0 );
245  
246 <  diffEta = sqrt( sumEta / 3.0 );
257 <
258 <  return ( diffEta <= etaTolerance );
246 >    return ( diffEta <= etaTolerance );
247   }
248  
249 < template<typename T> double NPTf<T>::getConservedQuantity(void){
249 > double NPTf::calcConservedQuantity(){
250  
251 <  double conservedQuantity;
252 <  double totalEnergy;
253 <  double thermostat_kinetic;
254 <  double thermostat_potential;
255 <  double barostat_kinetic;
256 <  double barostat_potential;
257 <  double trEta;
270 <  double a[3][3], b[3][3];
251 >    double conservedQuantity;
252 >    double totalEnergy;
253 >    double thermostat_kinetic;
254 >    double thermostat_potential;
255 >    double barostat_kinetic;
256 >    double barostat_potential;
257 >    double trEta;
258  
259 <  totalEnergy = tStats->getTotalE();
259 >    totalEnergy = tStats->getTotalE();
260  
261 <  thermostat_kinetic = fkBT * tt2 * chi * chi /
275 <    (2.0 * eConvert);
261 >    thermostat_kinetic = fkBT * tt2 * chi * chi /(2.0 * eConvert);
262  
263 <  thermostat_potential = fkBT* integralOfChidt / eConvert;
263 >    thermostat_potential = fkBT* integralOfChidt / eConvert;
264  
265 <  transposeMat3(eta, a);
266 <  matMul3(a, eta, b);
267 <  trEta = matTrace3(b);
265 >    trEta = (eta.transpose() * eta).trace();
266 >    
267 >    barostat_kinetic = NkBT * tb2 * trEta /(2.0 * eConvert);
268  
269 <  barostat_kinetic = NkBT * tb2 * trEta /
284 <    (2.0 * eConvert);
269 >    barostat_potential = (targetPressure * tStats->getVolume() / p_convert) /eConvert;
270  
271 <  barostat_potential = (targetPressure * tStats->getVolume() / p_convert) /
272 <    eConvert;
271 >    conservedQuantity = totalEnergy + thermostat_kinetic + thermostat_potential +
272 >        barostat_kinetic + barostat_potential;
273  
274 <  conservedQuantity = totalEnergy + thermostat_kinetic + thermostat_potential +
290 <    barostat_kinetic + barostat_potential;
274 >    return conservedQuantity;
275  
292  return conservedQuantity;
293
276   }
277  
296 template<typename T> string NPTf<T>::getAdditionalParameters(void){
297  string parameters;
298  const int BUFFERSIZE = 2000; // size of the read buffer
299  char buffer[BUFFERSIZE];
300
301  sprintf(buffer,"\t%G\t%G;", chi, integralOfChidt);
302  parameters += buffer;
303
304  for(int i = 0; i < 3; i++){
305    sprintf(buffer,"\t%G\t%G\t%G;", eta[i][0], eta[i][1], eta[i][2]);
306    parameters += buffer;
307  }
308
309  return parameters;
310
311 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines