ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-3.0/src/integrators/NPTi.cpp
Revision: 1822
Committed: Thu Dec 2 02:08:29 2004 UTC (19 years, 9 months ago) by tim
File size: 3432 byte(s)
Log Message:
oopse get compiled, still has some linking problem

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 1822 #include "integrators/NPT.hpp"
5     #include "primitives/Molecule.hpp"
6     #include "utils/OOPSEConstant.hpp"
7 tim 1492 #include "utils/simError.h"
8 gezelter 1490
9 tim 1822 namespace oopse {
10 gezelter 1490
11     // Basic isotropic thermostating and barostating via the Melchionna
12     // modification of the Hoover algorithm:
13     //
14     // Melchionna, S., Ciccotti, G., and Holian, B. L., 1993,
15     // Molec. Phys., 78, 533.
16     //
17     // and
18     //
19     // Hoover, W. G., 1986, Phys. Rev. A, 34, 2499.
20    
21 tim 1822 NPTi::NPTi ( SimInfo *info) : NPT(info){
22 gezelter 1490
23 tim 1822 Globals* globals = info_->getGlobals();
24 gezelter 1490
25     }
26    
27 tim 1774 void NPTi::evolveEtaA() {
28 tim 1822 eta += dt2 * ( instaVol * (instaPress - targetPressure) /
29     (OOPSEConstant::pressureConvert*NkBT*tb2));
30     oldEta = eta;
31 gezelter 1490 }
32    
33 tim 1774 void NPTi::evolveEtaB() {
34 gezelter 1490
35 tim 1822 prevEta = eta;
36     eta = oldEta + dt2 * ( instaVol * (instaPress - targetPressure) /
37     (OOPSEConstant::pressureConvert*NkBT*tb2));
38 gezelter 1490 }
39    
40 tim 1774 void NPTi::calcVelScale() {
41 tim 1822 vScale = chi + eta;
42 gezelter 1490 }
43    
44 tim 1774 void NPTi::getVelScaleA(Vector3d& sc, const Vector3d& vel) {
45     sc = vel * vScale;
46 gezelter 1490 }
47    
48 tim 1774 void NPTi::getVelScaleB(Vector3d& sc, int index ){
49     sc = oldVel[index] * vScale;
50 gezelter 1490 }
51    
52    
53 tim 1774 void NPTi::getPosScale(const Vector3d& pos, const Vector3d& COM,
54 tim 1822 int index, Vector3d& sc){
55 tim 1774 /**@todo*/
56     sc = oldPos[index] + pos/2.0 -COM;
57     sc *= eta;
58 gezelter 1490 }
59    
60 tim 1774 void NPTi::scaleSimBox(){
61 gezelter 1490
62 tim 1822 double scaleFactor;
63 gezelter 1490
64 tim 1822 scaleFactor = exp(dt*eta);
65 gezelter 1490
66 tim 1822 if ((scaleFactor > 1.1) || (scaleFactor < 0.9)) {
67     sprintf( painCave.errMsg,
68 gezelter 1490 "NPTi error: Attempting a Box scaling of more than 10 percent"
69     " check your tauBarostat, as it is probably too small!\n"
70     " eta = %lf, scaleFactor = %lf\n", eta, scaleFactor
71     );
72 tim 1822 painCave.isFatal = 1;
73     simError();
74     } else {
75     Mat3x3d hmat = currentSnapshot_->getHmat();
76     hmat *= scaleFactor;
77     currentSnapshot_->setHmat(hmat);
78     }
79 gezelter 1490
80     }
81    
82 tim 1774 bool NPTi::etaConverged() {
83 gezelter 1490
84 tim 1822 return ( fabs(prevEta - eta) <= etaTolerance );
85 gezelter 1490 }
86    
87 tim 1774 double NPTi::calcConservedQuantity(){
88 gezelter 1490
89 tim 1822 double conservedQuantity;
90     double Energy;
91     double thermostat_kinetic;
92     double thermostat_potential;
93     double barostat_kinetic;
94     double barostat_potential;
95 gezelter 1490
96 tim 1822 Energy =thermo.getTotalE();
97 gezelter 1490
98 tim 1822 thermostat_kinetic = fkBT* tt2 * chi * chi / (2.0 * OOPSEConstant::energyConvert);
99 gezelter 1490
100 tim 1822 thermostat_potential = fkBT* integralOfChidt / OOPSEConstant::energyConvert;
101 gezelter 1490
102    
103 tim 1822 barostat_kinetic = 3.0 * NkBT * tb2 * eta * eta /(2.0 * OOPSEConstant::energyConvert);
104 gezelter 1490
105 tim 1822 barostat_potential = (targetPressure * thermo.getVolume() / OOPSEConstant::pressureConvert) /
106     OOPSEConstant::energyConvert;
107 gezelter 1490
108 tim 1822 conservedQuantity = Energy + thermostat_kinetic + thermostat_potential +
109     barostat_kinetic + barostat_potential;
110 gezelter 1490
111 tim 1822 return conservedQuantity;
112 gezelter 1490 }
113    
114 tim 1822 void NPTi::loadEta() {
115     Mat3x3d etaMat = currentSnapshot_->getEta();
116     eta = etaMat(0,0);
117     if (fabs(etaMat(1,1) - eta) >= oopse::epsilon || fabs(etaMat(1,1) - eta) >= oopse::epsilon || etaMat.isDiagonal()) {
118     sprintf( painCave.errMsg,
119     "NPTi error: the diagonal elements of are eta matrix is not same or etaMat is not a diagonal matrix");
120     painCave.isFatal = 1;
121     simError();
122     }
123     }
124    
125     void NPTi::saveEta() {
126     Mat3x3d etaMat(0.0);
127     etaMat(0, 0) = eta;
128     etaMat(1, 1) = eta;
129     etaMat(2, 2) = eta;
130     currentSnapshot_->setEta(etaMat);
131     }
132    
133     }