示例#1
0
   /*
   * Build the PairList, i.e., populate it with atom pairs.
   */
   void PairList::build(CellList& cellList, bool reverseUpdateFlag)
   {
      // Precondition
      assert(isAllocated());
 
      Cell::NeighborArray neighbors;
      double dRSq, cutoffSq;
      const Cell*  cellPtr;
      Atom*  atom1Ptr;
      Atom*  atom2Ptr;
      Mask*  maskPtr;
      Vector dr;
      int    na;      // number of atoms in this cell
      int    nn;      // number of neighbors for a cell
      int    atom2Id; // atom Id for second atom
      int    i, j;
      bool   foundNeighbor;
  
      // Set maximum squared-separation for pairs in Pairlist
      cutoffSq = cutoff_*cutoff_;
   
      // Initialize counters for primary atoms and neighbors
      atom1Ptrs_.clear();
      atom2Ptrs_.clear();
      first_.clear();
      first_.append(0);
   
      // Find all neighbors (cell list)
      cellPtr = cellList.begin();
      while (cellPtr) {
         cellPtr->getNeighbors(neighbors, reverseUpdateFlag);
         na = cellPtr->nAtom();
         nn = neighbors.size();

         // Loop over primary atoms (atom1) in primary cell
         for (i = 0; i < na; ++i) {
            atom1Ptr = neighbors[i];
            maskPtr  = &(atom1Ptr->mask());
            foundNeighbor = false;

            // Loop over secondary atoms (atom2) in primary cell
            for (j = 0; j < na; ++j) {
               atom2Ptr = neighbors[j];
               if (atom2Ptr > atom1Ptr) {
                  atom2Id  = atom2Ptr->id();
                  if (!maskPtr->isMasked(atom2Id)) {
                     dr.subtract(atom2Ptr->position(), atom1Ptr->position()); 
                     dRSq = dr.square();
                     if (dRSq < cutoffSq) {
                        // If first neighbor of atom1, add atom1 to atom1Ptrs_
                        if (!foundNeighbor) {
                           atom1Ptrs_.append(atom1Ptr);
                           foundNeighbor = true;
                        }
                        // Append 2nd atom to atom2Ptrs_[]
                        atom2Ptrs_.append(atom2Ptr);
                     }
                  }
               }
            }

            // Atoms in neighboring cells
            for (j = na; j < nn; ++j) {
               atom2Ptr = neighbors[j];
               atom2Id  = atom2Ptr->id();
               if (!maskPtr->isMasked(atom2Id)) {
                  dr.subtract(atom2Ptr->position(), atom1Ptr->position()); 
                  dRSq = dr.square();
                  if (dRSq < cutoffSq) {
                     // If first_ neighbor, record iAtomId in atom1Ptrs_
                     if (!foundNeighbor) {
                        atom1Ptrs_.append(atom1Ptr);
                        foundNeighbor = true;
                     }
                     // Append Id of 2nd atom in pair to atom2Ptrs_[]
                     atom2Ptrs_.append(atom2Ptr);
                 }
              }
   
            }
  
            // When finished with atom1, set next element of first_ array.
            if (foundNeighbor) {
               first_.append(atom2Ptrs_.size());
            }
         }

         // Advance to next cell in a linked list
         cellPtr = cellPtr->nextCellPtr();
      }

      // Postconditions
      if (atom1Ptrs_.size()) {
         if (first_.size() != atom1Ptrs_.size() + 1) {
            UTIL_THROW("Array size problem");
         }
         if (first_[0] != 0) {
            UTIL_THROW("Incorrect first element of first_");
         }
         if (first_[atom1Ptrs_.size()] != atom2Ptrs_.size()) {
            UTIL_THROW("Incorrect last element of first_");
         }
      }

      // Increment buildCounter_= number of times the list has been built.
      ++buildCounter_;
 
      // Increment maxima
      if (atom1Ptrs_.size() > maxNAtomLocal_) {
         maxNAtomLocal_ = atom1Ptrs_.size();
      }
      if (atom2Ptrs_.size() > maxNPairLocal_) {
         maxNPairLocal_ = atom2Ptrs_.size();
      }
   }
示例#2
0
   /*
   * Build the PairList, i.e., populate it with atom pairs.
   */
   void PairList::build(CellList& cellList, bool reverseUpdateFlag)
   {
      // Precondition
      assert(isAllocated());
 
      Cell::NeighborArray neighbors;
      double cutoffSq;
      const Cell* cellPtr;
      CellAtom* atom1Ptr;
      CellAtom* atom2Ptr;
      Mask* maskPtr;
      Vector dr;
      int na;                 // number of atoms in this cell
      int nn;                 // number of neighbors for a cell
      int i, j;
      bool hasNeighbor;
  
      // Set maximum squared-separation for pairs in Pairlist
      cutoffSq = cutoff_*cutoff_;
   
      // Initialize counters for primary atoms and neighbors
      atom1Ptrs_.clear();
      atom2Ptrs_.clear();
      first_.clear();
      first_.append(0);

      // Copy positions and ids into cell list
      cellList.update();
   
      // Find all neighbors (cell list)
      cellPtr = cellList.begin();
      while (cellPtr) {
         na = cellPtr->nAtom(); // # of atoms in cell

         if (na) {
            cellPtr->getNeighbors(neighbors, reverseUpdateFlag);
            nn = neighbors.size();
   
            // Loop over primary atoms (atom1) in primary cell
            for (i = 0; i < na; ++i) {
               atom1Ptr = neighbors[i];
               maskPtr  = atom1Ptr->maskPtr();
   
               // Loop over secondary atoms
               hasNeighbor = false;
               for (j = i + 1; j < nn; ++j) {
                  atom2Ptr = neighbors[j];
                  dr.subtract(atom2Ptr->position(), atom1Ptr->position()); 
                  if (dr.square() < cutoffSq && !maskPtr->isMasked(atom2Ptr->id())) {
                     atom2Ptrs_.append(atom2Ptr->ptr());
                     hasNeighbor = true;
                  }
               }

               // Complete processing of atom1.
               if (hasNeighbor) {
                  atom1Ptrs_.append(atom1Ptr->ptr());
                  first_.append(atom2Ptrs_.size());
               }

            } // for ia 
         } // if (na)

         // Advance to next cell in a linked list
         cellPtr = cellPtr->nextCellPtr();
      }

      // Postconditions
      if (atom1Ptrs_.size()) {
         if (first_.size() != atom1Ptrs_.size() + 1) {
            UTIL_THROW("Array size problem");
         }
         if (first_[0] != 0) {
            UTIL_THROW("Incorrect first element of first_");
         }
         if (first_[atom1Ptrs_.size()] != atom2Ptrs_.size()) {
            UTIL_THROW("Incorrect last element of first_");
         }
      }

      // Increment buildCounter_= number of times the list has been built.
      ++buildCounter_;
 
      // Increment maxima
      if (atom1Ptrs_.size() > maxNAtomLocal_) {
         maxNAtomLocal_ = atom1Ptrs_.size();
      }
      if (atom2Ptrs_.size() > maxNPairLocal_) {
         maxNPairLocal_ = atom2Ptrs_.size();
      }
   }