ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/NPTi.cpp
Revision: 787
Committed: Thu Sep 25 19:27:15 2003 UTC (20 years, 9 months ago) by mmeineke
File size: 3355 byte(s)
Log Message:
cleaned things with gcc -Wall and g++ -Wall

File Contents

# Content
1 #include <cmath>
2 #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 #include "simError.h"
11
12 #ifdef IS_MPI
13 #include "mpiSimulation.hpp"
14 #endif
15
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 // Molec. Phys., 78, 533.
21 //
22 // and
23 //
24 // Hoover, W. G., 1986, Phys. Rev. A, 34, 2499.
25
26 template<typename T> NPTi<T>::NPTi ( SimInfo *theInfo, ForceFields* the_ff):
27 T( theInfo, the_ff )
28 {
29 eta = 0.0;
30 oldEta = 0.0;
31 }
32
33 template<typename T> NPTi<T>::~NPTi() {
34 //nothing for now
35 }
36
37 template<typename T> void NPTi<T>::resetIntegrator() {
38 eta = 0.0;
39 T::resetIntegrator();
40 }
41
42 template<typename T> void NPTi<T>::evolveEtaA() {
43 eta += dt2 * ( instaVol * (instaPress - targetPressure) /
44 (p_convert*NkBT*tb2));
45 oldEta = eta;
46 }
47
48 template<typename T> void NPTi<T>::evolveEtaB() {
49
50 prevEta = eta;
51 eta = oldEta + dt2 * ( instaVol * (instaPress - targetPressure) /
52 (p_convert*NkBT*tb2));
53 }
54
55 template<typename T> void NPTi<T>::getVelScaleA(double sc[3], double vel[3]) {
56 int i;
57
58 for(i=0; i<3; i++) sc[i] = vel[i] * ( chi + eta );
59 }
60
61 template<typename T> void NPTi<T>::getVelScaleB(double sc[3], int index ){
62 int i;
63
64 for(i=0; i<3; i++) sc[i] = oldVel[index*3 + i] * ( chi + eta );
65 }
66
67
68 template<typename T> void NPTi<T>::getPosScale(double pos[3], double COM[3],
69 int index, double sc[3]){
70 int j;
71
72 for(j=0; j<3; j++)
73 sc[j] = ( oldPos[index*3+j] + pos[j]) / 2.0 - COM[j];
74
75 for(j=0; j<3; j++)
76 sc[j] *= eta;
77 }
78
79 template<typename T> void NPTi<T>::scaleSimBox( void ){
80
81 double scaleFactor;
82
83 scaleFactor = exp(dt*eta);
84
85 if ((scaleFactor > 1.1) || (scaleFactor < 0.9)) {
86 sprintf( painCave.errMsg,
87 "NPTi error: Attempting a Box scaling of more than 10 percent"
88 " check your tauBarostat, as it is probably too small!\n"
89 " eta = %lf, scaleFactor = %lf\n", eta, scaleFactor
90 );
91 painCave.isFatal = 1;
92 simError();
93 } else {
94 info->scaleBox(scaleFactor);
95 }
96
97 }
98
99 template<typename T> bool NPTi<T>::etaConverged() {
100
101 return ( fabs(prevEta - eta) <= etaTolerance );
102 }
103
104 template<typename T> double NPTi<T>::getConservedQuantity(void){
105
106 double conservedQuantity;
107 double Energy;
108 double thermostat_kinetic;
109 double thermostat_potential;
110 double barostat_kinetic;
111 double barostat_potential;
112
113 Energy = tStats->getTotalE();
114
115 thermostat_kinetic = fkBT* tt2 * chi * chi /
116 (2.0 * eConvert);
117
118 thermostat_potential = fkBT* integralOfChidt / eConvert;
119
120
121 barostat_kinetic = 3.0 * NkBT * tb2 * eta * eta /
122 (2.0 * eConvert);
123
124 barostat_potential = (targetPressure * tStats->getVolume() / p_convert) /
125 eConvert;
126
127 conservedQuantity = Energy + thermostat_kinetic + thermostat_potential +
128 barostat_kinetic + barostat_potential;
129
130 // cout.width(8);
131 // cout.precision(8);
132
133 // cerr << info->getTime() << "\t" << Energy << "\t" << thermostat_kinetic <<
134 // "\t" << thermostat_potential << "\t" << barostat_kinetic <<
135 // "\t" << barostat_potential << "\t" << conservedQuantity << endl;
136 return conservedQuantity;
137 }