Simpatico  v1.10
mcMd/neighbor/Cell.cpp
1 /*
2 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
3 *
4 * Copyright 2010 - 2017, The Regents of the University of Minnesota
5 * Distributed under the terms of the GNU General Public License.
6 */
7 
8 #include "Cell.h"
9 #include <mcMd/chemistry/Atom.h>
10 
11 namespace McMd
12 {
13 
14  using namespace Util;
15 
16  /*
17  * Default constructor, creates an empty Cell.
18  */
20  { clear();}
21 
22  /*
23  * Reset Cell to empty state.
24  */
25  void Cell::clear()
26  {
27  nAtomCell_ = 0;
28  firstEmptyPos_ = 0;
29  firstClearPos_ = 0;
30  for (int j = 0; j < MaxAtomCell; ++j) {
31  atoms_[j] = 0;
32  }
33  }
34 
35 
36  /*
37  * Check validity of Cell data members.
38  */
39  bool Cell::isValid(const Array<CellTag> &cellTags, int nAtom, int icell)
40  const
41  {
42  int jp, atomId, nAtomCellTest;
43  nAtomCellTest=0;
44  for (jp=0; jp < Cell::MaxAtomCell; ++jp) {
45  if (atoms_[jp] != 0) {
46  atomId = atoms_[jp]->id();
47  ++nAtomCellTest;
48  if (cellTags[atomId].cellId != icell) {
49  UTIL_THROW("Value in CellTag.cellId inconsistent with icell");
50  }
51  if (cellTags[atomId].cellPos != jp) {
52  std::cout << "atomId =" << atomId << std::endl;
53  std::cout << "cellTags[atomId].cellPos ="
54  << cellTags[atomId].cellPos << std::endl;
55  std::cout << "index jp in Cell = " << jp << std::endl;
56  UTIL_THROW(
57  "Value in CellTag.cellPos inconsistent with Cell.atoms_");
58  }
59  if (jp >= firstClearPos_) {
60  UTIL_THROW("Value atoms_[i] >=0 for i >= firstClearPos_");
61  }
62  } else {
63  if (jp < firstEmptyPos_) {
64  UTIL_THROW("Value atoms_[i] < 0 for i < firstEmptyPos_");
65  }
66  }
67  }
68  if (firstClearPos_ > 0) {
69  if (atoms_[firstClearPos_-1] == 0) {
70  UTIL_THROW("Error: atoms_[firstClearPos_-1] == 0");
71  }
72  }
73  if (nAtomCellTest != nAtomCell_) {
74  UTIL_THROW("Number of atoms in cell != nAtomCell_");
75  }
76  return true;
77  }
78 
79 }
Cell()
Default constructor, creates an empty Cell.
bool isValid(const Array< CellTag > &cellTags, int nAtom, int icell) const
Check validity of Cell, and consistency with array of CellTags.
Array container class template.
Definition: AutoCorrArray.h:28
void clear()
Reset Cell to empty state.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
Utility classes for scientific computation.
Definition: accumulators.mod:1
static const int MaxAtomCell
Maximum number of atoms per cell.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).