ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/integrators/Velocitizer.cpp
(Generate patch)

Comparing trunk/OOPSE-4/src/integrators/Velocitizer.cpp (file contents):
Revision 1930 by gezelter, Wed Jan 12 22:41:40 2005 UTC vs.
Revision 2065 by tim, Tue Mar 1 14:45:45 2005 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines