ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/dynamicProps/LegendreCorrFunc.cpp
Revision: 1596
Committed: Mon Jul 25 17:30:53 2011 UTC (14 years, 1 month ago) by gezelter
File size: 6446 byte(s)
Log Message:
Updated the BlockSnapshotManager to use a specified memory footprint
in constructor and not to rely on physmem and residentMem to figure
out free memory. DynamicProps is the only program that uses the
BlockSnapshotManager, so substantial changes were needed there as
well.


File Contents

# User Rev Content
1 tim 876 /*
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 gezelter 1390 * 1. Redistributions of source code must retain the above copyright
10 tim 876 * notice, this list of conditions and the following disclaimer.
11     *
12 gezelter 1390 * 2. Redistributions in binary form must reproduce the above copyright
13 tim 876 * 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 gezelter 1390 *
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 tim 876 */
41    
42     #include "applications/dynamicProps/LegendreCorrFunc.hpp"
43     #include "math/LegendrePolynomial.hpp"
44     #include "utils/simError.h"
45    
46 gezelter 1390 namespace OpenMD {
47 gezelter 1596 LegendreCorrFunc::LegendreCorrFunc(SimInfo* info, const std::string& filename, const std::string& sele1, const std::string& sele2, int order, long long int memSize)
48     : ParticleTimeCorrFunc(info, filename, sele1, sele2, DataStorage::dslAmat | DataStorage::dslElectroFrame, memSize){
49 tim 876
50     setCorrFuncType("Legendre Correlation Function");
51     setOutputName(getPrefix(dumpFilename_) + ".lcorr");
52 xsun 1183 histogram_.resize(nTimeBins_);
53     count_.resize(nTimeBins_);
54     nSelected_ = seleMan1_.getSelectionCount();
55     std::cout << "sele1 = " << sele1 << "\n";
56     std::cout << "sele2 = " << sele2 << "\n";
57     std::cout << "nSelected = " << nSelected_ << "\n";
58     assert( nSelected_ == seleMan2_.getSelectionCount());
59    
60 tim 876 LegendrePolynomial polynomial(order);
61     legendre_ = polynomial.getLegendrePolynomial(order);
62 xsun 1183 }
63 tim 876
64 xsun 1183 void LegendreCorrFunc::correlateFrames(int frame1, int frame2) {
65     Snapshot* snapshot1 = bsMan_->getSnapshot(frame1);
66     Snapshot* snapshot2 = bsMan_->getSnapshot(frame2);
67     assert(snapshot1 && snapshot2);
68    
69     RealType time1 = snapshot1->getTime();
70     RealType time2 = snapshot2->getTime();
71    
72     int timeBin = int ((time2 - time1) /deltaTime_ + 0.5);
73     count_[timeBin] += nSelected_;
74    
75     int i;
76     int j;
77     StuntDouble* sd1;
78     StuntDouble* sd2;
79    
80     for (sd1 = seleMan1_.beginSelected(i), sd2 = seleMan2_.beginSelected(j);
81     sd1 != NULL && sd2 != NULL;
82     sd1 = seleMan1_.nextSelected(i), sd2 = seleMan2_.nextSelected(j)) {
83    
84     Vector3d corrVals = calcCorrVals(frame1, frame2, sd1, sd2);
85     histogram_[timeBin] += corrVals;
86 tim 876 }
87 xsun 1183
88     }
89 tim 876
90 xsun 1183 void LegendreCorrFunc::postCorrelate() {
91     for (int i =0 ; i < nTimeBins_; ++i) {
92     if (count_[i] > 0) {
93     histogram_[i] /= count_[i];
94     }
95     }
96     }
97 tim 876
98 xsun 1183 void LegendreCorrFunc::preCorrelate() {
99     // Fill the histogram with empty Vector3d:
100     std::fill(histogram_.begin(), histogram_.end(), Vector3d(0.0));
101     // count array set to zero
102     std::fill(count_.begin(), count_.end(), 0);
103 tim 876 }
104    
105    
106 xsun 1183
107     Vector3d LegendreCorrFunc::calcCorrVals(int frame1, int frame2, StuntDouble* sd1, StuntDouble* sd2) {
108 xsun 1213
109     // The lab frame vector corresponding to the body-fixed
110     // z-axis is simply the second column of A.transpose()
111     // or, identically, the second row of A itself.
112     // Similar identites give the 0th and 1st rows of A for
113     // the lab vectors associated with body-fixed x- and y- axes.
114 xsun 1183
115 xsun 1213 Vector3d v1x = sd1->getA(frame1).getRow(0);
116     Vector3d v2x = sd2->getA(frame2).getRow(0);
117     Vector3d v1y = sd1->getA(frame1).getRow(1);
118     Vector3d v2y = sd2->getA(frame2).getRow(1);
119     Vector3d v1z = sd1->getA(frame1).getRow(2);
120     Vector3d v2z = sd2->getA(frame2).getRow(2);
121    
122 xsun 1183 RealType uxprod = legendre_.evaluate(dot(v1x, v2x)/(v1x.length()*v2x.length()));
123     RealType uyprod = legendre_.evaluate(dot(v1y, v2y)/(v1y.length()*v2y.length()));
124     RealType uzprod = legendre_.evaluate(dot(v1z, v2z)/(v1z.length()*v2z.length()));
125    
126     return Vector3d(uxprod, uyprod, uzprod);
127    
128     }
129    
130    
131 tim 876 void LegendreCorrFunc::validateSelection(const SelectionManager& seleMan) {
132     StuntDouble* sd;
133     int i;
134     for (sd = seleMan1_.beginSelected(i); sd != NULL; sd = seleMan1_.nextSelected(i)) {
135     if (!sd->isDirectionalAtom()) {
136     sprintf(painCave.errMsg,
137 xsun 1183 "LegendreCorrFunc::validateSelection Error: selected atoms are not Directional\n");
138 tim 876 painCave.isFatal = 1;
139     simError();
140     }
141     }
142    
143     }
144    
145 xsun 1183 void LegendreCorrFunc::writeCorrelate() {
146     std::ofstream ofs(getOutputFileName().c_str());
147 tim 876
148 xsun 1183 if (ofs.is_open()) {
149 tim 876
150 xsun 1183 ofs << "#" << getCorrFuncType() << "\n";
151     ofs << "#time\tPn(costheta_x)\tPn(costheta_y)\tPn(costheta_z)\n";
152 tim 876
153 xsun 1183 for (int i = 0; i < nTimeBins_; ++i) {
154     ofs << time_[i] << "\t" <<
155     histogram_[i](0) << "\t" <<
156     histogram_[i](1) << "\t" <<
157     histogram_[i](2) << "\t" << "\n";
158     }
159    
160     } else {
161     sprintf(painCave.errMsg,
162     "LegendreCorrFunc::writeCorrelate Error: fail to open %s\n", getOutputFileName().c_str());
163     painCave.isFatal = 1;
164     simError();
165     }
166     ofs.close();
167     }
168     }

Properties

Name Value
svn:executable *
svn:keywords Author Id Revision Date