ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-4/src/integrators/NPTi.cpp
Revision: 1867
Committed: Tue Dec 7 23:08:14 2004 UTC (21 years, 6 months ago) by tim
File size: 5118 byte(s)
Log Message:
NPT in progress

File Contents

# User Rev Content
1 tim 1822 #include "NPTi.hpp"
2 tim 1492 #include "brains/SimInfo.hpp"
3     #include "brains/Thermo.hpp"
4 tim 1837 #include "integrators/IntegratorCreator.hpp"
5 tim 1822 #include "integrators/NPT.hpp"
6     #include "primitives/Molecule.hpp"
7     #include "utils/OOPSEConstant.hpp"
8 tim 1492 #include "utils/simError.h"
9 gezelter 1490
10 tim 1822 namespace oopse {
11 gezelter 1490
12 tim 1837 static IntegratorBuilder<NPTi>* NPTiCreator = new IntegratorBuilder<NPTi>("NPTi");
13    
14 gezelter 1490 // Basic isotropic thermostating and barostating via the Melchionna
15     // modification of the Hoover algorithm:
16     //
17     // Melchionna, S., Ciccotti, G., and Holian, B. L., 1993,
18     // Molec. Phys., 78, 533.
19     //
20     // and
21     //
22     // Hoover, W. G., 1986, Phys. Rev. A, 34, 2499.
23    
24 tim 1822 NPTi::NPTi ( SimInfo *info) : NPT(info){
25 gezelter 1490
26     }
27    
28 tim 1774 void NPTi::evolveEtaA() {
29 tim 1822 eta += dt2 * ( instaVol * (instaPress - targetPressure) /
30     (OOPSEConstant::pressureConvert*NkBT*tb2));
31     oldEta = eta;
32 gezelter 1490 }
33    
34 tim 1774 void NPTi::evolveEtaB() {
35 gezelter 1490
36 tim 1822 prevEta = eta;
37     eta = oldEta + dt2 * ( instaVol * (instaPress - targetPressure) /
38     (OOPSEConstant::pressureConvert*NkBT*tb2));
39 gezelter 1490 }
40    
41 tim 1774 void NPTi::calcVelScale() {
42 tim 1822 vScale = chi + eta;
43 gezelter 1490 }
44    
45 tim 1774 void NPTi::getVelScaleA(Vector3d& sc, const Vector3d& vel) {
46     sc = vel * vScale;
47 gezelter 1490 }
48    
49 tim 1774 void NPTi::getVelScaleB(Vector3d& sc, int index ){
50     sc = oldVel[index] * vScale;
51 gezelter 1490 }
52    
53    
54 tim 1774 void NPTi::getPosScale(const Vector3d& pos, const Vector3d& COM,
55 tim 1822 int index, Vector3d& sc){
56 tim 1774 /**@todo*/
57     sc = oldPos[index] + pos/2.0 -COM;
58     sc *= eta;
59 gezelter 1490 }
60    
61 tim 1774 void NPTi::scaleSimBox(){
62 gezelter 1490
63 tim 1822 double scaleFactor;
64 gezelter 1490
65 tim 1822 scaleFactor = exp(dt*eta);
66 gezelter 1490
67 tim 1822 if ((scaleFactor > 1.1) || (scaleFactor < 0.9)) {
68     sprintf( painCave.errMsg,
69 gezelter 1490 "NPTi error: Attempting a Box scaling of more than 10 percent"
70     " check your tauBarostat, as it is probably too small!\n"
71     " eta = %lf, scaleFactor = %lf\n", eta, scaleFactor
72     );
73 tim 1822 painCave.isFatal = 1;
74     simError();
75     } else {
76     Mat3x3d hmat = currentSnapshot_->getHmat();
77     hmat *= scaleFactor;
78     currentSnapshot_->setHmat(hmat);
79     }
80 gezelter 1490
81     }
82    
83 tim 1774 bool NPTi::etaConverged() {
84 gezelter 1490
85 tim 1822 return ( fabs(prevEta - eta) <= etaTolerance );
86 gezelter 1490 }
87    
88 tim 1774 double NPTi::calcConservedQuantity(){
89 gezelter 1490
90 tim 1867 chi= currentSnapshot_->getChi();
91     integralOfChidt = currentSnapshot_->getIntegralOfChiDt();
92     loadEta();
93     // We need NkBT a lot, so just set it here: This is the RAW number
94     // of integrableObjects, so no subtraction or addition of constraints or
95     // orientational degrees of freedom:
96     NkBT = info_->getNGlobalIntegrableObjects()*OOPSEConstant::kB *targetTemp;
97    
98     // fkBT is used because the thermostat operates on more degrees of freedom
99     // than the barostat (when there are particles with orientational degrees
100     // of freedom).
101     fkBT = info_->getNdf()*OOPSEConstant::kB *targetTemp;
102    
103 tim 1822 double conservedQuantity;
104     double Energy;
105     double thermostat_kinetic;
106     double thermostat_potential;
107     double barostat_kinetic;
108     double barostat_potential;
109 gezelter 1490
110 tim 1822 Energy =thermo.getTotalE();
111 gezelter 1490
112 tim 1822 thermostat_kinetic = fkBT* tt2 * chi * chi / (2.0 * OOPSEConstant::energyConvert);
113 gezelter 1490
114 tim 1822 thermostat_potential = fkBT* integralOfChidt / OOPSEConstant::energyConvert;
115 gezelter 1490
116    
117 tim 1822 barostat_kinetic = 3.0 * NkBT * tb2 * eta * eta /(2.0 * OOPSEConstant::energyConvert);
118 gezelter 1490
119 tim 1822 barostat_potential = (targetPressure * thermo.getVolume() / OOPSEConstant::pressureConvert) /
120     OOPSEConstant::energyConvert;
121 gezelter 1490
122 tim 1822 conservedQuantity = Energy + thermostat_kinetic + thermostat_potential +
123     barostat_kinetic + barostat_potential;
124 gezelter 1490
125 tim 1867 std::cout << "--------------------------------------------------------------" << std::endl;
126     std::cout << "time: " << currentSnapshot_->getTime() << std:: endl;
127     std::cout << "chi : " << chi << std::endl;
128     std::cout << "integralOfChidt : " << integralOfChidt << std::endl;
129     std::cout << "eta : " << eta << std::endl;
130     std::cout << "NkBT: " << NkBT << std::endl;
131     std::cout << "fkBT: " << fkBT << std::endl;
132     std::cout << "thermostat_kinetic : " << thermostat_kinetic<< std::endl;
133     std::cout << "thermostat_potential : " << thermostat_potential << std::endl;
134     std::cout << "barostat_kinetic : " << barostat_kinetic << std::endl;
135     std::cout << "barostat_potential : " << barostat_potential << std::endl;
136     std::cout << "Total Energy: " << Energy << std::endl;
137     std::cout << "Conserved Quantity: " << conservedQuantity <<std::endl;
138     std::cout << "--------------------------------------------------------------" << std::endl;
139 tim 1822 return conservedQuantity;
140 gezelter 1490 }
141    
142 tim 1822 void NPTi::loadEta() {
143     Mat3x3d etaMat = currentSnapshot_->getEta();
144     eta = etaMat(0,0);
145 tim 1867 if (fabs(etaMat(1,1) - eta) >= oopse::epsilon || fabs(etaMat(1,1) - eta) >= oopse::epsilon || !etaMat.isDiagonal()) {
146 tim 1822 sprintf( painCave.errMsg,
147     "NPTi error: the diagonal elements of are eta matrix is not same or etaMat is not a diagonal matrix");
148     painCave.isFatal = 1;
149     simError();
150     }
151     }
152    
153     void NPTi::saveEta() {
154     Mat3x3d etaMat(0.0);
155     etaMat(0, 0) = eta;
156     etaMat(1, 1) = eta;
157     etaMat(2, 2) = eta;
158     currentSnapshot_->setEta(etaMat);
159     }
160    
161     }