void System::removeTotalMomentum() { StatisticsSampler sampler; vector<double> momentum = sampler.calculateTotalMomentum(shared_from_this()); if(numberOfAtoms() > 0) { momentum[0] /= numberOfAtoms(); momentum[1] /= numberOfAtoms(); momentum[2] /= numberOfAtoms(); } atomManager().atoms().iterate([&](Atom &atom) { atom.velocity[0] -= momentum[0]*atom.type()->massInverse(); atom.velocity[1] -= momentum[1]*atom.type()->massInverse(); atom.velocity[2] -= momentum[2]*atom.type()->massInverse(); }); }
std::ostream& operator<<(std::ostream &stream, System &system) { StatisticsSampler sampler; stream << "System information:" << endl; stream << "Length [Å]: " << UnitConverter::lengthToAngstroms(system.systemLength()) << endl; stream << "Number of atoms: " << system.numberOfAtoms() << endl; stream << "Number of ghost atoms: " << system.numberOfGhostAtoms() << endl; stream << "Potentials (" << system.potentials().size() << "): " << endl; for(Potential *potential : system.potentials()) { stream << " " << potential->name() << endl; } std::shared_ptr<System> system_ptr(&system); vector<double> momentum = sampler.calculateTotalMomentum(system_ptr); stream << "Total momentum: (" << momentum.at(0) << "," << momentum.at(1) << "," << momentum.at(2) << ")"; return stream; }