ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/dynamicProps/MultipassCorrFunc.cpp
Revision: 2056
Committed: Fri Feb 20 15:12:07 2015 UTC (10 years, 6 months ago) by gezelter
File size: 9754 byte(s)
Log Message:
Fixes to HullFinder (and by extension to RNEMD) for getSurfaceArea() call.
Adding Multipass Correlation Function (unused right now).

File Contents

# User Rev Content
1 gezelter 2056 /*
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, 234107 (2008).
39     * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010).
40     * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41     */
42    
43     #include "applications/dynamicProps/MultipassCorrFunc.hpp"
44     #include "utils/simError.h"
45     #include "primitives/Molecule.hpp"
46     using namespace std;
47     namespace OpenMD {
48    
49     MultipassCorrFunc::MultipassCorrFunc(SimInfo* info, const string& filename,
50     const string& sele1, const string& sele2,
51     int storageLayout)
52     : info_(info), storageLayout_(storageLayout),
53     dumpFilename_(filename), selectionScript1_(sele1),
54     selectionScript2_(sele2), evaluator1_(info), evaluator2_(info),
55     seleMan1_(info), seleMan2_(info) {
56    
57     int nAtoms = info->getNGlobalAtoms();
58     int nRigidBodies = info->getNGlobalRigidBodies();
59    
60     // Request maximum needed storage for the simulation (including of
61     // whatever was passed down by the individual correlation
62     // function).
63    
64     storageLayout_ = info->getStorageLayout() | storageLayout;
65    
66     DumpReader reader(info_, dumpFilename_);
67    
68     evaluator1_.loadScriptString(selectionScript1_);
69     evaluator2_.loadScriptString(selectionScript2_);
70    
71     //if selection is static, we only need to evaluate it once
72     if (!evaluator1_.isDynamic()) {
73     seleMan1_.setSelectionSet(evaluator1_.evaluate());
74     validateSelection(seleMan1_);
75     }
76    
77     if (!evaluator2_.isDynamic()) {
78     seleMan2_.setSelectionSet(evaluator2_.evaluate());
79     validateSelection(seleMan2_);
80     }
81    
82     /**@todo Fix Me */
83     Globals* simParams = info_->getSimParams();
84     if (simParams->haveSampleTime()){
85     deltaTime_ = simParams->getSampleTime();
86     } else {
87     sprintf(painCave.errMsg,
88     "MultipassCorrFunc::writeCorrelate Error: can not figure out deltaTime\n");
89     painCave.isFatal = 1;
90     simError();
91     }
92    
93     }
94    
95     void MultipassCorrFunc::preCorrelate() {
96     Molecule* mol;
97     RigidBody* rb;
98     SimInfo::MoleculeIterator mi;
99     Molecule::RigidBodyIterator rbIter;
100     StuntDouble* sd;
101    
102     int index, isd1, isd2;
103    
104     fill(histogram_.begin(), histogram_.end(), 0.0);
105     fill(count_.begin(), count_.end(), 0);
106    
107     DumpReader reader(info_, dumpFilename_);
108    
109     nFrames_ = reader.getNFrames();
110     times_.resize(nFrames_);
111    
112     for (int istep = 0; istep < nFrames_; istep++) {
113     reader.readFrame(istep);
114     currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
115     times_[istep] = currentSnapshot_->getTime();
116    
117     // update the positions of atoms which belong to the rigidbodies
118     for (mol = info_->beginMolecule(mi); mol != NULL;
119     mol = info_->nextMolecule(mi)) {
120     for (rb = mol->beginRigidBody(rbIter); rb != NULL;
121     rb = mol->nextRigidBody(rbIter)) {
122     rb->updateAtoms();
123     }
124     }
125    
126     if (evaluator1_.isDynamic()) {
127     seleMan1_.setSelectionSet(evaluator1_.evaluate());
128     }
129    
130     if (evaluator2_.isDynamic()) {
131     seleMan2_.setSelectionSet(evaluator2_.evaluate());
132     }
133    
134     for (sd = seleMan1_.beginSelected(isd1); sd != NULL;
135     sd = seleMan1_.nextSelected(isd1)) {
136    
137     sele1ToIndex_[istep].push_back(sd->getGlobalIndex());
138     index = sele1ToIndex_[istep].size();
139     computeProperty1(istep, sd, index);
140     }
141    
142     for (sd = seleMan2_.beginSelected(isd2); sd != NULL;
143     sd = seleMan2_.nextSelected(isd2)) {
144    
145     sele2ToIndex_[istep].push_back(sd->getGlobalIndex());
146     index = sele2ToIndex_[istep].size();
147    
148     computeProperty2(istep, sd, index);
149     }
150     }
151     }
152    
153    
154     void MultipassCorrFunc::doCorrelate() {
155     preCorrelate();
156     correlation();
157     postCorrelate();
158     writeCorrelate();
159     }
160    
161     void MultipassCorrFunc::correlation() {
162     std::vector<int> s1;
163     std::vector<int> s2;
164    
165     std::vector<int>::iterator i1;
166     std::vector<int>::iterator i2;
167    
168    
169     for (int i = 0; i < nFrames_; ++i) {
170    
171     RealType time1 = times_[i];
172     s1 = sele1ToIndex_[i];
173    
174     for(int j = i; j < nFrames_; ++j) {
175    
176     // Perform a sanity check on the actual configuration times to
177     // make sure the configurations are spaced the same amount the
178     // sample time said they were spaced:
179    
180     RealType time2 = times_[j];
181    
182     if ( fabs( (time2 - time1) - (j-i)*deltaTime_ ) > 1.0e-4 ) {
183     sprintf(painCave.errMsg,
184     "MultipassCorrFunc::correlateBlocks Error: sampleTime (%f)\n"
185     "\tin %s does not match actual time-spacing between\n"
186     "\tconfigurations %d (t = %f) and %d (t = %f).\n",
187     deltaTime_, dumpFilename_.c_str(), i, time1, j, time2);
188     painCave.isFatal = 1;
189     simError();
190     }
191    
192     int timeBin = int ((time2 - time1) / deltaTime_ + 0.5);
193     s2 = sele2ToIndex_[j];
194    
195     for (i1 = s1.begin(), i2 = s2.begin();
196     i1 != s1.end() && i2 != s2.end(); ++i1, ++i2){
197    
198     // If the selections are dynamic, they might not have the
199     // same objects in both frames, so we need to roll either of
200     // the selections until we have the same object to
201     // correlate.
202    
203     while ( *i1 < *i2 && i1 != s1.end()) {
204     ++i1;
205     }
206    
207     while ( *i2 < *i1 && i2 != s2.end() ) {
208     ++i2;
209     }
210    
211     if ( i1 == s1.end() || i2 == s2.end() ) break;
212    
213     RealType corrVal = calcCorrVal(i, j, *i1, *i2);
214     histogram_[timeBin] += corrVal;
215     count_[timeBin]++;
216    
217     }
218     }
219     }
220     }
221    
222    
223    
224     void MultipassCorrFunc::postCorrelate() {
225     for (int i =0 ; i < nTimeBins_; ++i) {
226     if (count_[i] > 0) {
227     histogram_[i] /= count_[i];
228     } else {
229     histogram_[i] = 0;
230     }
231     }
232     }
233    
234    
235     void MultipassCorrFunc::updateFrame(int frame){
236     Molecule* mol;
237     RigidBody* rb;
238     SimInfo::MoleculeIterator mi;
239     Molecule::RigidBodyIterator rbIter;
240     /** @todo need improvement */
241     if (storageLayout_ & DataStorage::dslPosition) {
242     for (mol = info_->beginMolecule(mi); mol != NULL;
243     mol = info_->nextMolecule(mi)) {
244    
245     //change the positions of atoms which belong to the rigidbodies
246     for (rb = mol->beginRigidBody(rbIter); rb != NULL;
247     rb = mol->nextRigidBody(rbIter)) {
248     rb->updateAtoms(frame);
249     }
250     }
251     }
252    
253     if (storageLayout_ & DataStorage::dslVelocity) {
254     for (mol = info_->beginMolecule(mi); mol != NULL;
255     mol = info_->nextMolecule(mi)) {
256    
257     //change the positions of atoms which belong to the rigidbodies
258     for (rb = mol->beginRigidBody(rbIter); rb != NULL;
259     rb = mol->nextRigidBody(rbIter)) {
260     rb->updateAtomVel(frame);
261     }
262     }
263     }
264     }
265    
266    
267    
268     void MultipassCorrFunc::writeCorrelate() {
269     ofstream ofs(outputFilename_.c_str());
270    
271     if (ofs.is_open()) {
272    
273     ofs << "#" << getCorrFuncType() << "\n";
274     ofs << "#selection script1: \"" << selectionScript1_ ;
275     ofs << "\"\tselection script2: \"" << selectionScript2_ << "\"\n";
276     ofs << "#extra information: " << extra_ << "\n";
277     ofs << "#time\tcorrVal\n";
278    
279     for (int i = 0; i < nTimeBins_; ++i) {
280     ofs << times_[i]-times_[0] << "\t" << histogram_[i] << "\n";
281     }
282    
283     } else {
284     sprintf(painCave.errMsg,
285     "MultipassCorrFunc::writeCorrelate Error: fail to open %s\n",
286     outputFilename_.c_str());
287     painCave.isFatal = 1;
288     simError();
289     }
290    
291     ofs.close();
292     }
293    
294     }

Properties

Name Value
svn:eol-style native
svn:executable *