48#include "applications/staticProps/GofRZ.hpp"
53#include "utils/simError.h"
57 GofRZ::GofRZ(
SimInfo* info,
const std::string& filename,
58 const std::string& sele1,
const std::string& sele2, RealType len,
59 RealType zlen,
int nrbins,
int nZBins,
int axis) :
61 len_(len), zLen_(zlen), nZBins_(nZBins), axis_(axis) {
62 setOutputName(
getPrefix(filename) +
".gofrz");
64 deltaR_ = len_ / (double)nBins_;
65 deltaZ_ = zLen_ / (double)nZBins_;
67 histogram_.resize(nBins_);
68 avgGofr_.resize(nBins_);
69 for (
unsigned int i = 0; i < nBins_; ++i) {
70 histogram_[i].resize(nZBins_);
71 avgGofr_[i].resize(nZBins_);
75 xaxis_ = (axis_ + 1) % 3;
76 yaxis_ = (axis_ + 2) % 3;
93 void GofRZ::preProcess() {
94 for (
unsigned int i = 0; i < avgGofr_.size(); ++i) {
95 std::fill(avgGofr_[i].begin(), avgGofr_[i].end(), 0);
99 void GofRZ::initializeHistogram() {
101 for (
unsigned int i = 0; i < histogram_.size(); ++i) {
102 std::fill(histogram_[i].begin(), histogram_[i].end(), 0);
106 void GofRZ::processHistogram() {
107 int nPairs = getNPairs();
109 info_->getSnapshotManager()->getCurrentSnapshot()->getVolume();
110 RealType pairDensity = nPairs / volume * 2.0;
112 for (
unsigned int i = 0; i < histogram_.size(); ++i) {
113 RealType rLower = i * deltaR_;
114 RealType rUpper = rLower + deltaR_;
116 Constants::PI * deltaZ_ * ((rUpper * rUpper) - (rLower * rLower));
117 RealType nIdeal = volSlice * pairDensity;
119 for (
unsigned int j = 0; j < histogram_[i].size(); ++j) {
120 avgGofr_[i][j] += histogram_[i][j] / nIdeal;
125 void GofRZ::collectHistogram(StuntDouble* sd1, StuntDouble* sd2) {
126 if (sd1 == sd2) {
return; }
127 bool usePeriodicBoundaryConditions_ =
128 info_->getSimParams()->getUsePeriodicBoundaryConditions();
130 Vector3d pos1 = sd1->getPos();
131 Vector3d pos2 = sd2->getPos();
132 Vector3d r12 = pos2 - pos1;
133 if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(r12);
135 RealType
distance = sqrt(pow(r12[xaxis_], 2) + pow(r12[yaxis_], 2));
137 int whichRBin = int(distance / deltaR_);
139 if (distance <= len_) {
140 RealType Z = fabs(r12[axis_]);
143 int whichZBin = int(Z / deltaZ_);
145 ++histogram_[whichRBin][whichZBin];
151 void GofRZ::writeRdf() {
152 std::ofstream rdfStream(outputFilename_.c_str());
153 if (rdfStream.is_open()) {
154 rdfStream <<
"#radial distribution function\n";
155 rdfStream <<
"#selection1: (" << selectionScript1_ <<
")\t";
156 rdfStream <<
"selection2: (" << selectionScript2_ <<
")\n";
157 rdfStream <<
"#nBins = " << nBins_ <<
"\t maxLen = " << len_
158 <<
"deltaR = " << deltaR_ <<
"\n";
159 rdfStream <<
"#n" << axisLabel_ <<
"Bins =" << nZBins_ <<
"\t delta"
160 << axisLabel_ <<
" = " << deltaZ_ <<
"\n";
161 for (
unsigned int i = 0; i < avgGofr_.size(); ++i) {
164 for (
unsigned int j = 0; j < avgGofr_[i].size(); ++j) {
166 rdfStream << avgGofr_[i][j] / nProcessed_ <<
"\t";
173 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
174 "GofRZ: unable to open %s\n", outputFilename_.c_str());
175 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.