1 |
/*
|
2 |
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
|
3 |
*
|
4 |
* The University of Notre Dame grants you ("Licensee") a
|
5 |
* non-exclusive, royalty free, license to use, modify and
|
6 |
* redistribute this software in source and binary code form, provided
|
7 |
* that the following conditions are met:
|
8 |
*
|
9 |
* 1. Acknowledgement of the program authors must be made in any
|
10 |
* publication of scientific results based in part on use of the
|
11 |
* program. An acceptable form of acknowledgement is citation of
|
12 |
* the article in which the program was described (Matthew
|
13 |
* A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher
|
14 |
* J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented
|
15 |
* Parallel Simulation Engine for Molecular Dynamics,"
|
16 |
* J. Comput. Chem. 26, pp. 252-271 (2005))
|
17 |
*
|
18 |
* 2. Redistributions of source code must retain the above copyright
|
19 |
* notice, this list of conditions and the following disclaimer.
|
20 |
*
|
21 |
* 3. Redistributions in binary form must reproduce the above copyright
|
22 |
* notice, this list of conditions and the following disclaimer in the
|
23 |
* documentation and/or other materials provided with the
|
24 |
* distribution.
|
25 |
*
|
26 |
* This software is provided "AS IS," without a warranty of any
|
27 |
* kind. All express or implied conditions, representations and
|
28 |
* warranties, including any implied warranty of merchantability,
|
29 |
* fitness for a particular purpose or non-infringement, are hereby
|
30 |
* excluded. The University of Notre Dame and its licensors shall not
|
31 |
* be liable for any damages suffered by licensee as a result of
|
32 |
* using, modifying or distributing the software or its
|
33 |
* derivatives. In no event will the University of Notre Dame or its
|
34 |
* licensors be liable for any lost revenue, profit or data, or for
|
35 |
* direct, indirect, special, consequential, incidental or punitive
|
36 |
* damages, however caused and regardless of the theory of liability,
|
37 |
* arising out of the use of or inability to use software, even if the
|
38 |
* University of Notre Dame has been advised of the possibility of
|
39 |
* such damages.
|
40 |
*/
|
41 |
|
42 |
#include "integrators/Velocitizer.hpp"
|
43 |
#include "math/SquareMatrix3.hpp"
|
44 |
#include "primitives/Molecule.hpp"
|
45 |
#include "primitives/StuntDouble.hpp"
|
46 |
|
47 |
namespace oopse {
|
48 |
|
49 |
Velocitizer::Velocitizer(SimInfo* info) {
|
50 |
|
51 |
int seedValue;
|
52 |
Globals * simParams = info->getSimParams();
|
53 |
|
54 |
if (simParams->haveSeed()) {
|
55 |
seedValue = simParams->getSeed();
|
56 |
randNumGen_ = new OOPSERandNumGen(seedValue);
|
57 |
}else {
|
58 |
randNumGen_ = new OOPSERandNumGen();
|
59 |
}
|
60 |
|
61 |
}
|
62 |
|
63 |
Velocitizer::~Velocitizer() {
|
64 |
delete randNumGen_;
|
65 |
}
|
66 |
|
67 |
void Velocitizer::velocitize(double temperature) {
|
68 |
Vector3d aVel;
|
69 |
Vector3d aJ;
|
70 |
Mat3x3d I;
|
71 |
int l;
|
72 |
int m;
|
73 |
int n;
|
74 |
Vector3d vdrift;
|
75 |
double vbar;
|
76 |
/**@todo refactory kb */
|
77 |
const double kb = 8.31451e-7; // kb in amu, angstroms, fs, etc.
|
78 |
double av2;
|
79 |
double kebar;
|
80 |
|
81 |
SimInfo::MoleculeIterator i;
|
82 |
Molecule::IntegrableObjectIterator j;
|
83 |
Molecule * mol;
|
84 |
StuntDouble * integrableObject;
|
85 |
|
86 |
|
87 |
|
88 |
kebar = kb * temperature * info_->getNdfRaw() / (2.0 * info_->getNdf());
|
89 |
|
90 |
for( mol = info_->beginMolecule(i); mol != NULL;
|
91 |
mol = info_->nextMolecule(i) ) {
|
92 |
for( integrableObject = mol->beginIntegrableObject(j);
|
93 |
integrableObject != NULL;
|
94 |
integrableObject = mol->nextIntegrableObject(j) ) {
|
95 |
|
96 |
// uses equipartition theory to solve for vbar in angstrom/fs
|
97 |
|
98 |
av2 = 2.0 * kebar / integrableObject->getMass();
|
99 |
vbar = sqrt(av2);
|
100 |
|
101 |
// picks random velocities from a gaussian distribution
|
102 |
// centered on vbar
|
103 |
|
104 |
for( int k = 0; k < 3; k++ ) {
|
105 |
aVel[k] = vbar * randNumGen_->randNorm(0.0, 1.0);
|
106 |
}
|
107 |
|
108 |
integrableObject->setVel(aVel);
|
109 |
|
110 |
if (integrableObject->isDirectional()) {
|
111 |
I = integrableObject->getI();
|
112 |
|
113 |
if (integrableObject->isLinear()) {
|
114 |
l = integrableObject->linearAxis();
|
115 |
m = (l + 1) % 3;
|
116 |
n = (l + 2) % 3;
|
117 |
|
118 |
aJ[l] = 0.0;
|
119 |
vbar = sqrt(2.0 * kebar * I(m, m));
|
120 |
aJ[m] = vbar * randNumGen_->randNorm(0.0, 1.0);
|
121 |
vbar = sqrt(2.0 * kebar * I(n, n));
|
122 |
aJ[n] = vbar * randNumGen_->randNorm(0.0, 1.0);
|
123 |
} else {
|
124 |
for( int k = 0; k < 3; k++ ) {
|
125 |
vbar = sqrt(2.0 * kebar * I(k, k));
|
126 |
aJ[k] = vbar *randNumGen_->randNorm(0.0, 1.0);
|
127 |
}
|
128 |
} // else isLinear
|
129 |
|
130 |
integrableObject->setJ(aJ);
|
131 |
} //isDirectional
|
132 |
}
|
133 |
} //end for (mol = beginMolecule(i); ...)
|
134 |
|
135 |
|
136 |
|
137 |
removeComDrift();
|
138 |
|
139 |
}
|
140 |
|
141 |
|
142 |
|
143 |
void Velocitizer::removeComDrift() {
|
144 |
// Get the Center of Mass drift velocity.
|
145 |
Vector3d vdrift = info_->getComVel();
|
146 |
|
147 |
SimInfo::MoleculeIterator i;
|
148 |
Molecule::IntegrableObjectIterator j;
|
149 |
Molecule * mol;
|
150 |
StuntDouble * integrableObject;
|
151 |
|
152 |
// Corrects for the center of mass drift.
|
153 |
// sums all the momentum and divides by total mass.
|
154 |
for( mol = info_->beginMolecule(i); mol != NULL;
|
155 |
mol = info_->nextMolecule(i) ) {
|
156 |
for( integrableObject = mol->beginIntegrableObject(j);
|
157 |
integrableObject != NULL;
|
158 |
integrableObject = mol->nextIntegrableObject(j) ) {
|
159 |
integrableObject->setVel(integrableObject->getVel() - vdrift);
|
160 |
}
|
161 |
}
|
162 |
|
163 |
}
|
164 |
|
165 |
}
|