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

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 = info.n_atoms;
14 atoms = info.atoms;
15 nMols = info.n_mol;
16 molecules = info.molecules;
17 zeta = 0.0;
18 epsilonDot = 0.0;
19
20 }
21
22 ExtendedSystem::~ExtendedSystem() {
23 }
24
25
26 void ExtendedSystem::NoseHooverNVT( double dt, double ke ){
27
28 // Basic thermostating via Hoover, Phys.Rev.A, 1985, Vol. 31 (5) 1695-1697
29
30 int i;
31 double NkBT, zetaScale, ke_temp;
32 double vx, vy, vz, jx, jy, jz;
33 const double kB = 8.31451e-7; // boltzmann constant in amu*Ang^2*fs^-2/K
34 const double e_convert = 4.184e-4; // to convert ke from kcal/mol to
35 // amu*Ang^2*fs^-2/K
36
37 ke_temp = ke * e_convert;
38 NkBT = (double)getNDF() * 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 < n_atoms; 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( n_oriented ){
58
59 for( i=0; i < n_atoms; 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;
93
94 p_ext = targetPressure * p_units;
95 p_mol = p_int * p_units;
96
97 getBox(oldBox);
98
99 volume = oldBox[0]*oldBox[1]*oldBox[2];
100
101 ke_temp = ke * e_convert;
102 NkBT = (double)getNDF() * 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 // perform affine transform to update positions with volume fluctuations
118 this->AffineTransform( oldBox, newBox );
119
120 epsilonScale = epsilonDot * dt;
121
122 // advance the zeta term to zeta(t + dt) - zeta is 0.0d0 on config. readin
123 // qmass is set in the parameter file
124
125 zeta += dt * ( (ke_temp*2.0 - NkBT) / qmass );
126 zetaScale = zeta * dt;
127
128 // apply barostating and thermostating to velocities and angular momenta
129 for(i = 0; i < n_atoms; i++){
130
131 vx = atoms[i]->get_vx();
132 vy = atoms[i]->get_vy();
133 vz = atoms[i]->get_vz();
134
135 atoms[i]->set_vx(vx * (1.0 - zetaScale - epsilonScale));
136 atoms[i]->set_vy(vy * (1.0 - zetaScale - epsilonScale));
137 atoms[i]->set_vz(vz * (1.0 - zetaScale - epsilonScale));
138 }
139 if( n_oriented ){
140
141 for( i=0; i < n_atoms; i++ ){
142
143 if( atoms[i]->isDirectional() ){
144
145 dAtom = (DirectionalAtom *)atoms[i];
146
147 jx = dAtom->getJx();
148 jy = dAtom->getJy();
149 jz = dAtom->getJz();
150
151 dAtom->setJx( jx * (1.0 - zetaScale));
152 dAtom->setJy( jy * (1.0 - zetaScale));
153 dAtom->setJz( jz * (1.0 - zetaScale));
154 }
155 }
156 }
157 }
158
159 void ExtendedSystem::AffineTransform( double oldBox[3], double newBox[3] ){
160
161 int i;
162 double r[3];
163 double boxNum[3];
164 double percentScale[3];
165 double rxi, ryi, rzi;
166
167 // first determine the scaling factor from the box size change
168 percentScale[0] = (newBox[0] - oldBox[0]) / oldBox[0];
169 percentScale[1] = (newBox[1] - oldBox[1]) / oldBox[1];
170 percentScale[2] = (newBox[2] - oldBox[2]) / oldBox[2];
171
172 for (i=0; i < nMols; i++) {
173
174 molecules[i]->getCOM(r);
175
176 // find the minimum image coordinates of the molecular centers of mass:
177
178 boxNum[0] = oldBox[0] * copysign(1.0,r[0]) *
179 (double)(int)(fabs(r[0]/oldBox[0]) + 0.5);
180
181 boxNum[1] = oldBox[1] * copysign(1.0,r[1]) *
182 (double)(int)(fabs(r[1]/oldBox[1]) + 0.5);
183
184 boxNum[2] = oldBox[2] * copysign(1.0,r[2]) *
185 (double)(int)(fabs(r[2]/oldBox[2]) + 0.5);
186
187 rxi = r[0] - boxNum[0];
188 ryi = r[1] - boxNum[1];
189 rzi = r[2] - boxNum[2];
190
191 // update the minimum image coordinates using the scaling factor
192 rxi += rxi*percentScale[0];
193 ryi += ryi*percentScale[1];
194 rzi += rzi*percentScale[2];
195
196 r[0] = rxi + boxNum[0];
197 r[1] = ryi + boxNum[1];
198 r[2] = rzi + boxNum[2];
199
200 molecules[i]->moveCOM(r);
201 }
202 }