ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/applications/staticProps/RhoR.cpp
Revision: 1465
Committed: Fri Jul 9 23:08:25 2010 UTC (14 years, 9 months ago) by chuckv
File size: 5223 byte(s)
Log Message:
Creating busticated version of OpenMD

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     * [4] Vardeman & Gezelter, in progress (2009).
40 chuckv 1091 */
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 chuckv 1306 #include <math.h>
51 chuckv 1091
52 gezelter 1390 namespace OpenMD {
53 chuckv 1091
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 chuckv 1092 histogram_[whichBin] += 1;
110 chuckv 1091 }
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    

Properties

Name Value
svn:keywords Author Id Revision Date