25 #include <mxx/comm.hpp>
37 return ( x >= 0 ) ? floor( x + 0.5 ) : ceil( x - 0.5 );
94 Snapshot(
const MPI_Comm& comm,
unsigned int wid) :
251 Hinv_ = hmat.inverse();
394 for(
int i = 0; i < 3; ++i)
409 for(
int i = 0; i < 3; ++i)
426 for(
auto& i : indices)
428 MPI_Allreduce(MPI_IN_PLACE, &mtot, 1, MPI_DOUBLE, MPI_SUM,
comm_);
445 std::vector<double> pos, mass, gpos, gmass;
446 std::vector<int> pcounts(
comm_.size(), 0), mcounts(
comm_.size(), 0);
447 std::vector<int> pdispls(
comm_.size()+1, 0), mdispls(
comm_.size()+1, 0);
450 double mtot = mass_weight ?
TotalMass(indices) : indices.size();
452 pcounts[
comm_.rank()] = 3*indices.size();
453 mcounts[
comm_.rank()] = indices.size();
456 MPI_Allreduce(MPI_IN_PLACE, pcounts.data(), pcounts.size(), MPI_INT, MPI_SUM,
comm_);
457 MPI_Allreduce(MPI_IN_PLACE, mcounts.data(), mcounts.size(), MPI_INT, MPI_SUM,
comm_);
460 std::partial_sum(pcounts.begin(), pcounts.end(), pdispls.begin() + 1);
461 std::partial_sum(mcounts.begin(), mcounts.end(), mdispls.begin() + 1);
464 for(
auto& idx : indices)
474 gpos.resize(pdispls.back(), 0);
475 gmass.resize(mdispls.back(), 1.0);
478 MPI_Allgatherv(pos.data(), pos.size(), MPI_DOUBLE, gpos.data(), pcounts.data(), pdispls.data(), MPI_DOUBLE,
comm_);
480 MPI_Allgatherv(mass.data(), mass.size(), MPI_DOUBLE, gmass.data(), mcounts.data(), mdispls.data(), MPI_DOUBLE,
comm_);
486 Vector3 ppos = {gpos[0], gpos[1], gpos[2]};
490 for(
size_t i = 1, j = 3; i < gmass.size(); ++i, j += 3)
492 cpos = {gpos[j], gpos[j+1], gpos[j+2]};
494 xcm += gmass[i]*cpos;
543 indices->push_back(idx);
605 std::vector<int> pcounts(
comm_.size(), 0);
606 std::vector<int> pdispls(
comm_.size()+1, 0);
611 MPI_Allreduce(MPI_IN_PLACE, pcounts.data(), pcounts.size(), MPI_INT, MPI_SUM,
comm_);
614 std::partial_sum(pcounts.begin(), pcounts.end(), pdispls.begin() + 1);
617 std::vector<double> positions;
618 positions.resize(pdispls.back(), 0);
620 std::vector<double> ptemp;
624 ptemp.push_back(p[0]);
625 ptemp.push_back(p[1]);
626 ptemp.push_back(p[2]);
630 MPI_Allgatherv(ptemp.data(), ptemp.size(), MPI_DOUBLE, positions.data(), pcounts.data(), pdispls.data(), MPI_DOUBLE,
comm_);
640 std::vector<int> vcounts(
comm_.size(), 0);
641 std::vector<int> vdispls(
comm_.size()+1, 0);
646 MPI_Allreduce(MPI_IN_PLACE, vcounts.data(), vcounts.size(), MPI_INT, MPI_SUM,
comm_);
649 std::partial_sum(vcounts.begin(), vcounts.end(), vdispls.begin() + 1);
652 std::vector<double> velocities;
653 velocities.resize(vdispls.back(), 0);
655 std::vector<double> vtemp;
659 vtemp.push_back(v[0]);
660 vtemp.push_back(v[1]);
661 vtemp.push_back(v[2]);
665 MPI_Allgatherv(vtemp.data(), vtemp.size(), MPI_DOUBLE, velocities.data(), vcounts.data(), vdispls.data(), MPI_DOUBLE,
comm_);
675 std::vector<int> mcounts(
comm_.size(), 0);
676 std::vector<int> mdispls(
comm_.size()+1, 0);
681 MPI_Allreduce(MPI_IN_PLACE, mcounts.data(), mcounts.size(), MPI_INT, MPI_SUM,
comm_);
684 std::partial_sum(mcounts.begin(), mcounts.end(), mdispls.begin() + 1);
687 std::vector<int> IDs;
688 IDs.resize(mdispls.back(), 0);
691 MPI_Allgatherv(
atomids_.data(),
atomids_.size(), MPI_INT, IDs.data(), mcounts.data(), mdispls.data(), MPI_INT,
comm_);
Class containing a snapshot of the current simulation in time.
double GetKb() const
Get system Kb.
double energy_
Average per-particle energy.
const Matrix3 & GetVirial() const
Get box virial.
std::vector< double > masses_
Masses.
double Getqqrd2e() const
Get qqrd2e value.
std::string & GetSnapshotID()
Access the snapshot ID.
Vector3 origin_
Box origin.
void Setqqrd2e(double qqrd2e)
Set the value for qqrd2e.
const std::string & GetSnapshotID() const
Access the snapshot ID.
unsigned int nlocal_
Number of atoms located on this snapshot.
unsigned GetNumAtoms() const
Get number of atoms in this snapshot.
bool HasChanged() const
Query if Snapshot was modified.
std::vector< double > & GetCharges()
Access the atom charges.
double dielectric_
Dielectric.
std::vector< double > SerializeVelocities()
Return the serialized velocities across all local cores.
void GetLocalIndices(const Label &ids, Label *indices) const
Label atomids_
List of Atom IDs.
void Changed(bool state)
Set the "changed" flag of the Snapshot.
std::vector< Vector3 > & GetPositions()
Access the particle positions.
double GetTemperature() const
Get current temperature.
double temperature_
Current temperature.
Bool3 isperiodic_
Periodicity of box.
const std::vector< Vector3 > & GetForces() const
Access the per-particle forces.
std::vector< int > SerializeIDs()
Return the serialized IDs across all local cores.
mxx::comm comm_
Local snapshot (walker) communicator.
void SetPeriodicity(const Bool3 &isperiodic)
Change the periodicity of the system.
const Bool3 & IsPeriodic() const
Get periodicity of three dimensions.
void SetHMatrix(const Matrix3 &hmat)
Change the Box H-matrix.
std::vector< double > & GetMasses()
Const access to the particle masses.
const Matrix3 & GetHMatrix() const
Get system H-matrix.
double GetEnergy() const
Get per-particle energy.
void SetNumAtoms(unsigned int natoms)
Set number of atoms in this snapshot.
double GetVolume() const
Get system volume.
std::vector< Vector3 > positions_
Positions.
const mxx::comm & GetCommunicator() const
Get communicator for walker.
std::vector< Vector3 > velocities_
Velocities.
void SetVirial(const Matrix3 &virial)
Change the box virial.
void SetTargetIterations(int target)
Set target iterations.
size_t GetTargetIterations() const
Get target iterations.
Label & GetAtomTypes()
Access the atom types.
Label types_
List of Atom types.
void SetIteration(size_t iteration)
Set the iteration.
int GetLocalIndex(int id) const
Gets the local atom index corresponding to an atom ID.
std::vector< double > charges_
Charges.
Vector3 ApplyMinimumImage(const Vector3 &v) const
Apply minimum image to a vector.
double TotalMass(const Label &indices) const
Compute the total mass of a group of particles based on index.
Vector3 ScaleVector(const Vector3 &v) const
Scale a vector into fractional coordinates.
void SetEnergy(double energy)
Change the energy.
size_t targetiter_
Iteration target of simulation.
const std::vector< Vector3 > & GetPositions() const
Access the particle positions.
bool changed_
TRUE is Simulation state changed
Matrix3 H_
Parrinello-Rahman box H-matrix.
const Label & GetAtomTypes() const
Access the atom types.
Matrix3 virial_
Virial tensor.
Matrix3 & GetVirial()
Get box virial.
unsigned int wid_
Walker ID.
Matrix3 Hinv_
Parinello-Rahman box inverse.
Label & GetAtomIDs()
Access the atom IDs.
double kb_
Kb from the MD driver.
size_t GetIteration() const
Get the current iteration.
std::string ID_
ID string.
void SetTemperature(double temperature)
Change the temperature.
std::vector< Vector3 > forces_
Forces.
const std::vector< double > & GetMasses() const
Const access to the particle masses.
const std::vector< double > & GetCharges() const
Access the atom charges.
Vector3 CenterOfMass(const Label &indices, bool mass_weight=true) const
Compute center of mass of a group of atoms based on index.
std::vector< Vector3 > & GetForces()
Access the per-particle forces.
double GetDielectric() const
Get dielectric constant.
void SetOrigin(const Vector3 &origin)
Change the box origin.
const Label & GetAtomIDs() const
Access the atom IDs.
Snapshot(const MPI_Comm &comm, unsigned int wid)
Constructor.
void ApplyMinimumImage(Vector3 *v) const
Apply minimum image to a vector.
std::vector< Vector3 > & GetVelocities()
Access the particle velocities.
const std::vector< Vector3 > & GetVelocities() const
Access the particle velocities.
void SetDielectric(double dielectric)
Set the dielectric constant.
const Vector3 & GetOrigin() const
Get origin of the system.
std::vector< double > SerializePositions()
Return the serialized positions across all local cores.
void SetKb(double kb)
Change the kb.
unsigned GetWalkerID() const
Get walker ID.
size_t iteration_
Iteration of Simulation.
Eigen::Matrix3d Matrix3
3x3 matrix.
double roundf(double x)
Quick helper function to round a double.
Eigen::Vector3d Vector3
Three-dimensional vector.
Eigen::Matrix< bool, 3, 1 > Bool3
Three-dimensional boolean.
std::vector< int > Label
List of integers.