ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/applications/dynamicProps/TimeCorrFunc.cpp
Revision: 1465
Committed: Fri Jul 9 23:08:25 2010 UTC (14 years, 10 months ago) by chuckv
File size: 8368 byte(s)
Log Message:
Creating busticated version of OpenMD

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

Properties

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