ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-3.0/src/applications/dynamicProps/TimeCorrFunc.cpp
Revision: 2037
Committed: Wed Feb 16 19:36:30 2005 UTC (19 years, 5 months ago) by tim
File size: 8632 byte(s)
Log Message:
change the suffix of output files;fix the problem of counting in staticProps

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

Properties

Name Value
svn:executable *