36 |
|
* [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). |
37 |
|
* [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). |
38 |
|
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). |
39 |
< |
* [4] Vardeman & Gezelter, in progress (2009). |
39 |
> |
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
40 |
> |
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
41 |
|
*/ |
42 |
|
|
43 |
|
#include "integrators/Velocitizer.hpp" |
51 |
|
#include "math/ParallelRandNumGen.hpp" |
52 |
|
#endif |
53 |
|
|
53 |
– |
/* Remove me after testing*/ |
54 |
– |
/* |
55 |
– |
#include <cstdio> |
56 |
– |
#include <iostream> |
57 |
– |
*/ |
58 |
– |
/*End remove me*/ |
59 |
– |
|
54 |
|
namespace OpenMD { |
55 |
|
|
56 |
< |
Velocitizer::Velocitizer(SimInfo* info) : info_(info) { |
56 |
> |
Velocitizer::Velocitizer(SimInfo* info) : info_(info), thermo(info) { |
57 |
|
|
58 |
|
int seedValue; |
59 |
|
Globals * simParams = info->getSimParams(); |
83 |
|
Vector3d aVel; |
84 |
|
Vector3d aJ; |
85 |
|
Mat3x3d I; |
86 |
< |
int l; |
93 |
< |
int m; |
94 |
< |
int n; |
86 |
> |
int l, m, n; |
87 |
|
Vector3d vdrift; |
88 |
|
RealType vbar; |
89 |
< |
/**@todo refactory kb */ |
89 |
> |
/**@todo refactor kb */ |
90 |
|
const RealType kb = 8.31451e-7; // kb in amu, angstroms, fs, etc. |
91 |
|
RealType av2; |
92 |
|
RealType kebar; |
96 |
|
SimInfo::MoleculeIterator i; |
97 |
|
Molecule::IntegrableObjectIterator j; |
98 |
|
Molecule * mol; |
99 |
< |
StuntDouble * integrableObject; |
99 |
> |
StuntDouble * sd; |
100 |
|
|
101 |
|
kebar = kb * temperature * info_->getNdfRaw() / (2.0 * info_->getNdf()); |
102 |
+ |
|
103 |
|
for( mol = info_->beginMolecule(i); mol != NULL; |
104 |
|
mol = info_->nextMolecule(i) ) { |
105 |
< |
for( integrableObject = mol->beginIntegrableObject(j); |
106 |
< |
integrableObject != NULL; |
107 |
< |
integrableObject = mol->nextIntegrableObject(j) ) { |
105 |
> |
|
106 |
> |
for( sd = mol->beginIntegrableObject(j); sd != NULL; |
107 |
> |
sd = mol->nextIntegrableObject(j) ) { |
108 |
|
|
109 |
|
// uses equipartition theory to solve for vbar in angstrom/fs |
110 |
|
|
111 |
< |
av2 = 2.0 * kebar / integrableObject->getMass(); |
111 |
> |
av2 = 2.0 * kebar / sd->getMass(); |
112 |
|
vbar = sqrt(av2); |
113 |
|
|
114 |
|
// picks random velocities from a gaussian distribution |
117 |
|
for( int k = 0; k < 3; k++ ) { |
118 |
|
aVel[k] = vbar * randNumGen_->randNorm(0.0, 1.0); |
119 |
|
} |
120 |
< |
integrableObject->setVel(aVel); |
120 |
> |
sd->setVel(aVel); |
121 |
|
|
122 |
< |
if (integrableObject->isDirectional()) { |
123 |
< |
I = integrableObject->getI(); |
122 |
> |
if (sd->isDirectional()) { |
123 |
> |
I = sd->getI(); |
124 |
|
|
125 |
< |
if (integrableObject->isLinear()) { |
126 |
< |
l = integrableObject->linearAxis(); |
125 |
> |
if (sd->isLinear()) { |
126 |
> |
l = sd->linearAxis(); |
127 |
|
m = (l + 1) % 3; |
128 |
|
n = (l + 2) % 3; |
129 |
|
|
137 |
|
vbar = sqrt(2.0 * kebar * I(k, k)); |
138 |
|
aJ[k] = vbar *randNumGen_->randNorm(0.0, 1.0); |
139 |
|
} |
140 |
< |
} // else isLinear |
140 |
> |
} |
141 |
|
|
142 |
< |
integrableObject->setJ(aJ); |
143 |
< |
} //isDirectional |
142 |
> |
sd->setJ(aJ); |
143 |
> |
} |
144 |
|
} |
145 |
< |
} //end for (mol = beginMolecule(i); ...) |
146 |
< |
|
154 |
< |
|
155 |
< |
|
145 |
> |
} |
146 |
> |
|
147 |
|
removeComDrift(); |
148 |
< |
// Remove angular drift if we are not using periodic boundary conditions. |
149 |
< |
if(!simParams->getUsePeriodicBoundaryConditions()) removeAngularDrift(); |
150 |
< |
|
148 |
> |
|
149 |
> |
// Remove angular drift if we are not using periodic boundary |
150 |
> |
// conditions: |
151 |
> |
|
152 |
> |
if(!simParams->getUsePeriodicBoundaryConditions()) removeAngularDrift(); |
153 |
|
} |
154 |
< |
|
162 |
< |
|
163 |
< |
|
154 |
> |
|
155 |
|
void Velocitizer::removeComDrift() { |
156 |
|
// Get the Center of Mass drift velocity. |
157 |
< |
Vector3d vdrift = info_->getComVel(); |
157 |
> |
Vector3d vdrift = thermo.getComVel(); |
158 |
|
|
159 |
|
SimInfo::MoleculeIterator i; |
160 |
|
Molecule::IntegrableObjectIterator j; |
161 |
|
Molecule * mol; |
162 |
< |
StuntDouble * integrableObject; |
162 |
> |
StuntDouble * sd; |
163 |
|
|
164 |
|
// Corrects for the center of mass drift. |
165 |
|
// sums all the momentum and divides by total mass. |
166 |
|
for( mol = info_->beginMolecule(i); mol != NULL; |
167 |
< |
mol = info_->nextMolecule(i) ) { |
168 |
< |
for( integrableObject = mol->beginIntegrableObject(j); |
169 |
< |
integrableObject != NULL; |
170 |
< |
integrableObject = mol->nextIntegrableObject(j) ) { |
171 |
< |
integrableObject->setVel(integrableObject->getVel() - vdrift); |
167 |
> |
mol = info_->nextMolecule(i) ) { |
168 |
> |
|
169 |
> |
for( sd = mol->beginIntegrableObject(j); sd != NULL; |
170 |
> |
sd = mol->nextIntegrableObject(j) ) { |
171 |
> |
|
172 |
> |
sd->setVel(sd->getVel() - vdrift); |
173 |
> |
|
174 |
|
} |
175 |
< |
} |
183 |
< |
|
175 |
> |
} |
176 |
|
} |
177 |
< |
|
186 |
< |
|
177 |
> |
|
178 |
|
void Velocitizer::removeAngularDrift() { |
179 |
|
// Get the Center of Mass drift velocity. |
180 |
|
|
181 |
|
Vector3d vdrift; |
182 |
|
Vector3d com; |
183 |
|
|
184 |
< |
info_->getComAll(com,vdrift); |
184 |
> |
thermo.getComAll(com, vdrift); |
185 |
|
|
186 |
|
Mat3x3d inertiaTensor; |
187 |
|
Vector3d angularMomentum; |
188 |
|
Vector3d omega; |
189 |
< |
|
190 |
< |
|
191 |
< |
|
201 |
< |
info_->getInertiaTensor(inertiaTensor,angularMomentum); |
189 |
> |
|
190 |
> |
thermo.getInertiaTensor(inertiaTensor, angularMomentum); |
191 |
> |
|
192 |
|
// We now need the inverse of the inertia tensor. |
193 |
< |
/* |
194 |
< |
std::cerr << "Angular Momentum before is " |
195 |
< |
<< angularMomentum << std::endl; |
206 |
< |
std::cerr << "Inertia Tensor before is " |
207 |
< |
<< inertiaTensor << std::endl; |
208 |
< |
*/ |
209 |
< |
inertiaTensor =inertiaTensor.inverse(); |
210 |
< |
/* |
211 |
< |
std::cerr << "Inertia Tensor after inverse is " |
212 |
< |
<< inertiaTensor << std::endl; |
213 |
< |
*/ |
214 |
< |
omega = inertiaTensor*angularMomentum; |
215 |
< |
|
193 |
> |
inertiaTensor = inertiaTensor.inverse(); |
194 |
> |
omega = inertiaTensor * angularMomentum; |
195 |
> |
|
196 |
|
SimInfo::MoleculeIterator i; |
197 |
|
Molecule::IntegrableObjectIterator j; |
198 |
< |
Molecule * mol; |
199 |
< |
StuntDouble * integrableObject; |
198 |
> |
Molecule* mol; |
199 |
> |
StuntDouble* sd; |
200 |
|
Vector3d tempComPos; |
201 |
< |
|
202 |
< |
// Corrects for the center of mass angular drift. |
203 |
< |
// sums all the angular momentum and divides by total mass. |
201 |
> |
|
202 |
> |
// Corrects for the center of mass angular drift by summing all |
203 |
> |
// the angular momentum and dividing by the total mass. |
204 |
> |
|
205 |
|
for( mol = info_->beginMolecule(i); mol != NULL; |
206 |
|
mol = info_->nextMolecule(i) ) { |
207 |
< |
for( integrableObject = mol->beginIntegrableObject(j); |
208 |
< |
integrableObject != NULL; |
209 |
< |
integrableObject = mol->nextIntegrableObject(j) ) { |
210 |
< |
tempComPos = integrableObject->getPos()-com; |
211 |
< |
integrableObject->setVel((integrableObject->getVel() - vdrift)-cross(omega,tempComPos)); |
207 |
> |
|
208 |
> |
for( sd = mol->beginIntegrableObject(j); sd != NULL; |
209 |
> |
sd = mol->nextIntegrableObject(j) ) { |
210 |
> |
|
211 |
> |
tempComPos = sd->getPos() - com; |
212 |
> |
sd->setVel((sd->getVel() - vdrift) - cross(omega, tempComPos)); |
213 |
> |
|
214 |
|
} |
215 |
< |
} |
216 |
< |
|
234 |
< |
angularMomentum = info_->getAngularMomentum(); |
235 |
< |
/* |
236 |
< |
std::cerr << "Angular Momentum after is " |
237 |
< |
<< angularMomentum << std::endl; |
238 |
< |
*/ |
239 |
< |
} |
240 |
< |
|
241 |
< |
|
242 |
< |
|
243 |
< |
|
215 |
> |
} |
216 |
> |
} |
217 |
|
} |