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: 1865
Committed: Tue Dec 7 05:12:41 2004 UTC (19 years, 6 months ago) by tim
File size: 3516 byte(s)
Log Message:
fix a bug in UseInitXSstate

File Contents

# Content
1 #include "NPTi.hpp"
2 #include "brains/SimInfo.hpp"
3 #include "brains/Thermo.hpp"
4 #include "integrators/IntegratorCreator.hpp"
5 #include "integrators/NPT.hpp"
6 #include "primitives/Molecule.hpp"
7 #include "utils/OOPSEConstant.hpp"
8 #include "utils/simError.h"
9
10 namespace oopse {
11
12 static IntegratorBuilder<NPTi>* NPTiCreator = new IntegratorBuilder<NPTi>("NPTi");
13
14 // 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 NPTi::NPTi ( SimInfo *info) : NPT(info){
25
26 }
27
28 void NPTi::evolveEtaA() {
29 eta += dt2 * ( instaVol * (instaPress - targetPressure) /
30 (OOPSEConstant::pressureConvert*NkBT*tb2));
31 oldEta = eta;
32 }
33
34 void NPTi::evolveEtaB() {
35
36 prevEta = eta;
37 eta = oldEta + dt2 * ( instaVol * (instaPress - targetPressure) /
38 (OOPSEConstant::pressureConvert*NkBT*tb2));
39 }
40
41 void NPTi::calcVelScale() {
42 vScale = chi + eta;
43 }
44
45 void NPTi::getVelScaleA(Vector3d& sc, const Vector3d& vel) {
46 sc = vel * vScale;
47 }
48
49 void NPTi::getVelScaleB(Vector3d& sc, int index ){
50 sc = oldVel[index] * vScale;
51 }
52
53
54 void NPTi::getPosScale(const Vector3d& pos, const Vector3d& COM,
55 int index, Vector3d& sc){
56 /**@todo*/
57 sc = oldPos[index] + pos/2.0 -COM;
58 sc *= eta;
59 }
60
61 void NPTi::scaleSimBox(){
62
63 double scaleFactor;
64
65 scaleFactor = exp(dt*eta);
66
67 if ((scaleFactor > 1.1) || (scaleFactor < 0.9)) {
68 sprintf( painCave.errMsg,
69 "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 painCave.isFatal = 1;
74 simError();
75 } else {
76 Mat3x3d hmat = currentSnapshot_->getHmat();
77 hmat *= scaleFactor;
78 currentSnapshot_->setHmat(hmat);
79 }
80
81 }
82
83 bool NPTi::etaConverged() {
84
85 return ( fabs(prevEta - eta) <= etaTolerance );
86 }
87
88 double NPTi::calcConservedQuantity(){
89
90 double conservedQuantity;
91 double Energy;
92 double thermostat_kinetic;
93 double thermostat_potential;
94 double barostat_kinetic;
95 double barostat_potential;
96
97 Energy =thermo.getTotalE();
98
99 thermostat_kinetic = fkBT* tt2 * chi * chi / (2.0 * OOPSEConstant::energyConvert);
100
101 thermostat_potential = fkBT* integralOfChidt / OOPSEConstant::energyConvert;
102
103
104 barostat_kinetic = 3.0 * NkBT * tb2 * eta * eta /(2.0 * OOPSEConstant::energyConvert);
105
106 barostat_potential = (targetPressure * thermo.getVolume() / OOPSEConstant::pressureConvert) /
107 OOPSEConstant::energyConvert;
108
109 conservedQuantity = Energy + thermostat_kinetic + thermostat_potential +
110 barostat_kinetic + barostat_potential;
111
112 return conservedQuantity;
113 }
114
115 void NPTi::loadEta() {
116 Mat3x3d etaMat = currentSnapshot_->getEta();
117 eta = etaMat(0,0);
118 if (fabs(etaMat(1,1) - eta) >= oopse::epsilon || fabs(etaMat(1,1) - eta) >= oopse::epsilon || etaMat.isDiagonal()) {
119 sprintf( painCave.errMsg,
120 "NPTi error: the diagonal elements of are eta matrix is not same or etaMat is not a diagonal matrix");
121 painCave.isFatal = 1;
122 simError();
123 }
124 }
125
126 void NPTi::saveEta() {
127 Mat3x3d etaMat(0.0);
128 etaMat(0, 0) = eta;
129 etaMat(1, 1) = eta;
130 etaMat(2, 2) = eta;
131 currentSnapshot_->setEta(etaMat);
132 }
133
134 }