ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-2.0/src/integrators/Velocitizer.cpp
Revision: 1774
Committed: Tue Nov 23 23:12:23 2004 UTC (19 years, 7 months ago) by tim
File size: 4185 byte(s)
Log Message:
refactory NPT integrator

File Contents

# Content
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
28 namespace oopse {
29
30 void Velocitizer::velocitize(double temperature) {
31 Vector3d aVel;
32 Vector3d aJ;
33 Mat3x3d I;
34 int l;
35 int m;
36 int n;
37 Vector3d vdrift;
38 double vbar;
39 const double kb = 8.31451e - 7; // kb in amu, angstroms, fs, etc.
40 double av2;
41 double kebar;
42
43 std::vector<Molecule *>::iterator i;
44 std::vector<StuntDouble *>::iterator j;
45 Molecule * mol;
46 StuntDouble * integrableObject;
47 gaussianSPRNG gaussStream(info_->getSeed());
48
49 kebar = kb * temperature * info_->getNdfRaw() / (2.0 * info_->getNdf());
50
51 for( mol = info_->beginMolecule(i); mol != NULL;
52 mol = info_->nextMolecule(i) ) {
53 for( integrableObject = mol->beginIntegrableObject(j);
54 integrableObject != NULL;
55 integrableObject = mol->nextIntegrableObject(j) ) {
56
57 // uses equipartition theory to solve for vbar in angstrom/fs
58
59 av2 = 2.0 * kebar / integrableObject->getMass();
60 vbar = sqrt(av2);
61
62 // picks random velocities from a gaussian distribution
63 // centered on vbar
64
65 for( int k = 0; k < 3; k++ ) {
66 aVel[k] = vbar * gaussStream.getGaussian();
67 }
68
69 integrableObject->setVel(aVel);
70
71 if (integrableObject->isDirectional()) {
72 I = integrableObject->getI();
73
74 if (integrableObject->isLinear()) {
75 l = integrableObject->linearAxis();
76 m = (l + 1) % 3;
77 n = (l + 2) % 3;
78
79 aJ[l] = 0.0;
80 vbar = sqrt(2.0 * kebar * I(m, m));
81 aJ[m] = vbar * gaussStream.getGaussian();
82 vbar = sqrt(2.0 * kebar * I(n, n));
83 aJ[n] = vbar * gaussStream.getGaussian();
84 } else {
85 for( int k = 0; k < 3; k++ ) {
86 vbar = sqrt(2.0 * kebar * I(k, k));
87 aJ[k] = vbar * gaussStream.getGaussian();
88 }
89 } // else isLinear
90
91 integrableObject->setJ(aJ);
92 } //isDirectional
93 }
94 } //end for (mol = beginMolecule(i); ...)
95
96 // Get the Center of Mass drift velocity.
97 vdrift = info_->getComVel();
98
99 removeComDrift(vdrift);
100
101 }
102
103
104
105 void Velocitizer::removeComDrift(const Vector3d& vdrift) {
106
107 std::vector<Molecule *>::iterator i;
108 std::vector<StuntDouble *>::iterator j;
109 Molecule * mol;
110 StuntDouble * integrableObject;
111
112 // Corrects for the center of mass drift.
113 // sums all the momentum and divides by total mass.
114 for( mol = info_->beginMolecule(i); mol != NULL;
115 mol = info_->nextMolecule(i) ) {
116 for( integrableObject = mol->beginIntegrableObject(j);
117 integrableObject != NULL;
118 integrableObject = mol->nextIntegrableObject(j) ) {
119 integrableObject->setVel(integrableObject->getVel() - vdrift);
120 }
121 }
122
123 }
124
125 }