ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/ExtendedSystem.cpp
Revision: 458
Committed: Fri Apr 4 19:47:19 2003 UTC (21 years, 3 months ago) by gezelter
File size: 5735 byte(s)
Log Message:
Changes for Extended System

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