ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new-templateless/OOPSE/libmdtools/NPTi.cpp
Revision: 850
Committed: Mon Nov 3 22:07:17 2003 UTC (20 years, 9 months ago) by mmeineke
File size: 3970 byte(s)
Log Message:
begun work on removing templates and most of standard template library from OOPSE.

File Contents

# Content
1 #include <math.h>
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 NPTi::NPTi ( SimInfo *theInfo, ForceFields* the_ff):
27 NPT( theInfo, the_ff )
28 {
29 GenericData* data;
30 double *etaArray;
31
32 eta = 0.0;
33 oldEta = 0.0;
34
35 // retrieve eta array from simInfo if it exists
36 data = info->getProperty(ETAVALUE_ID);
37 if(data != NULL){
38
39 int test = data->getDarray(etaArray);
40
41 if( test == 9 ){
42
43 eta = etaArray[0];
44 }
45 delete[] etaArray;
46 }
47 else
48 std::cerr << "NPTi error: etaArray is not length 9 (actual = " << test
49 << ").\n"
50 << " Simulation wil proceed with eta = 0;\n";
51 }
52 }
53
54 NPTi::~NPTi() {
55 //nothing for now
56 }
57
58 void NPTi::resetIntegrator() {
59 eta = 0.0;
60 NPT::resetIntegrator();
61 }
62
63 void NPTi::evolveEtaA() {
64 eta += dt2 * ( instaVol * (instaPress - targetPressure) /
65 (p_convert*NkBT*tb2));
66 oldEta = eta;
67 }
68
69 void NPTi::evolveEtaB() {
70
71 prevEta = eta;
72 eta = oldEta + dt2 * ( instaVol * (instaPress - targetPressure) /
73 (p_convert*NkBT*tb2));
74 }
75
76 void NPTi::getVelScaleA(double sc[3], double vel[3]) {
77 int i;
78
79 for(i=0; i<3; i++) sc[i] = vel[i] * ( chi + eta );
80 }
81
82 void NPTi::getVelScaleB(double sc[3], int index ){
83 int i;
84
85 for(i=0; i<3; i++) sc[i] = oldVel[index*3 + i] * ( chi + eta );
86 }
87
88
89 void NPTi::getPosScale(double pos[3], double COM[3],
90 int index, double sc[3]){
91 int j;
92
93 for(j=0; j<3; j++)
94 sc[j] = ( oldPos[index*3+j] + pos[j]) / 2.0 - COM[j];
95
96 for(j=0; j<3; j++)
97 sc[j] *= eta;
98 }
99
100 void NPTi::scaleSimBox( void ){
101
102 double scaleFactor;
103
104 scaleFactor = exp(dt*eta);
105
106 if ((scaleFactor > 1.1) || (scaleFactor < 0.9)) {
107 sprintf( painCave.errMsg,
108 "NPTi error: Attempting a Box scaling of more than 10 percent"
109 " check your tauBarostat, as it is probably too small!\n"
110 " eta = %lf, scaleFactor = %lf\n", eta, scaleFactor
111 );
112 painCave.isFatal = 1;
113 simError();
114 } else {
115 info->scaleBox(scaleFactor);
116 }
117
118 }
119
120 bool NPTi::etaConverged() {
121
122 return ( fabs(prevEta - eta) <= etaTolerance );
123 }
124
125 double NPTi::getConservedQuantity(void){
126
127 double conservedQuantity;
128 double Energy;
129 double thermostat_kinetic;
130 double thermostat_potential;
131 double barostat_kinetic;
132 double barostat_potential;
133
134 Energy = tStats->getTotalE();
135
136 thermostat_kinetic = fkBT* tt2 * chi * chi /
137 (2.0 * eConvert);
138
139 thermostat_potential = fkBT* integralOfChidt / eConvert;
140
141
142 barostat_kinetic = 3.0 * NkBT * tb2 * eta * eta /
143 (2.0 * eConvert);
144
145 barostat_potential = (targetPressure * tStats->getVolume() / p_convert) /
146 eConvert;
147
148 conservedQuantity = Energy + thermostat_kinetic + thermostat_potential +
149 barostat_kinetic + barostat_potential;
150
151 // cout.width(8);
152 // cout.precision(8);
153
154 // cerr << info->getTime() << "\t" << Energy << "\t" << thermostat_kinetic <<
155 // "\t" << thermostat_potential << "\t" << barostat_kinetic <<
156 // "\t" << barostat_potential << "\t" << conservedQuantity << endl;
157 return conservedQuantity;
158 }
159
160 string NPTi::getAdditionalParameters(void){
161 string parameters;
162 const int BUFFERSIZE = 2000; // size of the read buffer
163 char buffer[BUFFERSIZE];
164
165 sprintf(buffer,"\t%lf\t%lf;", chi, integralOfChidt);
166 parameters += buffer;
167
168 sprintf(buffer,"\t%lf\t0\t0;", eta);
169 parameters += buffer;
170
171 sprintf(buffer,"\t0\t%lf\t0;", eta);
172 parameters += buffer;
173
174 sprintf(buffer,"\t0\t0\t%lf;", eta);
175 parameters += buffer;
176
177 return parameters;
178
179 }