ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/applications/dynamicProps/MomentumCorrFunc.cpp
Revision: 1629
Committed: Wed Sep 14 21:15:17 2011 UTC (13 years, 8 months ago) by gezelter
File size: 7806 byte(s)
Log Message:
Merging changes from old branch into development branch

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     * [4] Vardeman & Gezelter, in progress (2009).
40     */
41    
42     /* Uses the Helfand-moment method for calculating thermal
43     * 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>
44     * where G_K is the Helfand moment for thermal conductivity definded as
45     * G_K(t) = sum_{a=1}{^N} x_a(E_a-<E_a>) and E_a is defined to be
46     * 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
47     * particle pair a-b. This routine calculates E_a, <E_a> and does the correlation
48     * <[G_K(t)-G_K(0)]^2>.
49     * See Viscardy et al. JCP 126, 184513 (2007)
50     */
51    
52     #include "applications/dynamicProps/MomentumCorrFunc.hpp"
53     #include "utils/PhysicalConstants.hpp"
54     #include "primitives/Molecule.hpp"
55    
56     namespace OpenMD {
57    
58     // We need all of the positions, velocities, etc. so that we can
59     // recalculate pressures and actions on the fly:
60     MomentumCorrFunc::MomentumCorrFunc(SimInfo* info, const std::string& filename,
61     const std::string& sele1,
62     const std::string& sele2,
63     long long int memSize)
64     : FrameTimeCorrFunc(info, filename, sele1, sele2,
65     DataStorage::dslPosition |
66     DataStorage::dslVelocity,
67     memSize){
68    
69     setCorrFuncType("MomentumCorrFunc");
70     setOutputName(getPrefix(dumpFilename_) + ".momcorr");
71     histogram_.resize(nTimeBins_);
72     count_.resize(nTimeBins_);
73     }
74    
75     void MomentumCorrFunc::correlateFrames(int frame1, int frame2) {
76     SimInfo::MoleculeIterator mi1;
77     SimInfo::MoleculeIterator mi2;
78     Molecule::IntegrableObjectIterator mj1;
79     Molecule::IntegrableObjectIterator mj2;
80     Molecule* mol1;
81     Molecule* mol2;
82     Molecule::AtomIterator ai1;
83     Molecule::AtomIterator ai2;
84     Atom* atom1;
85     Atom* atom2;
86    
87     std::vector<Vector3d> atomPositions1;
88     std::vector<Vector3d> atomPositions2;
89     std::vector<Vector3d> atomVelocity1;
90     std::vector<Vector3d> atomVelocity2;
91     int thisAtom1, thisAtom2;
92    
93     Snapshot* snapshot1 = bsMan_->getSnapshot(frame1);
94     Snapshot* snapshot2 = bsMan_->getSnapshot(frame2);
95    
96     assert(snapshot1 && snapshot2);
97    
98     RealType time1 = snapshot1->getTime();
99     RealType time2 = snapshot2->getTime();
100    
101     int timeBin = int ((time2 - time1) /deltaTime_ + 0.5);
102    
103     updateFrame(frame1);
104     atomPositions1.clear();
105     for (mol1 = info_->beginMolecule(mi1); mol1 != NULL;
106     mol1 = info_->nextMolecule(mi1)) {
107     for(atom1 = mol1->beginAtom(ai1); atom1 != NULL;
108     atom1 = mol1->nextAtom(ai1)) {
109     atomPositions1.push_back(atom1->getPos(frame1));
110     atomVelocity1.push_back(atom1->getVel(frame1));
111     }
112     }
113     updateFrame(frame2);
114     atomPositions2.clear();
115     for (mol2 = info_->beginMolecule(mi2); mol2 != NULL;
116     mol2 = info_->nextMolecule(mi2)) {
117     for(atom2 = mol2->beginAtom(ai2); atom2 != NULL;
118     atom2 = mol2->nextAtom(ai2)) {
119     atomPositions2.push_back(atom2->getPos(frame2));
120     atomVelocity2.push_back(atom2->getVel(frame2));
121     }
122     }
123    
124     thisAtom1 = 0;
125    
126     for (mol1 = info_->beginMolecule(mi1); mol1 != NULL;
127     mol1 = info_->nextMolecule(mi1)) {
128     for(atom1 = mol1->beginAtom(ai1); atom1 != NULL;
129     atom1 = mol1->nextAtom(ai1)) {
130    
131     Vector3d r1 = atomPositions1[thisAtom1];
132     Vector3d p1 = atom1->getMass() * atomVelocity1[thisAtom1];
133    
134     thisAtom2 = 0;
135    
136     for (mol2 = info_->beginMolecule(mi2); mol2 != NULL;
137     mol2 = info_->nextMolecule(mi2)) {
138     for(atom2 = mol2->beginAtom(ai2); atom2 != NULL;
139     atom2 = mol2->nextAtom(ai2)) {
140    
141     Vector3d r2 = atomPositions2[thisAtom2];
142     Vector3d p2 = atom2->getMass() * atomVelocity1[thisAtom1];
143    
144     Vector3d deltaPos = (r2-r1);
145     Vector3d dp2( deltaPos.x() * deltaPos.x(),
146     deltaPos.y() * deltaPos.y(),
147     deltaPos.z() * deltaPos.z());
148     Vector3d pprod( p1.x() * p2.x(),
149     p1.y() * p2.y(),
150     p1.z() * p2.z());
151    
152     histogram_[timeBin] += outProduct(dp2, pprod);
153    
154     thisAtom2++;
155     }
156     }
157    
158     thisAtom1++;
159     }
160     }
161    
162     count_[timeBin]++;
163    
164     }
165    
166     void MomentumCorrFunc::postCorrelate() {
167     for (int i =0 ; i < nTimeBins_; ++i) {
168     if (count_[i] > 0) {
169     histogram_[i] /= count_[i];
170     }
171     }
172     }
173    
174     void MomentumCorrFunc::preCorrelate() {
175     // Fill the histogram with empty 3x3 matrices:
176     std::fill(histogram_.begin(), histogram_.end(), Mat3x3d(0.0));
177     // count array set to zero
178     std::fill(count_.begin(), count_.end(), 0);
179     }
180    
181    
182    
183     void MomentumCorrFunc::writeCorrelate() {
184     std::ofstream ofs(getOutputFileName().c_str());
185    
186     if (ofs.is_open()) {
187    
188     ofs << "#" << getCorrFuncType() << "\n";
189     ofs << "#time\tcorrTensor\txx\txy\txz\tyx\tyy\tyz\tzx\tzy\tzz\n";
190    
191     for (int i = 0; i < nTimeBins_; ++i) {
192     ofs << time_[i] << "\t" <<
193     histogram_[i](0,0) << "\t" <<
194     histogram_[i](0,1) << "\t" <<
195     histogram_[i](0,2) << "\t" <<
196     histogram_[i](1,0) << "\t" <<
197     histogram_[i](1,1) << "\t" <<
198     histogram_[i](1,2) << "\t" <<
199     histogram_[i](2,0) << "\t" <<
200     histogram_[i](2,1) << "\t" <<
201     histogram_[i](2,2) << "\t" << "\n";
202     }
203    
204     } else {
205     sprintf(painCave.errMsg,
206     "MomentumCorrFunc::writeCorrelate Error: fail to open %s\n", getOutputFileName().c_str());
207     painCave.isFatal = 1;
208     simError();
209     }
210    
211     ofs.close();
212    
213     }
214    
215     }
216    

Properties

Name Value
svn:eol-style native