47#include "applications/staticProps/RhoZ.hpp"
54#include "utils/simError.h"
58 RhoZ::RhoZ(SimInfo* info,
const std::string& filename,
59 const std::string& sele,
int nzbins,
int axis) :
60 StaticAnalyser(info, filename, nzbins),
61 selectionScript_(sele), evaluator_(info), seleMan_(info), axis_(axis) {
62 evaluator_.loadScriptString(sele);
63 if (!evaluator_.isDynamic()) {
64 seleMan_.setSelectionSet(evaluator_.evaluate());
69 sliceSDLists_.resize(nBins_);
70 density_.resize(nBins_);
85 setOutputName(
getPrefix(filename) +
".RhoZ");
88 void RhoZ::process() {
92 bool usePeriodicBoundaryConditions_ =
93 info_->getSimParams()->getUsePeriodicBoundaryConditions();
95 DumpReader reader(info_, dumpFilename_);
96 int nFrames = reader.getNFrames();
97 nProcessed_ = nFrames / step_;
99 for (
int istep = 0; istep < nFrames; istep += step_) {
100 reader.readFrame(istep);
101 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
103 for (
unsigned int i = 0; i < nBins_; i++) {
104 sliceSDLists_[i].clear();
107 RealType sliceVolume = currentSnapshot_->getVolume() / nBins_;
108 Mat3x3d hmat = currentSnapshot_->getHmat();
109 zBox_.push_back(hmat(axis_, axis_));
113 if (evaluator_.isDynamic()) {
114 seleMan_.setSelectionSet(evaluator_.evaluate());
118 for (sd = seleMan_.beginSelected(ii); sd != NULL;
119 sd = seleMan_.nextSelected(ii)) {
120 Vector3d pos = sd->getPos();
121 if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(pos);
126 for (sd = seleMan_.beginSelected(ii); sd != NULL;
127 sd = seleMan_.nextSelected(ii)) {
128 Vector3d pos = sd->getPos();
136 int(nBins_ * (pos[axis_] / hmat(axis_, axis_) + 0.5)) % nBins_;
137 sliceSDLists_[binNo].push_back(sd);
141 for (
unsigned int i = 0; i < nBins_; i++) {
142 RealType totalMass = 0;
143 for (
unsigned int k = 0; k < sliceSDLists_[i].size(); ++k) {
144 totalMass += sliceSDLists_[i][k]->getMass();
146 density_[i] += totalMass / sliceVolume;
153 void RhoZ::writeDensity() {
155 std::vector<RealType>::iterator j;
157 for (j = zBox_.begin(); j != zBox_.end(); ++j) {
160 RealType zAve = zSum / zBox_.size();
162 std::ofstream rdfStream(outputFilename_.c_str());
163 if (rdfStream.is_open()) {
164 rdfStream <<
"#Rho(" << axisLabel_ <<
")\n";
165 rdfStream <<
"#nFrames:\t" << nProcessed_ <<
"\n";
166 rdfStream <<
"#selection: (" << selectionScript_ <<
")\n";
167 rdfStream <<
"#" << axisLabel_ <<
"\tdensity (g cm^-3)\t";
169 rdfStream << std::endl;
171 rdfStream.precision(8);
173 for (
unsigned int i = 0; i < density_.size(); ++i) {
174 RealType z = zAve * (i + 0.5) / density_.size();
175 rdfStream << z <<
"\t"
176 << Constants::densityConvert * density_[i] / nProcessed_
179 rdfStream << std::endl;
183 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
184 "RhoZ: unable to open %s\n", outputFilename_.c_str());
185 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)