ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/applications/staticProps/RhoZ.cpp
Revision: 3054
Committed: Wed Oct 18 21:58:48 2006 UTC (17 years, 10 months ago) by gezelter
File size: 5708 byte(s)
Log Message:
fixing a wrapVector problem in staticProps, also making Shifted force
and electrostatic damping the default behavior

File Contents

# User Rev Content
1 chuckv 2468 /*
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 gezelter 3054 * @version $Id: RhoZ.cpp,v 1.6 2006-10-18 21:58:47 gezelter Exp $
48 chuckv 2468 *
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 2539 #include "io/DumpReader.hpp"
58     #include "primitives/Molecule.hpp"
59 chuckv 2468 namespace oopse {
60    
61 tim 2759 RhoZ::RhoZ(SimInfo* info, const std::string& filename, const std::string& sele, RealType len, int nrbins)
62 gezelter 2603 : StaticAnalyser(info, filename), selectionScript_(sele), evaluator_(info), seleMan_(info), len_(len), nRBins_(nrbins){
63 tim 2539
64     evaluator_.loadScriptString(sele);
65     if (!evaluator_.isDynamic()) {
66     seleMan_.setSelectionSet(evaluator_.evaluate());
67     }
68    
69 chuckv 2468
70 gezelter 2603 deltaR_ = len_ /(nRBins_);
71 chuckv 2468
72 tim 2539 sliceSDLists_.resize(nRBins_);
73     density_.resize(nRBins_);
74 chuckv 2468
75     setOutputName(getPrefix(filename) + ".RhoZ");
76     }
77 tim 2539
78     void RhoZ::process() {
79     DumpReader reader(info_, dumpFilename_);
80     int nFrames = reader.getNFrames();
81 gezelter 2603 nProcessed_ = nFrames/step_;
82 tim 2539
83     for (int istep = 0; istep < nFrames; istep += step_) {
84    
85 gezelter 2603 int i;
86     for (i=0; i < nRBins_; i++) {
87     sliceSDLists_[i].clear();
88     }
89 tim 2539
90 gezelter 2603 StuntDouble* sd;
91     reader.readFrame(istep);
92     currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
93    
94 tim 2759 RealType sliceVolume = currentSnapshot_->getVolume() /nRBins_;
95 gezelter 2603 //assume simulation box will never change
96     //Mat3x3d hmat = currentSnapshot_->getHmat();
97 tim 2759 RealType halfBoxZ_ = len_ / 2.0;
98 tim 2539
99     if (evaluator_.isDynamic()) {
100     seleMan_.setSelectionSet(evaluator_.evaluate());
101     }
102    
103     //wrap the stuntdoubles into a cell
104     for (sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) {
105     Vector3d pos = sd->getPos();
106 gezelter 3054 if (usePeriodicBoundaryConditions_)
107     currentSnapshot_->wrapVector(pos);
108 tim 2539 sd->setPos(pos);
109     }
110    
111 tim 2544 //determine which atom belongs to which slice
112 tim 2539 for (sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) {
113     Vector3d pos = sd->getPos();
114 gezelter 2603 //int binNo = (pos.z() /deltaR_) - 1;
115     int binNo = (pos.z() + halfBoxZ_) /deltaR_ ;
116     //std::cout << "pos.z = " << pos.z() << " halfBoxZ_ = " << halfBoxZ_ << " deltaR_ = " << deltaR_ << " binNo = " << binNo << "\n";
117 tim 2539 sliceSDLists_[binNo].push_back(sd);
118     }
119    
120     //loop over the slices to calculate the densities
121 gezelter 2603 for (i = 0; i < nRBins_; i++) {
122 tim 2759 RealType totalMass = 0;
123 gezelter 2603 for (int k = 0; k < sliceSDLists_[i].size(); ++k) {
124     totalMass += sliceSDLists_[i][k]->getMass();
125 tim 2539 }
126 gezelter 2603 density_[i] += totalMass/sliceVolume;
127 tim 2539 }
128 chuckv 2468 }
129 tim 2539
130     writeDensity();
131    
132 chuckv 2468 }
133 tim 2539
134    
135 chuckv 2468
136 tim 2539 void RhoZ::writeDensity() {
137 chuckv 2468 std::ofstream rdfStream(outputFilename_.c_str());
138     if (rdfStream.is_open()) {
139 tim 2539 rdfStream << "#RhoZ\n";
140 gezelter 2603 rdfStream << "#nFrames:\t" << nProcessed_ << "\n";
141     rdfStream << "#selection: (" << selectionScript_ << ")\n";
142 tim 2539 rdfStream << "#z\tdensity\n";
143     for (int i = 0; i < density_.size(); ++i) {
144 tim 2759 RealType r = deltaR_ * (i + 0.5);
145 gezelter 2603 rdfStream << r << "\t" << 1.660535*density_[i]/nProcessed_ << "\n";
146 chuckv 2468 }
147    
148     } else {
149    
150     sprintf(painCave.errMsg, "RhoZ: unable to open %s\n", outputFilename_.c_str());
151     painCave.isFatal = 1;
152     simError();
153     }
154    
155     rdfStream.close();
156     }
157    
158     }
159