ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/dynamicProps/TimeCorrFunc.cpp
Revision: 2071
Committed: Sat Mar 7 21:41:51 2015 UTC (10 years, 5 months ago) by gezelter
File size: 8635 byte(s)
Log Message:
Reducing the number of warnings when using g++ to compile.

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 1879 * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
39 gezelter 1782 * [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 1782 using namespace std;
47 gezelter 1390 namespace OpenMD {
48 tim 333
49 gezelter 1782 TimeCorrFunc::TimeCorrFunc(SimInfo* info, const string& filename,
50     const string& sele1, const string& sele2,
51 gezelter 1596 int storageLayout, long long int memSize)
52     : info_(info), storageLayout_(storageLayout), memSize_(memSize),
53 gezelter 2071 dumpFilename_(filename), seleMan1_(info_), seleMan2_(info_),
54     selectionScript1_(sele1), selectionScript2_(sele2),
55     evaluator1_(info_), evaluator2_(info_) {
56 tim 333
57 gezelter 1879 // Request maximum needed storage for the simulation (including of
58     // whatever was passed down by the individual correlation
59     // function).
60    
61     storageLayout_ = info->getStorageLayout() | storageLayout;
62    
63 gezelter 1811 bsMan_ = new BlockSnapshotManager(info, dumpFilename_, storageLayout_,
64     memSize_);
65 gezelter 1782 info_->setSnapshotManager(bsMan_);
66    
67     evaluator1_.loadScriptString(selectionScript1_);
68     evaluator2_.loadScriptString(selectionScript2_);
69    
70     //if selection is static, we only need to evaluate it once
71     if (!evaluator1_.isDynamic()) {
72     seleMan1_.setSelectionSet(evaluator1_.evaluate());
73     validateSelection(seleMan1_);
74     }
75    
76     if (!evaluator2_.isDynamic()) {
77     seleMan2_.setSelectionSet(evaluator2_.evaluate());
78     validateSelection(seleMan2_);
79     }
80    
81     /**@todo Fix Me */
82     Globals* simParams = info_->getSimParams();
83     if (simParams->haveSampleTime()){
84     deltaTime_ = simParams->getSampleTime();
85     } else {
86     sprintf(painCave.errMsg,
87     "TimeCorrFunc::writeCorrelate Error: can not figure out deltaTime\n");
88     painCave.isFatal = 1;
89     simError();
90     }
91 tim 333
92 gezelter 1782 int nframes = bsMan_->getNFrames();
93     nTimeBins_ = nframes;
94     histogram_.resize(nTimeBins_);
95     count_.resize(nTimeBins_);
96     time_.resize(nTimeBins_);
97 tim 333
98 gezelter 1782 for (int i = 0; i < nTimeBins_; ++i) {
99     time_[i] = i * deltaTime_;
100 gezelter 1937 }
101 gezelter 1782 }
102 tim 333
103 gezelter 507 void TimeCorrFunc::doCorrelate() {
104 tim 333 preCorrelate();
105    
106     int nblocks = bsMan_->getNBlocks();
107    
108     for (int i = 0; i < nblocks; ++i) {
109 gezelter 507 bsMan_->loadBlock(i);
110 tim 351
111 gezelter 507 for (int j = i; j < nblocks; ++j) {
112     bsMan_->loadBlock(j);
113     correlateBlocks(i, j);
114     bsMan_->unloadBlock(j);
115     }
116 tim 351
117 gezelter 507 bsMan_->unloadBlock(i);
118 tim 333 }
119    
120     postCorrelate();
121    
122     writeCorrelate();
123 gezelter 507 }
124 tim 333
125 gezelter 507 void TimeCorrFunc::correlateBlocks(int block1, int block2) {
126 tim 333
127 tim 334 int jstart, jend;
128 gezelter 1937 RealType i_t, j_t;
129 tim 333
130 tim 334 assert(bsMan_->isBlockActive(block1) && bsMan_->isBlockActive(block2));
131 tim 333
132 tim 334 SnapshotBlock snapshotBlock1 = bsMan_->getSnapshotBlock(block1);
133     SnapshotBlock snapshotBlock2 = bsMan_->getSnapshotBlock(block2);
134 tim 333
135 tim 334 jend = snapshotBlock2.second;
136    
137     for (int i = snapshotBlock1.first; i < snapshotBlock1.second; ++i) {
138 gezelter 1937
139 gezelter 507 //update the position or velocity of the atoms belong to rigid bodies
140     updateFrame(i);
141 tim 334
142 gezelter 1811 if (evaluator1_.isDynamic()) {
143 gezelter 1816 seleMan1_.clearSelection();
144     seleMan1_.setSelectionSet(evaluator1_.evaluate(i));
145 gezelter 1811 }
146    
147 gezelter 507 // if the two blocks are the same, we don't want to correlate
148     // backwards in time, so start j at the same frame as i
149     if (block1 == block2) {
150 tim 334 jstart = i;
151 gezelter 507 } else {
152     jstart = snapshotBlock2.first;
153     }
154 gezelter 1937
155     i_t = bsMan_->getSnapshot(i)->getTime();
156    
157 gezelter 507 for(int j = jstart; j < jend; ++j) {
158 gezelter 1937
159     // Perform a sanity check on the actual configuration times to
160     // make sure the configurations are spaced the same amount the
161     // sample time said they were spaced:
162    
163     j_t = bsMan_->getSnapshot(j)->getTime();
164    
165     if ( fabs( (j_t - i_t) - (j-i)*deltaTime_ ) > 1.0e-4 ) {
166     sprintf(painCave.errMsg,
167     "TimeCorrFunc::correlateBlocks Error: sampleTime (%f)\n"
168     "\tin %s does not match actual time-spacing between\n"
169     "\tconfigurations %d (t = %f) and %d (t = %f).\n",
170     deltaTime_, dumpFilename_.c_str(), i, i_t, j, j_t);
171     painCave.isFatal = 1;
172     simError();
173     }
174    
175 gezelter 507 //update the position or velocity of the atoms belong to rigid bodies
176     updateFrame(j);
177 gezelter 1811 if (evaluator2_.isDynamic()) {
178 gezelter 1816 seleMan2_.clearSelection();
179     seleMan2_.setSelectionSet(evaluator2_.evaluate(j));
180 gezelter 1811 }
181    
182 gezelter 507 correlateFrames(i, j);
183     }
184 tim 333 }
185 gezelter 507 }
186 tim 333
187 gezelter 507 void TimeCorrFunc::updateFrame(int frame){
188 tim 333 Molecule* mol;
189     RigidBody* rb;
190     SimInfo::MoleculeIterator mi;
191     Molecule::RigidBodyIterator rbIter;
192     /** @todo need improvement */
193     if (storageLayout_ & DataStorage::dslPosition) {
194 xsun 1183 for (mol = info_->beginMolecule(mi); mol != NULL;
195     mol = info_->nextMolecule(mi)) {
196 tim 333
197 gezelter 507 //change the positions of atoms which belong to the rigidbodies
198 xsun 1183 for (rb = mol->beginRigidBody(rbIter); rb != NULL;
199     rb = mol->nextRigidBody(rbIter)) {
200 gezelter 507 rb->updateAtoms(frame);
201     }
202     }
203 tim 333 }
204    
205     if (storageLayout_ & DataStorage::dslVelocity) {
206 xsun 1183 for (mol = info_->beginMolecule(mi); mol != NULL;
207     mol = info_->nextMolecule(mi)) {
208    
209 gezelter 507 //change the positions of atoms which belong to the rigidbodies
210 xsun 1183 for (rb = mol->beginRigidBody(rbIter); rb != NULL;
211     rb = mol->nextRigidBody(rbIter)) {
212 gezelter 507 rb->updateAtomVel(frame);
213     }
214 gezelter 1782 }
215     }
216 gezelter 507 }
217 tim 333
218    
219 gezelter 507 void TimeCorrFunc::preCorrelate() {
220 gezelter 1782 fill(histogram_.begin(), histogram_.end(), 0.0);
221     fill(count_.begin(), count_.end(), 0);
222 gezelter 507 }
223 tim 333
224 gezelter 507 void TimeCorrFunc::postCorrelate() {
225 tim 333 for (int i =0 ; i < nTimeBins_; ++i) {
226 gezelter 507 if (count_[i] > 0) {
227     histogram_[i] /= count_[i];
228 gezelter 1815 } else {
229     histogram_[i] = 0;
230 gezelter 507 }
231 tim 333 }
232 gezelter 507 }
233 tim 333
234    
235 gezelter 507 void TimeCorrFunc::writeCorrelate() {
236 gezelter 1782 ofstream ofs(outputFilename_.c_str());
237 tim 333
238     if (ofs.is_open()) {
239    
240 gezelter 507 ofs << "#" << getCorrFuncType() << "\n";
241 gezelter 1782 ofs << "#selection script1: \"" << selectionScript1_ ;
242     ofs << "\"\tselection script2: \"" << selectionScript2_ << "\"\n";
243 gezelter 507 ofs << "#extra information: " << extra_ << "\n";
244     ofs << "#time\tcorrVal\n";
245 tim 333
246 gezelter 507 for (int i = 0; i < nTimeBins_; ++i) {
247     ofs << time_[i] << "\t" << histogram_[i] << "\n";
248     }
249 tim 333
250     } else {
251 gezelter 507 sprintf(painCave.errMsg,
252 gezelter 1782 "TimeCorrFunc::writeCorrelate Error: fail to open %s\n",
253     outputFilename_.c_str());
254 gezelter 507 painCave.isFatal = 1;
255     simError();
256 tim 333 }
257    
258     ofs.close();
259 gezelter 507 }
260 tim 333
261     }

Properties

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