ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/NPTi.cpp
Revision: 645
Committed: Tue Jul 22 19:54:52 2003 UTC (20 years, 11 months ago) by tim
File size: 6087 byte(s)
Log Message:
*** empty log message ***

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
13 // Basic isotropic thermostating and barostating via the Melchionna
14 // modification of the Hoover algorithm:
15 //
16 // Melchionna, S., Ciccotti, G., and Holian, B. L., 1993,
17 // Molec. Phys., 78, 533.
18 //
19 // and
20 //
21 // Hoover, W. G., 1986, Phys. Rev. A, 34, 2499.
22
23 template<typename T> NPTi<T>::NPTi ( SimInfo *theInfo, ForceFields* the_ff):
24 T( theInfo, the_ff )
25 {
26 chi = 0.0;
27 eta = 0.0;
28 have_tau_thermostat = 0;
29 have_tau_barostat = 0;
30 have_target_temp = 0;
31 have_target_pressure = 0;
32 }
33
34 template<typename T> void NPTi<T>::moveA() {
35
36 int i, j;
37 DirectionalAtom* dAtom;
38 double Tb[3], ji[3];
39 double A[3][3], I[3][3];
40 double angle, mass;
41 double vel[3], pos[3], frc[3];
42
43 double rj[3];
44 double instaTemp, instaPress, instaVol;
45 double tt2, tb2, scaleFactor;
46
47 tt2 = tauThermostat * tauThermostat;
48 tb2 = tauBarostat * tauBarostat;
49
50 instaTemp = tStats->getTemperature();
51 instaPress = tStats->getPressure();
52 instaVol = tStats->getVolume();
53
54 // first evolve chi a half step
55
56 chi += dt2 * ( instaTemp / targetTemp - 1.0) / tt2;
57 eta += dt2 * ( instaVol * (instaPress - targetPressure) /
58 (p_convert*NkBT*tb2));
59
60 for( i=0; i<nAtoms; i++ ){
61 atoms[i]->getVel( vel );
62 atoms[i]->getPos( pos );
63 atoms[i]->getFrc( frc );
64
65 mass = atoms[i]->getMass();
66
67 for (j=0; j < 3; j++) {
68 vel[j] += dt2 * ((frc[j] / mass ) * eConvert - vel[j]*(chi+eta));
69 rj[j] = pos[j];
70 }
71
72 atoms[i]->setVel( vel );
73
74 info->wrapVector(rj);
75
76 for (j = 0; j < 3; j++)
77 pos[j] += dt * (vel[j] + eta*rj[j]);
78
79 atoms[i]->setPos( pos );
80
81 if( atoms[i]->isDirectional() ){
82
83 dAtom = (DirectionalAtom *)atoms[i];
84
85 // get and convert the torque to body frame
86
87 dAtom->getTrq( Tb );
88 dAtom->lab2Body( Tb );
89
90 // get the angular momentum, and propagate a half step
91
92 dAtom->getJ( ji );
93
94 for (j=0; j < 3; j++)
95 ji[j] += dt2 * (Tb[j] * eConvert - ji[j]*chi);
96
97 // use the angular velocities to propagate the rotation matrix a
98 // full time step
99
100 dAtom->getA(A);
101 dAtom->getI(I);
102
103 // rotate about the x-axis
104 angle = dt2 * ji[0] / I[0][0];
105 this->rotate( 1, 2, angle, ji, A );
106
107 // rotate about the y-axis
108 angle = dt2 * ji[1] / I[1][1];
109 this->rotate( 2, 0, angle, ji, A );
110
111 // rotate about the z-axis
112 angle = dt * ji[2] / I[2][2];
113 this->rotate( 0, 1, angle, ji, A);
114
115 // rotate about the y-axis
116 angle = dt2 * ji[1] / I[1][1];
117 this->rotate( 2, 0, angle, ji, A );
118
119 // rotate about the x-axis
120 angle = dt2 * ji[0] / I[0][0];
121 this->rotate( 1, 2, angle, ji, A );
122
123 dAtom->setJ( ji );
124 dAtom->setA( A );
125 }
126
127 }
128
129 // Scale the box after all the positions have been moved:
130
131 scaleFactor = exp(dt*eta);
132
133 if ((scaleFactor > 1.1) || (scaleFactor < 0.9)) {
134 sprintf( painCave.errMsg,
135 "NPTi error: Attempting a Box scaling of more than 10 percent"
136 " check your tauBarostat, as it is probably too small!\n"
137 " eta = %lf, scaleFactor = %lf\n", eta, scaleFactor
138 );
139 painCave.isFatal = 1;
140 simError();
141 } else {
142 info->scaleBox(exp(dt*eta));
143 }
144
145 }
146
147 template<typename T> void NPTi<T>::moveB( void ){
148
149 int i, j;
150 DirectionalAtom* dAtom;
151 double Tb[3], ji[3];
152 double vel[3], frc[3];
153 double mass;
154
155 double instaTemp, instaPress, instaVol;
156 double tt2, tb2;
157
158 tt2 = tauThermostat * tauThermostat;
159 tb2 = tauBarostat * tauBarostat;
160
161 instaTemp = tStats->getTemperature();
162 instaPress = tStats->getPressure();
163 instaVol = tStats->getVolume();
164
165 chi += dt2 * ( instaTemp / targetTemp - 1.0) / tt2;
166 eta += dt2 * ( instaVol * (instaPress - targetPressure) /
167 (p_convert*NkBT*tb2));
168
169 for( i=0; i<nAtoms; i++ ){
170
171 atoms[i]->getVel( vel );
172 atoms[i]->getFrc( frc );
173
174 mass = atoms[i]->getMass();
175
176 // velocity half step
177 for (j=0; j < 3; j++)
178 vel[j] += dt2 * ((frc[j] / mass ) * eConvert - vel[j]*(chi+eta));
179
180 atoms[i]->setVel( vel );
181
182 if( atoms[i]->isDirectional() ){
183
184 dAtom = (DirectionalAtom *)atoms[i];
185
186 // get and convert the torque to body frame
187
188 dAtom->getTrq( Tb );
189 dAtom->lab2Body( Tb );
190
191 // get the angular momentum, and propagate a half step
192
193 dAtom->getJ( ji );
194
195 for (j=0; j < 3; j++)
196 ji[j] += dt2 * (Tb[j] * eConvert - ji[j]*chi);
197
198 dAtom->setJ( ji );
199 }
200 }
201 }
202
203 template<typename T> int NPTi<T>::readyCheck() {
204
205 // First check to see if we have a target temperature.
206 // Not having one is fatal.
207
208 if (!have_target_temp) {
209 sprintf( painCave.errMsg,
210 "NPTi error: You can't use the NPTi integrator\n"
211 " without a targetTemp!\n"
212 );
213 painCave.isFatal = 1;
214 simError();
215 return -1;
216 }
217
218 if (!have_target_pressure) {
219 sprintf( painCave.errMsg,
220 "NPTi error: You can't use the NPTi integrator\n"
221 " without a targetPressure!\n"
222 );
223 painCave.isFatal = 1;
224 simError();
225 return -1;
226 }
227
228 // We must set tauThermostat.
229
230 if (!have_tau_thermostat) {
231 sprintf( painCave.errMsg,
232 "NPTi error: If you use the NPTi\n"
233 " integrator, you must set tauThermostat.\n");
234 painCave.isFatal = 1;
235 simError();
236 return -1;
237 }
238
239 // We must set tauBarostat.
240
241 if (!have_tau_barostat) {
242 sprintf( painCave.errMsg,
243 "NPTi error: If you use the NPTi\n"
244 " integrator, you must set tauBarostat.\n");
245 painCave.isFatal = 1;
246 simError();
247 return -1;
248 }
249
250 // We need NkBT a lot, so just set it here:
251
252 NkBT = (double)info->ndf * kB * targetTemp;
253
254 return 1;
255 }