ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/applications/dynamicProps/MomentumCorrFunc.cpp
Revision: 1665
Committed: Tue Nov 22 20:38:56 2011 UTC (13 years, 6 months ago) by gezelter
File size: 7872 byte(s)
Log Message:
updated copyright notices

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::IntegrableObjectIterator mj1;
80     Molecule::IntegrableObjectIterator mj2;
81     Molecule* mol1;
82     Molecule* mol2;
83     Molecule::AtomIterator ai1;
84     Molecule::AtomIterator ai2;
85     Atom* atom1;
86     Atom* atom2;
87    
88     std::vector<Vector3d> atomPositions1;
89     std::vector<Vector3d> atomPositions2;
90     std::vector<Vector3d> atomVelocity1;
91     std::vector<Vector3d> atomVelocity2;
92     int thisAtom1, thisAtom2;
93    
94     Snapshot* snapshot1 = bsMan_->getSnapshot(frame1);
95     Snapshot* snapshot2 = bsMan_->getSnapshot(frame2);
96    
97     assert(snapshot1 && snapshot2);
98    
99     RealType time1 = snapshot1->getTime();
100     RealType time2 = snapshot2->getTime();
101    
102     int timeBin = int ((time2 - time1) /deltaTime_ + 0.5);
103    
104     updateFrame(frame1);
105     atomPositions1.clear();
106     for (mol1 = info_->beginMolecule(mi1); mol1 != NULL;
107     mol1 = info_->nextMolecule(mi1)) {
108     for(atom1 = mol1->beginAtom(ai1); atom1 != NULL;
109     atom1 = mol1->nextAtom(ai1)) {
110     atomPositions1.push_back(atom1->getPos(frame1));
111     atomVelocity1.push_back(atom1->getVel(frame1));
112     }
113     }
114     updateFrame(frame2);
115     atomPositions2.clear();
116     for (mol2 = info_->beginMolecule(mi2); mol2 != NULL;
117     mol2 = info_->nextMolecule(mi2)) {
118     for(atom2 = mol2->beginAtom(ai2); atom2 != NULL;
119     atom2 = mol2->nextAtom(ai2)) {
120     atomPositions2.push_back(atom2->getPos(frame2));
121     atomVelocity2.push_back(atom2->getVel(frame2));
122     }
123     }
124    
125     thisAtom1 = 0;
126    
127     for (mol1 = info_->beginMolecule(mi1); mol1 != NULL;
128     mol1 = info_->nextMolecule(mi1)) {
129     for(atom1 = mol1->beginAtom(ai1); atom1 != NULL;
130     atom1 = mol1->nextAtom(ai1)) {
131    
132     Vector3d r1 = atomPositions1[thisAtom1];
133     Vector3d p1 = atom1->getMass() * atomVelocity1[thisAtom1];
134    
135     thisAtom2 = 0;
136    
137     for (mol2 = info_->beginMolecule(mi2); mol2 != NULL;
138     mol2 = info_->nextMolecule(mi2)) {
139     for(atom2 = mol2->beginAtom(ai2); atom2 != NULL;
140     atom2 = mol2->nextAtom(ai2)) {
141    
142     Vector3d r2 = atomPositions2[thisAtom2];
143     Vector3d p2 = atom2->getMass() * atomVelocity1[thisAtom1];
144    
145     Vector3d deltaPos = (r2-r1);
146     Vector3d dp2( deltaPos.x() * deltaPos.x(),
147     deltaPos.y() * deltaPos.y(),
148     deltaPos.z() * deltaPos.z());
149     Vector3d pprod( p1.x() * p2.x(),
150     p1.y() * p2.y(),
151     p1.z() * p2.z());
152    
153     histogram_[timeBin] += outProduct(dp2, pprod);
154    
155     thisAtom2++;
156     }
157     }
158    
159     thisAtom1++;
160     }
161     }
162    
163     count_[timeBin]++;
164    
165     }
166    
167     void MomentumCorrFunc::postCorrelate() {
168     for (int i =0 ; i < nTimeBins_; ++i) {
169     if (count_[i] > 0) {
170     histogram_[i] /= count_[i];
171     }
172     }
173     }
174    
175     void MomentumCorrFunc::preCorrelate() {
176     // Fill the histogram with empty 3x3 matrices:
177     std::fill(histogram_.begin(), histogram_.end(), Mat3x3d(0.0));
178     // count array set to zero
179     std::fill(count_.begin(), count_.end(), 0);
180     }
181    
182    
183    
184     void MomentumCorrFunc::writeCorrelate() {
185     std::ofstream ofs(getOutputFileName().c_str());
186    
187     if (ofs.is_open()) {
188    
189     ofs << "#" << getCorrFuncType() << "\n";
190     ofs << "#time\tcorrTensor\txx\txy\txz\tyx\tyy\tyz\tzx\tzy\tzz\n";
191    
192     for (int i = 0; i < nTimeBins_; ++i) {
193     ofs << time_[i] << "\t" <<
194     histogram_[i](0,0) << "\t" <<
195     histogram_[i](0,1) << "\t" <<
196     histogram_[i](0,2) << "\t" <<
197     histogram_[i](1,0) << "\t" <<
198     histogram_[i](1,1) << "\t" <<
199     histogram_[i](1,2) << "\t" <<
200     histogram_[i](2,0) << "\t" <<
201     histogram_[i](2,1) << "\t" <<
202     histogram_[i](2,2) << "\t" << "\n";
203     }
204    
205     } else {
206     sprintf(painCave.errMsg,
207     "MomentumCorrFunc::writeCorrelate Error: fail to open %s\n", getOutputFileName().c_str());
208     painCave.isFatal = 1;
209     simError();
210     }
211    
212     ofs.close();
213    
214     }
215    
216     }
217    

Properties

Name Value
svn:eol-style native