Verylong operator* (const Verylong &u, const Verylong &v) { Verylong pprod("1"), tempsum("0"); for (int j=0; j<v.vlen; j++) { int digit = v.vlstr[j] - '0'; pprod = u.multdigit(digit); pprod = pprod.mult10(j); tempsum += pprod; } tempsum.vlsign = u.vlsign ^ v.vlsign; return tempsum; }
void MomentumCorrFunc::correlateFrames(int frame1, int frame2) { SimInfo::MoleculeIterator mi1; SimInfo::MoleculeIterator mi2; Molecule* mol1; Molecule* mol2; Molecule::AtomIterator ai1; Molecule::AtomIterator ai2; Atom* atom1; Atom* atom2; std::vector<Vector3d> atomPositions1; std::vector<Vector3d> atomPositions2; std::vector<Vector3d> atomVelocity1; std::vector<Vector3d> atomVelocity2; int thisAtom1, thisAtom2; Snapshot* snapshot1 = bsMan_->getSnapshot(frame1); Snapshot* snapshot2 = bsMan_->getSnapshot(frame2); assert(snapshot1 && snapshot2); RealType time1 = snapshot1->getTime(); RealType time2 = snapshot2->getTime(); int timeBin = int ((time2 - time1) /deltaTime_ + 0.5); updateFrame(frame1); atomPositions1.clear(); for (mol1 = info_->beginMolecule(mi1); mol1 != NULL; mol1 = info_->nextMolecule(mi1)) { for(atom1 = mol1->beginAtom(ai1); atom1 != NULL; atom1 = mol1->nextAtom(ai1)) { atomPositions1.push_back(atom1->getPos(frame1)); atomVelocity1.push_back(atom1->getVel(frame1)); } } updateFrame(frame2); atomPositions2.clear(); for (mol2 = info_->beginMolecule(mi2); mol2 != NULL; mol2 = info_->nextMolecule(mi2)) { for(atom2 = mol2->beginAtom(ai2); atom2 != NULL; atom2 = mol2->nextAtom(ai2)) { atomPositions2.push_back(atom2->getPos(frame2)); atomVelocity2.push_back(atom2->getVel(frame2)); } } thisAtom1 = 0; for (mol1 = info_->beginMolecule(mi1); mol1 != NULL; mol1 = info_->nextMolecule(mi1)) { for(atom1 = mol1->beginAtom(ai1); atom1 != NULL; atom1 = mol1->nextAtom(ai1)) { Vector3d r1 = atomPositions1[thisAtom1]; Vector3d p1 = atom1->getMass() * atomVelocity1[thisAtom1]; thisAtom2 = 0; for (mol2 = info_->beginMolecule(mi2); mol2 != NULL; mol2 = info_->nextMolecule(mi2)) { for(atom2 = mol2->beginAtom(ai2); atom2 != NULL; atom2 = mol2->nextAtom(ai2)) { Vector3d r2 = atomPositions2[thisAtom2]; Vector3d p2 = atom2->getMass() * atomVelocity1[thisAtom1]; Vector3d deltaPos = (r2-r1); Vector3d dp2( deltaPos.x() * deltaPos.x(), deltaPos.y() * deltaPos.y(), deltaPos.z() * deltaPos.z()); Vector3d pprod( p1.x() * p2.x(), p1.y() * p2.y(), p1.z() * p2.z()); histogram_[timeBin] += outProduct(dp2, pprod); thisAtom2++; } } thisAtom1++; } } count_[timeBin]++; }