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

File Contents

# Content
1 #include "NPTi.hpp"
2 #include "brains/SimInfo.hpp"
3 #include "brains/Thermo.hpp"
4 #include "integrators/NPT.hpp"
5 #include "primitives/Molecule.hpp"
6 #include "utils/OOPSEConstant.hpp"
7 #include "utils/simError.h"
8
9 namespace oopse {
10
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 NPTi::NPTi ( SimInfo *info) : NPT(info){
22
23 Globals* globals = info_->getGlobals();
24
25 }
26
27 void NPTi::evolveEtaA() {
28 eta += dt2 * ( instaVol * (instaPress - targetPressure) /
29 (OOPSEConstant::pressureConvert*NkBT*tb2));
30 oldEta = eta;
31 }
32
33 void NPTi::evolveEtaB() {
34
35 prevEta = eta;
36 eta = oldEta + dt2 * ( instaVol * (instaPress - targetPressure) /
37 (OOPSEConstant::pressureConvert*NkBT*tb2));
38 }
39
40 void NPTi::calcVelScale() {
41 vScale = chi + eta;
42 }
43
44 void NPTi::getVelScaleA(Vector3d& sc, const Vector3d& vel) {
45 sc = vel * vScale;
46 }
47
48 void NPTi::getVelScaleB(Vector3d& sc, int index ){
49 sc = oldVel[index] * vScale;
50 }
51
52
53 void NPTi::getPosScale(const Vector3d& pos, const Vector3d& COM,
54 int index, Vector3d& sc){
55 /**@todo*/
56 sc = oldPos[index] + pos/2.0 -COM;
57 sc *= eta;
58 }
59
60 void NPTi::scaleSimBox(){
61
62 double scaleFactor;
63
64 scaleFactor = exp(dt*eta);
65
66 if ((scaleFactor > 1.1) || (scaleFactor < 0.9)) {
67 sprintf( painCave.errMsg,
68 "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 painCave.isFatal = 1;
73 simError();
74 } else {
75 Mat3x3d hmat = currentSnapshot_->getHmat();
76 hmat *= scaleFactor;
77 currentSnapshot_->setHmat(hmat);
78 }
79
80 }
81
82 bool NPTi::etaConverged() {
83
84 return ( fabs(prevEta - eta) <= etaTolerance );
85 }
86
87 double NPTi::calcConservedQuantity(){
88
89 double conservedQuantity;
90 double Energy;
91 double thermostat_kinetic;
92 double thermostat_potential;
93 double barostat_kinetic;
94 double barostat_potential;
95
96 Energy =thermo.getTotalE();
97
98 thermostat_kinetic = fkBT* tt2 * chi * chi / (2.0 * OOPSEConstant::energyConvert);
99
100 thermostat_potential = fkBT* integralOfChidt / OOPSEConstant::energyConvert;
101
102
103 barostat_kinetic = 3.0 * NkBT * tb2 * eta * eta /(2.0 * OOPSEConstant::energyConvert);
104
105 barostat_potential = (targetPressure * thermo.getVolume() / OOPSEConstant::pressureConvert) /
106 OOPSEConstant::energyConvert;
107
108 conservedQuantity = Energy + thermostat_kinetic + thermostat_potential +
109 barostat_kinetic + barostat_potential;
110
111 return conservedQuantity;
112 }
113
114 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 }