ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/applications/staticProps/RhoZ.cpp
Revision: 1267
Committed: Mon Jun 30 17:53:42 2008 UTC (16 years, 10 months ago) by gpuliti
Original Path: trunk/src/applications/staticProps/RhoZ.cpp
File size: 6142 byte(s)
Log Message:
Fixed a number of bugs in slab_density calculation

File Contents

# User Rev Content
1 chuckv 769 /*
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     * RhoZ.cpp
43     * OOPSE-2.0
44     *
45     * Created by Charles F. Vardeman II on 11/26/05.
46     * @author Charles F. Vardeman II
47 gpuliti 1267 * @version $Id: RhoZ.cpp,v 1.7 2008-06-30 17:53:42 gpuliti Exp $
48 chuckv 769 *
49     */
50    
51     /* Calculates Rho(Z) for density profile of liquid slab. */
52    
53     #include <algorithm>
54     #include <fstream>
55     #include "applications/staticProps/RhoZ.hpp"
56     #include "utils/simError.h"
57 tim 840 #include "io/DumpReader.hpp"
58     #include "primitives/Molecule.hpp"
59 chuckv 769 namespace oopse {
60    
61 gpuliti 1267 RhoZ::RhoZ(SimInfo* info, const std::string& filename, const std::string& sele, int nzbins)
62     : StaticAnalyser(info, filename), selectionScript_(sele), evaluator_(info), seleMan_(info), nZBins_(nzbins){
63 tim 840
64     evaluator_.loadScriptString(sele);
65     if (!evaluator_.isDynamic()) {
66     seleMan_.setSelectionSet(evaluator_.evaluate());
67 gpuliti 1267 }
68 chuckv 769
69 gpuliti 1267 // fixed number of bins
70    
71     sliceSDLists_.resize(nZBins_);
72     density_.resize(nZBins_);
73 chuckv 769
74     setOutputName(getPrefix(filename) + ".RhoZ");
75     }
76 tim 840
77     void RhoZ::process() {
78 gpuliti 1267 Molecule* mol;
79     RigidBody* rb;
80     StuntDouble* sd;
81     SimInfo::MoleculeIterator mi;
82     Molecule::RigidBodyIterator rbIter;
83    
84 tim 840 DumpReader reader(info_, dumpFilename_);
85     int nFrames = reader.getNFrames();
86 gezelter 894 nProcessed_ = nFrames/step_;
87 tim 840
88     for (int istep = 0; istep < nFrames; istep += step_) {
89 gpuliti 1267 reader.readFrame(istep);
90     currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
91 tim 840
92 gpuliti 1267 for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
93     //change the positions of atoms which belong to the rigidbodies
94     for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
95     rb->updateAtoms();
96     }
97     }
98    
99 gezelter 894 int i;
100 gpuliti 1267 for (i=0; i < nZBins_; i++) {
101 gezelter 894 sliceSDLists_[i].clear();
102     }
103 tim 840
104 gpuliti 1267 RealType sliceVolume = currentSnapshot_->getVolume() /nZBins_;
105     Mat3x3d hmat = currentSnapshot_->getHmat();
106     zBox_.push_back(hmat(2,2));
107 gezelter 894
108 gpuliti 1267 RealType halfBoxZ_ = hmat(2,2) / 2.0;
109 tim 840
110 gpuliti 1267 if (evaluator_.isDynamic()) {
111     seleMan_.setSelectionSet(evaluator_.evaluate());
112     }
113    
114     //wrap the stuntdoubles into a cell
115     for (sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) {
116     Vector3d pos = sd->getPos();
117     if (usePeriodicBoundaryConditions_)
118     currentSnapshot_->wrapVector(pos);
119     sd->setPos(pos);
120     }
121    
122     //determine which atom belongs to which slice
123     for (sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) {
124     Vector3d pos = sd->getPos();
125     // shift molecules by half a box to have bins start at 0
126     int binNo = int(nZBins_ * (halfBoxZ_ + pos.z()) / hmat(2,2));
127     sliceSDLists_[binNo].push_back(sd);
128     }
129 tim 840
130 gpuliti 1267 //loop over the slices to calculate the densities
131     for (i = 0; i < nZBins_; i++) {
132     RealType totalMass = 0;
133     for (int k = 0; k < sliceSDLists_[i].size(); ++k) {
134     totalMass += sliceSDLists_[i][k]->getMass();
135 tim 840 }
136 gpuliti 1267 density_[i] += totalMass/sliceVolume;
137     }
138 chuckv 769 }
139 gpuliti 1267
140 tim 840 writeDensity();
141    
142 chuckv 769 }
143 gpuliti 1267
144    
145    
146     void RhoZ::writeDensity() {
147 tim 840
148 gpuliti 1267 // compute average box length:
149     std::vector<RealType>::iterator j;
150     RealType zSum = 0.0;
151     for (j = zBox_.begin(); j != zBox_.end(); ++j) {
152     zSum += *j;
153     }
154     RealType zAve = zSum / zBox_.size();
155    
156 chuckv 769 std::ofstream rdfStream(outputFilename_.c_str());
157     if (rdfStream.is_open()) {
158 tim 840 rdfStream << "#RhoZ\n";
159 gezelter 894 rdfStream << "#nFrames:\t" << nProcessed_ << "\n";
160     rdfStream << "#selection: (" << selectionScript_ << ")\n";
161 tim 840 rdfStream << "#z\tdensity\n";
162     for (int i = 0; i < density_.size(); ++i) {
163 gpuliti 1267 RealType z = zAve * (i+0.5)/density_.size();
164     rdfStream << z << "\t" << 1.660535*density_[i]/nProcessed_ << "\n";
165 chuckv 769 }
166    
167     } else {
168    
169     sprintf(painCave.errMsg, "RhoZ: unable to open %s\n", outputFilename_.c_str());
170     painCave.isFatal = 1;
171     simError();
172     }
173    
174     rdfStream.close();
175     }
176    
177     }
178