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