ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/applications/staticProps/RhoR.cpp
Revision: 1665
Committed: Tue Nov 22 20:38:56 2011 UTC (13 years, 5 months ago) by gezelter
File size: 5289 byte(s)
Log Message:
updated copyright notices

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 chuckv 1306 #include <math.h>
52 chuckv 1091
53 gezelter 1390 namespace OpenMD {
54 chuckv 1091
55    
56     RhoR::RhoR(SimInfo* info, const std::string& filename, const std::string& sele, RealType len, int nrbins, RealType particleR)
57     : StaticAnalyser(info, filename), selectionScript_(sele), evaluator_(info), seleMan_(info), len_(len), nRBins_(nrbins){
58    
59    
60     evaluator_.loadScriptString(sele);
61     if (!evaluator_.isDynamic()) {
62     seleMan_.setSelectionSet(evaluator_.evaluate());
63     }
64    
65    
66     deltaR_ = len_ /nRBins_;
67    
68     histogram_.resize(nRBins_);
69     avgRhoR_.resize(nRBins_);
70     particleR_ = particleR;
71     setOutputName(getPrefix(filename) + ".RhoR");
72     }
73    
74    
75     void RhoR::process() {
76    
77    
78    
79     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     Vector3d CenterOfMass = info_->getCom();
93    
94    
95    
96    
97     if (evaluator_.isDynamic()) {
98     seleMan_.setSelectionSet(evaluator_.evaluate());
99     }
100    
101     //determine which atom belongs to which slice
102     for (sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) {
103     Vector3d pos = sd->getPos();
104     Vector3d r12 = CenterOfMass - pos;
105    
106     RealType distance = r12.length();
107    
108     if (distance < len_) {
109     int whichBin = distance / deltaR_;
110 chuckv 1092 histogram_[whichBin] += 1;
111 chuckv 1091 }
112    
113     }
114    
115     }
116    
117     processHistogram();
118     writeRhoR();
119     }
120    
121    
122    
123     void RhoR::processHistogram() {
124    
125     RealType particleDensity = 3.0 * info_->getNGlobalMolecules() / (4.0 * NumericConstant::PI * pow(particleR_,3));
126     RealType pairConstant = ( 4.0 * NumericConstant::PI * particleDensity ) / 3.0;
127    
128     for(int i = 0 ; i < histogram_.size(); ++i){
129    
130     RealType rLower = i * deltaR_;
131     RealType rUpper = rLower + deltaR_;
132     RealType volSlice = ( rUpper * rUpper * rUpper ) - ( rLower * rLower * rLower );
133     RealType nIdeal = volSlice * pairConstant;
134    
135     avgRhoR_[i] += histogram_[i] / nIdeal;
136     }
137    
138     }
139    
140    
141    
142     void RhoR::writeRhoR() {
143     std::ofstream rdfStream(outputFilename_.c_str());
144     if (rdfStream.is_open()) {
145     rdfStream << "#radial density function rho(r)\n";
146     rdfStream << "#r\tcorrValue\n";
147     for (int i = 0; i < avgRhoR_.size(); ++i) {
148     RealType r = deltaR_ * (i + 0.5);
149     rdfStream << r << "\t" << avgRhoR_[i]/nProcessed_ << "\n";
150     }
151    
152     } else {
153    
154     sprintf(painCave.errMsg, "RhoR: unable to open %s\n", outputFilename_.c_str());
155     painCave.isFatal = 1;
156     simError();
157     }
158    
159     rdfStream.close();
160     }
161    
162     }
163    

Properties

Name Value
svn:keywords Author Id Revision Date