ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/applications/dynamicProps/TimeCorrFunc.cpp
Revision: 2018
Committed: Mon Feb 14 17:57:01 2005 UTC (19 years, 5 months ago) by tim
File size: 8612 byte(s)
Log Message:
begin bug fix

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     for (int j = i; j < nblocks; ++j) {
140     bsMan_->loadBlock(j);
141     correlateBlocks(i, j);
142    
143     if (i != j) {
144     //if i equals to j, the block is still used, should not unload it
145     bsMan_->unloadBlock(j);
146     }
147     }
148     bsMan_->unloadBlock(i);
149     }
150    
151     postCorrelate();
152    
153     writeCorrelate();
154     }
155    
156     void TimeCorrFunc::correlateBlocks(int block1, int block2) {
157    
158 tim 2018 int jstart, jend;
159 tim 2017
160 tim 2018 assert(bsMan_->isBlockActive(block1) && bsMan_->isBlockActive(block2));
161 tim 2017
162 tim 2018 SnapshotBlock snapshotBlock1 = bsMan_->getSnapshotBlock(block1);
163     SnapshotBlock snapshotBlock2 = bsMan_->getSnapshotBlock(block2);
164 tim 2017
165 tim 2018 jend = snapshotBlock2.second;
166    
167     for (int i = snapshotBlock1.first; i < snapshotBlock1.second; ++i) {
168    
169     //update the position or velocity of the atoms belong to rigid bodies
170     updateFrame(i);
171    
172     // if the two blocks are the same, we don't want to correlate
173     // backwards in time, so start j at the same frame as i
174     if (block1 == block2) {
175     jstart = i;
176     } else {
177     jstart = snapshotBlock2.first;
178     }
179    
180     for(int j = jstart; j < jend; ++j) {
181     //update the position or velocity of the atoms belong to rigid bodies
182     updateFrame(j);
183    
184     correlateFrames(i, j);
185     }
186 tim 2017 }
187     }
188    
189     void TimeCorrFunc::updateFrame(int frame){
190     Molecule* mol;
191     RigidBody* rb;
192     SimInfo::MoleculeIterator mi;
193     Molecule::RigidBodyIterator rbIter;
194    
195     /** @todo need improvement */
196     if (storageLayout_ & DataStorage::dslPosition) {
197     for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
198    
199     //change the positions of atoms which belong to the rigidbodies
200     for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
201     rb->updateAtoms(frame);
202     }
203     }
204     }
205    
206     if (storageLayout_ & DataStorage::dslVelocity) {
207     for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
208    
209     //change the positions of atoms which belong to the rigidbodies
210     for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
211     rb->updateAtomVel(frame);
212     }
213     }
214    
215     }
216    
217     }
218    
219    
220     void TimeCorrFunc::preCorrelate() {
221     std::fill(histogram_.begin(), histogram_.end(), 0.0);
222     std::fill(count_.begin(), count_.end(), 0);
223     }
224    
225     void TimeCorrFunc::postCorrelate() {
226     for (int i =0 ; i < nTimeBins_; ++i) {
227     if (count_[i] > 0) {
228     histogram_[i] /= count_[i];
229     }
230     }
231     }
232    
233    
234     void TimeCorrFunc::writeCorrelate() {
235     std::ofstream ofs(outputFilename_.c_str());
236    
237     if (ofs.is_open()) {
238    
239     ofs << "#" << getCorrFuncType() << "\n";
240     ofs << "#selection script1: \"" << selectionScript1_ <<"\"\tselection script2: \"" << selectionScript2_ << "\"\n";
241     ofs << "#extra information: " << extra_ << "\n";
242     ofs << "#time\tcorrVal\n";
243    
244     for (int i = 0; i < nTimeBins_; ++i) {
245     ofs << time_[i] << "\t" << histogram_[i] << "\n";
246     }
247    
248     } else {
249     sprintf(painCave.errMsg,
250     "TimeCorrFunc::writeCorrelate Error: fail to open %s\n", outputFilename_.c_str());
251     painCave.isFatal = 1;
252     simError();
253     }
254    
255     ofs.close();
256     }
257    
258     }

Properties

Name Value
svn:executable *