1 |
/* |
2 |
* Copyright (C) 2000-2004 Object Oriented Parallel Simulation Engine (OOPSE) project |
3 |
* |
4 |
* Contact: oopse@oopse.org |
5 |
* |
6 |
* This program is free software; you can redistribute it and/or |
7 |
* modify it under the terms of the GNU Lesser General Public License |
8 |
* as published by the Free Software Foundation; either version 2.1 |
9 |
* of the License, or (at your option) any later version. |
10 |
* All we ask is that proper credit is given for our work, which includes |
11 |
* - but is not limited to - adding the above copyright notice to the beginning |
12 |
* of your source code files, and to any copyright notice that you may distribute |
13 |
* with programs based on this work. |
14 |
* |
15 |
* This program is distributed in the hope that it will be useful, |
16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
* GNU Lesser General Public License for more details. |
19 |
* |
20 |
* You should have received a copy of the GNU Lesser General Public License |
21 |
* along with this program; if not, write to the Free Software |
22 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23 |
* |
24 |
*/ |
25 |
|
26 |
#include "integrators/Velocitizer.hpp" |
27 |
#include "math/SquareMatrix3.hpp" |
28 |
#include "primitives/Molecule.hpp" |
29 |
#include "primitives/StuntDouble.hpp" |
30 |
#include "math/randomSPRNG.hpp" |
31 |
|
32 |
namespace oopse { |
33 |
|
34 |
void Velocitizer::velocitize(double temperature) { |
35 |
Vector3d aVel; |
36 |
Vector3d aJ; |
37 |
Mat3x3d I; |
38 |
int l; |
39 |
int m; |
40 |
int n; |
41 |
Vector3d vdrift; |
42 |
double vbar; |
43 |
/**@todo refactory kb */ |
44 |
const double kb = 8.31451e-7; // kb in amu, angstroms, fs, etc. |
45 |
double av2; |
46 |
double kebar; |
47 |
|
48 |
SimInfo::MoleculeIterator i; |
49 |
Molecule::IntegrableObjectIterator j; |
50 |
Molecule * mol; |
51 |
StuntDouble * integrableObject; |
52 |
gaussianSPRNG gaussStream(info_->getSeed()); |
53 |
|
54 |
kebar = kb * temperature * info_->getNdfRaw() / (2.0 * info_->getNdf()); |
55 |
|
56 |
for( mol = info_->beginMolecule(i); mol != NULL; |
57 |
mol = info_->nextMolecule(i) ) { |
58 |
for( integrableObject = mol->beginIntegrableObject(j); |
59 |
integrableObject != NULL; |
60 |
integrableObject = mol->nextIntegrableObject(j) ) { |
61 |
|
62 |
// uses equipartition theory to solve for vbar in angstrom/fs |
63 |
|
64 |
av2 = 2.0 * kebar / integrableObject->getMass(); |
65 |
vbar = sqrt(av2); |
66 |
|
67 |
// picks random velocities from a gaussian distribution |
68 |
// centered on vbar |
69 |
|
70 |
for( int k = 0; k < 3; k++ ) { |
71 |
aVel[k] = vbar * gaussStream.getGaussian(); |
72 |
} |
73 |
|
74 |
integrableObject->setVel(aVel); |
75 |
|
76 |
if (integrableObject->isDirectional()) { |
77 |
I = integrableObject->getI(); |
78 |
|
79 |
if (integrableObject->isLinear()) { |
80 |
l = integrableObject->linearAxis(); |
81 |
m = (l + 1) % 3; |
82 |
n = (l + 2) % 3; |
83 |
|
84 |
aJ[l] = 0.0; |
85 |
vbar = sqrt(2.0 * kebar * I(m, m)); |
86 |
aJ[m] = vbar * gaussStream.getGaussian(); |
87 |
vbar = sqrt(2.0 * kebar * I(n, n)); |
88 |
aJ[n] = vbar * gaussStream.getGaussian(); |
89 |
} else { |
90 |
for( int k = 0; k < 3; k++ ) { |
91 |
vbar = sqrt(2.0 * kebar * I(k, k)); |
92 |
aJ[k] = vbar * gaussStream.getGaussian(); |
93 |
} |
94 |
} // else isLinear |
95 |
|
96 |
integrableObject->setJ(aJ); |
97 |
} //isDirectional |
98 |
} |
99 |
} //end for (mol = beginMolecule(i); ...) |
100 |
|
101 |
|
102 |
|
103 |
removeComDrift(); |
104 |
|
105 |
} |
106 |
|
107 |
|
108 |
|
109 |
void Velocitizer::removeComDrift() { |
110 |
// Get the Center of Mass drift velocity. |
111 |
Vector3d vdrift = info_->getComVel(); |
112 |
|
113 |
SimInfo::MoleculeIterator i; |
114 |
Molecule::IntegrableObjectIterator j; |
115 |
Molecule * mol; |
116 |
StuntDouble * integrableObject; |
117 |
|
118 |
// Corrects for the center of mass drift. |
119 |
// sums all the momentum and divides by total mass. |
120 |
for( mol = info_->beginMolecule(i); mol != NULL; |
121 |
mol = info_->nextMolecule(i) ) { |
122 |
for( integrableObject = mol->beginIntegrableObject(j); |
123 |
integrableObject != NULL; |
124 |
integrableObject = mol->nextIntegrableObject(j) ) { |
125 |
integrableObject->setVel(integrableObject->getVel() - vdrift); |
126 |
} |
127 |
} |
128 |
|
129 |
} |
130 |
|
131 |
} |