--- trunk/src/applications/staticProps/GofRZ.cpp 2010/06/08 18:35:22 1444 +++ trunk/src/applications/staticProps/GofRZ.cpp 2010/06/08 20:26:50 1445 @@ -46,121 +46,111 @@ namespace OpenMD { namespace OpenMD { - GofRZ::GofRZ(SimInfo* info, const std::string& filename, const std::string& sele1, - const std::string& sele2, RealType len, int nrbins, int nZBins) - : RadialDistrFunc(info, filename, sele1, sele2), len_(len), nRBins_(nrbins), nZBins_(nZBins){ + GofRZ::GofRZ(SimInfo* info, const std::string& filename, const std::string& sele1, + const std::string& sele2, RealType len, RealType zlen, int nrbins, int nZBins) + : RadialDistrFunc(info, filename, sele1, sele2), len_(len), zLen_(zlen), nRBins_(nrbins), nZBins_(nZBins){ - setOutputName(getPrefix(filename) + ".gofrz"); + setOutputName(getPrefix(filename) + ".gofrz"); - deltaR_ = len_ / (double) nRBins_; - deltaZ_ = 86.52361692 / (double)nZBins_; // for solvated_NVT.md4 + deltaR_ = len_ / (double) nRBins_; + deltaZ_ = zLen_ / (double)nZBins_; // for solvated_NVT.md4 - histogram_.resize(nRBins_); - avgGofr_.resize(nRBins_); - for (int i = 0 ; i < nRBins_; ++i) { - histogram_[i].resize(nRBins_); - avgGofr_[i].resize(nRBins_); - for (int j = 0 ; j < nZBins_; ++j) { - histogram_[i][j].resize(nZBins_); - avgGofr_[i][j].resize(nZBins_); - } + histogram_.resize(nRBins_); + avgGofr_.resize(nRBins_); + for (int i = 0 ; i < nRBins_; ++i) { + histogram_[i].resize(nZBins_); + avgGofr_[i].resize(nZBins_); + } } - - } - void GofRZ::preProcess() { - for (int i = 0; i < avgGofr_[i].size(); ++i) { - avgGofr_[i].resize(nRBins_); - for (int j = 0; j < avgGofr_[i][j].size(); ++j) { - std::fill(avgGofr_[i][j].begin(), avgGofr_[i][j].end(), 0); - } + + void GofRZ::preProcess() { + for (int i = 0; i < avgGofr_.size(); ++i) { + std::fill(avgGofr_[i].begin(), avgGofr_[i].end(), 0); + } } - } - void GofRZ::initalizeHistogram() { - npairs_ = 0; - for (int i = 0; i < histogram_[i].size(); ++i){ - histogram_[i].resize(nRBins_); - for (int j = 0; j < histogram_[i][j].size(); ++j){ - std::fill(histogram_[i][j].begin(), histogram_[i][j].end(), 0); - } + void GofRZ::initalizeHistogram() { + npairs_ = 0; + for (int i = 0; i < histogram_.size(); ++i){ + std::fill(histogram_[i].begin(), histogram_[i].end(), 0); + } } - } - void GofRZ::processHistogram() { - int nPairs = getNPairs(); - RealType volume = info_->getSnapshotManager()->getCurrentSnapshot()->getVolume(); - RealType pairDensity = nPairs / volume * 2.0; + void GofRZ::processHistogram() { + int nPairs = getNPairs(); + RealType volume = info_->getSnapshotManager()->getCurrentSnapshot()->getVolume(); + RealType pairDensity = nPairs / volume * 2.0; - for(int i = 0 ; i < histogram_[i].size(); ++i){ + for(int i = 0 ; i < histogram_.size(); ++i){ - RealType rLower = i * deltaR_; - RealType rUpper = rLower + deltaR_; - RealType volSlice = NumericConstant::PI * deltaZ_ * (( rUpper * rUpper ) - ( rLower * rLower )); - RealType nIdeal = volSlice * pairDensity; + RealType rLower = i * deltaR_; + RealType rUpper = rLower + deltaR_; + RealType volSlice = NumericConstant::PI * deltaZ_ * (( rUpper * rUpper ) - ( rLower * rLower )); + RealType nIdeal = volSlice * pairDensity; - for (int j = 0; j < histogram_[i][j].size(); ++j){ - avgGofr_[i][j] += histogram_[i][j] / nIdeal; - } + for (int j = 0; j < histogram_[i].size(); ++j){ + avgGofr_[i][j] += histogram_[i][j] / nIdeal; + } + } + } - } + void GofRZ::collectHistogram(StuntDouble* sd1, StuntDouble* sd2) { - void GofRZ::collectHistogram(StuntDouble* sd1, StuntDouble* sd2) { + if (sd1 == sd2) { + return; + } + Vector3d pos1 = sd1->getPos(); + Vector3d pos2 = sd2->getPos(); + Vector3d r12 = pos2 - pos1; + if (usePeriodicBoundaryConditions_) + currentSnapshot_->wrapVector(r12); - if (sd1 == sd2) { - return; - } - Vector3d pos1 = sd1->getPos(); - Vector3d pos2 = sd2->getPos(); - Vector3d r12 = pos2 - pos1; - if (usePeriodicBoundaryConditions_) - currentSnapshot_->wrapVector(r12); + RealType distance = sqrt(pow(r12.x(), 2) + pow(r12.y(), 2)); - RealType distance = sqrt(pow(r12.x(), 2) + pow(r12.y(), 2)); + int whichRBin = distance / deltaR_; - int whichRBin = distance / deltaR_; - - if (distance <= len_) { + if (distance <= len_) { - RealType Z = fabs(r12.z()); + RealType Z = fabs(r12.z()); - if (Z <= 86.52361692) { - int whichZBin = Z / deltaZ_; + if (Z <= zLen_) { + int whichZBin = Z / deltaZ_; - ++histogram_[whichRBin][whichZBin]; - ++npairs_; - } + ++histogram_[whichRBin][whichZBin]; + ++npairs_; + } + } } - } - void GofRZ::writeRdf() { - std::ofstream rdfStream(outputFilename_.c_str()); - if (rdfStream.is_open()) { - rdfStream << "#radial distribution function\n"; - rdfStream << "#selection1: (" << selectionScript1_ << ")\t"; - rdfStream << "selection2: (" << selectionScript2_ << ")\n"; - rdfStream << "#nRBins = " << nRBins_ << "\t maxLen = " << len_ << "deltaR = " << deltaR_ <<"\n"; - rdfStream << "#nZBins =" << nZBins_ << "\t deltaZ = " << deltaZ_ << "\n"; - for (int i = 0; i < avgGofr_[i].size(); ++i) { - RealType r = deltaR_ * (i + 0.5); + void GofRZ::writeRdf() { + std::ofstream rdfStream(outputFilename_.c_str()); + if (rdfStream.is_open()) { + rdfStream << "#radial distribution function\n"; + rdfStream << "#selection1: (" << selectionScript1_ << ")\t"; + rdfStream << "selection2: (" << selectionScript2_ << ")\n"; + rdfStream << "#nRBins = " << nRBins_ << "\t maxLen = " << len_ << "deltaR = " << deltaR_ <<"\n"; + rdfStream << "#nZBins =" << nZBins_ << "\t deltaZ = " << deltaZ_ << "\n"; + for (int i = 0; i < avgGofr_.size(); ++i) { + RealType r = deltaR_ * (i + 0.5); - for(int j = 0; j < avgGofr_[i][j].size(); ++j) { - RealType z = deltaZ_ * (j + 0.5); - rdfStream << avgGofr_[i][j]/nProcessed_ << "\t"; - } + for(int j = 0; j < avgGofr_[i].size(); ++j) { + RealType z = deltaZ_ * (j + 0.5); + rdfStream << avgGofr_[i][j]/nProcessed_ << "\t"; + } - rdfStream << "\n"; - } + rdfStream << "\n"; + } - } else { - sprintf(painCave.errMsg, "GofRZ: unable to open %s\n", outputFilename_.c_str()); - painCave.isFatal = 1; - simError(); + } else { + sprintf(painCave.errMsg, "GofRZ: unable to open %s\n", outputFilename_.c_str()); + painCave.isFatal = 1; + simError(); + } + + rdfStream.close(); } - rdfStream.close(); - } - }