45#include "applications/staticProps/GofRZ.hpp"
50#include "utils/simError.h"
54 GofRZ::GofRZ(SimInfo* info,
const std::string& filename,
55 const std::string& sele1,
const std::string& sele2, RealType len,
56 RealType zlen,
int nrbins,
int nZBins,
int axis) :
57 RadialDistrFunc(info, filename, sele1, sele2, nrbins),
58 len_(len), zLen_(zlen), nZBins_(nZBins), axis_(axis) {
59 setOutputName(
getPrefix(filename) +
".gofrz");
61 deltaR_ = len_ / (double)nBins_;
62 deltaZ_ = zLen_ / (double)nZBins_;
64 histogram_.resize(nBins_);
65 avgGofr_.resize(nBins_);
66 for (
unsigned int i = 0; i < nBins_; ++i) {
67 histogram_[i].resize(nZBins_);
68 avgGofr_[i].resize(nZBins_);
72 xaxis_ = (axis_ + 1) % 3;
73 yaxis_ = (axis_ + 2) % 3;
90 void GofRZ::preProcess() {
91 for (
unsigned int i = 0; i < avgGofr_.size(); ++i) {
92 std::fill(avgGofr_[i].begin(), avgGofr_[i].end(), 0);
96 void GofRZ::initializeHistogram() {
98 for (
unsigned int i = 0; i < histogram_.size(); ++i) {
99 std::fill(histogram_[i].begin(), histogram_[i].end(), 0);
103 void GofRZ::processHistogram() {
104 int nPairs = getNPairs();
106 info_->getSnapshotManager()->getCurrentSnapshot()->getVolume();
107 RealType pairDensity = nPairs / volume * 2.0;
109 for (
unsigned int i = 0; i < histogram_.size(); ++i) {
110 RealType rLower = i * deltaR_;
111 RealType rUpper = rLower + deltaR_;
113 Constants::PI * deltaZ_ * ((rUpper * rUpper) - (rLower * rLower));
114 RealType nIdeal = volSlice * pairDensity;
116 for (
unsigned int j = 0; j < histogram_[i].size(); ++j) {
117 avgGofr_[i][j] += histogram_[i][j] / nIdeal;
122 void GofRZ::collectHistogram(StuntDouble* sd1, StuntDouble* sd2) {
123 if (sd1 == sd2) {
return; }
124 bool usePeriodicBoundaryConditions_ =
125 info_->getSimParams()->getUsePeriodicBoundaryConditions();
127 Vector3d pos1 = sd1->getPos();
128 Vector3d pos2 = sd2->getPos();
129 Vector3d r12 = pos2 - pos1;
130 if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(r12);
132 RealType
distance = sqrt(pow(r12[xaxis_], 2) + pow(r12[yaxis_], 2));
134 int whichRBin = int(distance / deltaR_);
136 if (distance <= len_) {
137 RealType Z = fabs(r12[axis_]);
140 int whichZBin = int(Z / deltaZ_);
142 ++histogram_[whichRBin][whichZBin];
148 void GofRZ::writeRdf() {
149 std::ofstream rdfStream(outputFilename_.c_str());
150 if (rdfStream.is_open()) {
151 rdfStream <<
"#radial distribution function\n";
152 rdfStream <<
"#selection1: (" << selectionScript1_ <<
")\t";
153 rdfStream <<
"selection2: (" << selectionScript2_ <<
")\n";
154 rdfStream <<
"#nBins = " << nBins_ <<
"\t maxLen = " << len_
155 <<
"deltaR = " << deltaR_ <<
"\n";
156 rdfStream <<
"#n" << axisLabel_ <<
"Bins =" << nZBins_ <<
"\t delta"
157 << axisLabel_ <<
" = " << deltaZ_ <<
"\n";
158 for (
unsigned int i = 0; i < avgGofr_.size(); ++i) {
161 for (
unsigned int j = 0; j < avgGofr_[i].size(); ++j) {
163 rdfStream << avgGofr_[i][j] / nProcessed_ <<
"\t";
170 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
171 "GofRZ: unable to open %s\n", outputFilename_.c_str());
172 painCave.isFatal = 1;
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.