ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/integrators/Velocitizer.cpp
Revision: 2072
Committed: Tue Mar 1 23:02:33 2005 UTC (19 years, 4 months ago) by tim
File size: 5944 byte(s)
Log Message:
replace SPRNG by MTRand

File Contents

# User Rev Content
1 tim 2065 /*
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 tim 2068
47 tim 2065 namespace oopse {
48    
49 tim 2068 Velocitizer::Velocitizer(SimInfo* info) {
50    
51     int seedValue;
52     Globals * simParams = info->getSimParams();
53    
54 tim 2072 #ifndef IS_MPI
55 tim 2068 if (simParams->haveSeed()) {
56     seedValue = simParams->getSeed();
57 tim 2072 randNumGen_ = new MTRand(seedValue);
58 tim 2068 }else {
59 tim 2072 randNumGen_ = new MTRand();
60 tim 2068 }
61 tim 2072 #else
62     if (simParams->haveSeed()) {
63     seedValue = simParams->getSeed();
64     randNumGen_ = new ParallelRandNumGen(seedValue);
65     }else {
66     randNumGen_ = new ParallelRandNumGen();
67     }
68     #endif
69 tim 2068 }
70    
71     Velocitizer::~Velocitizer() {
72     delete randNumGen_;
73     }
74    
75 tim 2065 void Velocitizer::velocitize(double temperature) {
76     Vector3d aVel;
77     Vector3d aJ;
78     Mat3x3d I;
79     int l;
80     int m;
81     int n;
82     Vector3d vdrift;
83     double vbar;
84     /**@todo refactory kb */
85     const double kb = 8.31451e-7; // kb in amu, angstroms, fs, etc.
86     double av2;
87     double kebar;
88    
89     SimInfo::MoleculeIterator i;
90     Molecule::IntegrableObjectIterator j;
91     Molecule * mol;
92     StuntDouble * integrableObject;
93    
94    
95 tim 2068
96 tim 2065 kebar = kb * temperature * info_->getNdfRaw() / (2.0 * info_->getNdf());
97    
98     for( mol = info_->beginMolecule(i); mol != NULL;
99     mol = info_->nextMolecule(i) ) {
100     for( integrableObject = mol->beginIntegrableObject(j);
101     integrableObject != NULL;
102     integrableObject = mol->nextIntegrableObject(j) ) {
103    
104     // uses equipartition theory to solve for vbar in angstrom/fs
105    
106     av2 = 2.0 * kebar / integrableObject->getMass();
107     vbar = sqrt(av2);
108    
109     // picks random velocities from a gaussian distribution
110     // centered on vbar
111    
112     for( int k = 0; k < 3; k++ ) {
113 tim 2068 aVel[k] = vbar * randNumGen_->randNorm(0.0, 1.0);
114 tim 2065 }
115    
116     integrableObject->setVel(aVel);
117    
118     if (integrableObject->isDirectional()) {
119     I = integrableObject->getI();
120    
121     if (integrableObject->isLinear()) {
122     l = integrableObject->linearAxis();
123     m = (l + 1) % 3;
124     n = (l + 2) % 3;
125    
126     aJ[l] = 0.0;
127     vbar = sqrt(2.0 * kebar * I(m, m));
128 tim 2068 aJ[m] = vbar * randNumGen_->randNorm(0.0, 1.0);
129 tim 2065 vbar = sqrt(2.0 * kebar * I(n, n));
130 tim 2068 aJ[n] = vbar * randNumGen_->randNorm(0.0, 1.0);
131 tim 2065 } else {
132     for( int k = 0; k < 3; k++ ) {
133     vbar = sqrt(2.0 * kebar * I(k, k));
134 tim 2068 aJ[k] = vbar *randNumGen_->randNorm(0.0, 1.0);
135 tim 2065 }
136     } // else isLinear
137    
138     integrableObject->setJ(aJ);
139     } //isDirectional
140     }
141     } //end for (mol = beginMolecule(i); ...)
142    
143    
144    
145     removeComDrift();
146    
147     }
148    
149    
150    
151     void Velocitizer::removeComDrift() {
152     // Get the Center of Mass drift velocity.
153     Vector3d vdrift = info_->getComVel();
154    
155     SimInfo::MoleculeIterator i;
156     Molecule::IntegrableObjectIterator j;
157     Molecule * mol;
158     StuntDouble * integrableObject;
159    
160     // Corrects for the center of mass drift.
161     // sums all the momentum and divides by total mass.
162     for( mol = info_->beginMolecule(i); mol != NULL;
163     mol = info_->nextMolecule(i) ) {
164     for( integrableObject = mol->beginIntegrableObject(j);
165     integrableObject != NULL;
166     integrableObject = mol->nextIntegrableObject(j) ) {
167     integrableObject->setVel(integrableObject->getVel() - vdrift);
168     }
169     }
170    
171     }
172    
173     }