ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/applications/dynamicProps/TimeCorrFunc.cpp
Revision: 1787
Committed: Wed Aug 29 18:13:11 2012 UTC (12 years, 8 months ago) by gezelter
File size: 8707 byte(s)
Log Message:
Massive multipole rewrite

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

Properties

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