ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/applications/dynamicProps/TimeCorrFunc.cpp
Revision: 1535
Committed: Fri Dec 31 18:31:56 2010 UTC (14 years, 4 months ago) by gezelter
File size: 8405 byte(s)
Log Message:
Well, it compiles and builds, but still has a bus error at runtime.

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

Properties

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