ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/ExtendedSystem.cpp
Revision: 474
Committed: Mon Apr 7 21:42:19 2003 UTC (21 years, 3 months ago) by gezelter
File size: 6032 byte(s)
Log Message:
Fixes for NPT and NVT

File Contents

# Content
1 #include <math.h>
2 #include "Atom.hpp"
3 #include "Molecule.hpp"
4 #include "SimInfo.hpp"
5 #include "Thermo.hpp"
6 #include "ExtendedSystem.hpp"
7
8 ExtendedSystem::ExtendedSystem( SimInfo* the_entry_plug ) {
9
10 // get what information we need from the SimInfo object
11
12 entry_plug = the_entry_plug;
13 zeta = 0.0;
14 epsilonDot = 0.0;
15 }
16
17 void ExtendedSystem::NoseHooverNVT( double dt, double ke ){
18
19 // Basic thermostating via Hoover, Phys.Rev.A, 1985, Vol. 31 (5) 1695-1697
20
21 int i;
22 double NkBT, zetaScale, ke_temp;
23 double vx, vy, vz, jx, jy, jz;
24 const double kB = 8.31451e-7; // boltzmann constant in amu*Ang^2*fs^-2/K
25 const double e_convert = 4.184e-4; // to convert ke from kcal/mol to
26 // amu*Ang^2*fs^-2/K
27 DirectionalAtom* dAtom;
28 atoms = entry_plug->atoms;
29
30 ke_temp = ke * e_convert;
31 NkBT = (double)entry_plug->ndf * kB * targetTemp;
32
33 // advance the zeta term to zeta(t + dt) - zeta is 0.0d0 on config. readin
34 // qmass is set in the parameter file
35
36 zeta += dt * ( (ke_temp*2.0 - NkBT) / qmass );
37
38 zetaScale = zeta * dt;
39
40 std::cerr << "zetaScale = " << zetaScale << "\n";
41
42 // perform thermostat scaling on linear velocities and angular momentum
43 for(i = 0; i < entry_plug->n_atoms; i++){
44
45 vx = atoms[i]->get_vx();
46 vy = atoms[i]->get_vy();
47 vz = atoms[i]->get_vz();
48
49 atoms[i]->set_vx(vx * (1.0 - zetaScale));
50 atoms[i]->set_vy(vy * (1.0 - zetaScale));
51 atoms[i]->set_vz(vz * (1.0 - zetaScale));
52 }
53 if( entry_plug->n_oriented ){
54
55 for( i=0; i < entry_plug->n_atoms; i++ ){
56
57 if( atoms[i]->isDirectional() ){
58
59 dAtom = (DirectionalAtom *)atoms[i];
60
61 jx = dAtom->getJx();
62 jy = dAtom->getJy();
63 jz = dAtom->getJz();
64
65 dAtom->setJx(jx * (1.0 - zetaScale));
66 dAtom->setJy(jy * (1.0 - zetaScale));
67 dAtom->setJz(jz * (1.0 - zetaScale));
68 }
69 }
70 }
71 }
72
73
74 void ExtendedSystem::NoseHooverAndersonNPT( double dt,
75 double ke,
76 double p_int ) {
77
78 // Basic barostating via Hoover, Phys.Rev.A, 1985, Vol. 31 (5) 1695-1697
79 // Hoover, Phys.Rev.A, 1986, Vol.34 (3) 2499-2500
80
81 double oldBox[3];
82 double newBox[3];
83 const double kB = 8.31451e-7; // boltzmann constant in amu*Ang^2*fs^-2/K
84 const double p_units = 6.10192996e-9; // converts atm to amu*fs^-2*Ang^-1
85 const double e_convert = 4.184e-4; // to convert ke from kcal/mol to
86 // amu*Ang^2*fs^-2/K
87
88 int i;
89 double p_ext, zetaScale, epsilonScale, scale, NkBT, ke_temp;
90 double volume, p_mol;
91 double vx, vy, vz, jx, jy, jz;
92 DirectionalAtom* dAtom;
93 atoms = entry_plug->atoms;
94
95 p_ext = targetPressure * p_units;
96 p_mol = p_int;
97
98 entry_plug->getBox(oldBox);
99
100 volume = oldBox[0]*oldBox[1]*oldBox[2];
101
102 ke_temp = ke * e_convert;
103 NkBT = (double)entry_plug->ndf * kB * targetTemp;
104
105 // propogate the strain rate
106
107 epsilonDot += dt * ((p_mol - p_ext) * volume /
108 (tauRelax*tauRelax * kB * targetTemp) );
109
110
111 std::cerr << "p_mol = " << p_mol << " p_ext = " << p_ext << " volume = " << volume << " tauRelax = " << tauRelax << "\n";
112
113
114 // determine the change in cell volume
115 scale = pow( (1.0 + dt * 3.0 * epsilonDot), (1.0 / 3.0));
116
117 newBox[0] = oldBox[0] * scale;
118 newBox[1] = oldBox[1] * scale;
119 newBox[2] = oldBox[2] * scale;
120 volume = newBox[0]*newBox[1]*newBox[2];
121
122 entry_plug->setBox(newBox);
123
124 // perform affine transform to update positions with volume fluctuations
125 this->AffineTransform( oldBox, newBox );
126
127 epsilonScale = epsilonDot * dt;
128
129 // advance the zeta term to zeta(t + dt) - zeta is 0.0d0 on config. readin
130 // qmass is set in the parameter file
131
132 zeta += dt * ( (ke_temp*2.0 - NkBT) / qmass );
133 zetaScale = zeta * dt;
134
135 std::cerr << "zetaScale = " << zetaScale << "epsilonScale = " << epsilonScale << "\n";
136
137 // apply barostating and thermostating to velocities and angular momenta
138 for(i = 0; i < entry_plug->n_atoms; i++){
139
140 vx = atoms[i]->get_vx();
141 vy = atoms[i]->get_vy();
142 vz = atoms[i]->get_vz();
143
144 atoms[i]->set_vx(vx * (1.0 - zetaScale - epsilonScale));
145 atoms[i]->set_vy(vy * (1.0 - zetaScale - epsilonScale));
146 atoms[i]->set_vz(vz * (1.0 - zetaScale - epsilonScale));
147 }
148 if( entry_plug->n_oriented ){
149
150 for( i=0; i < entry_plug->n_atoms; i++ ){
151
152 if( atoms[i]->isDirectional() ){
153
154 dAtom = (DirectionalAtom *)atoms[i];
155
156 jx = dAtom->getJx();
157 jy = dAtom->getJy();
158 jz = dAtom->getJz();
159
160 dAtom->setJx( jx * (1.0 - zetaScale));
161 dAtom->setJy( jy * (1.0 - zetaScale));
162 dAtom->setJz( jz * (1.0 - zetaScale));
163 }
164 }
165 }
166 }
167
168 void ExtendedSystem::AffineTransform( double oldBox[3], double newBox[3] ){
169
170 int i;
171 double r[3];
172 double boxNum[3];
173 double percentScale[3];
174 double rxi, ryi, rzi;
175
176 molecules = entry_plug->molecules;
177
178 // first determine the scaling factor from the box size change
179 percentScale[0] = (newBox[0] - oldBox[0]) / oldBox[0];
180 percentScale[1] = (newBox[1] - oldBox[1]) / oldBox[1];
181 percentScale[2] = (newBox[2] - oldBox[2]) / oldBox[2];
182
183 for (i=0; i < entry_plug->n_mol; i++) {
184
185 molecules[i].getCOM(r);
186
187 // find the minimum image coordinates of the molecular centers of mass:
188
189 boxNum[0] = oldBox[0] * copysign(1.0,r[0]) *
190 (double)(int)(fabs(r[0]/oldBox[0]) + 0.5);
191
192 boxNum[1] = oldBox[1] * copysign(1.0,r[1]) *
193 (double)(int)(fabs(r[1]/oldBox[1]) + 0.5);
194
195 boxNum[2] = oldBox[2] * copysign(1.0,r[2]) *
196 (double)(int)(fabs(r[2]/oldBox[2]) + 0.5);
197
198 rxi = r[0] - boxNum[0];
199 ryi = r[1] - boxNum[1];
200 rzi = r[2] - boxNum[2];
201
202 // update the minimum image coordinates using the scaling factor
203 rxi += rxi*percentScale[0];
204 ryi += ryi*percentScale[1];
205 rzi += rzi*percentScale[2];
206
207 r[0] = rxi + boxNum[0];
208 r[1] = ryi + boxNum[1];
209 r[2] = rzi + boxNum[2];
210
211 molecules[i].moveCOM(r);
212 }
213 }