ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/applications/dynamicProps/TimeCorrFunc.cpp
Revision: 1850
Committed: Wed Feb 20 15:39:39 2013 UTC (12 years, 3 months ago) by gezelter
File size: 7926 byte(s)
Log Message:
Fixed a widespread typo in the license 

File Contents

# User Rev Content
1 tim 333 /*
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 333 * 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 333 * 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 gezelter 1850 * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (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 tim 333 */
42    
43     #include "applications/dynamicProps/TimeCorrFunc.hpp"
44     #include "utils/simError.h"
45     #include "primitives/Molecule.hpp"
46 gezelter 1535 using namespace std;
47 gezelter 1390 namespace OpenMD {
48 tim 333
49 gezelter 1535 TimeCorrFunc::TimeCorrFunc(SimInfo* info, const string& filename,
50     const string& sele1, const string& sele2,
51 gezelter 1629 int storageLayout, long long int memSize)
52     : info_(info), storageLayout_(storageLayout), memSize_(memSize),
53     dumpFilename_(filename), selectionScript1_(sele1),
54     selectionScript2_(sele2), evaluator1_(info), evaluator2_(info),
55     seleMan1_(info), seleMan2_(info) {
56 tim 333
57 gezelter 1535 int nAtoms = info->getNGlobalAtoms();
58     int nRigidBodies = info->getNGlobalRigidBodies();
59 gezelter 1787
60 gezelter 1838 // 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 gezelter 1812 bsMan_ = new BlockSnapshotManager(info, dumpFilename_, storageLayout_,
67     memSize_);
68 gezelter 1535 info_->setSnapshotManager(bsMan_);
69    
70     evaluator1_.loadScriptString(selectionScript1_);
71     evaluator2_.loadScriptString(selectionScript2_);
72    
73     //if selection is static, we only need to evaluate it once
74     if (!evaluator1_.isDynamic()) {
75     seleMan1_.setSelectionSet(evaluator1_.evaluate());
76     validateSelection(seleMan1_);
77     }
78    
79     if (!evaluator2_.isDynamic()) {
80     seleMan2_.setSelectionSet(evaluator2_.evaluate());
81     validateSelection(seleMan2_);
82     }
83    
84     /**@todo Fix Me */
85     Globals* simParams = info_->getSimParams();
86     if (simParams->haveSampleTime()){
87     deltaTime_ = simParams->getSampleTime();
88     } else {
89     sprintf(painCave.errMsg,
90     "TimeCorrFunc::writeCorrelate Error: can not figure out deltaTime\n");
91     painCave.isFatal = 1;
92     simError();
93     }
94 tim 333
95 gezelter 1535 int nframes = bsMan_->getNFrames();
96     nTimeBins_ = nframes;
97     histogram_.resize(nTimeBins_);
98     count_.resize(nTimeBins_);
99     time_.resize(nTimeBins_);
100 tim 333
101 gezelter 1535 for (int i = 0; i < nTimeBins_; ++i) {
102     time_[i] = i * deltaTime_;
103     }
104 gezelter 507
105 gezelter 1535 }
106 tim 333
107    
108 gezelter 507 void TimeCorrFunc::doCorrelate() {
109 tim 333 preCorrelate();
110    
111     int nblocks = bsMan_->getNBlocks();
112    
113     for (int i = 0; i < nblocks; ++i) {
114 gezelter 507 bsMan_->loadBlock(i);
115 tim 351
116 gezelter 507 for (int j = i; j < nblocks; ++j) {
117     bsMan_->loadBlock(j);
118     correlateBlocks(i, j);
119     bsMan_->unloadBlock(j);
120     }
121 tim 351
122 gezelter 507 bsMan_->unloadBlock(i);
123 tim 333 }
124    
125     postCorrelate();
126    
127     writeCorrelate();
128 gezelter 507 }
129 tim 333
130 gezelter 507 void TimeCorrFunc::correlateBlocks(int block1, int block2) {
131 tim 333
132 tim 334 int jstart, jend;
133 tim 333
134 tim 334 assert(bsMan_->isBlockActive(block1) && bsMan_->isBlockActive(block2));
135 tim 333
136 tim 334 SnapshotBlock snapshotBlock1 = bsMan_->getSnapshotBlock(block1);
137     SnapshotBlock snapshotBlock2 = bsMan_->getSnapshotBlock(block2);
138 tim 333
139 tim 334 jend = snapshotBlock2.second;
140    
141     for (int i = snapshotBlock1.first; i < snapshotBlock1.second; ++i) {
142    
143 gezelter 507 //update the position or velocity of the atoms belong to rigid bodies
144     updateFrame(i);
145 tim 334
146 gezelter 1812 if (evaluator1_.isDynamic()) {
147 gezelter 1831 seleMan1_.clearSelection();
148     seleMan1_.setSelectionSet(evaluator1_.evaluate(i));
149 gezelter 1812 }
150    
151 gezelter 507 // if the two blocks are the same, we don't want to correlate
152     // backwards in time, so start j at the same frame as i
153     if (block1 == block2) {
154 tim 334 jstart = i;
155 gezelter 507 } else {
156     jstart = snapshotBlock2.first;
157     }
158 tim 334
159 gezelter 507 for(int j = jstart; j < jend; ++j) {
160     //update the position or velocity of the atoms belong to rigid bodies
161     updateFrame(j);
162 gezelter 1812 if (evaluator2_.isDynamic()) {
163 gezelter 1831 seleMan2_.clearSelection();
164     seleMan2_.setSelectionSet(evaluator2_.evaluate(j));
165 gezelter 1812 }
166    
167 gezelter 507 correlateFrames(i, j);
168     }
169 tim 333 }
170 gezelter 507 }
171 tim 333
172 gezelter 507 void TimeCorrFunc::updateFrame(int frame){
173 tim 333 Molecule* mol;
174     RigidBody* rb;
175     SimInfo::MoleculeIterator mi;
176     Molecule::RigidBodyIterator rbIter;
177     /** @todo need improvement */
178     if (storageLayout_ & DataStorage::dslPosition) {
179 xsun 1183 for (mol = info_->beginMolecule(mi); mol != NULL;
180     mol = info_->nextMolecule(mi)) {
181 tim 333
182 gezelter 507 //change the positions of atoms which belong to the rigidbodies
183 xsun 1183 for (rb = mol->beginRigidBody(rbIter); rb != NULL;
184     rb = mol->nextRigidBody(rbIter)) {
185 gezelter 507 rb->updateAtoms(frame);
186     }
187     }
188 tim 333 }
189    
190     if (storageLayout_ & DataStorage::dslVelocity) {
191 xsun 1183 for (mol = info_->beginMolecule(mi); mol != NULL;
192     mol = info_->nextMolecule(mi)) {
193    
194 gezelter 507 //change the positions of atoms which belong to the rigidbodies
195 xsun 1183 for (rb = mol->beginRigidBody(rbIter); rb != NULL;
196     rb = mol->nextRigidBody(rbIter)) {
197 gezelter 507 rb->updateAtomVel(frame);
198     }
199 gezelter 1535 }
200     }
201 gezelter 507 }
202 tim 333
203    
204 gezelter 507 void TimeCorrFunc::preCorrelate() {
205 gezelter 1535 fill(histogram_.begin(), histogram_.end(), 0.0);
206     fill(count_.begin(), count_.end(), 0);
207 gezelter 507 }
208 tim 333
209 gezelter 507 void TimeCorrFunc::postCorrelate() {
210 tim 333 for (int i =0 ; i < nTimeBins_; ++i) {
211 gezelter 507 if (count_[i] > 0) {
212     histogram_[i] /= count_[i];
213 gezelter 1831 } else {
214     histogram_[i] = 0;
215 gezelter 507 }
216 tim 333 }
217 gezelter 507 }
218 tim 333
219    
220 gezelter 507 void TimeCorrFunc::writeCorrelate() {
221 gezelter 1535 ofstream ofs(outputFilename_.c_str());
222 tim 333
223     if (ofs.is_open()) {
224    
225 gezelter 507 ofs << "#" << getCorrFuncType() << "\n";
226 gezelter 1535 ofs << "#selection script1: \"" << selectionScript1_ ;
227     ofs << "\"\tselection script2: \"" << selectionScript2_ << "\"\n";
228 gezelter 507 ofs << "#extra information: " << extra_ << "\n";
229     ofs << "#time\tcorrVal\n";
230 tim 333
231 gezelter 507 for (int i = 0; i < nTimeBins_; ++i) {
232     ofs << time_[i] << "\t" << histogram_[i] << "\n";
233     }
234 tim 333
235     } else {
236 gezelter 507 sprintf(painCave.errMsg,
237 gezelter 1535 "TimeCorrFunc::writeCorrelate Error: fail to open %s\n",
238     outputFilename_.c_str());
239 gezelter 507 painCave.isFatal = 1;
240     simError();
241 tim 333 }
242    
243     ofs.close();
244 gezelter 507 }
245 tim 333
246     }

Properties

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