ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-3.0/src/applications/staticProps/RhoZ.cpp
Revision: 2468
Committed: Wed Nov 30 21:00:39 2005 UTC (18 years, 8 months ago) by chuckv
File size: 4788 byte(s)
Log Message:
Code to calculate rho(Z) to calculate density profiles for water slabs.

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     * @version $Id: RhoZ.cpp,v 1.1 2005-11-30 21:00:39 chuckv Exp $
48     *
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    
58     namespace oopse {
59    
60     RhoZ::RhoZ(SimInfo* info, const std::string& filename, const std::string& sele1, const std::string& sele2, double len, int nrbins)
61     : RadialDistrFunc(info, filename, sele1, sele2), len_(len), nRBins_(nrbins){
62    
63     deltaR_ = len_ /nRBins_;
64    
65     histogram_.resize(nRBins_);
66     avgRhoZ_.resize(nRBins_);
67    
68     setOutputName(getPrefix(filename) + ".RhoZ");
69     }
70    
71    
72     void RhoZ::preProcess() {
73     std::fill(avgRhoZ_.begin(), avgRhoZ_.end(), 0.0);
74     }
75    
76     void RhoZ::initalizeHistogram() {
77     std::fill(histogram_.begin(), histogram_.end(), 0);
78     }
79    
80    
81     void RhoZ::processHistogram() {
82    
83     int nPairs = getNPairs();
84     double volume = info_->getSnapshotManager()->getCurrentSnapshot()->getVolume();
85     double pairDensity = nPairs /volume * 2.0;
86     double pairConstant = ( 4.0 * NumericConstant::PI * pairDensity ) / 3.0;
87    
88     for(int i = 0 ; i < histogram_.size(); ++i){
89    
90     double rLower = i * deltaR_;
91     double rUpper = rLower + deltaR_;
92     double volSlice = ( rUpper * rUpper * rUpper ) - ( rLower * rLower * rLower );
93     double nIdeal = volSlice * pairConstant;
94    
95     avgRhoZ_[i] += histogram_[i] / nIdeal;
96     }
97    
98     }
99    
100     void RhoZ::collectHistogram(StuntDouble* sd1, StuntDouble* sd2) {
101    
102     if (sd1 == sd2) {
103     return;
104     }
105    
106     Vector3d pos1 = sd1->getPosZ();
107     Vector3d pos2 = sd2->getPosZ();
108     Vector3d r12 = pos2 - pos1;
109     currentSnapshot_->wrapVector(r12);
110    
111     double distance = r12.length();
112    
113     if (distance < len_) {
114     int whichBin = distance / deltaR_;
115     histogram_[whichBin] += 2;
116     }
117     }
118    
119    
120     void RhoZ::writeRdf() {
121     std::ofstream rdfStream(outputFilename_.c_str());
122     if (rdfStream.is_open()) {
123     rdfStream << "#radial distribution function\n";
124     rdfStream << "#selection1: (" << selectionScript1_ << ")\t";
125     rdfStream << "selection2: (" << selectionScript2_ << ")\n";
126     rdfStream << "#r\tcorrValue\n";
127     for (int i = 0; i < avgRhoZ_.size(); ++i) {
128     double r = deltaR_ * (i + 0.5);
129     rdfStream << r << "\t" << avgRhoZ_[i]/nProcessed_ << "\n";
130     }
131    
132     } else {
133    
134     sprintf(painCave.errMsg, "RhoZ: unable to open %s\n", outputFilename_.c_str());
135     painCave.isFatal = 1;
136     simError();
137     }
138    
139     rdfStream.close();
140     }
141    
142     }
143