45#include "applications/staticProps/MassDensityR.hpp"
50#include "brains/Thermo.hpp"
52#include "utils/simError.h"
56 MassDensityR::MassDensityR(SimInfo* info,
const std::string& filename,
57 const std::string& sele, RealType len,
59 StaticAnalyser(info, filename, nrbins),
60 selectionScript_(sele), evaluator_(info), seleMan_(info), thermo_(info),
62 evaluator_.loadScriptString(sele);
63 if (!evaluator_.isDynamic()) {
64 seleMan_.setSelectionSet(evaluator_.evaluate());
67 deltaR_ = len_ / nBins_;
71 massR_.resize(nBins_);
72 setOutputName(
getPrefix(filename) +
".MassDensityR");
73 std::stringstream params;
74 params <<
" len = " << len_ <<
", nrbins = " << nBins_;
75 const std::string paramString = params.str();
76 setParameterString(paramString);
79 void MassDensityR::process() {
83 DumpReader reader(info_, dumpFilename_);
84 int nFrames = reader.getNFrames();
85 nProcessed_ = nFrames / step_;
87 for (
int istep = 0; istep < nFrames; istep += step_) {
88 reader.readFrame(istep);
89 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
91 Vector3d CenterOfMass = thermo_.getCom();
93 if (evaluator_.isDynamic()) {
94 seleMan_.setSelectionSet(evaluator_.evaluate());
98 for (sd = seleMan_.beginSelected(ii); sd != NULL;
99 sd = seleMan_.nextSelected(ii)) {
100 Vector3d pos = CenterOfMass - sd->getPos();
102 RealType mass = sd->getMass();
104 if (distance < len_) {
105 int binNo = int(distance / deltaR_);
106 massR_[binNo] += mass;
113 void MassDensityR::writeMassDensityR() {
114 std::ofstream rdfStream(outputFilename_.c_str());
115 if (rdfStream.is_open()) {
116 rdfStream <<
"#mass_density(r)\n";
117 rdfStream <<
"#nFrames:\t" << nProcessed_ <<
"\n";
118 rdfStream <<
"#selection: (" << selectionScript_ <<
")\n";
119 rdfStream <<
"# r\tdensity (g cm^-3)\n";
120 rdfStream.precision(8);
122 RealType massDensity;
123 for (
unsigned int i = 0; i < massR_.size(); ++i) {
124 RealType rLower = i * deltaR_;
125 RealType rUpper = rLower + deltaR_;
127 (4.0 * Constants::PI) * (pow(rUpper, 3) - pow(rLower, 3)) / 3.0;
129 RealType r = deltaR_ * (i + 0.5);
132 Constants::densityConvert * massR_[i] / (volShell * nProcessed_);
134 rdfStream << r <<
"\t" << massDensity <<
"\n";
138 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
139 "MassDensityR: unable to open %s\n", outputFilename_.c_str());
140 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.