48#include "applications/staticProps/MassDensityR.hpp"
53#include "brains/Thermo.hpp"
55#include "utils/simError.h"
59 MassDensityR::MassDensityR(
SimInfo* info,
const std::string& filename,
60 const std::string& sele, RealType len,
63 selectionScript_(sele), evaluator_(info), seleMan_(info), thermo_(info),
65 evaluator_.loadScriptString(sele);
66 if (!evaluator_.isDynamic()) {
67 seleMan_.setSelectionSet(evaluator_.evaluate());
70 deltaR_ = len_ / nBins_;
74 massR_.resize(nBins_);
75 setOutputName(
getPrefix(filename) +
".MassDensityR");
76 std::stringstream params;
77 params <<
" len = " << len_ <<
", nrbins = " << nBins_;
78 const std::string paramString = params.str();
79 setParameterString(paramString);
82 void MassDensityR::process() {
86 DumpReader reader(info_, dumpFilename_);
87 int nFrames = reader.getNFrames();
88 nProcessed_ = nFrames / step_;
90 for (
int istep = 0; istep < nFrames; istep += step_) {
91 reader.readFrame(istep);
92 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
94 Vector3d CenterOfMass = thermo_.getCom();
96 if (evaluator_.isDynamic()) {
97 seleMan_.setSelectionSet(evaluator_.evaluate());
101 for (sd = seleMan_.beginSelected(ii); sd != NULL;
102 sd = seleMan_.nextSelected(ii)) {
103 Vector3d pos = CenterOfMass - sd->getPos();
105 RealType mass = sd->getMass();
107 if (distance < len_) {
108 int binNo = int(distance / deltaR_);
109 massR_[binNo] += mass;
116 void MassDensityR::writeMassDensityR() {
117 std::ofstream rdfStream(outputFilename_.c_str());
118 if (rdfStream.is_open()) {
119 rdfStream <<
"#mass_density(r)\n";
120 rdfStream <<
"#nFrames:\t" << nProcessed_ <<
"\n";
121 rdfStream <<
"#selection: (" << selectionScript_ <<
")\n";
122 rdfStream <<
"# r\tdensity (g cm^-3)\n";
123 rdfStream.precision(8);
125 RealType massDensity;
126 for (
unsigned int i = 0; i < massR_.size(); ++i) {
127 RealType rLower = i * deltaR_;
128 RealType rUpper = rLower + deltaR_;
130 (4.0 * Constants::PI) * (pow(rUpper, 3) - pow(rLower, 3)) / 3.0;
132 RealType r = deltaR_ * (i + 0.5);
135 Constants::densityConvert * massR_[i] / (volShell * nProcessed_);
137 rdfStream << r <<
"\t" << massDensity <<
"\n";
141 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
142 "MassDensityR: unable to open %s\n", outputFilename_.c_str());
143 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.