Simpatico  v1.10
mcMd/chemistry/Group.h
1 #ifndef MCMD_GROUP_H
2 #define MCMD_GROUP_H
3 
4 /*
5 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
6 *
7 * Copyright 2010 - 2017, The Regents of the University of Minnesota
8 * Distributed under the terms of the GNU General Public License.
9 */
10 
11 namespace McMd
12 {
13 
14  using namespace Util;
15 
16  class Atom;
17 
36  template <int NAtom>
37  class Group
38  {
39 
40  public:
41 
45  Group();
46 
48 
49 
56  void setAtom(int i, Atom &atom);
57 
63  void setTypeId(int typeId);
64 
66 
68 
74  Atom& atom(int i);
75 
81  const Atom& atom(int i) const;
82 
86  int typeId() const;
87 
95  bool isActive() const;
96 
100  int nInActive() const;
101 
107  bool checkInactive() const;
108 
110 
111  private:
112 
114  Atom* atoms_[NAtom];
115 
117  int typeId_;
118 
120  int nInActive_;
121 
122  // Private member functions, accessible by class Activate
123 
127  void activate();
128 
132  void incrementInactive();
133 
137  void decrementInactive();
138 
139  // friends:
140 
141  friend class Activate;
142 
143  };
144 
145  /*
146  * Constructor
147  */
148  template <int NAtom>
150  : typeId_(-1),
151  nInActive_(0)
152  {
153  for (int i=0; i < NAtom; ++i) {
154  atoms_[i] = 0;
155  }
156  }
157 
158  /*
159  * Add an atom to the group.
160  */
161  template <int NAtom>
162  inline void Group<NAtom>::setAtom(int i, Atom &atom)
163  { atoms_[i] = &atom; }
164 
165  /*
166  * Set the group type id for this group.
167  */
168  template <int NAtom>
170  { typeId_ = typeId; }
171 
172  // Accessors
173 
174  /*
175  * Get a specific Atom in the Group.
176  */
177  template <int NAtom>
178  inline Atom& Group<NAtom>::atom(int i)
179  {
180  assert(atoms_[i]);
181  return *atoms_[i];
182  }
183 
184  /*
185  * Get a const reference to a specific Atom in the Group.
186  */
187  template <int NAtom>
188  inline const Atom& Group<NAtom>::atom(int i) const
189  {
190  assert(atoms_[i]);
191  return *atoms_[i];
192  }
193 
194  /*
195  * Get the typeId for this covalent group.
196  */
197  template <int NAtom>
198  inline int Group<NAtom>::typeId() const
199  { return typeId_; }
200 
201  /*
202  * Is this group active?
203  */
204  template <int NAtom>
205  inline bool Group<NAtom>::isActive() const
206  { return (nInActive_ == 0); }
207 
208  /*
209  * Return number of inactive atoms.
210  */
211  template <int NAtom>
212  inline int Group<NAtom>::nInActive() const
213  { return nInActive_; }
214 
215  /*
216  * Check consistency of nInActive counter.
217  */
218  template <int NAtom>
220  {
221  int counter = 0;
222  for (int i=0; i < NAtom; ++i) {
223  assert(atoms_[i]);
224  if (!atoms_[i]->isActive()) ++counter;
225  }
226  if (counter != nInActive_) {
227  UTIL_THROW("Inconsistent number of inactive atoms");
228  }
229  return true;
230  }
231 
232  // Private functions that modify nInActive_
233 
234  /*
235  * Activate the group (set nInActive_ = 0)
236  */
237  template <int NAtom>
238  inline void Group<NAtom>::activate()
239  { nInActive_ = 0; }
240 
241  /*
242  * Increment the number of inactive atoms.
243  */
244  template <int NAtom>
245  inline void Group<NAtom>::incrementInactive()
246  {
247  assert(nInActive_ < NAtom);
248  ++nInActive_;
249  }
250 
251  /*
252  * Decrement the number of inactive atoms.
253  */
254  template <int NAtom>
255  inline void Group<NAtom>::decrementInactive()
256  {
257  assert(nInActive_ > 0);
258  --nInActive_;
259  }
260 
261 }
262 #endif
void setAtom(int i, Atom &atom)
Add an atom to this group.
void setTypeId(int typeId)
Set the group type id for this group.
bool checkInactive() const
Check consistency of number of inactive atoms.
bool isActive() const
Is this group active?
int typeId() const
Get the typeId for this covalent group.
Static member functions to de-active and re-active atoms.
Definition: Activate.h:41
int nInActive() const
Return number of inactive atoms.
Group()
Constructor.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
A point particle within a Molecule.
Utility classes for scientific computation.
Definition: accumulators.mod:1
Atom & atom(int i)
Get a specific Atom in the Group by reference.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
A sequence of NAtom covalently interacting atoms.