47#include "applications/staticProps/PipeDensity.hpp"
54#include "utils/simError.h"
58 PipeDensity::PipeDensity(SimInfo* info,
const std::string& filename,
59 const std::string& sele,
int nbins,
int nbins2,
61 StaticAnalyser(info, filename, nbins2),
62 selectionScript_(sele), evaluator_(info), seleMan_(info), nBins2_(nbins),
64 evaluator_.loadScriptString(sele);
65 if (!evaluator_.isDynamic()) {
66 seleMan_.setSelectionSet(evaluator_.evaluate());
71 sliceSDLists_.resize(nBins2_);
72 density_.resize(nBins2_);
73 for (
unsigned int i = 0; i < nBins2_; ++i) {
74 sliceSDLists_[i].resize(nBins_);
75 density_[i].resize(nBins_);
79 axis1_ = (axis_ + 1) % 3;
80 axis2_ = (axis_ + 2) % 3;
99 setOutputName(
getPrefix(filename) +
".PipeDensity");
102 void PipeDensity::process() {
106 bool usePeriodicBoundaryConditions_ =
107 info_->getSimParams()->getUsePeriodicBoundaryConditions();
109 DumpReader reader(info_, dumpFilename_);
110 int nFrames = reader.getNFrames();
111 nProcessed_ = nFrames / step_;
113 for (
int istep = 0; istep < nFrames; istep += step_) {
114 reader.readFrame(istep);
115 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
117 for (
unsigned int i = 0; i < nBins2_; i++) {
118 for (
unsigned int j = 0; j < nBins_; j++) {
119 sliceSDLists_[i][j].clear();
123 RealType sliceVolume = currentSnapshot_->getVolume() / (nBins2_ * nBins_);
124 Mat3x3d hmat = currentSnapshot_->getHmat();
126 RealType halfBox1_ = hmat(axis1_, axis1_) / 2.0;
127 RealType halfBox2_ = hmat(axis2_, axis2_) / 2.0;
129 if (evaluator_.isDynamic()) {
130 seleMan_.setSelectionSet(evaluator_.evaluate());
134 for (sd = seleMan_.beginSelected(ii); sd != NULL;
135 sd = seleMan_.nextSelected(ii)) {
136 Vector3d pos = sd->getPos();
137 if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(pos);
142 for (sd = seleMan_.beginSelected(ii); sd != NULL;
143 sd = seleMan_.nextSelected(ii)) {
144 Vector3d pos = sd->getPos();
147 int(nBins2_ * (halfBox1_ + pos[axis1_]) / hmat(axis1_, axis1_));
149 int(nBins_ * (halfBox2_ + pos[axis2_]) / hmat(axis2_, axis2_));
150 sliceSDLists_[binNo1][binNo2].push_back(sd);
154 for (
unsigned int i = 0; i < nBins2_; i++) {
155 for (
unsigned int j = 0; j < nBins_; j++) {
156 RealType totalMass = 0;
157 for (
unsigned int k = 0; k < sliceSDLists_[i][j].size(); ++k) {
158 totalMass += sliceSDLists_[i][j][k]->getMass();
160 density_[i][j] += totalMass / sliceVolume;
168 void PipeDensity::writeDensity() {
169 std::ofstream rdfStream(outputFilename_.c_str());
171 if (rdfStream.is_open()) {
172 rdfStream <<
"#PipeDensity\n";
173 rdfStream <<
"#nFrames:\t" << nProcessed_ <<
"\n";
174 rdfStream <<
"#selection: (" << selectionScript_ <<
")\n";
175 rdfStream <<
"#density (" << axisLabel1_ <<
"," << axisLabel2_ <<
")\n";
176 for (
unsigned int i = 0; i < density_.size(); ++i) {
177 for (
unsigned int j = 0; j < density_[i].size(); ++j) {
178 rdfStream << Constants::densityConvert * density_[i][j] / nProcessed_;
185 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
186 "PipeDensity: unable to open %s\n", outputFilename_.c_str());
187 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)