ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/integrators/Velocitizer.cpp
Revision: 2320
Committed: Thu Sep 22 00:04:56 2005 UTC (18 years, 9 months ago) by chuckv
File size: 7814 byte(s)
Log Message:
Removed print statements for remove angular momentum.

File Contents

# User Rev Content
1 gezelter 2204 /*
2 tim 2065 * 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 gezelter 2204
42 tim 2065 #include "integrators/Velocitizer.hpp"
43     #include "math/SquareMatrix3.hpp"
44     #include "primitives/Molecule.hpp"
45     #include "primitives/StuntDouble.hpp"
46 tim 2068
47 tim 2076 #ifndef IS_MPI
48     #include "math/SeqRandNumGen.hpp"
49     #else
50     #include "math/ParallelRandNumGen.hpp"
51     #endif
52    
53 chuckv 2252 /* Remove me after testing*/
54     #include <cstdio>
55     #include <iostream>
56     /*End remove me*/
57    
58 tim 2065 namespace oopse {
59 gezelter 2204
60     Velocitizer::Velocitizer(SimInfo* info) : info_(info) {
61    
62 tim 2068 int seedValue;
63     Globals * simParams = info->getSimParams();
64 gezelter 2204
65 tim 2072 #ifndef IS_MPI
66 tim 2068 if (simParams->haveSeed()) {
67 gezelter 2204 seedValue = simParams->getSeed();
68     randNumGen_ = new SeqRandNumGen(seedValue);
69 tim 2068 }else {
70 gezelter 2204 randNumGen_ = new SeqRandNumGen();
71 tim 2068 }
72 tim 2072 #else
73     if (simParams->haveSeed()) {
74 gezelter 2204 seedValue = simParams->getSeed();
75     randNumGen_ = new ParallelRandNumGen(seedValue);
76 tim 2072 }else {
77 gezelter 2204 randNumGen_ = new ParallelRandNumGen();
78 tim 2072 }
79     #endif
80 gezelter 2204 }
81    
82     Velocitizer::~Velocitizer() {
83 tim 2068 delete randNumGen_;
84 gezelter 2204 }
85    
86     void Velocitizer::velocitize(double temperature) {
87 tim 2065 Vector3d aVel;
88     Vector3d aJ;
89     Mat3x3d I;
90     int l;
91     int m;
92     int n;
93     Vector3d vdrift;
94     double vbar;
95     /**@todo refactory kb */
96     const double kb = 8.31451e-7; // kb in amu, angstroms, fs, etc.
97     double av2;
98     double kebar;
99 gezelter 2204
100 chuckv 2252 Globals * simParams = info_->getSimParams();
101    
102 tim 2065 SimInfo::MoleculeIterator i;
103     Molecule::IntegrableObjectIterator j;
104     Molecule * mol;
105     StuntDouble * integrableObject;
106 gezelter 2204
107    
108    
109 tim 2065 kebar = kb * temperature * info_->getNdfRaw() / (2.0 * info_->getNdf());
110 gezelter 2204
111 tim 2065 for( mol = info_->beginMolecule(i); mol != NULL;
112 gezelter 2204 mol = info_->nextMolecule(i) ) {
113     for( integrableObject = mol->beginIntegrableObject(j);
114     integrableObject != NULL;
115     integrableObject = mol->nextIntegrableObject(j) ) {
116    
117     // uses equipartition theory to solve for vbar in angstrom/fs
118    
119     av2 = 2.0 * kebar / integrableObject->getMass();
120     vbar = sqrt(av2);
121    
122     // picks random velocities from a gaussian distribution
123     // centered on vbar
124    
125     for( int k = 0; k < 3; k++ ) {
126     aVel[k] = vbar * randNumGen_->randNorm(0.0, 1.0);
127     }
128    
129     integrableObject->setVel(aVel);
130    
131     if (integrableObject->isDirectional()) {
132     I = integrableObject->getI();
133    
134     if (integrableObject->isLinear()) {
135     l = integrableObject->linearAxis();
136     m = (l + 1) % 3;
137     n = (l + 2) % 3;
138    
139     aJ[l] = 0.0;
140     vbar = sqrt(2.0 * kebar * I(m, m));
141     aJ[m] = vbar * randNumGen_->randNorm(0.0, 1.0);
142     vbar = sqrt(2.0 * kebar * I(n, n));
143     aJ[n] = vbar * randNumGen_->randNorm(0.0, 1.0);
144     } else {
145     for( int k = 0; k < 3; k++ ) {
146     vbar = sqrt(2.0 * kebar * I(k, k));
147     aJ[k] = vbar *randNumGen_->randNorm(0.0, 1.0);
148     }
149     } // else isLinear
150    
151     integrableObject->setJ(aJ);
152     } //isDirectional
153     }
154 tim 2065 } //end for (mol = beginMolecule(i); ...)
155 gezelter 2204
156    
157    
158 tim 2065 removeComDrift();
159 chuckv 2252 // Remove angular drift if we are not using periodic boundary conditions.
160 chuckv 2256 if(!simParams->getPBC()) removeAngularDrift();
161 gezelter 2204
162     }
163    
164    
165    
166     void Velocitizer::removeComDrift() {
167 tim 2065 // Get the Center of Mass drift velocity.
168     Vector3d vdrift = info_->getComVel();
169    
170     SimInfo::MoleculeIterator i;
171     Molecule::IntegrableObjectIterator j;
172     Molecule * mol;
173     StuntDouble * integrableObject;
174    
175     // Corrects for the center of mass drift.
176     // sums all the momentum and divides by total mass.
177     for( mol = info_->beginMolecule(i); mol != NULL;
178 gezelter 2204 mol = info_->nextMolecule(i) ) {
179     for( integrableObject = mol->beginIntegrableObject(j);
180     integrableObject != NULL;
181     integrableObject = mol->nextIntegrableObject(j) ) {
182     integrableObject->setVel(integrableObject->getVel() - vdrift);
183     }
184 tim 2065 }
185 gezelter 2204
186     }
187    
188 chuckv 2252
189     void Velocitizer::removeAngularDrift() {
190     // Get the Center of Mass drift velocity.
191    
192     Vector3d vdrift;
193     Vector3d com;
194    
195     info_->getComAll(com,vdrift);
196    
197     Mat3x3d inertiaTensor;
198     Vector3d angularMomentum;
199     Vector3d omega;
200    
201    
202    
203     info_->getInertiaTensor(inertiaTensor,angularMomentum);
204     // We now need the inverse of the inertia tensor.
205 chuckv 2320 /*
206 chuckv 2252 std::cerr << "Angular Momentum before is "
207 chuckv 2256 << angularMomentum << std::endl;
208     std::cerr << "Inertia Tensor before is "
209     << inertiaTensor << std::endl;
210 chuckv 2320 */
211 chuckv 2252
212 chuckv 2256 inertiaTensor =inertiaTensor.inverse();
213     std::cerr << "Inertia Tensor after inverse is "
214     << inertiaTensor << std::endl;
215 chuckv 2252
216     omega = inertiaTensor*angularMomentum;
217    
218     SimInfo::MoleculeIterator i;
219     Molecule::IntegrableObjectIterator j;
220     Molecule * mol;
221     StuntDouble * integrableObject;
222     Vector3d tempComPos;
223    
224     // Corrects for the center of mass angular drift.
225     // sums all the angular momentum and divides by total mass.
226     for( mol = info_->beginMolecule(i); mol != NULL;
227     mol = info_->nextMolecule(i) ) {
228     for( integrableObject = mol->beginIntegrableObject(j);
229     integrableObject != NULL;
230     integrableObject = mol->nextIntegrableObject(j) ) {
231     tempComPos = integrableObject->getPos()-com;
232     integrableObject->setVel((integrableObject->getVel() - vdrift)-cross(omega,tempComPos));
233     }
234     }
235    
236     angularMomentum = info_->getAngularMomentum();
237 chuckv 2320 /*
238 chuckv 2252 std::cerr << "Angular Momentum after is "
239     << angularMomentum << std::endl;
240 chuckv 2320 */
241 chuckv 2252
242     }
243    
244    
245    
246    
247 tim 2065 }