ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-3.0/src/applications/dynamicProps/TimeCorrFunc.cpp
Revision: 2204
Committed: Fri Apr 15 22:04:00 2005 UTC (19 years, 3 months ago) by gezelter
File size: 8348 byte(s)
Log Message:
xemacs has been drafted to perform our indentation services

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

Properties

Name Value
svn:executable *