ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/applications/staticProps/RhoR.cpp
Revision: 1764
Committed: Tue Jul 3 18:32:27 2012 UTC (12 years, 10 months ago) by gezelter
File size: 5316 byte(s)
Log Message:
Refactored Snapshot and Stats to use the Accumulator classes.  Collected
a number of methods into Thermo that belonged there.

File Contents

# User Rev Content
1 chuckv 1091 /*
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 gezelter 1390 * 1. Redistributions of source code must retain the above copyright
10 chuckv 1091 * notice, this list of conditions and the following disclaimer.
11     *
12 gezelter 1390 * 2. Redistributions in binary form must reproduce the above copyright
13 chuckv 1091 * notice, this list of conditions and the following disclaimer in the
14     * documentation and/or other materials provided with the
15     * distribution.
16     *
17     * This software is provided "AS IS," without a warranty of any
18     * kind. All express or implied conditions, representations and
19     * warranties, including any implied warranty of merchantability,
20     * fitness for a particular purpose or non-infringement, are hereby
21     * excluded. The University of Notre Dame and its licensors shall not
22     * be liable for any damages suffered by licensee as a result of
23     * using, modifying or distributing the software or its
24     * derivatives. In no event will the University of Notre Dame or its
25     * licensors be liable for any lost revenue, profit or data, or for
26     * direct, indirect, special, consequential, incidental or punitive
27     * damages, however caused and regardless of the theory of liability,
28     * arising out of the use of or inability to use software, even if the
29     * University of Notre Dame has been advised of the possibility of
30     * such damages.
31 gezelter 1390 *
32     * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your
33     * research, please cite the appropriate papers when you publish your
34     * work. Good starting points are:
35     *
36     * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
37     * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
38     * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).
39 gezelter 1665 * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010).
40     * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41 chuckv 1091 */
42    
43     /* Calculates Rho(R) for nanoparticle with radius R*/
44     #include <algorithm>
45     #include <fstream>
46     #include "applications/staticProps/RhoR.hpp"
47     #include "utils/simError.h"
48     #include "utils/NumericConstant.hpp"
49     #include "io/DumpReader.hpp"
50     #include "primitives/Molecule.hpp"
51 gezelter 1764 #include "brains/Thermo.hpp"
52 chuckv 1306 #include <math.h>
53 chuckv 1091
54 gezelter 1390 namespace OpenMD {
55 chuckv 1091
56    
57     RhoR::RhoR(SimInfo* info, const std::string& filename, const std::string& sele, RealType len, int nrbins, RealType particleR)
58     : StaticAnalyser(info, filename), selectionScript_(sele), evaluator_(info), seleMan_(info), len_(len), nRBins_(nrbins){
59    
60    
61     evaluator_.loadScriptString(sele);
62     if (!evaluator_.isDynamic()) {
63     seleMan_.setSelectionSet(evaluator_.evaluate());
64     }
65    
66    
67     deltaR_ = len_ /nRBins_;
68    
69     histogram_.resize(nRBins_);
70     avgRhoR_.resize(nRBins_);
71     particleR_ = particleR;
72     setOutputName(getPrefix(filename) + ".RhoR");
73     }
74    
75    
76     void RhoR::process() {
77 gezelter 1764
78     Thermo thermo(info_);
79 chuckv 1091 DumpReader reader(info_, dumpFilename_);
80     int nFrames = reader.getNFrames();
81     nProcessed_ = nFrames/step_;
82    
83     std::fill(avgRhoR_.begin(), avgRhoR_.end(), 0.0);
84     std::fill(histogram_.begin(), histogram_.end(), 0);
85    
86     for (int istep = 0; istep < nFrames; istep += step_) {
87    
88     int i;
89     StuntDouble* sd;
90     reader.readFrame(istep);
91     currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
92 gezelter 1764 Vector3d CenterOfMass = thermo.getCom();
93 chuckv 1091
94     if (evaluator_.isDynamic()) {
95     seleMan_.setSelectionSet(evaluator_.evaluate());
96     }
97    
98     //determine which atom belongs to which slice
99     for (sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) {
100     Vector3d pos = sd->getPos();
101     Vector3d r12 = CenterOfMass - pos;
102    
103     RealType distance = r12.length();
104    
105     if (distance < len_) {
106     int whichBin = distance / deltaR_;
107 chuckv 1092 histogram_[whichBin] += 1;
108 chuckv 1091 }
109    
110     }
111    
112     }
113    
114     processHistogram();
115     writeRhoR();
116     }
117    
118    
119    
120     void RhoR::processHistogram() {
121    
122     RealType particleDensity = 3.0 * info_->getNGlobalMolecules() / (4.0 * NumericConstant::PI * pow(particleR_,3));
123     RealType pairConstant = ( 4.0 * NumericConstant::PI * particleDensity ) / 3.0;
124    
125     for(int i = 0 ; i < histogram_.size(); ++i){
126    
127     RealType rLower = i * deltaR_;
128     RealType rUpper = rLower + deltaR_;
129     RealType volSlice = ( rUpper * rUpper * rUpper ) - ( rLower * rLower * rLower );
130     RealType nIdeal = volSlice * pairConstant;
131    
132     avgRhoR_[i] += histogram_[i] / nIdeal;
133     }
134    
135     }
136    
137    
138    
139     void RhoR::writeRhoR() {
140     std::ofstream rdfStream(outputFilename_.c_str());
141     if (rdfStream.is_open()) {
142     rdfStream << "#radial density function rho(r)\n";
143     rdfStream << "#r\tcorrValue\n";
144     for (int i = 0; i < avgRhoR_.size(); ++i) {
145     RealType r = deltaR_ * (i + 0.5);
146     rdfStream << r << "\t" << avgRhoR_[i]/nProcessed_ << "\n";
147     }
148    
149     } else {
150    
151     sprintf(painCave.errMsg, "RhoR: unable to open %s\n", outputFilename_.c_str());
152     painCave.isFatal = 1;
153     simError();
154     }
155    
156     rdfStream.close();
157     }
158    
159     }
160    

Properties

Name Value
svn:keywords Author Id Revision Date