50#include "applications/staticProps/MassDensityZ.hpp"
55#include "brains/Thermo.hpp"
57#include "utils/simError.h"
61 MassDensityZ::MassDensityZ(SimInfo* info,
const std::string& filename,
62 const std::string& sele,
int nzbins,
int axis) :
63 StaticAnalyser(info, filename, nzbins),
64 selectionScript_(sele), evaluator_(info), seleMan_(info), thermo_(info),
66 evaluator_.loadScriptString(sele);
67 if (!evaluator_.isDynamic()) {
68 seleMan_.setSelectionSet(evaluator_.evaluate());
71 massZ_.resize(nBins_);
86 setOutputName(
getPrefix(filename) +
".MassDensityZ");
89 void MassDensityZ::process() {
93 bool usePeriodicBoundaryConditions_ =
94 info_->getSimParams()->getUsePeriodicBoundaryConditions();
96 DumpReader reader(info_, dumpFilename_);
97 int nFrames = reader.getNFrames();
98 nProcessed_ = nFrames / step_;
100 for (
int istep = 0; istep < nFrames; istep += step_) {
101 reader.readFrame(istep);
102 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
104 Mat3x3d hmat = currentSnapshot_->getHmat();
105 zBox_.push_back(hmat(axis_, axis_));
107 RealType halfBoxZ_ = hmat(axis_, axis_) / 2.0;
111 area = currentSnapshot_->getYZarea();
114 area = currentSnapshot_->getXZarea();
118 area = currentSnapshot_->getXYarea();
122 areas_.push_back(area);
124 if (evaluator_.isDynamic()) {
125 seleMan_.setSelectionSet(evaluator_.evaluate());
128 for (sd = seleMan_.beginSelected(ii); sd != NULL;
129 sd = seleMan_.nextSelected(ii)) {
130 Vector3d pos = sd->getPos();
131 RealType mass = sd->getMass();
132 if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(pos);
134 int binNo = int(nBins_ * (halfBoxZ_ + pos[axis_]) / hmat(axis_, axis_));
135 massZ_[binNo] += mass;
141 void MassDensityZ::writeMassDensityZ() {
143 std::vector<RealType>::iterator j;
145 for (j = zBox_.begin(); j != zBox_.end(); ++j) {
148 RealType zAve = zSum / zBox_.size();
150 RealType areaSum = 0.0;
151 for (j = areas_.begin(); j != areas_.end(); ++j) {
154 RealType areaAve = areaSum / areas_.size();
156 std::ofstream rdfStream(outputFilename_.c_str());
157 if (rdfStream.is_open()) {
158 rdfStream <<
"#MassDensity(" << axisLabel_ <<
")\n";
159 rdfStream <<
"#nFrames:\t" << nProcessed_ <<
"\n";
160 rdfStream <<
"#selection: (" << selectionScript_ <<
")\n";
161 rdfStream <<
"#" << axisLabel_ <<
"\tdensity (g cm^-3)\n";
162 rdfStream.precision(8);
164 RealType massDensity;
165 for (
unsigned int i = 0; i < massZ_.size(); ++i) {
166 RealType z = zAve * (i + 0.5) / nBins_;
168 RealType volSlice = areaAve * zAve / nBins_;
171 Constants::densityConvert * massZ_[i] / (volSlice * nProcessed_);
173 rdfStream << z <<
"\t" << massDensity <<
"\n";
177 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
178 "MassDensityZ: unable to open %s\n", outputFilename_.c_str());
179 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)