ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/NPTi.cpp
Revision: 837
Committed: Wed Oct 29 00:19:10 2003 UTC (20 years, 8 months ago) by tim
File size: 4119 byte(s)
Log Message:
add chi and eta to the comment line of dump file.

File Contents

# User Rev Content
1 gezelter 829 #include <math.h>
2 gezelter 574 #include "Atom.hpp"
3     #include "SRI.hpp"
4     #include "AbstractClasses.hpp"
5     #include "SimInfo.hpp"
6     #include "ForceFields.hpp"
7     #include "Thermo.hpp"
8     #include "ReadWrite.hpp"
9     #include "Integrator.hpp"
10 tim 837 #include "simError.h"
11 gezelter 574
12 tim 763 #ifdef IS_MPI
13     #include "mpiSimulation.hpp"
14     #endif
15 gezelter 574
16     // Basic isotropic thermostating and barostating via the Melchionna
17     // modification of the Hoover algorithm:
18     //
19     // Melchionna, S., Ciccotti, G., and Holian, B. L., 1993,
20 tim 837 // Molec. Phys., 78, 533.
21 gezelter 574 //
22     // and
23 tim 837 //
24 gezelter 574 // Hoover, W. G., 1986, Phys. Rev. A, 34, 2499.
25    
26 tim 645 template<typename T> NPTi<T>::NPTi ( SimInfo *theInfo, ForceFields* the_ff):
27     T( theInfo, the_ff )
28 gezelter 574 {
29 tim 837 GenericData* data;
30     DoubleArrayData * etaValue;
31     vector<double> etaArray;
32    
33 gezelter 574 eta = 0.0;
34 mmeineke 778 oldEta = 0.0;
35 tim 837
36     // retrieve eta from simInfo if
37     data = info->getProperty(ETAVALUE_ID);
38     if(data){
39     etaValue = dynamic_cast<DoubleArrayData*>(data);
40    
41     if(etaValue){
42     etaArray = etaValue->getData();
43     eta = etaArray[0];
44     oldEta = eta;
45     }
46     }
47    
48 gezelter 574 }
49    
50 tim 763 template<typename T> NPTi<T>::~NPTi() {
51 mmeineke 778 //nothing for now
52 tim 763 }
53    
54 mmeineke 778 template<typename T> void NPTi<T>::resetIntegrator() {
55     eta = 0.0;
56     T::resetIntegrator();
57     }
58 gezelter 600
59 mmeineke 778 template<typename T> void NPTi<T>::evolveEtaA() {
60 tim 837 eta += dt2 * ( instaVol * (instaPress - targetPressure) /
61 mmeineke 778 (p_convert*NkBT*tb2));
62     oldEta = eta;
63     }
64 gezelter 574
65 mmeineke 778 template<typename T> void NPTi<T>::evolveEtaB() {
66 tim 837
67 mmeineke 778 prevEta = eta;
68 tim 837 eta = oldEta + dt2 * ( instaVol * (instaPress - targetPressure) /
69 mmeineke 778 (p_convert*NkBT*tb2));
70     }
71 gezelter 574
72 mmeineke 778 template<typename T> void NPTi<T>::getVelScaleA(double sc[3], double vel[3]) {
73     int i;
74 gezelter 574
75 mmeineke 778 for(i=0; i<3; i++) sc[i] = vel[i] * ( chi + eta );
76     }
77 gezelter 574
78 mmeineke 778 template<typename T> void NPTi<T>::getVelScaleB(double sc[3], int index ){
79     int i;
80 gezelter 600
81 mmeineke 778 for(i=0; i<3; i++) sc[i] = oldVel[index*3 + i] * ( chi + eta );
82     }
83 gezelter 574
84 tim 763
85 tim 837 template<typename T> void NPTi<T>::getPosScale(double pos[3], double COM[3],
86 mmeineke 778 int index, double sc[3]){
87     int j;
88 gezelter 574
89 mmeineke 778 for(j=0; j<3; j++)
90     sc[j] = ( oldPos[index*3+j] + pos[j]) / 2.0 - COM[j];
91 gezelter 600
92 mmeineke 778 for(j=0; j<3; j++)
93     sc[j] *= eta;
94     }
95 gezelter 600
96 mmeineke 778 template<typename T> void NPTi<T>::scaleSimBox( void ){
97 gezelter 600
98 mmeineke 778 double scaleFactor;
99 gezelter 600
100 gezelter 611 scaleFactor = exp(dt*eta);
101    
102 mmeineke 614 if ((scaleFactor > 1.1) || (scaleFactor < 0.9)) {
103 gezelter 611 sprintf( painCave.errMsg,
104     "NPTi error: Attempting a Box scaling of more than 10 percent"
105     " check your tauBarostat, as it is probably too small!\n"
106     " eta = %lf, scaleFactor = %lf\n", eta, scaleFactor
107     );
108     painCave.isFatal = 1;
109     simError();
110 tim 837 } else {
111     info->scaleBox(scaleFactor);
112     }
113 mmeineke 614
114 gezelter 574 }
115    
116 mmeineke 778 template<typename T> bool NPTi<T>::etaConverged() {
117 tim 763
118 mmeineke 778 return ( fabs(prevEta - eta) <= etaTolerance );
119 gezelter 574 }
120    
121 tim 763 template<typename T> double NPTi<T>::getConservedQuantity(void){
122    
123     double conservedQuantity;
124 tim 769 double Energy;
125     double thermostat_kinetic;
126     double thermostat_potential;
127     double barostat_kinetic;
128     double barostat_potential;
129 tim 837
130 tim 769 Energy = tStats->getTotalE();
131 tim 763
132 tim 837 thermostat_kinetic = fkBT* tt2 * chi * chi /
133 tim 769 (2.0 * eConvert);
134 tim 763
135 tim 769 thermostat_potential = fkBT* integralOfChidt / eConvert;
136 tim 763
137    
138 tim 837 barostat_kinetic = 3.0 * NkBT * tb2 * eta * eta /
139 tim 769 (2.0 * eConvert);
140 tim 837
141     barostat_potential = (targetPressure * tStats->getVolume() / p_convert) /
142 tim 769 eConvert;
143 tim 767
144 tim 769 conservedQuantity = Energy + thermostat_kinetic + thermostat_potential +
145     barostat_kinetic + barostat_potential;
146 tim 837
147 mmeineke 778 // cout.width(8);
148     // cout.precision(8);
149 tim 763
150 tim 837 // cerr << info->getTime() << "\t" << Energy << "\t" << thermostat_kinetic <<
151     // "\t" << thermostat_potential << "\t" << barostat_kinetic <<
152 mmeineke 778 // "\t" << barostat_potential << "\t" << conservedQuantity << endl;
153 tim 837 return conservedQuantity;
154 tim 763 }
155 tim 837
156     template<typename T> string NPTi<T>::getAdditionalParameters(void){
157     string parameters;
158     const int BUFFERSIZE = 2000; // size of the read buffer
159     char buffer[BUFFERSIZE];
160    
161     sprintf(buffer,"\t%g\t%g;", chi, integralOfChidt);
162     parameters += buffer;
163    
164     sprintf(buffer,"\t%g\t0\t0;", eta);
165     parameters += buffer;
166    
167     sprintf(buffer,"\t0\t%g\t0;", eta);
168     parameters += buffer;
169    
170     sprintf(buffer,"\t0\t0\t%g;", eta);
171     parameters += buffer;
172    
173     return parameters;
174    
175     }