48#include "applications/staticProps/TwoDGofR.hpp"
53#include "utils/simError.h"
57 TwoDGofR::TwoDGofR(
SimInfo* info,
const std::string& filename,
58 const std::string& sele1,
const std::string& sele2,
59 RealType len, RealType dz,
int nrbins) :
62 deltaR_ = len_ / nBins_;
66 histogram_.resize(nBins_);
67 avgTwoDGofR_.resize(nBins_);
69 setOutputName(
getPrefix(filename) +
".TwoDGofR");
72 void TwoDGofR::preProcess() {
73 std::fill(avgTwoDGofR_.begin(), avgTwoDGofR_.end(), 0.0);
76 void TwoDGofR::initializeHistogram() {
77 std::fill(histogram_.begin(), histogram_.end(), 0);
80 void TwoDGofR::processHistogram() {
81 int nPairs = getNPairs();
83 Mat3x3d hmat = info_->getSnapshotManager()->getCurrentSnapshot()->getHmat();
85 RealType volume = hmat(0, 0) * hmat(1, 1) * deltaZ_;
87 RealType pairDensity = nPairs / volume * 2.0;
88 RealType pairConstant = (Constants::PI * pairDensity);
90 for (
unsigned int i = 0; i < histogram_.size(); ++i) {
91 RealType rLower = i * deltaR_;
92 RealType rUpper = rLower + deltaR_;
93 RealType volSlice = deltaZ_ * ((rUpper * rUpper) - (rLower * rLower));
94 RealType nIdeal = volSlice * pairConstant;
96 avgTwoDGofR_[i] += histogram_[i] / nIdeal;
100 void TwoDGofR::collectHistogram(StuntDouble* sd1, StuntDouble* sd2) {
101 if (sd1 == sd2) {
return; }
102 bool usePeriodicBoundaryConditions_ =
103 info_->getSimParams()->getUsePeriodicBoundaryConditions();
105 Vector3d pos1 = sd1->getPos();
106 Vector3d pos2 = sd2->getPos();
107 Vector3d r12 = pos2 - pos1;
108 if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(r12);
110 RealType
distance = sqrt(r12.x() * r12.x() + r12.y() * r12.y());
112 if (distance < len_) {
113 int whichBin = int(distance / deltaR_);
114 histogram_[whichBin] += 2;
118 void TwoDGofR::writeRdf() {
119 std::ofstream rdfStream(outputFilename_.c_str());
120 if (rdfStream.is_open()) {
121 rdfStream <<
"#2D radial distribution function\n";
122 rdfStream <<
"#selection1: (" << selectionScript1_ <<
")\t";
123 rdfStream <<
"selection2: (" << selectionScript2_ <<
")\n";
124 rdfStream <<
"#r\tcorrValue\n";
125 for (
unsigned int i = 0; i < avgTwoDGofR_.size(); ++i) {
126 RealType r = deltaR_ * (i + 0.5);
127 rdfStream << r <<
"\t" << avgTwoDGofR_[i] / nProcessed_ <<
"\n";
131 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
132 "TwoDGofR: unable to open %s\n", outputFilename_.c_str());
133 painCave.isFatal = 1;
Radial Distribution Function.
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
std::string getPrefix(const std::string &str)
Real distance(const DynamicVector< Real > &v1, const DynamicVector< Real > &v2)
Returns the distance between two DynamicVectors.