ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-3.0/src/applications/dynamicProps/TimeCorrFunc.cpp
Revision: 2035
Committed: Tue Feb 15 19:36:07 2005 UTC (19 years, 5 months ago) by tim
File size: 8495 byte(s)
Log Message:
BlockSnapshotManager is using reference counting now

File Contents

# User Rev Content
1 tim 2017 /*
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     * 1. Acknowledgement of the program authors must be made in any
10     * publication of scientific results based in part on use of the
11     * program. An acceptable form of acknowledgement is citation of
12     * the article in which the program was described (Matthew
13     * A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher
14     * J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented
15     * Parallel Simulation Engine for Molecular Dynamics,"
16     * J. Comput. Chem. 26, pp. 252-271 (2005))
17     *
18     * 2. Redistributions of source code must retain the above copyright
19     * notice, this list of conditions and the following disclaimer.
20     *
21     * 3. Redistributions in binary form must reproduce the above copyright
22     * notice, this list of conditions and the following disclaimer in the
23     * documentation and/or other materials provided with the
24     * distribution.
25     *
26     * This software is provided "AS IS," without a warranty of any
27     * kind. All express or implied conditions, representations and
28     * warranties, including any implied warranty of merchantability,
29     * fitness for a particular purpose or non-infringement, are hereby
30     * excluded. The University of Notre Dame and its licensors shall not
31     * be liable for any damages suffered by licensee as a result of
32     * using, modifying or distributing the software or its
33     * derivatives. In no event will the University of Notre Dame or its
34     * licensors be liable for any lost revenue, profit or data, or for
35     * direct, indirect, special, consequential, incidental or punitive
36     * damages, however caused and regardless of the theory of liability,
37     * arising out of the use of or inability to use software, even if the
38     * University of Notre Dame has been advised of the possibility of
39     * such damages.
40     */
41    
42     #include "applications/dynamicProps/TimeCorrFunc.hpp"
43     #include "utils/simError.h"
44     #include "primitives/Molecule.hpp"
45     namespace oopse {
46    
47     TimeCorrFunc::TimeCorrFunc(SimInfo* info, const std::string& filename,
48     const std::string& sele1, const std::string& sele2, int storageLayout)
49     : info_(info), storageLayout_(storageLayout), dumpFilename_(filename), selectionScript1_(sele1),
50     selectionScript2_(sele2), evaluator1_(info), evaluator2_(info), seleMan1_(info), seleMan2_(info){
51    
52     int nAtoms = info->getNGlobalAtoms();
53     int nRigidBodies = info->getNGlobalRigidBodies();
54     int nStuntDoubles = nAtoms + nRigidBodies;
55    
56     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     if ((*i)->isDirectional()){
62     hasDirectionalAtom = true;
63     }
64     if ((*i)->isMultipole()){
65     hasMultipole = true;
66     }
67     }
68    
69     if (nRigidBodies > 0 || hasDirectionalAtom) {
70     storageLayout_ |= DataStorage::dslAmat;
71     }
72     if (hasMultipole) {
73     storageLayout_ |= DataStorage::dslElectroFrame;
74     if (nRigidBodies > 0) {
75     storageLayout_ |= DataStorage::dslAngularMomentum;
76     }
77     }
78    
79     bsMan_ = new BlockSnapshotManager(info, dumpFilename_, storageLayout_);
80     info_->setSnapshotManager(bsMan_);
81    
82 tim 2018 evaluator1_.loadScriptString(selectionScript1_);
83     evaluator2_.loadScriptString(selectionScript2_);
84    
85 tim 2017 //if selection is static, we only need to evaluate it once
86     if (!evaluator1_.isDynamic()) {
87     seleMan1_.setSelectionSet(evaluator1_.evaluate());
88     validateSelection(seleMan1_);
89     } else {
90     sprintf(painCave.errMsg,
91     "TimeCorrFunc Error: dynamic selection is not supported\n");
92     painCave.isFatal = 1;
93     simError();
94     }
95    
96     if (!evaluator2_.isDynamic()) {
97     seleMan2_.setSelectionSet(evaluator2_.evaluate());
98     validateSelection(seleMan2_);
99     } else {
100     sprintf(painCave.errMsg,
101     "TimeCorrFunc Error: dynamic selection is not supported\n");
102     painCave.isFatal = 1;
103     simError();
104     }
105    
106    
107    
108 tim 2018 /**@todo Fix Me */
109 tim 2017 Globals* simParams = info_->getSimParams();
110     if (simParams->haveSampleTime()){
111     deltaTime_ = simParams->getSampleTime();
112     } else {
113     sprintf(painCave.errMsg,
114     "TimeCorrFunc::writeCorrelate Error: can not figure out deltaTime\n");
115     painCave.isFatal = 1;
116     simError();
117     }
118    
119     int nframes = bsMan_->getNFrames();
120     nTimeBins_ = nframes;
121     histogram_.resize(nTimeBins_);
122     count_.resize(nTimeBins_);
123     time_.resize(nTimeBins_);
124    
125     for (int i = 0; i < nTimeBins_; ++i) {
126     time_[i] = i * deltaTime_;
127     }
128    
129     }
130    
131    
132     void TimeCorrFunc::doCorrelate() {
133     preCorrelate();
134    
135     int nblocks = bsMan_->getNBlocks();
136    
137     for (int i = 0; i < nblocks; ++i) {
138     bsMan_->loadBlock(i);
139 tim 2035
140 tim 2017 for (int j = i; j < nblocks; ++j) {
141     bsMan_->loadBlock(j);
142     correlateBlocks(i, j);
143 tim 2035 bsMan_->unloadBlock(j);
144 tim 2017 }
145 tim 2035
146 tim 2017 bsMan_->unloadBlock(i);
147     }
148    
149     postCorrelate();
150    
151     writeCorrelate();
152     }
153    
154     void TimeCorrFunc::correlateBlocks(int block1, int block2) {
155    
156 tim 2018 int jstart, jend;
157 tim 2017
158 tim 2018 assert(bsMan_->isBlockActive(block1) && bsMan_->isBlockActive(block2));
159 tim 2017
160 tim 2018 SnapshotBlock snapshotBlock1 = bsMan_->getSnapshotBlock(block1);
161     SnapshotBlock snapshotBlock2 = bsMan_->getSnapshotBlock(block2);
162 tim 2017
163 tim 2018 jend = snapshotBlock2.second;
164    
165     for (int i = snapshotBlock1.first; i < snapshotBlock1.second; ++i) {
166    
167     //update the position or velocity of the atoms belong to rigid bodies
168     updateFrame(i);
169    
170     // if the two blocks are the same, we don't want to correlate
171     // backwards in time, so start j at the same frame as i
172     if (block1 == block2) {
173     jstart = i;
174     } else {
175     jstart = snapshotBlock2.first;
176     }
177    
178     for(int j = jstart; j < jend; ++j) {
179     //update the position or velocity of the atoms belong to rigid bodies
180     updateFrame(j);
181    
182     correlateFrames(i, j);
183     }
184 tim 2017 }
185     }
186    
187     void TimeCorrFunc::updateFrame(int frame){
188     Molecule* mol;
189     RigidBody* rb;
190     SimInfo::MoleculeIterator mi;
191     Molecule::RigidBodyIterator rbIter;
192    
193     /** @todo need improvement */
194     if (storageLayout_ & DataStorage::dslPosition) {
195     for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
196    
197     //change the positions of atoms which belong to the rigidbodies
198     for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
199     rb->updateAtoms(frame);
200     }
201     }
202     }
203    
204     if (storageLayout_ & DataStorage::dslVelocity) {
205     for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
206    
207     //change the positions of atoms which belong to the rigidbodies
208     for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
209     rb->updateAtomVel(frame);
210     }
211     }
212    
213     }
214    
215     }
216    
217    
218     void TimeCorrFunc::preCorrelate() {
219     std::fill(histogram_.begin(), histogram_.end(), 0.0);
220     std::fill(count_.begin(), count_.end(), 0);
221     }
222    
223     void TimeCorrFunc::postCorrelate() {
224     for (int i =0 ; i < nTimeBins_; ++i) {
225     if (count_[i] > 0) {
226     histogram_[i] /= count_[i];
227     }
228     }
229     }
230    
231    
232     void TimeCorrFunc::writeCorrelate() {
233     std::ofstream ofs(outputFilename_.c_str());
234    
235     if (ofs.is_open()) {
236    
237     ofs << "#" << getCorrFuncType() << "\n";
238     ofs << "#selection script1: \"" << selectionScript1_ <<"\"\tselection script2: \"" << selectionScript2_ << "\"\n";
239     ofs << "#extra information: " << extra_ << "\n";
240     ofs << "#time\tcorrVal\n";
241    
242     for (int i = 0; i < nTimeBins_; ++i) {
243     ofs << time_[i] << "\t" << histogram_[i] << "\n";
244     }
245    
246     } else {
247     sprintf(painCave.errMsg,
248     "TimeCorrFunc::writeCorrelate Error: fail to open %s\n", outputFilename_.c_str());
249     painCave.isFatal = 1;
250     simError();
251     }
252    
253     ofs.close();
254     }
255    
256     }

Properties

Name Value
svn:executable *