50#include "applications/staticProps/VelocityZ.hpp"
57#include "utils/simError.h"
61 VelocityZ::VelocityZ(
SimInfo* info,
const std::string& filename,
62 const std::string& sele,
int nbins1,
int nbins2,
63 int axis1,
int axis2) :
65 selectionScript_(sele), evaluator_(info), seleMan_(info), nBins2_(nbins2),
66 axis1_(axis1), axis2_(axis2) {
67 evaluator_.loadScriptString(sele);
68 if (!evaluator_.isDynamic()) {
69 seleMan_.setSelectionSet(evaluator_.evaluate());
77 sliceSDLists_.resize(nBins2_);
78 velocity_.resize(nBins2_);
79 for (
unsigned int i = 0; i < nBins2_; ++i) {
80 sliceSDLists_[i].resize(nBins_);
81 velocity_[i].resize(nBins_);
85 axis3_ = (3 - axis1_ - axis2_);
100 else if (axis2_ == 2)
108 else if (axis2_ == 1)
113 setOutputName(
getPrefix(filename) +
".VelocityZ");
116 void VelocityZ::process() {
120 bool usePeriodicBoundaryConditions_ =
121 info_->getSimParams()->getUsePeriodicBoundaryConditions();
123 DumpReader reader(info_, dumpFilename_);
124 int nFrames = reader.getNFrames();
125 nProcessed_ = nFrames / step_;
127 for (
int istep = 0; istep < nFrames; istep += step_) {
128 reader.readFrame(istep);
129 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
131 for (
unsigned int i = 0; i < nBins2_; i++) {
132 for (
unsigned int j = 0; j < nBins_; j++) {
133 sliceSDLists_[i][j].clear();
137 Mat3x3d hmat = currentSnapshot_->getHmat();
139 zBox_.push_back(hmat(axis2_, axis2_));
141 RealType halfBox1_ = hmat(axis1_, axis1_) / 2.0;
142 RealType halfBox2_ = hmat(axis2_, axis2_) / 2.0;
144 if (evaluator_.isDynamic()) {
145 seleMan_.setSelectionSet(evaluator_.evaluate());
149 for (sd = seleMan_.beginSelected(ii); sd != NULL;
150 sd = seleMan_.nextSelected(ii)) {
151 Vector3d pos = sd->getPos();
152 if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(pos);
157 for (sd = seleMan_.beginSelected(ii); sd != NULL;
158 sd = seleMan_.nextSelected(ii)) {
159 Vector3d pos = sd->getPos();
162 int(nBins_ * (halfBox1_ + pos[axis1_]) / hmat(axis1_, axis1_));
164 int(nBins2_ * (halfBox2_ + pos[axis2_]) / hmat(axis2_, axis2_));
165 sliceSDLists_[binNo2][binNo1].push_back(sd);
169 for (
unsigned int i = 0; i < nBins2_; i++) {
170 for (
unsigned int j = 0; j < nBins_; j++) {
171 RealType totalVelocity = 0;
172 for (
unsigned int k = 0; k < sliceSDLists_[i][j].size(); ++k) {
173 totalVelocity += sliceSDLists_[i][j][k]->getVel()[axis3_];
176 if (sliceSDLists_[i][j].size() > 0)
177 velocity_[i][j] += totalVelocity / sliceSDLists_[i][j].size();
185 void VelocityZ::writeVelocity() {
189 for (std::vector<RealType>::iterator j = zBox_.begin(); j != zBox_.end();
193 RealType zAve = zSum / zBox_.size();
195 std::ofstream rdfStream(outputFilename_.c_str());
196 if (rdfStream.is_open()) {
197 rdfStream <<
"#VelocityZ\n";
198 rdfStream <<
"#nFrames:\t" << nProcessed_ <<
"\n";
199 rdfStream <<
"#selection: (" << selectionScript_ <<
")\n";
200 rdfStream <<
"#velocity (" << axisLabel1_ <<
"," << axisLabel2_ <<
")\n";
202 for (
unsigned int i = 0; i < velocity_.size(); ++i) {
203 RealType z = zAve * (i + 0.5) / velocity_.size();
204 rdfStream << z <<
"\t";
205 for (
unsigned int j = 0; j < velocity_[i].size(); ++j) {
206 rdfStream << velocity_[i][j] / nProcessed_;
213 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
214 "VelocityZ: unable to open %s\n", outputFilename_.c_str());
215 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)