45#include "applications/dynamicProps/LegendreCorrFuncZ.hpp"
50#include "utils/Revision.hpp"
51#include "utils/simError.h"
54 LegendreCorrFuncZ::LegendreCorrFuncZ(
SimInfo* info,
55 const std::string& filename,
56 const std::string& sele1,
57 const std::string& sele2,
int order,
58 int nZbins,
int axis) :
60 nZBins_(nZbins), axis_(axis) {
61 setCorrFuncType(
"Legendre Correlation Function of Z");
62 setOutputName(
getPrefix(dumpFilename_) +
".lcorrZ");
64 std::stringstream params;
65 params <<
" order = " << order <<
", nzbins = " << nZBins_;
66 const std::string paramString = params.str();
67 setParameterString(paramString);
69 if (!uniqueSelections_) { seleMan2_ = seleMan1_; }
72 xaxis_ = (axis_ + 1) % 3;
73 yaxis_ = (axis_ + 2) % 3;
88 rotMats_.resize(nTimeBins_);
89 zbin_.resize(nTimeBins_);
90 histogram_.resize(nTimeBins_);
91 counts_.resize(nTimeBins_);
92 for (
unsigned int i = 0; i < nTimeBins_; i++) {
93 histogram_[i].resize(nZBins_);
94 std::fill(histogram_[i].begin(), histogram_[i].end(), 0.0);
95 counts_[i].resize(nZBins_);
96 std::fill(counts_[i].begin(), counts_[i].end(), 0);
99 legendre_ = polynomial.getLegendrePolynomial(order);
102 void LegendreCorrFuncZ::computeFrame(
int frame) {
104 boxZ_ = hmat(axis_, axis_);
105 halfBoxZ_ = boxZ_ / 2.0;
110 int LegendreCorrFuncZ::computeProperty1(
int frame,
StuntDouble* sd) {
112 rotMats_[frame].push_back(A);
115 if (info_->getSimParams()->getUsePeriodicBoundaryConditions())
117 int zBin = int(nZBins_ * (halfBoxZ_ + pos[axis_]) / boxZ_);
118 zbin_[frame].push_back(zBin);
120 return rotMats_[frame].size() - 1;
123 Vector3d LegendreCorrFuncZ::calcCorrVal(
int frame1,
int frame2,
int id1,
125 Vector3d v1x = rotMats_[frame1][id1].getRow(xaxis_);
126 Vector3d v1y = rotMats_[frame1][id1].getRow(yaxis_);
127 Vector3d v1z = rotMats_[frame1][id1].getRow(axis_);
129 Vector3d v2x = rotMats_[frame2][id2].getRow(xaxis_);
130 Vector3d v2y = rotMats_[frame2][id2].getRow(yaxis_);
131 Vector3d v2z = rotMats_[frame2][id2].getRow(axis_);
140 return Vector3d(uxprod, uyprod, uzprod);
143 void LegendreCorrFuncZ::correlateFrames(
int frame1,
int frame2,
int timeBin) {
147 std::vector<int>::iterator i1;
148 std::vector<int>::iterator i2;
152 s1 = sele1ToIndex_[frame1];
154 if (uniqueSelections_)
155 s2 = sele2ToIndex_[frame2];
157 s2 = sele1ToIndex_[frame2];
159 for (i1 = s1.begin(), i2 = s2.begin(); i1 != s1.end() && i2 != s2.end();
166 while (i1 != s1.end() && *i1 < *i2) {
170 while (i2 != s2.end() && *i2 < *i1) {
174 if (i1 == s1.end() || i2 == s2.end())
break;
176 corrVal = calcCorrVal(frame1, frame2, i1 - s1.begin(), i2 - s2.begin());
177 int zBin = zbin_[frame1][i1 - s1.begin()];
178 histogram_[timeBin][zBin] += corrVal;
179 counts_[timeBin][zBin]++;
183 void LegendreCorrFuncZ::postCorrelate() {
184 for (
unsigned int i = 0; i < nTimeBins_; ++i) {
185 for (
unsigned int j = 0; j < nZBins_; ++j) {
186 if (counts_[i][j] > 0) { histogram_[i][j] /= counts_[i][j]; }
197 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
198 "LegendreCorrFuncZ::validateSelection Error: "
199 "at least one of the selected objects is not Directional\n");
200 painCave.isFatal = 1;
206 void LegendreCorrFuncZ::writeCorrelate() {
207 std::ofstream ofs(getOutputFileName().c_str());
212 ofs <<
"# " << getCorrFuncType() <<
"\n";
213 ofs <<
"# OpenMD " << r.getFullRevision() <<
"\n";
214 ofs <<
"# " << r.getBuildDate() <<
"\n";
215 ofs <<
"# selection script1: \"" << selectionScript1_;
216 ofs <<
"\"\tselection script2: \"" << selectionScript2_ <<
"\"\n";
217 ofs <<
"# privilegedAxis computed as " << axisLabel_ <<
" axis \n";
218 if (!paramString_.empty())
219 ofs <<
"# parameters: " << paramString_ <<
"\n";
221 ofs <<
"#time\tPn(costheta_z)\n";
223 for (
unsigned int i = 0; i < nTimeBins_; ++i) {
224 ofs << times_[i] - times_[0];
226 for (
unsigned int j = 0; j < nZBins_; ++j) {
227 ofs <<
"\t" << histogram_[i][j](2);
233 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
234 "LegendreCorrFuncZ::writeCorrelate Error: failed to open %s\n",
235 getOutputFileName().c_str());
236 painCave.isFatal = 1;
A collection of Legendre Polynomials.
Real evaluate(const Real &x)
Calculates the value of this Polynomial evaluated at the given x value.
StuntDouble * nextSelected(int &i)
Finds the next selected StuntDouble in the selection.
StuntDouble * beginSelected(int &i)
Finds the first selected StuntDouble in the selection.
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
Mat3x3d getHmat()
Returns the H-Matrix.
void wrapVector(Vector3d &v)
Wrapping the vector according to periodic boundary condition.
"Don't move, or you're dead! Stand up! Captain, we've got them!"
RotMat3x3d getA()
Returns the current rotation matrix of this stuntDouble.
Vector3d getPos()
Returns the current position of this stuntDouble.
bool isDirectional()
Tests if this stuntDouble is a directional one.
Real length()
Returns the length of this vector.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
Real dot(const DynamicVector< Real > &v1, const DynamicVector< Real > &v2)
Returns the dot product of two DynamicVectors.
std::string getPrefix(const std::string &str)