ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/applications/dynamicProps/MomentumCorrFunc.cpp
Revision: 1826
Committed: Wed Jan 9 19:41:48 2013 UTC (12 years, 4 months ago) by gezelter
File size: 7784 byte(s)
Log Message:
Cleaning more cruft and unused variables.

File Contents

# User Rev Content
1 gezelter 1629 /*
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. Redistributions of source code must retain the above copyright
10     * notice, this list of conditions and the following disclaimer.
11     *
12     * 2. Redistributions in binary form must reproduce the above copyright
13     * notice, this list of conditions and the following disclaimer in the
14     * documentation and/or other materials provided with the
15     * distribution.
16     *
17     * This software is provided "AS IS," without a warranty of any
18     * kind. All express or implied conditions, representations and
19     * warranties, including any implied warranty of merchantability,
20     * fitness for a particular purpose or non-infringement, are hereby
21     * excluded. The University of Notre Dame and its licensors shall not
22     * be liable for any damages suffered by licensee as a result of
23     * using, modifying or distributing the software or its
24     * derivatives. In no event will the University of Notre Dame or its
25     * licensors be liable for any lost revenue, profit or data, or for
26     * direct, indirect, special, consequential, incidental or punitive
27     * damages, however caused and regardless of the theory of liability,
28     * arising out of the use of or inability to use software, even if the
29     * University of Notre Dame has been advised of the possibility of
30     * such damages.
31     *
32     * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your
33     * research, please cite the appropriate papers when you publish your
34     * work. Good starting points are:
35     *
36     * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
37     * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
38     * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).
39 gezelter 1665 * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010).
40     * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41 gezelter 1629 */
42    
43     /* Uses the Helfand-moment method for calculating thermal
44     * conductivity using the relation kappa = (N,V)lim(t)->inf 1/(2*k_B*T^2*V*t) <[G_K(t)-G_K(0)]^2>
45     * where G_K is the Helfand moment for thermal conductivity definded as
46     * G_K(t) = sum_{a=1}{^N} x_a(E_a-<E_a>) and E_a is defined to be
47     * E_a = p_2^2/(2*m)+1/2 sum_{b.ne.a} u(r_ab) where p is momentum and u is pot energy for the
48     * particle pair a-b. This routine calculates E_a, <E_a> and does the correlation
49     * <[G_K(t)-G_K(0)]^2>.
50     * See Viscardy et al. JCP 126, 184513 (2007)
51     */
52    
53     #include "applications/dynamicProps/MomentumCorrFunc.hpp"
54     #include "utils/PhysicalConstants.hpp"
55     #include "primitives/Molecule.hpp"
56    
57     namespace OpenMD {
58    
59     // We need all of the positions, velocities, etc. so that we can
60     // recalculate pressures and actions on the fly:
61     MomentumCorrFunc::MomentumCorrFunc(SimInfo* info, const std::string& filename,
62     const std::string& sele1,
63     const std::string& sele2,
64     long long int memSize)
65     : FrameTimeCorrFunc(info, filename, sele1, sele2,
66     DataStorage::dslPosition |
67     DataStorage::dslVelocity,
68     memSize){
69    
70     setCorrFuncType("MomentumCorrFunc");
71     setOutputName(getPrefix(dumpFilename_) + ".momcorr");
72     histogram_.resize(nTimeBins_);
73     count_.resize(nTimeBins_);
74     }
75    
76     void MomentumCorrFunc::correlateFrames(int frame1, int frame2) {
77     SimInfo::MoleculeIterator mi1;
78     SimInfo::MoleculeIterator mi2;
79     Molecule* mol1;
80     Molecule* mol2;
81     Molecule::AtomIterator ai1;
82     Molecule::AtomIterator ai2;
83     Atom* atom1;
84     Atom* atom2;
85    
86     std::vector<Vector3d> atomPositions1;
87     std::vector<Vector3d> atomPositions2;
88     std::vector<Vector3d> atomVelocity1;
89     std::vector<Vector3d> atomVelocity2;
90     int thisAtom1, thisAtom2;
91    
92     Snapshot* snapshot1 = bsMan_->getSnapshot(frame1);
93     Snapshot* snapshot2 = bsMan_->getSnapshot(frame2);
94    
95     assert(snapshot1 && snapshot2);
96    
97     RealType time1 = snapshot1->getTime();
98     RealType time2 = snapshot2->getTime();
99    
100     int timeBin = int ((time2 - time1) /deltaTime_ + 0.5);
101    
102     updateFrame(frame1);
103     atomPositions1.clear();
104     for (mol1 = info_->beginMolecule(mi1); mol1 != NULL;
105     mol1 = info_->nextMolecule(mi1)) {
106     for(atom1 = mol1->beginAtom(ai1); atom1 != NULL;
107     atom1 = mol1->nextAtom(ai1)) {
108     atomPositions1.push_back(atom1->getPos(frame1));
109     atomVelocity1.push_back(atom1->getVel(frame1));
110     }
111     }
112     updateFrame(frame2);
113     atomPositions2.clear();
114     for (mol2 = info_->beginMolecule(mi2); mol2 != NULL;
115     mol2 = info_->nextMolecule(mi2)) {
116     for(atom2 = mol2->beginAtom(ai2); atom2 != NULL;
117     atom2 = mol2->nextAtom(ai2)) {
118     atomPositions2.push_back(atom2->getPos(frame2));
119     atomVelocity2.push_back(atom2->getVel(frame2));
120     }
121     }
122    
123     thisAtom1 = 0;
124    
125     for (mol1 = info_->beginMolecule(mi1); mol1 != NULL;
126     mol1 = info_->nextMolecule(mi1)) {
127     for(atom1 = mol1->beginAtom(ai1); atom1 != NULL;
128     atom1 = mol1->nextAtom(ai1)) {
129    
130     Vector3d r1 = atomPositions1[thisAtom1];
131     Vector3d p1 = atom1->getMass() * atomVelocity1[thisAtom1];
132    
133     thisAtom2 = 0;
134    
135     for (mol2 = info_->beginMolecule(mi2); mol2 != NULL;
136     mol2 = info_->nextMolecule(mi2)) {
137     for(atom2 = mol2->beginAtom(ai2); atom2 != NULL;
138     atom2 = mol2->nextAtom(ai2)) {
139    
140     Vector3d r2 = atomPositions2[thisAtom2];
141     Vector3d p2 = atom2->getMass() * atomVelocity1[thisAtom1];
142    
143     Vector3d deltaPos = (r2-r1);
144     Vector3d dp2( deltaPos.x() * deltaPos.x(),
145     deltaPos.y() * deltaPos.y(),
146     deltaPos.z() * deltaPos.z());
147     Vector3d pprod( p1.x() * p2.x(),
148     p1.y() * p2.y(),
149     p1.z() * p2.z());
150    
151     histogram_[timeBin] += outProduct(dp2, pprod);
152    
153     thisAtom2++;
154     }
155     }
156    
157     thisAtom1++;
158     }
159     }
160    
161     count_[timeBin]++;
162    
163     }
164    
165     void MomentumCorrFunc::postCorrelate() {
166     for (int i =0 ; i < nTimeBins_; ++i) {
167     if (count_[i] > 0) {
168     histogram_[i] /= count_[i];
169     }
170     }
171     }
172    
173     void MomentumCorrFunc::preCorrelate() {
174     // Fill the histogram with empty 3x3 matrices:
175     std::fill(histogram_.begin(), histogram_.end(), Mat3x3d(0.0));
176     // count array set to zero
177     std::fill(count_.begin(), count_.end(), 0);
178     }
179    
180    
181    
182     void MomentumCorrFunc::writeCorrelate() {
183     std::ofstream ofs(getOutputFileName().c_str());
184    
185     if (ofs.is_open()) {
186    
187     ofs << "#" << getCorrFuncType() << "\n";
188     ofs << "#time\tcorrTensor\txx\txy\txz\tyx\tyy\tyz\tzx\tzy\tzz\n";
189    
190     for (int i = 0; i < nTimeBins_; ++i) {
191     ofs << time_[i] << "\t" <<
192     histogram_[i](0,0) << "\t" <<
193     histogram_[i](0,1) << "\t" <<
194     histogram_[i](0,2) << "\t" <<
195     histogram_[i](1,0) << "\t" <<
196     histogram_[i](1,1) << "\t" <<
197     histogram_[i](1,2) << "\t" <<
198     histogram_[i](2,0) << "\t" <<
199     histogram_[i](2,1) << "\t" <<
200     histogram_[i](2,2) << "\t" << "\n";
201     }
202    
203     } else {
204     sprintf(painCave.errMsg,
205     "MomentumCorrFunc::writeCorrelate Error: fail to open %s\n", getOutputFileName().c_str());
206     painCave.isFatal = 1;
207     simError();
208     }
209    
210     ofs.close();
211    
212     }
213    
214     }
215    

Properties

Name Value
svn:eol-style native