ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/ExtendedSystem.cpp
Revision: 475
Committed: Tue Apr 8 12:44:18 2003 UTC (21 years, 3 months ago) by gezelter
File size: 6312 byte(s)
Log Message:
Changes to integrate the NVT and NPT ensembles

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 volume = oldBox[0]*oldBox[1]*oldBox[2];
100
101 ke_temp = ke * e_convert;
102 NkBT = (double)entry_plug->ndf * kB * targetTemp;
103
104 // propogate the strain rate
105
106 epsilonDot += dt * ((p_mol - p_ext) * volume /
107 (tauRelax*tauRelax * kB * targetTemp) );
108
109
110 std::cerr << "dt = " << dt << " tauRelax = " << tauRelax << " kB = " << kB << "targetTemp = " << targetTemp << "\n";
111
112 // determine the change in cell volume
113 scale = pow( (1.0 + dt * 3.0 * epsilonDot), (1.0 / 3.0));
114
115 std::cerr << "p_mol = " << p_mol << " p_ext = " << p_ext << " scale = " << scale << "\n";
116
117
118 newBox[0] = oldBox[0] * scale;
119 newBox[1] = oldBox[1] * scale;
120 newBox[2] = oldBox[2] * scale;
121 volume = newBox[0]*newBox[1]*newBox[2];
122
123 entry_plug->setBox(newBox);
124
125 // perform affine transform to update positions with volume fluctuations
126 this->AffineTransform( oldBox, newBox );
127
128 epsilonScale = epsilonDot * dt;
129
130 // advance the zeta term to zeta(t + dt) - zeta is 0.0d0 on config. readin
131 // qmass is set in the parameter file
132
133 zeta += dt * ( (ke_temp*2.0 - NkBT) / qmass );
134 zetaScale = zeta * dt;
135
136 std::cerr << "zetaScale = " << zetaScale << "epsilonScale = " << epsilonScale << "\n";
137
138 // apply barostating and thermostating to velocities and angular momenta
139 for(i = 0; i < entry_plug->n_atoms; i++){
140
141 vx = atoms[i]->get_vx();
142 vy = atoms[i]->get_vy();
143 vz = atoms[i]->get_vz();
144
145 atoms[i]->set_vx(vx * (1.0 - zetaScale - epsilonScale));
146 atoms[i]->set_vy(vy * (1.0 - zetaScale - epsilonScale));
147 atoms[i]->set_vz(vz * (1.0 - zetaScale - epsilonScale));
148 }
149 if( entry_plug->n_oriented ){
150
151 for( i=0; i < entry_plug->n_atoms; i++ ){
152
153 if( atoms[i]->isDirectional() ){
154
155 dAtom = (DirectionalAtom *)atoms[i];
156
157 jx = dAtom->getJx();
158 jy = dAtom->getJy();
159 jz = dAtom->getJz();
160
161 dAtom->setJx( jx * (1.0 - zetaScale));
162 dAtom->setJy( jy * (1.0 - zetaScale));
163 dAtom->setJz( jz * (1.0 - zetaScale));
164 }
165 }
166 }
167 }
168
169 void ExtendedSystem::AffineTransform( double oldBox[3], double newBox[3] ){
170
171 int i;
172 double r[3];
173 double boxNum[3];
174 double percentScale[3];
175 double rxi, ryi, rzi;
176
177 molecules = entry_plug->molecules;
178
179 // first determine the scaling factor from the box size change
180 percentScale[0] = (newBox[0] - oldBox[0]) / oldBox[0];
181 percentScale[1] = (newBox[1] - oldBox[1]) / oldBox[1];
182 percentScale[2] = (newBox[2] - oldBox[2]) / oldBox[2];
183
184 std::cerr << "ps = " << percentScale[0] <<" " << percentScale[1] << " " << percentScale[2] << "\n";
185
186
187 for (i=0; i < entry_plug->n_mol; i++) {
188
189 molecules[i].getCOM(r);
190
191 // find the minimum image coordinates of the molecular centers of mass:
192
193 boxNum[0] = oldBox[0] * copysign(1.0,r[0]) *
194 (double)(int)(fabs(r[0]/oldBox[0]) + 0.5);
195
196 boxNum[1] = oldBox[1] * copysign(1.0,r[1]) *
197 (double)(int)(fabs(r[1]/oldBox[1]) + 0.5);
198
199 boxNum[2] = oldBox[2] * copysign(1.0,r[2]) *
200 (double)(int)(fabs(r[2]/oldBox[2]) + 0.5);
201
202
203 std::cerr << "boxNum = " << boxNum[0] << " " << boxNum[1] << " " << boxNum[2] << "\n";
204
205 rxi = r[0] - boxNum[0];
206 ryi = r[1] - boxNum[1];
207 rzi = r[2] - boxNum[2];
208
209 // update the minimum image coordinates using the scaling factor
210 rxi += rxi*percentScale[0];
211 ryi += ryi*percentScale[1];
212 rzi += rzi*percentScale[2];
213
214 r[0] = rxi + boxNum[0];
215 r[1] = ryi + boxNum[1];
216 r[2] = rzi + boxNum[2];
217
218 molecules[i].moveCOM(r);
219 }
220 }