ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/NPTi.cpp
Revision: 614
Committed: Tue Jul 15 17:57:04 2003 UTC (20 years, 11 months ago) by mmeineke
File size: 6002 byte(s)
Log Message:
fixed some bugs, Changed entry_plug to info where appropriate

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 NPTi::NPTi ( SimInfo *theInfo, ForceFields* the_ff):
24 Integrator( 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 void NPTi::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
80 atoms[i]->setPos( pos );
81
82
83 if( atoms[i]->isDirectional() ){
84
85 dAtom = (DirectionalAtom *)atoms[i];
86
87 // get and convert the torque to body frame
88
89 dAtom->getTrq( Tb );
90 dAtom->lab2Body( Tb );
91
92 // get the angular momentum, and propagate a half step
93
94 dAtom->getJ( ji );
95
96 for (j=0; j < 3; j++)
97 ji[j] += dt2 * (Tb[j] * eConvert - ji[j]*chi);
98
99 // use the angular velocities to propagate the rotation matrix a
100 // full time step
101
102 dAtom->getA(A);
103 dAtom->getI(I);
104
105 // rotate about the x-axis
106 angle = dt2 * ji[0] / I[0][0];
107 this->rotate( 1, 2, angle, ji, A );
108
109 // rotate about the y-axis
110 angle = dt2 * ji[1] / I[1][1];
111 this->rotate( 2, 0, angle, ji, A );
112
113 // rotate about the z-axis
114 angle = dt * ji[2] / I[2][2];
115 this->rotate( 0, 1, angle, ji, A);
116
117 // rotate about the y-axis
118 angle = dt2 * ji[1] / I[1][1];
119 this->rotate( 2, 0, angle, ji, A );
120
121 // rotate about the x-axis
122 angle = dt2 * ji[0] / I[0][0];
123 this->rotate( 1, 2, angle, ji, A );
124
125 dAtom->setJ( ji );
126 dAtom->setA( A );
127 }
128
129 }
130
131 // Scale the box after all the positions have been moved:
132
133 scaleFactor = exp(dt*eta);
134
135 if ((scaleFactor > 1.1) || (scaleFactor < 0.9)) {
136 sprintf( painCave.errMsg,
137 "NPTi error: Attempting a Box scaling of more than 10 percent"
138 " check your tauBarostat, as it is probably too small!\n"
139 " eta = %lf, scaleFactor = %lf\n", eta, scaleFactor
140 );
141 painCave.isFatal = 1;
142 simError();
143 } else {
144 info->scaleBox(exp(dt*eta));
145 }
146
147 }
148
149 void NPTi::moveB( void ){
150
151 int i, j;
152 DirectionalAtom* dAtom;
153 double Tb[3], ji[3];
154 double vel[3], frc[3];
155 double mass;
156
157 double instaTemp, instaPress, instaVol;
158 double tt2, tb2;
159
160 tt2 = tauThermostat * tauThermostat;
161 tb2 = tauBarostat * tauBarostat;
162
163 instaTemp = tStats->getTemperature();
164 instaPress = tStats->getPressure();
165 instaVol = tStats->getVolume();
166
167 chi += dt2 * ( instaTemp / targetTemp - 1.0) / tt2;
168 eta += dt2 * ( instaVol * (instaPress - targetPressure) /
169 (p_convert*NkBT*tb2));
170
171 for( i=0; i<nAtoms; i++ ){
172
173 atoms[i]->getVel( vel );
174 atoms[i]->getFrc( frc );
175
176 mass = atoms[i]->getMass();
177
178 // velocity half step
179 for (j=0; j < 3; j++)
180 vel[j] += dt2 * ((frc[j] / mass ) * eConvert - vel[j]*(chi+eta));
181
182 atoms[i]->setVel( vel );
183
184 if( atoms[i]->isDirectional() ){
185
186 dAtom = (DirectionalAtom *)atoms[i];
187
188 // get and convert the torque to body frame
189
190 dAtom->getTrq( Tb );
191 dAtom->lab2Body( Tb );
192
193 // get the angular momentum, and propagate a half step
194
195 dAtom->getJ( ji );
196
197 for (j=0; j < 3; j++)
198 ji[j] += dt2 * (Tb[j] * eConvert - ji[j]*chi);
199
200 dAtom->setJ( ji );
201 }
202 }
203 }
204
205 int NPTi::readyCheck() {
206
207 // First check to see if we have a target temperature.
208 // Not having one is fatal.
209
210 if (!have_target_temp) {
211 sprintf( painCave.errMsg,
212 "NPTi error: You can't use the NPTi integrator\n"
213 " without a targetTemp!\n"
214 );
215 painCave.isFatal = 1;
216 simError();
217 return -1;
218 }
219
220 if (!have_target_pressure) {
221 sprintf( painCave.errMsg,
222 "NPTi error: You can't use the NPTi integrator\n"
223 " without a targetPressure!\n"
224 );
225 painCave.isFatal = 1;
226 simError();
227 return -1;
228 }
229
230 // We must set tauThermostat.
231
232 if (!have_tau_thermostat) {
233 sprintf( painCave.errMsg,
234 "NPTi error: If you use the NPTi\n"
235 " integrator, you must set tauThermostat.\n");
236 painCave.isFatal = 1;
237 simError();
238 return -1;
239 }
240
241 // We must set tauBarostat.
242
243 if (!have_tau_barostat) {
244 sprintf( painCave.errMsg,
245 "NPTi error: If you use the NPTi\n"
246 " integrator, you must set tauBarostat.\n");
247 painCave.isFatal = 1;
248 simError();
249 return -1;
250 }
251
252 // We need NkBT a lot, so just set it here:
253
254 NkBT = (double)info->ndf * kB * targetTemp;
255
256 return 1;
257 }