47#include "applications/staticProps/VelocityZ.hpp"
54#include "utils/simError.h"
58 VelocityZ::VelocityZ(SimInfo* info,
const std::string& filename,
59 const std::string& sele,
int nbins1,
int nbins2,
60 int axis1,
int axis2) :
61 StaticAnalyser(info, filename, nbins1),
62 selectionScript_(sele), evaluator_(info), seleMan_(info), nBins2_(nbins2),
63 axis1_(axis1), axis2_(axis2) {
64 evaluator_.loadScriptString(sele);
65 if (!evaluator_.isDynamic()) {
66 seleMan_.setSelectionSet(evaluator_.evaluate());
74 sliceSDLists_.resize(nBins2_);
75 velocity_.resize(nBins2_);
76 for (
unsigned int i = 0; i < nBins2_; ++i) {
77 sliceSDLists_[i].resize(nBins_);
78 velocity_[i].resize(nBins_);
82 axis3_ = (3 - axis1_ - axis2_);
105 else if (axis2_ == 1)
110 setOutputName(
getPrefix(filename) +
".VelocityZ");
113 void VelocityZ::process() {
117 bool usePeriodicBoundaryConditions_ =
118 info_->getSimParams()->getUsePeriodicBoundaryConditions();
120 DumpReader reader(info_, dumpFilename_);
121 int nFrames = reader.getNFrames();
122 nProcessed_ = nFrames / step_;
124 for (
int istep = 0; istep < nFrames; istep += step_) {
125 reader.readFrame(istep);
126 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
128 for (
unsigned int i = 0; i < nBins2_; i++) {
129 for (
unsigned int j = 0; j < nBins_; j++) {
130 sliceSDLists_[i][j].clear();
134 Mat3x3d hmat = currentSnapshot_->getHmat();
136 zBox_.push_back(hmat(axis2_, axis2_));
138 RealType halfBox1_ = hmat(axis1_, axis1_) / 2.0;
139 RealType halfBox2_ = hmat(axis2_, axis2_) / 2.0;
141 if (evaluator_.isDynamic()) {
142 seleMan_.setSelectionSet(evaluator_.evaluate());
146 for (sd = seleMan_.beginSelected(ii); sd != NULL;
147 sd = seleMan_.nextSelected(ii)) {
148 Vector3d pos = sd->getPos();
149 if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(pos);
154 for (sd = seleMan_.beginSelected(ii); sd != NULL;
155 sd = seleMan_.nextSelected(ii)) {
156 Vector3d pos = sd->getPos();
159 int(nBins_ * (halfBox1_ + pos[axis1_]) / hmat(axis1_, axis1_));
161 int(nBins2_ * (halfBox2_ + pos[axis2_]) / hmat(axis2_, axis2_));
162 sliceSDLists_[binNo2][binNo1].push_back(sd);
166 for (
unsigned int i = 0; i < nBins2_; i++) {
167 for (
unsigned int j = 0; j < nBins_; j++) {
168 RealType totalVelocity = 0;
169 for (
unsigned int k = 0; k < sliceSDLists_[i][j].size(); ++k) {
170 totalVelocity += sliceSDLists_[i][j][k]->getVel()[axis3_];
173 if (sliceSDLists_[i][j].size() > 0)
174 velocity_[i][j] += totalVelocity / sliceSDLists_[i][j].size();
182 void VelocityZ::writeVelocity() {
186 for (std::vector<RealType>::iterator j = zBox_.begin(); j != zBox_.end();
190 RealType zAve = zSum / zBox_.size();
192 std::ofstream rdfStream(outputFilename_.c_str());
193 if (rdfStream.is_open()) {
194 rdfStream <<
"#VelocityZ\n";
195 rdfStream <<
"#nFrames:\t" << nProcessed_ <<
"\n";
196 rdfStream <<
"#selection: (" << selectionScript_ <<
")\n";
197 rdfStream <<
"#velocity (" << axisLabel1_ <<
"," << axisLabel2_ <<
")\n";
199 for (
unsigned int i = 0; i < velocity_.size(); ++i) {
200 RealType z = zAve * (i + 0.5) / velocity_.size();
201 rdfStream << z <<
"\t";
202 for (
unsigned int j = 0; j < velocity_[i].size(); ++j) {
203 rdfStream << velocity_[i][j] / nProcessed_;
210 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
211 "VelocityZ: unable to open %s\n", outputFilename_.c_str());
212 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)