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

Comparing trunk/src/applications/staticProps/RhoZ.cpp (file contents):
Revision 963 by tim, Wed May 17 21:51:42 2006 UTC vs.
Revision 1267 by gpuliti, Mon Jun 30 17:53:42 2008 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.5 2006-05-17 21:51:42 tim Exp $
47 > *  @version $Id: RhoZ.cpp,v 1.7 2008-06-30 17:53:42 gpuliti Exp $
48   *
49   */
50  
# Line 58 | Line 58 | namespace oopse {
58   #include "primitives/Molecule.hpp"
59   namespace oopse {
60    
61 <  RhoZ::RhoZ(SimInfo* info, const std::string& filename, const std::string& sele, RealType len, int nrbins)
62 <    : StaticAnalyser(info, filename), selectionScript_(sele),  evaluator_(info), seleMan_(info), len_(len), nRBins_(nrbins){
61 >  RhoZ::RhoZ(SimInfo* info, const std::string& filename, const std::string& sele, int nzbins)
62 >    : StaticAnalyser(info, filename), selectionScript_(sele),  evaluator_(info), seleMan_(info), nZBins_(nzbins){
63  
64      evaluator_.loadScriptString(sele);
65      if (!evaluator_.isDynamic()) {
66        seleMan_.setSelectionSet(evaluator_.evaluate());
67 <    }
68 <      
67 >    }      
68      
69 <    deltaR_ = len_ /(nRBins_);
69 >    // fixed number of bins
70 >
71 >    sliceSDLists_.resize(nZBins_);
72 >    density_.resize(nZBins_);
73      
72    sliceSDLists_.resize(nRBins_);
73    density_.resize(nRBins_);
74    
74      setOutputName(getPrefix(filename) + ".RhoZ");
75    }
76  
77    void RhoZ::process() {
78 +    Molecule* mol;
79 +    RigidBody* rb;
80 +    StuntDouble* sd;
81 +    SimInfo::MoleculeIterator mi;
82 +    Molecule::RigidBodyIterator rbIter;
83 +
84      DumpReader reader(info_, dumpFilename_);    
85      int nFrames = reader.getNFrames();
86      nProcessed_ = nFrames/step_;
87  
88      for (int istep = 0; istep < nFrames; istep += step_) {
89 +      reader.readFrame(istep);
90 +      currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
91  
92 +      for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
93 +        //change the positions of atoms which belong to the rigidbodies
94 +        for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
95 +          rb->updateAtoms();
96 +        }
97 +      }
98 +
99        int i;    
100 <      for (i=0; i < nRBins_; i++) {
100 >      for (i=0; i < nZBins_; i++) {
101          sliceSDLists_[i].clear();
102        }
103  
104 <      StuntDouble* sd;
105 <      reader.readFrame(istep);
106 <      currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
104 >      RealType sliceVolume = currentSnapshot_->getVolume() /nZBins_;
105 >      Mat3x3d hmat = currentSnapshot_->getHmat();
106 >      zBox_.push_back(hmat(2,2));
107        
108 <      RealType sliceVolume = currentSnapshot_->getVolume() /nRBins_;
95 <      //assume simulation box will never change
96 <      //Mat3x3d hmat = currentSnapshot_->getHmat();
97 <      RealType halfBoxZ_ = len_ / 2.0;      
98 <        
99 <        if (evaluator_.isDynamic()) {
100 <          seleMan_.setSelectionSet(evaluator_.evaluate());
101 <        }
108 >      RealType halfBoxZ_ = hmat(2,2) / 2.0;      
109  
110 <        //wrap the stuntdoubles into a cell      
111 <        for (sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) {
112 <            Vector3d pos = sd->getPos();
113 <            currentSnapshot_->wrapVector(pos);
114 <            sd->setPos(pos);
115 <        }
110 >      if (evaluator_.isDynamic()) {
111 >        seleMan_.setSelectionSet(evaluator_.evaluate());
112 >      }
113 >      
114 >      //wrap the stuntdoubles into a cell      
115 >      for (sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) {
116 >        Vector3d pos = sd->getPos();
117 >        if (usePeriodicBoundaryConditions_)
118 >          currentSnapshot_->wrapVector(pos);
119 >        sd->setPos(pos);
120 >      }
121 >      
122 >      //determine which atom belongs to which slice
123 >      for (sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) {
124 >        Vector3d pos = sd->getPos();
125 >        // shift molecules by half a box to have bins start at 0
126 >        int binNo = int(nZBins_ * (halfBoxZ_ + pos.z()) / hmat(2,2));
127 >        sliceSDLists_[binNo].push_back(sd);
128 >      }
129  
130 <        //determine which atom belongs to which slice
131 <        for (sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) {
132 <           Vector3d pos = sd->getPos();
133 <           //int binNo = (pos.z() /deltaR_) - 1;
134 <           int binNo = (pos.z() + halfBoxZ_) /deltaR_   ;
115 <           //std::cout << "pos.z = " << pos.z() << " halfBoxZ_ = " << halfBoxZ_ << " deltaR_ = "  << deltaR_ << " binNo = " << binNo << "\n";
116 <           sliceSDLists_[binNo].push_back(sd);
130 >      //loop over the slices to calculate the densities
131 >      for (i = 0; i < nZBins_; i++) {
132 >        RealType totalMass = 0;
133 >        for (int k = 0; k < sliceSDLists_[i].size(); ++k) {
134 >          totalMass += sliceSDLists_[i][k]->getMass();
135          }
136 <
137 <        //loop over the slices to calculate the densities
120 <        for (i = 0; i < nRBins_; i++) {
121 <            RealType totalMass = 0;
122 <            for (int k = 0; k < sliceSDLists_[i].size(); ++k) {
123 <                totalMass += sliceSDLists_[i][k]->getMass();
124 <            }
125 <            density_[i] += totalMass/sliceVolume;
126 <        }
136 >        density_[i] += totalMass/sliceVolume;
137 >      }
138      }
139 <
139 >    
140      writeDensity();
141  
142    }
143 <
144 <
145 <    
143 >  
144 >  
145 >  
146    void RhoZ::writeDensity() {
147 +
148 +    // compute average box length:
149 +    std::vector<RealType>::iterator j;
150 +    RealType zSum = 0.0;
151 +    for (j = zBox_.begin(); j != zBox_.end(); ++j) {
152 +      zSum += *j;      
153 +    }
154 +    RealType zAve = zSum / zBox_.size();
155 +
156      std::ofstream rdfStream(outputFilename_.c_str());
157      if (rdfStream.is_open()) {
158        rdfStream << "#RhoZ\n";
# Line 140 | Line 160 | namespace oopse {
160        rdfStream << "#selection: (" << selectionScript_ << ")\n";
161        rdfStream << "#z\tdensity\n";
162        for (int i = 0; i < density_.size(); ++i) {
163 <        RealType r = deltaR_ * (i + 0.5);
164 <        rdfStream << r << "\t" << 1.660535*density_[i]/nProcessed_ << "\n";
163 >        RealType z = zAve * (i+0.5)/density_.size();
164 >        rdfStream << z << "\t" << 1.660535*density_[i]/nProcessed_ << "\n";
165        }
166        
167      } else {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines