50#include "applications/staticProps/RhoZ.hpp"
57#include "utils/simError.h"
61 RhoZ::RhoZ(
SimInfo* info,
const std::string& filename,
62 const std::string& sele,
int nzbins,
int axis) :
64 selectionScript_(sele), evaluator_(info), seleMan_(info), axis_(axis) {
65 evaluator_.loadScriptString(sele);
66 if (!evaluator_.isDynamic()) {
67 seleMan_.setSelectionSet(evaluator_.evaluate());
72 sliceSDLists_.resize(nBins_);
73 density_.resize(nBins_);
88 setOutputName(
getPrefix(filename) +
".RhoZ");
91 void RhoZ::process() {
95 bool usePeriodicBoundaryConditions_ =
96 info_->getSimParams()->getUsePeriodicBoundaryConditions();
98 DumpReader reader(info_, dumpFilename_);
99 int nFrames = reader.getNFrames();
100 nProcessed_ = nFrames / step_;
102 for (
int istep = 0; istep < nFrames; istep += step_) {
103 reader.readFrame(istep);
104 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
106 for (
unsigned int i = 0; i < nBins_; i++) {
107 sliceSDLists_[i].clear();
110 RealType sliceVolume = currentSnapshot_->getVolume() / nBins_;
111 Mat3x3d hmat = currentSnapshot_->getHmat();
112 zBox_.push_back(hmat(axis_, axis_));
116 if (evaluator_.isDynamic()) {
117 seleMan_.setSelectionSet(evaluator_.evaluate());
121 for (sd = seleMan_.beginSelected(ii); sd != NULL;
122 sd = seleMan_.nextSelected(ii)) {
123 Vector3d pos = sd->getPos();
124 if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(pos);
129 for (sd = seleMan_.beginSelected(ii); sd != NULL;
130 sd = seleMan_.nextSelected(ii)) {
131 Vector3d pos = sd->getPos();
139 int(nBins_ * (pos[axis_] / hmat(axis_, axis_) + 0.5)) % nBins_;
140 sliceSDLists_[binNo].push_back(sd);
144 for (
unsigned int i = 0; i < nBins_; i++) {
145 RealType totalMass = 0;
146 for (
unsigned int k = 0; k < sliceSDLists_[i].size(); ++k) {
147 totalMass += sliceSDLists_[i][k]->getMass();
149 density_[i] += totalMass / sliceVolume;
156 void RhoZ::writeDensity() {
158 std::vector<RealType>::iterator j;
160 for (j = zBox_.begin(); j != zBox_.end(); ++j) {
163 RealType zAve = zSum / zBox_.size();
165 std::ofstream rdfStream(outputFilename_.c_str());
166 if (rdfStream.is_open()) {
167 rdfStream <<
"#Rho(" << axisLabel_ <<
")\n";
168 rdfStream <<
"#nFrames:\t" << nProcessed_ <<
"\n";
169 rdfStream <<
"#selection: (" << selectionScript_ <<
")\n";
170 rdfStream <<
"#" << axisLabel_ <<
"\tdensity (g cm^-3)\t";
172 rdfStream << std::endl;
174 rdfStream.precision(8);
176 for (
unsigned int i = 0; i < density_.size(); ++i) {
177 RealType z = zAve * (i + 0.5) / density_.size();
178 rdfStream << z <<
"\t"
179 << Constants::densityConvert * density_[i] / nProcessed_
182 rdfStream << std::endl;
186 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
187 "RhoZ: unable to open %s\n", outputFilename_.c_str());
188 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)