ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/applications/staticProps/RhoZ.cpp
(Generate patch)

Comparing trunk/OOPSE-2.0/src/applications/staticProps/RhoZ.cpp (file contents):
Revision 2468 by chuckv, Wed Nov 30 21:00:39 2005 UTC vs.
Revision 2600 by khaygart, Fri Mar 3 21:05:34 2006 UTC

# Line 44 | Line 44
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 $
47 > *  @version $Id: RhoZ.cpp,v 1.4 2006-03-03 21:05:34 khaygart Exp $
48   *
49   */
50  
# Line 54 | Line 54
54   #include <fstream>
55   #include "applications/staticProps/RhoZ.hpp"
56   #include "utils/simError.h"
57 <
57 > #include "io/DumpReader.hpp"
58 > #include "primitives/Molecule.hpp"
59   namespace oopse {
60    
61 <  RhoZ::RhoZ(SimInfo* info, const std::string& filename, const std::string& sele1, const std::string& sele2, double len, int nrbins)
62 <  : RadialDistrFunc(info, filename, sele1, sele2), len_(len), nRBins_(nrbins){
61 >  RhoZ::RhoZ(SimInfo* info, const std::string& filename, const std::string& sele, int len, int nrbins)
62 >    : StaticAnalyser(info, filename), selectionScript_(sele),  evaluator_(info), seleMan_(info), len_(len), nRBins_(nrbins){
63 >
64 >    evaluator_.loadScriptString(sele);
65 >    if (!evaluator_.isDynamic()) {
66 >      seleMan_.setSelectionSet(evaluator_.evaluate());
67 >    }
68 >      
69      
70      deltaR_ = len_ /nRBins_;
71      
72 <    histogram_.resize(nRBins_);
73 <    avgRhoZ_.resize(nRBins_);
72 >    sliceSDLists_.resize(nRBins_);
73 >    density_.resize(nRBins_);
74      
75      setOutputName(getPrefix(filename) + ".RhoZ");
76    }
77 <  
78 <  
79 <  void RhoZ::preProcess() {
80 <    std::fill(avgRhoZ_.begin(), avgRhoZ_.end(), 0.0);    
81 <  }
82 <  
83 <  void RhoZ::initalizeHistogram() {
84 <    std::fill(histogram_.begin(), histogram_.end(), 0);
85 <  }
86 <  
87 <  
88 <  void RhoZ::processHistogram() {
89 <    
90 <    int nPairs = getNPairs();
91 <    double volume = info_->getSnapshotManager()->getCurrentSnapshot()->getVolume();
92 <    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){
77 >
78 >  void RhoZ::process() {
79 >    DumpReader reader(info_, dumpFilename_);    
80 >    int nFrames = reader.getNFrames();
81 >    nProcessed_ = nFrames/step_;
82 >
83 >    for (int istep = 0; istep < nFrames; istep += step_) {
84 >
85 >      int i;    
86 >      for (i=0; i < nRBins_; i++) {
87 >        sliceSDLists_[i].clear();
88 >      }
89 >
90 >      StuntDouble* sd;
91 >      reader.readFrame(istep);
92 >      currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
93        
94 <      double rLower = i * deltaR_;
95 <      double rUpper = rLower + deltaR_;
96 <      double volSlice = ( rUpper * rUpper * rUpper ) - ( rLower * rLower * rLower );
97 <      double nIdeal = volSlice * pairConstant;
98 <      
99 <      avgRhoZ_[i] += histogram_[i] / nIdeal;    
94 >      double sliceVolume = currentSnapshot_->getVolume() /nRBins_;
95 >      //assume simulation box will never change
96 >      //Mat3x3d hmat = currentSnapshot_->getHmat();
97 >      double halfBoxZ_ = len_ /2;      
98 >        
99 >        if (evaluator_.isDynamic()) {
100 >          seleMan_.setSelectionSet(evaluator_.evaluate());
101 >        }
102 >
103 >        //wrap the stuntdoubles into a cell      
104 >        for (sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) {
105 >            Vector3d pos = sd->getPos();
106 >            currentSnapshot_->wrapVector(pos);
107 >            sd->setPos(pos);
108 >        }
109 >
110 >        //determine which atom belongs to which slice
111 >        for (sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) {
112 >           Vector3d pos = sd->getPos();
113 >           int binNo = (pos.z() + halfBoxZ_) /deltaR_;
114 >           sliceSDLists_[binNo].push_back(sd);
115 >        }
116 >
117 >        //loop over the slices to calculate the densities
118 >        for (i = 0; i < nRBins_; i++) {
119 >            double totalMass = 0;
120 >            for (int k = 0; k < sliceSDLists_[i].size(); ++k) {
121 >                totalMass += sliceSDLists_[i][k]->getMass();
122 >            }
123 >            density_[i] += totalMass/sliceVolume;
124 >        }
125      }
126 <    
126 >
127 >    writeDensity();
128 >
129    }
130 <  
131 <  void RhoZ::collectHistogram(StuntDouble* sd1, StuntDouble* sd2) {
130 >
131 >
132      
133 <    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() {
133 >  void RhoZ::writeDensity() {
134      std::ofstream rdfStream(outputFilename_.c_str());
135      if (rdfStream.is_open()) {
136 <      rdfStream << "#radial distribution function\n";
137 <      rdfStream << "#selection1: (" << selectionScript1_ << ")\t";
138 <      rdfStream << "selection2: (" << selectionScript2_ << ")\n";
139 <      rdfStream << "#r\tcorrValue\n";
140 <      for (int i = 0; i < avgRhoZ_.size(); ++i) {
141 <        double r = deltaR_ * (i + 0.5);
142 <        rdfStream << r << "\t" << avgRhoZ_[i]/nProcessed_ << "\n";
136 >      rdfStream << "#RhoZ\n";
137 >      rdfStream << "#nFrames:\t" << nProcessed_ << "\n";
138 >      rdfStream << "#selection: (" << selectionScript_ << ")\n";
139 >      rdfStream << "#z\tdensity\n";
140 >      for (int i = 0; i < density_.size(); ++i) {
141 >        double r = deltaR_ * (i + 0.5)-82;
142 >        rdfStream << r << "\t" << 1.660535*density_[i]/nProcessed_ << "\n";
143        }
144        
145      } else {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines