53#include "applications/staticProps/MassDensityZ.hpp"
58#include "brains/Thermo.hpp"
60#include "utils/simError.h"
64 MassDensityZ::MassDensityZ(
SimInfo* info,
const std::string& filename,
65 const std::string& sele,
int nzbins,
int axis) :
67 selectionScript_(sele), evaluator_(info), seleMan_(info), thermo_(info),
69 evaluator_.loadScriptString(sele);
70 if (!evaluator_.isDynamic()) {
71 seleMan_.setSelectionSet(evaluator_.evaluate());
74 massZ_.resize(nBins_);
89 setOutputName(
getPrefix(filename) +
".MassDensityZ");
92 void MassDensityZ::process() {
96 bool usePeriodicBoundaryConditions_ =
97 info_->getSimParams()->getUsePeriodicBoundaryConditions();
99 DumpReader reader(info_, dumpFilename_);
100 int nFrames = reader.getNFrames();
101 nProcessed_ = nFrames / step_;
103 for (
int istep = 0; istep < nFrames; istep += step_) {
104 reader.readFrame(istep);
105 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
107 Mat3x3d hmat = currentSnapshot_->getHmat();
108 zBox_.push_back(hmat(axis_, axis_));
110 RealType halfBoxZ_ = hmat(axis_, axis_) / 2.0;
114 area = currentSnapshot_->getYZarea();
117 area = currentSnapshot_->getXZarea();
121 area = currentSnapshot_->getXYarea();
125 areas_.push_back(area);
127 if (evaluator_.isDynamic()) {
128 seleMan_.setSelectionSet(evaluator_.evaluate());
131 for (sd = seleMan_.beginSelected(ii); sd != NULL;
132 sd = seleMan_.nextSelected(ii)) {
133 Vector3d pos = sd->getPos();
134 RealType mass = sd->getMass();
135 if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(pos);
137 int binNo = int(nBins_ * (halfBoxZ_ + pos[axis_]) / hmat(axis_, axis_));
138 massZ_[binNo] += mass;
144 void MassDensityZ::writeMassDensityZ() {
146 std::vector<RealType>::iterator j;
148 for (j = zBox_.begin(); j != zBox_.end(); ++j) {
151 RealType zAve = zSum / zBox_.size();
153 RealType areaSum = 0.0;
154 for (j = areas_.begin(); j != areas_.end(); ++j) {
157 RealType areaAve = areaSum / areas_.size();
159 std::ofstream rdfStream(outputFilename_.c_str());
160 if (rdfStream.is_open()) {
161 rdfStream <<
"#MassDensity(" << axisLabel_ <<
")\n";
162 rdfStream <<
"#nFrames:\t" << nProcessed_ <<
"\n";
163 rdfStream <<
"#selection: (" << selectionScript_ <<
")\n";
164 rdfStream <<
"#" << axisLabel_ <<
"\tdensity (g cm^-3)\n";
165 rdfStream.precision(8);
167 RealType massDensity;
168 for (
unsigned int i = 0; i < massZ_.size(); ++i) {
169 RealType z = zAve * (i + 0.5) / nBins_;
171 RealType volSlice = areaAve * zAve / nBins_;
174 Constants::densityConvert * massZ_[i] / (volSlice * nProcessed_);
176 rdfStream << z <<
"\t" << massDensity <<
"\n";
180 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
181 "MassDensityZ: unable to open %s\n", outputFilename_.c_str());
182 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)