48#include "applications/staticProps/GofZ.hpp"
53#include "utils/simError.h"
57 GofZ::GofZ(
SimInfo* info,
const std::string& filename,
58 const std::string& sele1,
const std::string& sele2, RealType len,
59 RealType maxz,
int nrbins,
int axis) :
62 deltaZ_ = maxz / nBins_;
65 histogram_.resize(nBins_);
66 avgGofz_.resize(nBins_);
68 setOutputName(
getPrefix(filename) +
".gofz");
85 void GofZ::preProcess() { std::fill(avgGofz_.begin(), avgGofz_.end(), 0.0); }
87 void GofZ::initializeHistogram() {
88 std::fill(histogram_.begin(), histogram_.end(), 0);
91 void GofZ::processHistogram() {
92 int nPairs = getNPairs();
94 info_->getSnapshotManager()->getCurrentSnapshot()->getVolume();
95 RealType pairDensity = nPairs / volume * 2.0;
96 RealType pairConstant = (2.0 * Constants::PI * pairDensity);
98 for (
unsigned int i = 0; i < histogram_.size(); ++i) {
99 RealType zLower = i * deltaZ_;
100 RealType zUpper = zLower + deltaZ_;
101 RealType cylSlice = (zUpper - zLower) * rC_ * rC_;
102 RealType nIdeal = cylSlice * pairConstant;
104 avgGofz_[i] += histogram_[i] / nIdeal;
108 void GofZ::collectHistogram(StuntDouble* sd1, StuntDouble* sd2) {
109 if (sd1 == sd2) {
return; }
110 bool usePeriodicBoundaryConditions_ =
111 info_->getSimParams()->getUsePeriodicBoundaryConditions();
113 Vector3d pos1 = sd1->getPos();
114 Vector3d pos2 = sd2->getPos();
115 Vector3d r12 = pos2 - pos1;
116 if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(r12);
119 RealType z2 = r12[axis_] * r12[axis_];
120 RealType xydist = sqrt(distance * distance - z2);
123 RealType thisZ = abs(r12[axis_]);
124 int whichBin = int(thisZ / deltaZ_);
125 if (whichBin <
int(nBins_)) histogram_[whichBin] += 2;
129 void GofZ::writeRdf() {
130 std::ofstream rdfStream(outputFilename_.c_str());
131 if (rdfStream.is_open()) {
132 rdfStream <<
"#" << axisLabel_ <<
"-separation distribution function\n";
133 rdfStream <<
"#selection1: (" << selectionScript1_ <<
")\t";
134 rdfStream <<
"selection2: (" << selectionScript2_ <<
")\n";
135 rdfStream <<
"#r\tcorrValue\n";
136 for (
unsigned int i = 0; i < avgGofz_.size(); ++i) {
137 RealType z = deltaZ_ * (i + 0.5);
138 rdfStream << z <<
"\t" << avgGofz_[i] / nProcessed_ <<
"\n";
141 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
142 "GofZ: unable to open %s\n", outputFilename_.c_str());
143 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.