53#include "applications/dynamicProps/MomentumCorrFunc.hpp"
54#include "utils/Revision.hpp"
61 MomentumCorrFunc::MomentumCorrFunc(SimInfo* info,
const std::string& filename,
62 const std::string& sele1,
63 const std::string& sele2)
64 : FrameTimeCorrFunc<Mat3x3d>(info, filename, sele1, sele2,
65 DataStorage::dslPosition |
66 DataStorage::dslVelocity){
68 setCorrFuncType(
"MomentumCorrFunc");
69 setOutputName(
getPrefix(dumpFilename_) +
".momcorr");
72 void MomentumCorrFunc::correlateFrames(
int frame1,
int frame2) {
73 SimInfo::MoleculeIterator mi1;
74 SimInfo::MoleculeIterator mi2;
77 Molecule::AtomIterator ai1;
78 Molecule::AtomIterator ai2;
82 std::vector<Vector3d> atomPositions1;
83 std::vector<Vector3d> atomPositions2;
84 std::vector<Vector3d> atomVelocity1;
85 std::vector<Vector3d> atomVelocity2;
86 int thisAtom1, thisAtom2;
88 Snapshot* snapshot1 = bsMan_->getSnapshot(frame1);
89 Snapshot* snapshot2 = bsMan_->getSnapshot(frame2);
91 assert(snapshot1 && snapshot2);
93 RealType time1 = snapshot1->getTime();
94 RealType time2 = snapshot2->getTime();
96 int timeBin = int ((time2 - time1) /deltaTime_ + 0.5);
98 atomPositions1.clear();
99 for (mol1 = info_->beginMolecule(mi1); mol1 != NULL;
100 mol1 = info_->nextMolecule(mi1)) {
101 for(atom1 = mol1->beginAtom(ai1); atom1 != NULL;
102 atom1 = mol1->nextAtom(ai1)) {
103 atomPositions1.push_back(atom1->getPos(frame1));
104 atomVelocity1.push_back(atom1->getVel(frame1));
108 atomPositions2.clear();
109 for (mol2 = info_->beginMolecule(mi2); mol2 != NULL;
110 mol2 = info_->nextMolecule(mi2)) {
111 for(atom2 = mol2->beginAtom(ai2); atom2 != NULL;
112 atom2 = mol2->nextAtom(ai2)) {
113 atomPositions2.push_back(atom2->getPos(frame2));
114 atomVelocity2.push_back(atom2->getVel(frame2));
120 for (mol1 = info_->beginMolecule(mi1); mol1 != NULL;
121 mol1 = info_->nextMolecule(mi1)) {
122 for(atom1 = mol1->beginAtom(ai1); atom1 != NULL;
123 atom1 = mol1->nextAtom(ai1)) {
125 Vector3d r1 = atomPositions1[thisAtom1];
126 Vector3d p1 = atom1->getMass() * atomVelocity1[thisAtom1];
130 for (mol2 = info_->beginMolecule(mi2); mol2 != NULL;
131 mol2 = info_->nextMolecule(mi2)) {
132 for(atom2 = mol2->beginAtom(ai2); atom2 != NULL;
133 atom2 = mol2->nextAtom(ai2)) {
135 Vector3d r2 = atomPositions2[thisAtom2];
136 Vector3d p2 = atom2->getMass() * atomVelocity1[thisAtom1];
138 Vector3d deltaPos = (r2-r1);
139 Vector3d dp2( deltaPos.x() * deltaPos.x(),
140 deltaPos.y() * deltaPos.y(),
141 deltaPos.z() * deltaPos.z());
142 Vector3d pprod( p1.x() * p2.x(),
146 histogram_[timeBin] += outProduct(dp2, pprod);
157 void MomentumCorrFunc::postCorrelate() {
158 for (
unsigned int i =0 ; i < nTimeBins_; ++i) {
160 histogram_[i] /= count_[i];
165 void MomentumCorrFunc::preCorrelate() {
167 std::fill(histogram_.begin(), histogram_.end(), Mat3x3d(0.0));
169 std::fill(count_.begin(), count_.end(), 0);
172 void MomentumCorrFunc::writeCorrelate() {
173 std::ofstream ofs(getOutputFileName().c_str());
178 ofs <<
"# " << getCorrFuncType() <<
"\n";
179 ofs <<
"# OpenMD " << r.getFullRevision() <<
"\n";
180 ofs <<
"# " << r.getBuildDate() <<
"\n";
181 ofs <<
"# selection script1: \"" << selectionScript1_ ;
182 ofs <<
"\"\tselection script2: \"" << selectionScript2_ <<
"\"\n";
183 if (!paramString_.empty())
184 ofs <<
"# parameters: " << paramString_ <<
"\n";
186 ofs <<
"#time\tcorrTensor\txx\txy\txz\tyx\tyy\tyz\tzx\tzy\tzz\n";
188 for (
unsigned int i = 0; i < nTimeBins_; ++i) {
189 ofs << time_[i] <<
"\t" <<
190 histogram_[i](0,0) <<
"\t" <<
191 histogram_[i](0,1) <<
"\t" <<
192 histogram_[i](0,2) <<
"\t" <<
193 histogram_[i](1,0) <<
"\t" <<
194 histogram_[i](1,1) <<
"\t" <<
195 histogram_[i](1,2) <<
"\t" <<
196 histogram_[i](2,0) <<
"\t" <<
197 histogram_[i](2,1) <<
"\t" <<
198 histogram_[i](2,2) <<
"\t" <<
"\n";
202 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
203 "MomentumCorrFunc::writeCorrelate Error: fail to open %s\n",
204 getOutputFileName().c_str());
205 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)