50#include "applications/staticProps/PipeDensity.hpp"
57#include "utils/simError.h"
61 PipeDensity::PipeDensity(
SimInfo* info,
const std::string& filename,
62 const std::string& sele,
int nbins,
int nbins2,
65 selectionScript_(sele), evaluator_(info), seleMan_(info), nBins2_(nbins),
67 evaluator_.loadScriptString(sele);
68 if (!evaluator_.isDynamic()) {
69 seleMan_.setSelectionSet(evaluator_.evaluate());
74 sliceSDLists_.resize(nBins2_);
75 density_.resize(nBins2_);
76 for (
unsigned int i = 0; i < nBins2_; ++i) {
77 sliceSDLists_[i].resize(nBins_);
78 density_[i].resize(nBins_);
82 axis1_ = (axis_ + 1) % 3;
83 axis2_ = (axis_ + 2) % 3;
102 setOutputName(
getPrefix(filename) +
".PipeDensity");
105 void PipeDensity::process() {
109 bool usePeriodicBoundaryConditions_ =
110 info_->getSimParams()->getUsePeriodicBoundaryConditions();
112 DumpReader reader(info_, dumpFilename_);
113 int nFrames = reader.getNFrames();
114 nProcessed_ = nFrames / step_;
116 for (
int istep = 0; istep < nFrames; istep += step_) {
117 reader.readFrame(istep);
118 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
120 for (
unsigned int i = 0; i < nBins2_; i++) {
121 for (
unsigned int j = 0; j < nBins_; j++) {
122 sliceSDLists_[i][j].clear();
126 RealType sliceVolume = currentSnapshot_->getVolume() / (nBins2_ * nBins_);
127 Mat3x3d hmat = currentSnapshot_->getHmat();
129 RealType halfBox1_ = hmat(axis1_, axis1_) / 2.0;
130 RealType halfBox2_ = hmat(axis2_, axis2_) / 2.0;
132 if (evaluator_.isDynamic()) {
133 seleMan_.setSelectionSet(evaluator_.evaluate());
137 for (sd = seleMan_.beginSelected(ii); sd != NULL;
138 sd = seleMan_.nextSelected(ii)) {
139 Vector3d pos = sd->getPos();
140 if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(pos);
145 for (sd = seleMan_.beginSelected(ii); sd != NULL;
146 sd = seleMan_.nextSelected(ii)) {
147 Vector3d pos = sd->getPos();
150 int(nBins2_ * (halfBox1_ + pos[axis1_]) / hmat(axis1_, axis1_));
152 int(nBins_ * (halfBox2_ + pos[axis2_]) / hmat(axis2_, axis2_));
153 sliceSDLists_[binNo1][binNo2].push_back(sd);
157 for (
unsigned int i = 0; i < nBins2_; i++) {
158 for (
unsigned int j = 0; j < nBins_; j++) {
159 RealType totalMass = 0;
160 for (
unsigned int k = 0; k < sliceSDLists_[i][j].size(); ++k) {
161 totalMass += sliceSDLists_[i][j][k]->getMass();
163 density_[i][j] += totalMass / sliceVolume;
171 void PipeDensity::writeDensity() {
172 std::ofstream rdfStream(outputFilename_.c_str());
174 if (rdfStream.is_open()) {
175 rdfStream <<
"#PipeDensity\n";
176 rdfStream <<
"#nFrames:\t" << nProcessed_ <<
"\n";
177 rdfStream <<
"#selection: (" << selectionScript_ <<
")\n";
178 rdfStream <<
"#density (" << axisLabel1_ <<
"," << axisLabel2_ <<
")\n";
179 for (
unsigned int i = 0; i < density_.size(); ++i) {
180 for (
unsigned int j = 0; j < density_[i].size(); ++j) {
181 rdfStream << Constants::densityConvert * density_[i][j] / nProcessed_;
188 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
189 "PipeDensity: unable to open %s\n", outputFilename_.c_str());
190 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)