8 #include "PairPotential.h" 9 #include <ddMd/simulation/Simulation.h> 10 #include <ddMd/storage/AtomStorage.h> 11 #include <ddMd/storage/AtomIterator.h> 12 #include <ddMd/storage/GhostIterator.h> 13 #include <ddMd/neighbor/PairIterator.h> 14 #include <ddMd/neighbor/PairList.h> 15 #include <ddMd/neighbor/CellList.h> 16 #include <ddMd/communicate/Domain.h> 17 #include <util/mpi/MpiLoader.h> 18 #include <util/space/Vector.h> 47 domainPtr_(&simulation.
domain()),
48 boundaryPtr_(&simulation.
boundary()),
49 storagePtr_(&simulation.atomStorage()),
91 read<double>(in,
"skin",
skin_);
93 readOptional<int>(in,
"nCellCut",
nCellCut_);
106 loadParameter<double>(ar,
"skin",
skin_);
107 loadParameter<int>(ar,
"nCellCut",
nCellCut_,
false);
109 loadParameter<Boundary>(ar,
"maxBoundary",
maxBoundary_);
113 loader.load(methodId_);
135 void PairPotential::allocate()
162 UTIL_THROW(
"Coordinates are Cartesian entering buildCellList");
180 for ( ; atomIter.
notEnd(); ++atomIter) {
187 for ( ; ghostIter.
notEnd(); ++ghostIter) {
199 UTIL_THROW(
"Coordinates are Cartesian exiting buildCellList");
208 if (!
storage().isCartesian()) {
209 UTIL_THROW(
"Coordinates not Cartesian entering buildPairList");
218 {
return pairEnergies_.value(); }
224 { pairEnergies_.set(pairEnergies); }
230 { pairEnergies_.unset(); }
242 double cutSq = cut*cut;
245 localNPair = nPairList(cutSq);
248 localNPair = nPairCell(cutSq);
250 localNPair = nPairNSq(cutSq);
254 communicator.Reduce(&localNPair, &nPair_, 1, MPI::INT, MPI::SUM, 0);
272 int PairPotential::nPairList(
double cutoffSq)
282 iter.
getPair(atom0Ptr, atom1Ptr);
286 if (rsq < cutoffSq) {
292 iter.
getPair(atom0Ptr, atom1Ptr);
296 if (rsq < cutoffSq) {
311 int PairPotential::nPairCell(
double cutoffSq)
327 na = cellPtr->
nAtom();
328 nn = neighbors.
size();
329 for (i = 0; i < na; ++i) {
330 atomPtr0 = neighbors[i]->ptr();
333 for (j = 0; j < na; ++j) {
334 atomPtr1 = neighbors[j]->ptr();
335 if (atomPtr1 > atomPtr0) {
338 if (rsq < cutoffSq) {
346 for (j = na; j < nn; ++j) {
347 atomPtr1 = neighbors[j]->ptr();
350 if (rsq < cutoffSq) {
355 for (j = na; j < nn; ++j) {
356 atomPtr1 = neighbors[j]->ptr();
359 if (rsq < cutoffSq) {
378 int PairPotential::nPairNSq(
double cutoffSq)
389 for ( ; atomIter0.
notEnd(); ++atomIter0) {
390 id0 = atomIter0->id();
394 for ( ; atomIter1.
notEnd(); ++atomIter1) {
395 id1 = atomIter1->id();
397 if (!atomIter0->mask().isMasked(id1)) {
398 f.
subtract(atomIter0->position(), atomIter1->position());
400 if (rsq < cutoffSq) {
410 for ( ; ghostIter.
notEnd(); ++ghostIter) {
411 id1 = ghostIter->id();
413 if (!atomIter0->mask().isMasked(id1)) {
414 f.
subtract(atomIter0->position(), ghostIter->position());
416 if (rsq < cutoffSq) {
423 for ( ; ghostIter.
notEnd(); ++ghostIter) {
424 id1 = ghostIter->id();
425 if (!atomIter0->mask().isMasked(id1)) {
426 f.
subtract(atomIter0->position(), ghostIter->position());
428 if (rsq < cutoffSq) {
const Cell * begin() const
Return pointer to first local cell in linked list.
void makeGrid(const Vector &lower, const Vector &upper, const Vector &cutoffs, int nCellCut=1)
Make the cell grid (using generalized coordinates).
Boundary & boundary()
Get the PairList by const reference.
const int Dimension
Dimensionality of space.
A Vector is a Cartesian vector.
void computeNPair(MPI::Intracomm &communicator)
Compute twice the number of pairs within the force cutoff.
void placeAtom(Atom &atom)
Determine the appropriate cell for an Atom, based on its position.
int nCellCut_
Approximate number of cells per cutoff distance in each direction.
Domain & domain()
Get the PairList by const reference.
An orthorhombic periodic unit cell.
double skin_
Difference between pairlist cutoff and pair potential cutoff.
Vector & position()
Get position Vector by reference.
void buildPairList()
Build the Verlet Pair list.
double cutoff_
Minimum cell size = pair potential cutoff + skin.
void getPair(Atom *&atom1Ptr, Atom *&atom2Ptr) const
Get pointers for current pair of Atoms.
int nAtom() const
Get total number of atoms (local and ghost) in this CellList.
File containing preprocessor macros for error handling.
void begin(PairIterator &iterator) const
Initialize a PairIterator.
A point particle in an MD simulation.
Parallel domain decomposition (DD) MD simulation.
bool isValid() const
Return true if valid, or throw Exception.
Main object for a domain-decomposition MD simulation.
void buildCellList()
Build a cell list.
int pairCapacity_
Maximum number of nonbonded pairs in pair list.
int nAtom() const
Return number of local atoms on this procesor (excluding ghosts)
virtual ~PairPotential()
Destructor.
void setPairEnergies(DMatrix< double > pairEnergies)
Set values for pair energies.
Saving / output archive for binary ostream.
bool notEnd() const
Return true if not at end of PairList.
int methodId() const
Return integer id for algorithm (0=PAIR, 1=CELL, 2=NSQ)
A fixed capacity (static) contiguous array with a variable logical size.
CellList cellList_
CellList to construct PairList or calculate nonbonded pair forces.
void unsetPairEnergies()
Mark pair energy as unknown (nullify).
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
bool isGhost() const
Is this atom a ghost?
void initialize(const Boundary &maxBoundary, double skin, int pairCapacity)
Set parameters and allocate memory.
int nGhost() const
Return current number of ghost atoms on this processor.
int nAtom() const
Number of atoms in cell.
bool notEnd() const
Is the current pointer not at the end of the PArray?
Utility classes for scientific computation.
virtual void save(Serializable::OArchive &ar)
Save internal state to an output archive.
void clear()
Reset the cell list to its empty state (no Atoms).
void build(CellList &cellList, bool reverseUpdateFlag=false)
Use a CellList to build a new PairList.
double length(int i) const
Get length in Cartesian direction i.
A container for all the atoms and ghost atoms on this processor.
void allocate(int atomCapacity, int pairCapacity, double cutoff)
Allocate memory and set cutoff.
bool reverseUpdateFlag() const
Get flag to identify if reverse communication is enabled.
int atomCapacity() const
Return capacity for local atoms on this processor (excluding ghosts).
PairList pairList_
Verlet pair list, to calculate nonbonded pair forces.
Decomposition of the system into domains associated with processors.
DMatrix< double > pairEnergies() const
Return total pair energies, from all processors.
Saving archive for binary istream.
Boundary maxBoundary_
Boundary used to allocate space for the cell list.
void getNeighbors(NeighborArray &neighbors, bool reverseUpdateFlag=false) const
Fill an array with pointers to atoms in a cell and neighboring cells.
AtomStorage & storage()
Get the AtomStorage by reference.
double domainBound(int i, int j) const
Get one boundary of the domain owned by this processor.
int nPair() const
Return twice the number of pairs within the specified force cutoff.
Provides methods for MPI-aware loading of data from input archive.
int ghostCapacity() const
Return capacity for ghost atoms on this processor.
bool isCartesian() const
Are atom coordinates Cartesian (true) or generalized (false)?
Iterator for all ghost atoms owned by an AtomStorage.
int nReject() const
Get number of atoms that were rejected (not placed in cells)
Vector & subtract(const Vector &v1, const Vector &v2)
Subtract vector v2 from v1.
void setClassName(const char *className)
Set class name string.
virtual void loadParameters(Serializable::IArchive &ar)
Load parameters for PairList from archive, and allocate memory.
void readParameters(std::istream &in)
Initialize, by reading parameters and allocating memory for PairList.
double skin() const
Get value of the pair list skin.
void allocate(int atomCapacity, const Vector &lower, const Vector &upper, const Vector &cutoffs, int nCellCut=1)
Allocate memory for this CellList (generalized coordinates).
Iterator for pairs in a PairList.
Iterator for all atoms owned by an AtomStorage.
static void saveOptional(Serializable::OArchive &ar, Type &value, bool isActive)
Save an optional parameter value to an output archive.
void build()
Build the cell list.
int size() const
Return logical size of this array (i.e., number of elements).
double square() const
Return square magnitude of this vector.
void begin(AtomIterator &iterator)
Set iterator to beginning of the set of atoms.
PairPotential()
Default constructor.
const Cell * nextCellPtr() const
Return a pointer to neighbor cell i.
A single Cell in a CellList.
virtual double maxPairCutoff() const =0
Return maximum cutoff.
void associate(Domain &domain, Boundary &boundary, AtomStorage &storage)
Associate with related objects.