ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/ExtendedSystem.cpp
Revision: 477
Committed: Tue Apr 8 14:34:30 2003 UTC (21 years, 3 months ago) by gezelter
File size: 5973 byte(s)
Log Message:
dt/2 fix in 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 * p_units;
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 // determine the change in cell volume
110 scale = pow( (1.0 + dt * 3.0 * epsilonDot), (1.0 / 3.0));
111
112 newBox[0] = oldBox[0] * scale;
113 newBox[1] = oldBox[1] * scale;
114 newBox[2] = oldBox[2] * scale;
115 volume = newBox[0]*newBox[1]*newBox[2];
116
117 entry_plug->setBox(newBox);
118
119 // perform affine transform to update positions with volume fluctuations
120 this->AffineTransform( oldBox, newBox );
121
122 epsilonScale = epsilonDot * dt;
123
124 // advance the zeta term to zeta(t + dt) - zeta is 0.0d0 on config. readin
125 // qmass is set in the parameter file
126
127 zeta += dt * ( (ke_temp*2.0 - NkBT) / qmass );
128 zetaScale = zeta * dt;
129
130 std::cerr << "zetaScale = " << zetaScale << " epsilonScale = " << epsilonScale << "\n";
131
132 // apply barostating and thermostating to velocities and angular momenta
133 for(i = 0; i < entry_plug->n_atoms; i++){
134
135 vx = atoms[i]->get_vx();
136 vy = atoms[i]->get_vy();
137 vz = atoms[i]->get_vz();
138
139 atoms[i]->set_vx(vx * (1.0 - zetaScale - epsilonScale));
140 atoms[i]->set_vy(vy * (1.0 - zetaScale - epsilonScale));
141 atoms[i]->set_vz(vz * (1.0 - zetaScale - epsilonScale));
142 }
143 if( entry_plug->n_oriented ){
144
145 for( i=0; i < entry_plug->n_atoms; i++ ){
146
147 if( atoms[i]->isDirectional() ){
148
149 dAtom = (DirectionalAtom *)atoms[i];
150
151 jx = dAtom->getJx();
152 jy = dAtom->getJy();
153 jz = dAtom->getJz();
154
155 dAtom->setJx( jx * (1.0 - zetaScale));
156 dAtom->setJy( jy * (1.0 - zetaScale));
157 dAtom->setJz( jz * (1.0 - zetaScale));
158 }
159 }
160 }
161 }
162
163 void ExtendedSystem::AffineTransform( double oldBox[3], double newBox[3] ){
164
165 int i;
166 double r[3];
167 double boxNum[3];
168 double percentScale[3];
169 double delta[3];
170 double rxi, ryi, rzi;
171
172 molecules = entry_plug->molecules;
173
174 // first determine the scaling factor from the box size change
175 percentScale[0] = (newBox[0] - oldBox[0]) / oldBox[0];
176 percentScale[1] = (newBox[1] - oldBox[1]) / oldBox[1];
177 percentScale[2] = (newBox[2] - oldBox[2]) / oldBox[2];
178
179 for (i=0; i < entry_plug->n_mol; i++) {
180
181 molecules[i].getCOM(r);
182
183 // find the minimum image coordinates of the molecular centers of mass:
184
185 boxNum[0] = oldBox[0] * copysign(1.0,r[0]) *
186 (double)(int)(fabs(r[0]/oldBox[0]) + 0.5);
187
188 boxNum[1] = oldBox[1] * copysign(1.0,r[1]) *
189 (double)(int)(fabs(r[1]/oldBox[1]) + 0.5);
190
191 boxNum[2] = oldBox[2] * copysign(1.0,r[2]) *
192 (double)(int)(fabs(r[2]/oldBox[2]) + 0.5);
193
194 rxi = r[0] - boxNum[0];
195 ryi = r[1] - boxNum[1];
196 rzi = r[2] - boxNum[2];
197
198 // update the minimum image coordinates using the scaling factor
199 rxi += rxi*percentScale[0];
200 ryi += ryi*percentScale[1];
201 rzi += rzi*percentScale[2];
202
203 delta[0] = r[0] - (rxi + boxNum[0]);
204 delta[1] = r[1] - (ryi + boxNum[1]);
205 delta[2] = r[2] - (rzi + boxNum[2]);
206
207 molecules[i].moveCOM(delta);
208 }
209 }