ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/applications/staticProps/RhoR.cpp
Revision: 3077
Committed: Fri Nov 17 19:45:38 2006 UTC (17 years, 7 months ago) by chuckv
File size: 5181 byte(s)
Log Message:
Histogram bin change.

File Contents

# Content
1 /*
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 /* Calculates Rho(R) for nanoparticle with radius R*/
43 #include <algorithm>
44 #include <fstream>
45 #include "applications/staticProps/RhoR.hpp"
46 #include "utils/simError.h"
47 #include "utils/NumericConstant.hpp"
48 #include "io/DumpReader.hpp"
49 #include "primitives/Molecule.hpp"
50 #include "math.h"
51
52 namespace oopse {
53
54
55 RhoR::RhoR(SimInfo* info, const std::string& filename, const std::string& sele, RealType len, int nrbins, RealType particleR)
56 : StaticAnalyser(info, filename), selectionScript_(sele), evaluator_(info), seleMan_(info), len_(len), nRBins_(nrbins){
57
58
59 evaluator_.loadScriptString(sele);
60 if (!evaluator_.isDynamic()) {
61 seleMan_.setSelectionSet(evaluator_.evaluate());
62 }
63
64
65 deltaR_ = len_ /nRBins_;
66
67 histogram_.resize(nRBins_);
68 avgRhoR_.resize(nRBins_);
69 particleR_ = particleR;
70 setOutputName(getPrefix(filename) + ".RhoR");
71 }
72
73
74 void RhoR::process() {
75
76
77
78 DumpReader reader(info_, dumpFilename_);
79 int nFrames = reader.getNFrames();
80 nProcessed_ = nFrames/step_;
81
82 std::fill(avgRhoR_.begin(), avgRhoR_.end(), 0.0);
83 std::fill(histogram_.begin(), histogram_.end(), 0);
84
85 for (int istep = 0; istep < nFrames; istep += step_) {
86
87 int i;
88 StuntDouble* sd;
89 reader.readFrame(istep);
90 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
91 Vector3d CenterOfMass = info_->getCom();
92
93
94
95
96 if (evaluator_.isDynamic()) {
97 seleMan_.setSelectionSet(evaluator_.evaluate());
98 }
99
100 //determine which atom belongs to which slice
101 for (sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) {
102 Vector3d pos = sd->getPos();
103 Vector3d r12 = CenterOfMass - pos;
104
105 RealType distance = r12.length();
106
107 if (distance < len_) {
108 int whichBin = distance / deltaR_;
109 histogram_[whichBin] += 1;
110 }
111
112 }
113
114 }
115
116 processHistogram();
117 writeRhoR();
118 }
119
120
121
122 void RhoR::processHistogram() {
123
124 RealType particleDensity = 3.0 * info_->getNGlobalMolecules() / (4.0 * NumericConstant::PI * pow(particleR_,3));
125 RealType pairConstant = ( 4.0 * NumericConstant::PI * particleDensity ) / 3.0;
126
127 for(int i = 0 ; i < histogram_.size(); ++i){
128
129 RealType rLower = i * deltaR_;
130 RealType rUpper = rLower + deltaR_;
131 RealType volSlice = ( rUpper * rUpper * rUpper ) - ( rLower * rLower * rLower );
132 RealType nIdeal = volSlice * pairConstant;
133
134 avgRhoR_[i] += histogram_[i] / nIdeal;
135 }
136
137 }
138
139
140
141 void RhoR::writeRhoR() {
142 std::ofstream rdfStream(outputFilename_.c_str());
143 if (rdfStream.is_open()) {
144 rdfStream << "#radial density function rho(r)\n";
145 rdfStream << "#r\tcorrValue\n";
146 for (int i = 0; i < avgRhoR_.size(); ++i) {
147 RealType r = deltaR_ * (i + 0.5);
148 rdfStream << r << "\t" << avgRhoR_[i]/nProcessed_ << "\n";
149 }
150
151 } else {
152
153 sprintf(painCave.errMsg, "RhoR: unable to open %s\n", outputFilename_.c_str());
154 painCave.isFatal = 1;
155 simError();
156 }
157
158 rdfStream.close();
159 }
160
161 }
162