ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/applications/dynamicProps/TimeCorrFunc.cpp
Revision: 1665
Committed: Tue Nov 22 20:38:56 2011 UTC (13 years, 6 months ago) by gezelter
File size: 8529 byte(s)
Log Message:
updated copyright notices

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

Properties

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