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

Comparing trunk/OOPSE-4/src/applications/staticProps/GofRAngle.cpp (file contents):
Revision 2012 by tim, Sun Feb 13 20:36:24 2005 UTC vs.
Revision 3054 by gezelter, Wed Oct 18 21:58:48 2006 UTC

# Line 46 | Line 46 | GofRAngle::GofRAngle(SimInfo* info, const std::string&
46  
47   namespace oopse {
48  
49 < GofRAngle::GofRAngle(SimInfo* info, const std::string& filename, const std::string& sele1, const std::string& sele2)
50 <    : RadialDistrFunc(info, filename, sele1, sele2){
49 >  GofRAngle::GofRAngle(SimInfo* info, const std::string& filename, const std::string& sele1,
50 >                       const std::string& sele2, RealType len, int nrbins, int nangleBins)
51 >    : RadialDistrFunc(info, filename, sele1, sele2), len_(len), nRBins_(nrbins), nAngleBins_(nangleBins){
52  
53 < }
53 >      deltaR_ = len_ /nRBins_;            
54 >      deltaCosAngle_ = 2.0 / nAngleBins_;    
55  
56 +      histogram_.resize(nRBins_);
57 +      avgGofr_.resize(nRBins_);
58 +      for (int i = 0 ; i < nRBins_; ++i) {
59 +        histogram_[i].resize(nAngleBins_);
60 +        avgGofr_[i].resize(nAngleBins_);
61 +      }
62 +    }
63  
55 void GofRAngle::preProcess() {
64  
65 +  void GofRAngle::preProcess() {
66 +
67      for (int i = 0; i < avgGofr_.size(); ++i) {
68 <        std::fill(avgGofr_[i].begin(), avgGofr_[i].end(), 0);
68 >      std::fill(avgGofr_[i].begin(), avgGofr_[i].end(), 0);
69      }
70 < }
70 >  }
71  
72 < void GofRAngle::initalizeHistogram() {
72 >  void GofRAngle::initalizeHistogram() {
73      npairs_ = 0;
74      for (int i = 0; i < histogram_.size(); ++i)
75 <        std::fill(histogram_[i].begin(), histogram_[i].end(), 0);
76 < }
75 >      std::fill(histogram_[i].begin(), histogram_[i].end(), 0);
76 >  }
77  
78  
79 < void GofRAngle::processHistogram() {
79 >  void GofRAngle::processHistogram() {
80  
81 <    double volume = info_->getSnapshotManager()->getCurrentSnapshot()->getVolume();
82 <    double pairDensity = npairs_ /volume;
83 <    double pairConstant = ( 4.0 * NumericConstant::PI * pairDensity ) / 3.0;
81 >    int nPairs = getNPairs();
82 >    RealType volume = info_->getSnapshotManager()->getCurrentSnapshot()->getVolume();
83 >    RealType pairDensity = nPairs /volume;
84 >    RealType pairConstant = ( 4.0 * NumericConstant::PI * pairDensity ) / 3.0;
85  
86      for(int i = 0 ; i < histogram_.size(); ++i){
87  
88 <        double rLower = i * deltaR_;
89 <        double rUpper = rLower + deltaR_;
90 <        double volSlice = ( rUpper * rUpper * rUpper ) - ( rLower * rLower * rLower );
91 <        double nIdeal = volSlice * pairConstant;
88 >      RealType rLower = i * deltaR_;
89 >      RealType rUpper = rLower + deltaR_;
90 >      RealType volSlice = ( rUpper * rUpper * rUpper ) - ( rLower * rLower * rLower );
91 >      RealType nIdeal = volSlice * pairConstant;
92  
93 <        for (int j = 0; j < histogram_[i].size(); ++j){
94 <            avgGofr_[i][j] += histogram_[i][j] / nIdeal;    
95 <        }
93 >      for (int j = 0; j < histogram_[i].size(); ++j){
94 >        avgGofr_[i][j] += histogram_[i][j] / nIdeal;    
95 >      }
96      }
97  
98 < }
98 >  }
99  
100 < void GofRAngle::collectHistogram(StuntDouble* sd1, StuntDouble* sd2) {
100 >  void GofRAngle::collectHistogram(StuntDouble* sd1, StuntDouble* sd2) {
101  
102      if (sd1 == sd2) {
103 <        return;
103 >      return;
104      }
105      
106      Vector3d pos1 = sd1->getPos();
107      Vector3d pos2 = sd2->getPos();
108 <    Vector3d r12 = pos1 - pos2;
109 <    currentSnapshot_->wrapVector(r12);
108 >    Vector3d r12 = pos2 - pos1;
109 >    if (usePeriodicBoundaryConditions_)
110 >      currentSnapshot_->wrapVector(r12);
111  
112 <    double distance = r12.length();
112 >    RealType distance = r12.length();
113      int whichRBin = distance / deltaR_;
114  
115      if (distance <= len_) {
116 <        double cosAngle = evaluateAngle(sd1, sd2);
117 <        double halfBin = (nAngleBins_ - 1) * 0.5;
118 <        int whichThetaBin = halfBin * (cosAngle + 1.0);
119 <        ++histogram_[whichRBin][whichThetaBin];
116 >      RealType cosAngle = evaluateAngle(sd1, sd2);
117 >      RealType halfBin = (nAngleBins_ - 1) * 0.5;
118 >      int whichThetaBin = halfBin * (cosAngle + 1.0);
119 >      ++histogram_[whichRBin][whichThetaBin];
120          
121 <        ++npairs_;
121 >      ++npairs_;
122      }
123 < }
123 >  }
124  
125 < void GofRAngle::writeRdf() {
125 >  void GofRAngle::writeRdf() {
126      std::ofstream rdfStream(outputFilename_.c_str());
127      if (rdfStream.is_open()) {
128 <        rdfStream << "#radial distribution function\n";
129 <        rdfStream << "#selection1: (" << selectionScript1_ << ")\t";
130 <        rdfStream << "selection2: (" << selectionScript2_ << ")\n";
131 <        rdfStream << "#r\tcorrValue\n";
132 <        for (int i = 0; i < avgGofr_.size(); ++i) {
133 <            double r = deltaR_ * (i + 0.5);
128 >      rdfStream << "#radial distribution function\n";
129 >      rdfStream << "#selection1: (" << selectionScript1_ << ")\t";
130 >      rdfStream << "selection2: (" << selectionScript2_ << ")\n";
131 >      rdfStream << "#nRBins = " << nRBins_ << "\t maxLen = " << len_ << "deltaR = " << deltaR_ <<"\n";
132 >      rdfStream << "#nAngleBins =" << nAngleBins_ << "deltaCosAngle = " << deltaCosAngle_ << "\n";
133 >      for (int i = 0; i < avgGofr_.size(); ++i) {
134 >        RealType r = deltaR_ * (i + 0.5);
135  
136 <            for(int j = 0; j < avgGofr_[i].size(); ++j) {
137 <                double cosAngle = -1.0 + (i + 0.5)*deltaCosAngle_;
138 <                rdfStream << r << "\t" << cosAngle << "\t" << avgGofr_[i][j]/nProcessed_ << "\n";
139 <            }
140 <        }
136 >        for(int j = 0; j < avgGofr_[i].size(); ++j) {
137 >          RealType cosAngle = -1.0 + (j + 0.5)*deltaCosAngle_;
138 >          rdfStream << avgGofr_[i][j]/nProcessed_ << "\t";
139 >        }
140 >
141 >        rdfStream << "\n";
142 >      }
143          
144      } else {
145 <
146 <
145 >      sprintf(painCave.errMsg, "GofRAngle: unable to open %s\n", outputFilename_.c_str());
146 >      painCave.isFatal = 1;
147 >      simError();  
148      }
149  
150      rdfStream.close();
151 < }
151 >  }
152  
153 < double GofRTheta::evaluateAngle(StuntDouble* sd1, StuntDouble* sd2) {
153 >  RealType GofRTheta::evaluateAngle(StuntDouble* sd1, StuntDouble* sd2) {
154      Vector3d pos1 = sd1->getPos();
155      Vector3d pos2 = sd2->getPos();
156 <    Vector3d r12 = pos1 - pos2;
157 <    currentSnapshot_->wrapVector(r12);
156 >    Vector3d r12 = pos2 - pos1;
157 >    
158 >    if (usePeriodicBoundaryConditions_)
159 >      currentSnapshot_->wrapVector(r12);
160 >
161      r12.normalize();
162      Vector3d dipole = sd1->getElectroFrame().getColumn(2);
163      dipole.normalize();    
164      return dot(r12, dipole);
165 < }
165 >  }
166  
167 < double GofROmega::evaluateAngle(StuntDouble* sd1, StuntDouble* sd2) {
167 >  RealType GofROmega::evaluateAngle(StuntDouble* sd1, StuntDouble* sd2) {
168      Vector3d v1 = sd1->getElectroFrame().getColumn(2);
169 <    Vector3d v2 = sd1->getElectroFrame().getColumn(2);    
169 >    Vector3d v2 = sd2->getElectroFrame().getColumn(2);    
170      v1.normalize();
171      v2.normalize();
172      return dot(v1, v2);
173 < }
173 >  }
174  
175  
176   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines