9 #include "PairIterator.h" 10 #include <mcMd/chemistry/Atom.h> 11 #include <util/space/Vector.h> 53 read<int>(in,
"atomCapacity", atomCapacity_);
54 read<int>(in,
"pairCapacity", pairCapacity_);
55 read<double>(in,
"skin", skin_);
63 loadParameter<int>(ar,
"atomCapacity", atomCapacity_);
64 loadParameter<int>(ar,
"pairCapacity", pairCapacity_);
65 loadParameter<double>(ar,
"skin", skin_);
92 UTIL_THROW(
"skin must be set before PairList::initialize");
96 cutoff_ = potentialCutoff + skin_;
107 void PairList::allocate()
110 if (atomCapacity_ <= 0 ) {
111 UTIL_THROW(
"atomCapacity_ not set in PairList::allocate");
113 if (pairCapacity_ <= 0 ) {
114 UTIL_THROW(
"pairCapacity_ not set in PairList::allocate");
118 atom1Ptrs_.allocate(atomCapacity_);
119 atom2Ptrs_.allocate(pairCapacity_);
121 oldPositions_.allocate(atomCapacity_);
124 for (
int i=0; i < atomCapacity_; ++i) {
126 first_[i] = PairList::NullIndex;
127 oldPositions_[i].zero();
129 first_[atomCapacity_] = PairList::NullIndex;
130 for (
int i=0; i < pairCapacity_; ++i) {
138 tList1_ = atomCapacity_ - 1;
141 isInitialized_ =
true;
149 cellList_.
setup(boundary, cutoff_);
153 tList1_ = atomCapacity_ - 1;
166 tList1_ = atomCapacity_ - 1;
177 Atom *iAtomPtr, *jAtomPtr;
178 double dRSq, cutoffSq;
179 int nCellNeighbor, nCellAtom, totCells;
180 int ic, ip, iAtomId, jp, jAtomId;
187 cutoffSq = cutoff_*cutoff_;
193 tList1_ = atomCapacity_ - 1;
198 for (ic = 0; ic < totCells; ++ic) {
204 nCellNeighbor = cellNeighbor.
size();
207 for (ip = 0; ip < nCellAtom; ++ip) {
208 iAtomPtr = cellNeighbor[ip];
210 iAtomId = iAtomPtr->
id();
212 if (nAtom_ > atomCapacity_) {
213 UTIL_THROW(
"Overflow: nAtom_ > atomCapacity_ in PairList");
217 foundNeighbor =
false;
220 for (jp = 0; jp < nCellNeighbor; ++jp) {
221 jAtomPtr = cellNeighbor[jp];
223 jAtomId = jAtomPtr->
id();
226 if ( jAtomId > iAtomId ) {
234 if (dRSq < cutoffSq) {
237 if (nAtom2_ >= pairCapacity_) {
238 UTIL_THROW(
"Overflow: # pairs > pairCapacity_");
242 if (!foundNeighbor) {
244 assert(nAtom1_ < atomCapacity_);
245 assert(nAtom1_ >= 0);
246 assert(tList1_ >= nAtom1_);
248 atom1Ptrs_[nAtom1_] = iAtomPtr;
249 oldPositions_[nAtom1_] = iPos;
250 foundNeighbor =
true;
254 assert(tList1_ < atomCapacity_);
255 atom2Ptrs_[nAtom2_] = jAtomPtr;
268 first_[nAtom1_] = nAtom2_;
271 assert(tList1_ >= nAtom1_);
272 assert(tList1_ < atomCapacity_);
273 assert(tList1_ >= 0);
274 atom1Ptrs_[tList1_] = iAtomPtr;
275 oldPositions_[tList1_] = iPos;
287 if (nAtom_ > maxNAtom_) maxNAtom_ = nAtom_;
288 if (nAtom2_ > maxNAtom2_) maxNAtom2_ = nAtom2_;
297 iterator.atom1Ptrs_ = &atom1Ptrs_[0];
298 iterator.atom2Ptrs_ = &atom2Ptrs_[0];
299 iterator.first_ = &first_[0];
300 iterator.nAtom1_ = nAtom1_;
301 iterator.nAtom2_ = nAtom2_;
302 iterator.atom1Id_ = 0;
303 iterator.atom2Id_ = 0;
316 double dRSq, dRSqMax;
320 if (buildCounter_ == 0)
return false;
322 dRSqMax = 0.25*skin_*skin_;
325 for (ip = 0; ip < nAtom1_; ++ip) {
326 dRSq = boundary.
distanceSq(atom1Ptrs_[ip]->position(),
328 if (dRSq > dRSqMax) {
334 for (ip = atomCapacity_ - 1; ip > tList1_; --ip) {
335 dRSq = boundary.
distanceSq(atom1Ptrs_[ip]->position(),
337 if (dRSq > dRSqMax) {
365 if (atomCapacity_ <= 0)
UTIL_THROW(
"atomCapacity_ <= 0");
366 if (pairCapacity_ <= 0)
UTIL_THROW(
"atomCapacity_ <= 0");
374 if (nAtom_ != nAtom1_ + atomCapacity_ - 1 - tList1_) {
375 UTIL_THROW(
"Inconsistent innAtom_, nAtom1_, tList1");
378 if (nAtom_ != cellList_.
nAtom()) {
383 if (nAtom1_ != 0)
UTIL_THROW(
"nAtom_ ==0 and nAtom1 != 0");
384 if (nAtom2_ != 0)
UTIL_THROW(
"nAtom_ ==0 and nAtom2 != 0");
void initialize(int atomIdEnd, double potentialCutoff)
Allocate memory and initialize.
A Vector is a Cartesian vector.
bool isValid(int nAtom=-1) const
Return true if valid, or throw Exception.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
double distanceSq(const Vector &r1, const Vector &r2) const
Return square distance between positions r1 and r2.
void build(const Boundary &boundary)
Use a complete CellList to build a new PairList.
bool isValid() const
Return true if valid, or throw Exception.
An orthorhombic periodic unit cell.
PairList()
Default constructor.
Mask & mask()
Get the associated Mask by reference.
File containing preprocessor macros for error handling.
void clear()
Sets all Cell objects to empty state (no Atoms).
bool isInitialized() const
Has the initialize function been called?
Saving / output archive for binary ostream.
bool isMasked(const Atom &atom) const
True if the atom is in the masked set for the target Atom.
virtual ~PairList()
Destructor.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
void getCellNeighbors(int ic, NeighborArray &neighbors, int &nInCell) const
Fill an array with pointers to atoms in a cell and neighboring cells.
void setup(const Boundary &boundary)
Setup an empty grid of cells for the internal cell list.
int nAtom() const
Get total number of atoms in this CellList.
A point particle within a Molecule.
Utility classes for scientific computation.
void setup(const Boundary &boundary, double cutoff)
Setup grid of empty cells.
int id() const
Get global index for this Atom within the Simulation.
int totCells() const
Get total number of cells in this CellList.
Iterator for pairs in a PairList.
void begin(PairIterator &iterator) const
Initialize a PairIterator.
void clearStatistics()
Clear statistical accumulators (maxNAtom, maxNPair, buildCounter).
Saving archive for binary istream.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
void setClassName(const char *className)
Set class name string.
bool isCurrent(const Boundary &boundary) const
Returns true if PairList is current, false otherwise.
void setAtomCapacity(int atomCapacity)
Set atom capacity.
void clear()
Clear the PairList and CellList.
void allocate(int capacity)
Allocate the underlying C array.
const Vector & position() const
Get the position Vector by const reference.
int size() const
Return logical size of this array (i.e., number of elements).
void readParameters(std::istream &in)
Read atomCapacity and pairCapacity (maximum numbers of atoms and pairs).
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.