49#include "applications/staticProps/RhoR.hpp"
55#include "brains/Thermo.hpp"
58#include "utils/Constants.hpp"
59#include "utils/simError.h"
63 RhoR::RhoR(
SimInfo* info,
const std::string& filename,
64 const std::string& sele, RealType len,
int nrbins,
67 selectionScript_(sele), evaluator_(info), seleMan_(info), len_(len) {
68 evaluator_.loadScriptString(sele);
69 if (!evaluator_.isDynamic()) {
70 seleMan_.setSelectionSet(evaluator_.evaluate());
73 deltaR_ = len_ / nBins_;
75 histogram_.resize(nBins_);
76 avgRhoR_.resize(nBins_);
77 particleR_ = particleR;
78 setOutputName(
getPrefix(filename) +
".RhoR");
81 void RhoR::process() {
83 DumpReader reader(info_, dumpFilename_);
84 int nFrames = reader.getNFrames();
85 nProcessed_ = nFrames / step_;
87 std::fill(avgRhoR_.begin(), avgRhoR_.end(), 0.0);
88 std::fill(histogram_.begin(), histogram_.end(), 0);
90 for (
int istep = 0; istep < nFrames; istep += step_) {
93 reader.readFrame(istep);
94 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
95 Vector3d CenterOfMass = thermo.getCom();
97 if (evaluator_.isDynamic()) {
98 seleMan_.setSelectionSet(evaluator_.evaluate());
102 for (sd = seleMan_.beginSelected(i); sd != NULL;
103 sd = seleMan_.nextSelected(i)) {
104 Vector3d pos = sd->getPos();
105 Vector3d r12 = CenterOfMass - pos;
109 if (distance < len_) {
110 int whichBin = int(distance / deltaR_);
111 histogram_[whichBin] += 1;
120 void RhoR::processHistogram() {
121 RealType particleDensity = 3.0 * info_->getNGlobalMolecules() /
122 (4.0 * Constants::PI * pow(particleR_, 3));
123 RealType pairConstant = (4.0 * Constants::PI * particleDensity) / 3.0;
125 for (
unsigned int i = 0; i < histogram_.size(); ++i) {
126 RealType rLower = i * deltaR_;
127 RealType rUpper = rLower + deltaR_;
129 (rUpper * rUpper * rUpper) - (rLower * rLower * rLower);
130 RealType nIdeal = volSlice * pairConstant;
132 avgRhoR_[i] += histogram_[i] / nIdeal;
136 void RhoR::writeRhoR() {
137 std::ofstream rdfStream(outputFilename_.c_str());
138 if (rdfStream.is_open()) {
139 rdfStream <<
"#radial density function rho(r)\n";
140 rdfStream <<
"#r\tcorrValue\n";
141 for (
unsigned int i = 0; i < avgRhoR_.size(); ++i) {
142 RealType r = deltaR_ * (i + 0.5);
143 rdfStream << r <<
"\t" << avgRhoR_[i] / nProcessed_ <<
"\n";
147 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
148 "RhoR: unable to open %s\n", outputFilename_.c_str());
149 painCave.isFatal = 1;
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.