--- trunk/src/applications/staticProps/RNEMDStats.cpp 2013/06/16 15:15:42 1879 +++ trunk/src/applications/staticProps/RNEMDStats.cpp 2013/06/18 17:08:40 1884 @@ -43,6 +43,7 @@ #include #include #include "applications/staticProps/RNEMDStats.hpp" +#include "primitives/Molecule.hpp" #include "utils/PhysicalConstants.hpp" namespace OpenMD { @@ -84,40 +85,101 @@ namespace OpenMD { data_.push_back(density); } - void RNEMDZ::processStuntDouble(StuntDouble* sd, int bin) { - RealType mass = sd->getMass(); - Vector3d pos = sd->getPos(); - Vector3d vel = sd->getVel(); - RealType KE = 0.5 * (mass * vel.lengthSquare()); - int dof = 3; + void RNEMDZ::processFrame(int istep) { + RealType z; - if (sd->isDirectional()) { - Vector3d angMom = sd->getJ(); - Mat3x3d I = sd->getI(); - if (sd->isLinear()) { - int i = sd->linearAxis(); - int j = (i + 1) % 3; - int k = (i + 2) % 3; - KE += 0.5 * (angMom[j] * angMom[j] / I(j, j) + - angMom[k] * angMom[k] / I(k, k)); - dof += 2; - } else { - KE += 0.5 * (angMom[0] * angMom[0] / I(0, 0) + - angMom[1] * angMom[1] / I(1, 1) + - angMom[2] * angMom[2] / I(2, 2)); - dof += 3; + hmat_ = currentSnapshot_->getHmat(); + for (int i = 0; i < nBins_; i++) { + z = (((RealType)i + 0.5) / (RealType)nBins_) * hmat_(2,2); + dynamic_cast(z_->accumulator[i])->add(z); + } + volume_ = currentSnapshot_->getVolume(); + + + Molecule* mol; + RigidBody* rb; + StuntDouble* sd; + SimInfo::MoleculeIterator mi; + Molecule::RigidBodyIterator rbIter; + int i; + + vector binMass(nBins_, 0.0); + vector binVel(nBins_, V3Zero); + vector binKE(nBins_, 0.0); + vector binDof(nBins_, 0); + vector binCount(nBins_, 0); + + + for (mol = info_->beginMolecule(mi); mol != NULL; + mol = info_->nextMolecule(mi)) { + + // change the positions of atoms which belong to the rigidbodies + + for (rb = mol->beginRigidBody(rbIter); rb != NULL; + rb = mol->nextRigidBody(rbIter)) { + rb->updateAtoms(); } } + + if (evaluator_.isDynamic()) { + seleMan_.setSelectionSet(evaluator_.evaluate()); + } - RealType temp = 2.0 * KE / (dof * PhysicalConstants::kb * - PhysicalConstants::energyConvert); - RealType den = mass * nBins_ * PhysicalConstants::densityConvert / volume_; + // loop over the selected atoms: - dynamic_cast(temperature->accumulator[bin])->add(temp); - dynamic_cast(velocity->accumulator[bin])->add(vel); - dynamic_cast(density->accumulator[bin])->add(den); + for (sd = seleMan_.beginSelected(i); sd != NULL; + sd = seleMan_.nextSelected(i)) { + + // figure out where that object is: + Vector3d pos = sd->getPos(); + Vector3d vel = sd->getVel(); + RealType m = sd->getMass(); + int bin = getBin(pos); + + binCount[bin] += 1; + + binMass[bin] += m; + binVel[bin] += vel; + binKE[bin] += 0.5 * (m * vel.lengthSquare()); + binDof[bin] += 3; + + if (sd->isDirectional()) { + Vector3d angMom = sd->getJ(); + Mat3x3d I = sd->getI(); + if (sd->isLinear()) { + int i = sd->linearAxis(); + int j = (i + 1) % 3; + int k = (i + 2) % 3; + binKE[bin] += 0.5 * (angMom[j] * angMom[j] / I(j, j) + + angMom[k] * angMom[k] / I(k, k)); + binDof[bin] += 2; + } else { + binKE[bin] += 0.5 * (angMom[0] * angMom[0] / I(0, 0) + + angMom[1] * angMom[1] / I(1, 1) + + angMom[2] * angMom[2] / I(2, 2)); + binDof[bin] += 3; + } + } + } + + for (unsigned int i = 0; i < nBins_; i++) { + if (binDof[i] > 0) { + RealType temp = 2.0 * binKE[i] / (binDof[i] * PhysicalConstants::kb * + PhysicalConstants::energyConvert); + RealType den = binMass[i] * nBins_ * PhysicalConstants::densityConvert + / volume_; + Vector3d vel = binVel[i] / RealType(binCount[i]); + dynamic_cast(temperature->accumulator[i])->add(temp); + dynamic_cast(velocity->accumulator[i])->add(vel); + dynamic_cast(density->accumulator[i])->add(den); + dynamic_cast(counts_->accumulator[i])->add(1); + } + } } + + void RNEMDZ::processStuntDouble(StuntDouble* sd, int bin) { + } RNEMDR::RNEMDR(SimInfo* info, const std::string& filename, const std::string& sele, int nrbins)