25 #include <mxx/comm.hpp>
33 return ( x >= 0 ) ? floor( x + 0.5 ) : ceil( x - 0.5 );
71 std::vector<std::vector<double> >
sigma_;
249 Hinv_ = hmat.inverse();
411 return H_*image.cast<
double>()+v;
422 for(
int i = 0; i < 3; ++i)
437 for(
int i = 0; i < 3; ++i)
454 for(
auto& i : indices)
456 MPI_Allreduce(MPI_IN_PLACE, &mtot, 1, MPI_DOUBLE, MPI_SUM,
comm_);
486 std::vector<double> pos, mass, gpos, gmass;
487 std::vector<int> pcounts(
comm_.size(), 0), mcounts(
comm_.size(), 0);
488 std::vector<int> pdispls(
comm_.size()+1, 0), mdispls(
comm_.size()+1, 0);
490 pcounts[
comm_.rank()] = 3*indices.size();
491 mcounts[
comm_.rank()] = indices.size();
494 MPI_Allreduce(MPI_IN_PLACE, pcounts.data(), pcounts.size(), MPI_INT, MPI_SUM,
comm_);
495 MPI_Allreduce(MPI_IN_PLACE, mcounts.data(), mcounts.size(), MPI_INT, MPI_SUM,
comm_);
498 std::partial_sum(pcounts.begin(), pcounts.end(), pdispls.begin() + 1);
499 std::partial_sum(mcounts.begin(), mcounts.end(), mdispls.begin() + 1);
502 for(
auto& idx : indices)
512 gpos.resize(pdispls.back(), 0);
513 gmass.resize(mdispls.back(), 0);
516 MPI_Allgatherv(pos.data(), pos.size(), MPI_DOUBLE, gpos.data(), pcounts.data(), pdispls.data(), MPI_DOUBLE,
comm_);
517 MPI_Allgatherv(mass.data(), mass.size(), MPI_DOUBLE, gmass.data(), mcounts.data(), mdispls.data(), MPI_DOUBLE,
comm_);
522 Vector3 ppos = {gpos[0], gpos[1], gpos[2]};
526 for(
size_t i = 1, j = 3; i < gmass.size(); ++i, j += 3)
528 cpos = {gpos[j], gpos[j+1], gpos[j+2]};
530 xcm += gmass[i]*cpos;
579 indices->push_back(idx);
651 std::vector<int> pcounts(
comm_.size(), 0);
652 std::vector<int> pdispls(
comm_.size()+1, 0);
657 MPI_Allreduce(MPI_IN_PLACE, pcounts.data(), pcounts.size(), MPI_INT, MPI_SUM,
comm_);
660 std::partial_sum(pcounts.begin(), pcounts.end(), pdispls.begin() + 1);
663 std::vector<double> positions;
664 positions.resize(pdispls.back(), 0);
666 std::vector<double> ptemp;
670 ptemp.push_back(p[0]);
671 ptemp.push_back(p[1]);
672 ptemp.push_back(p[2]);
676 MPI_Allgatherv(ptemp.data(), ptemp.size(), MPI_DOUBLE, positions.data(), pcounts.data(), pdispls.data(), MPI_DOUBLE,
comm_);
683 std::vector<int> vcounts(
comm_.size(), 0);
684 std::vector<int> vdispls(
comm_.size()+1, 0);
689 MPI_Allreduce(MPI_IN_PLACE, vcounts.data(), vcounts.size(), MPI_INT, MPI_SUM,
comm_);
692 std::partial_sum(vcounts.begin(), vcounts.end(), vdispls.begin() + 1);
695 std::vector<double> velocities;
696 velocities.resize(vdispls.back(), 0);
698 std::vector<double> vtemp;
702 vtemp.push_back(v[0]);
703 vtemp.push_back(v[1]);
704 vtemp.push_back(v[2]);
708 MPI_Allgatherv(vtemp.data(), vtemp.size(), MPI_DOUBLE, velocities.data(), vcounts.data(), vdispls.data(), MPI_DOUBLE,
comm_);
715 std::vector<int> mcounts(
comm_.size(), 0);
716 std::vector<int> mdispls(
comm_.size()+1, 0);
721 MPI_Allreduce(MPI_IN_PLACE, mcounts.data(), mcounts.size(), MPI_INT, MPI_SUM,
comm_);
724 std::partial_sum(mcounts.begin(), mcounts.end(), mdispls.begin() + 1);
727 std::vector<int> IDs;
728 IDs.resize(mdispls.back(), 0);
731 MPI_Allgatherv(
atomids_.data(),
atomids_.size(), MPI_INT, IDs.data(), mcounts.data(), mdispls.data(), MPI_INT,
comm_);
bool changed_
TRUE is Simulation state changed
std::vector< Integer3 > & GetImageFlags()
Access the particles image flags.
void SetOrigin(const Vector3 &origin)
Change the box origin.
uint nlocal_
Number of atoms located on this snapshot.
unsigned GetWalkerID() const
Get walker ID.
std::vector< int > Label
List of integers.
Eigen::Matrix3d Matrix3
3x3 matrix.
const std::vector< double > & GetCharges() const
Access the atom charges.
int GetIteration() const
Get the current iteration.
Eigen::Vector3i Integer3
Three-dimensional integer vector.
std::vector< Integer3 > images_
Unwrapped positions.
int iteration_
Iteration of Simulation.
unsigned GetNumAtoms() const
Get number of atoms in this snapshot.
const Matrix3 & GetVirial() const
Get box virial.
void Changed(bool state)
Set the "changed" flag of the Snapshot.
std::vector< Vector3 > forces_
Forces.
void SetNumAtoms(unsigned int natoms)
Set number of atoms in this snapshot.
const std::vector< Integer3 > & GetImageFlags() const
Access the particles image flags.
Matrix3 H_
Parrinello-Rahman box H-matrix.
double kb_
Kb from the MD driver.
Label & GetAtomIDs()
Access the atom IDs.
double TotalMass(const Label &indices) const
Compute the total mass of a group of particles based on index.
Class containing a snapshot of the current simulation in time.
std::vector< Vector3 > positions_
Positions.
const Vector3 & GetOrigin() const
Get origin of the system.
std::vector< Vector3 > & GetForces()
Access the per-particle forces.
Vector3 ScaleVector(const Vector3 &v) const
Scale a vector into fractional coordinates.
Matrix3 Hinv_
Parinello-Rahman box inverse.
void SetVirial(const Matrix3 &virial)
Change the box virial.
const Bool3 & IsPeriodic() const
Get periodicity of three dimensions.
void SetTargetIterations(int target)
Set target iterations.
double energy_
Average per-particle energy.
std::vector< double > SerializePositions()
Return the serialized positions across all local cores.
std::vector< double > charges_
Charges.
bool HasChanged() const
Query if Snapshot was modified.
double GetDielectric() const
Get dielectric constant.
double temperature_
Current temperature.
void SetEnergy(double energy)
Change the energy.
std::vector< int > SerializeIDs()
Return the serialized positions across all local cores.
std::vector< double > & GetCharges()
Access the atom charges.
int GetLocalIndex(int id) const
Gets the local atom index corresponding to an atom ID.
std::vector< std::vector< double > > & GetSigmas()
Access the atom sigmas.
Bool3 isperiodic_
Periodicity of box.
const mxx::comm & GetCommunicator() const
Get communicator for walker.
const std::vector< std::vector< double > > & GetSigmas() const
Access the atom sigmas.
std::vector< std::vector< double > > sigma_
Sigma.
void GetLocalIndices(const Label &ids, Label *indices) const
double Getqqrd2e() const
Get qqrd2e value.
void SetPeriodicity(const Bool3 &isperiodic)
Change the periodicity of the system.
mxx::comm comm_
Local snapshot (walker) communicator.
const Label & GetAtomIDs() const
Access the atom IDs.
Snapshot(const MPI_Comm &comm, uint wid)
Constructor.
int GetTargetIterations() const
Get target iterations.
std::vector< double > masses_
Masses.
Label types_
List of Atom types.
double GetTemperature() const
Get current temperature.
const Label & GetAtomTypes() const
Access the atom types.
double GetVolume() const
Get system volume.
Vector3 CenterOfMass(const Label &indices) const
double dielectric_
Dielectric.
const std::vector< double > & GetMasses() const
Const access to the particle masses.
Label & GetAtomTypes()
Access the atom types.
void SetIteration(int iteration)
Set the iteration.
double GetEnergy() const
Get per-particle energy.
std::vector< Vector3 > velocities_
Velocities.
void SetDielectric(double dielectric)
Set the dielectric constant.
void SetKb(double kb)
Change the kb.
void SetTemperature(double temperature)
Change the temperature.
double roundf(double x)
Quick helper function to round a double.
std::vector< Vector3 > & GetVelocities()
Access the particle velocities.
Vector3 ApplyMinimumImage(const Vector3 &v) const
Apply minimum image to a vector.
Vector3 CenterOfMass(const Label &indices, double mtot) const
Vector3 origin_
< Virial tensor.
double GetKb() const
Get system Kb.
std::string ID_
ID string.
Eigen::Vector3d Vector3
Three-dimensional vector.
int targetiter_
Iteration target of simulation.
const std::string & GetSnapshotID() const
Access the snapshot ID.
void ApplyMinimumImage(Vector3 *v) const
Apply minimum image to a vector.
void SetHMatrix(const Matrix3 &hmat)
Change the Box H-matrix.
std::string & GetSnapshotID()
Access the snapshot ID.
std::vector< double > SerializeVelocities()
Return the serialized velocities across all local cores.
Label atomids_
List of Atom IDs.
const std::vector< Vector3 > & GetVelocities() const
Access the particle velocities.
void Setqqrd2e(double qqrd2e)
Set the value for qqrd2e.
Vector3 UnwrapVector(const Vector3 &v, const Integer3 &image) const
Unwrap a vector's real coordinates according to its image replica count.
const std::vector< Vector3 > & GetForces() const
Access the per-particle forces.
const std::vector< Vector3 > & GetPositions() const
Access the particle positions.
std::vector< double > & GetMasses()
Const access to the particle masses.
const Matrix3 & GetHMatrix() const
Get system H-matrix.
std::vector< Vector3 > & GetPositions()
Access the particle positions.
Matrix3 & GetVirial()
Get box virial.
Eigen::Matrix< bool, 3, 1 > Bool3
Three-dimensional boolean.