1 #ifndef MCMD_CELL_LIST_H 2 #define MCMD_CELL_LIST_H 13 #include <mcMd/chemistry/Atom.h> 14 #include <simp/boundary/Boundary.h> 15 #include <util/space/IntVector.h> 16 #include <util/containers/DArray.h> 17 #include <util/containers/FSArray.h> 100 void setAtomCapacity(
int atomCapacity);
108 template <
class Archive>
109 void serialize(Archive& ar,
const unsigned int version);
128 void setup(
const Boundary &boundary,
double cutoff);
144 int cellIndexFromPosition(
const Vector &pos)
const;
151 void addAtom(
Atom &atom);
158 void deleteAtom(
Atom &atom);
175 void updateAtomCell(
Atom &atom,
const Vector &pos);
190 getNeighbors(
const Vector &pos, NeighborArray &neighbors)
const;
209 getCellNeighbors(
int ic, NeighborArray &neighbors,
int &nInCell)
const;
216 int gridDimension(
int i)
const;
221 int totCells()
const;
231 int atomCapacity()
const;
242 bool isValid(
int nAtom=-1)
const;
308 void setCellsAxis(
int axis,
double cutoff);
319 int shiftCellCoordAxis(
int i,
int x)
const;
328 int cellIndexFromCoord(
int cx,
int cy,
int cz)
const;
333 void cellCoordFromIndex(
int i,
int &cx,
int &cy,
int &cz)
const;
338 bool isValidAtomId(
int atomId)
339 {
return ( (0 <= atomId) && (atomId < cellTags_.
capacity()) ); }
345 friend class ::CellListTest;
356 {
return totCells_; }
368 cx = int(posG[0]*invCellWidths_[0]);
369 cy = int(posG[1]*invCellWidths_[1]);
370 cz = int(posG[2]*invCellWidths_[2]);
374 assert(cx < numCells_[0]);
376 assert(cy < numCells_[1]);
378 assert(cz < numCells_[2]);
380 return cz + cy*numCells_[2] + cx*YZCells_;
388 int atomId = atom.
id();
389 assert(isValidAtomId(atomId));
390 CellTag& cellTag = cellTags_[atomId];
391 cells_[cellTag.
cellId].deleteAtom(cellTag);
400 int cellId = cellIndexFromPosition(position);
401 int atomId = atom.
id();
402 assert(isValidAtomId(atomId));
403 cells_[cellId].addAtom(cellTags_[atomId], atom, cellId);
411 int atomId = atom.
id();
412 assert(isValidAtomId(atomId));
413 CellTag& cellTag = cellTags_[atomId];
414 int oldCell = cellTag.
cellId;
415 int newCell = cellIndexFromPosition(pos);
416 if (oldCell != newCell) {
417 cells_[oldCell].deleteAtom(cellTag);
418 cells_[newCell].addAtom(cellTag, atom, newCell);
429 int ic = cellIndexFromPosition(pos);
430 getCellNeighbors(ic, neighbors, nInCell);
439 inline int CellList::shiftCellCoordAxis(
int i,
int x)
const 441 if (x > maxCells_[i])
return x - numCells_[i];
442 if (x < minCells_[i])
return x + numCells_[i];
449 inline int CellList::cellIndexFromCoord(
int cx,
int cy,
int cz)
const 451 return cx*YZCells_ + cy*numCells_[2] + cz ;
458 void CellList::cellCoordFromIndex(
int i,
int &cx,
int &cy,
int &cz)
const 460 cx = (int)(i / YZCells_);
462 cy = (int)(i / numCells_[2]);
463 cz = i - cy*numCells_[2];
467 {
return numCells_[i]; }
472 template <
class Archive>
485 if (ar.is_loading()) {
A Vector is a Cartesian vector.
void getNeighbors(const Vector &pos, NeighborArray &neighbors) const
Fill a NeighborArray with pointers to atoms near a specified position.
An orthorhombic periodic unit cell.
int cellIndexFromPosition(const Vector &pos) const
Return index of the cell that contains the position pos = (x,y,z).
int cellId
Cell index of Cell containing associated Atom.
File containing preprocessor macros for error handling.
Classes used by all simpatico molecular simulations.
void serialize(Archive &ar, PairSelector &selector, const unsigned int version)
Serialize a PairSelector.
void serialize(Archive &ar, const unsigned int version)
Serialize to/from an Archive.
A point particle within a Molecule.
Utility classes for scientific computation.
Location of the pointer to a particular Atom in a CellList.
int id() const
Get global index for this Atom within the Simulation.
int totCells() const
Get total number of cells in this CellList.
void deleteAtom(Atom &atom)
Delete a Atom object from its cell.
A cell list for Atom objects in a periodic system boundary.
void updateAtomCell(Atom &atom, const Vector &pos)
Update CellList to reflect a new atom position.
static const int MaxAtomCell
Maximum number of atoms per cell.
Dynamically allocatable contiguous array template.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
An IntVector is an integer Cartesian vector.
int capacity() const
Return allocated size.
void allocate(int capacity)
Allocate the underlying C array.
const Vector & position() const
Get the position Vector by const reference.
int gridDimension(int i) const
Number of cells along axis i.
void addAtom(Atom &atom)
Add a Atom to the appropriate cell, based on its position.
FSArray< Atom *, MaxNeighbor > NeighborArray
Static array for holding neighbors in a cell list.
void transformCartToGen(const Vector &Rc, Vector &Rg) const
Transform Cartesian Vector to scaled / generalized coordinates.