Simpatico  v1.10
LinkMaster.h
1 #ifdef MCMD_LINK
2 #ifndef MCMD_LINK_MASTER_H
3 #define MCMD_LINK_MASTER_H
4 
5 /*
6 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
7 *
8 * Copyright 2010 - 2017, Veronica Chappa and The Regents of the University of Minnesota
9 * Distributed under the terms of the GNU General Public License.
10 */
11 
12 #include "Link.h"
13 #include "LinkEvents.h"
14 #include <mcMd/chemistry/Atom.h>
15 #include <util/param/ParamComposite.h>
16 #include <util/containers/DArray.h>
17 #include <util/containers/ArrayStack.h>
18 #include <util/containers/ArraySet.h>
19 #include <util/containers/SSet.h>
20 #include <util/containers/PArrayIterator.h>
21 #include <util/containers/ConstPArrayIterator.h>
22 #include <util/misc/Notifier.h>
23 
24 
25 namespace Util
26 { class Random; }
27 
28 namespace McMd
29 {
30 
31  using namespace Util;
32 
39  class LinkMaster : public ParamComposite,
40  public Notifier<LinkAddEvent>,
41  public Notifier<LinkResetEvent>,
42  public Notifier<LinkRemoveEvent>,
43  public Notifier<ReSetAtomEvent>
44  {
45 
46  public:
47 
50 
53 
58 
62  LinkMaster();
63 
64  // Use default destructor.
65 
71  void readParameters(std::istream& in);
72 
84  void addLink(Atom& atom0, Atom& atom1, int typeId);
85 
93  void removeLink(int id);
94 
95 
101  const AtomLinkSet& atomLinkSet(const Atom& atom) const;
102 
108  AtomLinkSet& atomLinkSet(const Atom& atom);
109 
124  Link& link(int id) const;
125 
129  void reSetAtoms(Link& link, Atom& atom0, Atom& atom1);
130 
134  void reSetAtom(Link& link, Atom& atom, int endId);
135 
139  int nLink() const;
140 
146  void begin(LinkIterator& iterator);
147 
153  void begin(ConstLinkIterator& iterator) const;
154 
160  Link& randomLink(Random& random);
161 
165  bool isValid() const;
166 
173  void clear();
174 
175  private:
176 
180  DArray<Link> links_;
181 
185  ArraySet<Link> linkSet_;
186 
190  ArrayStack<Link> reservoir_;
191 
198  DArray<AtomLinkSet> atomLinkSets_;
199 
203  int linkCapacity_;
204 
211  int atomCapacity_;
212 
216  void allocate();
217 
218  };
219 
220  // Inline methods
221 
222  /*
223  * Get the set of Links associated with an Atom by constant reference.
224  */
225  inline
226  const LinkMaster::AtomLinkSet& LinkMaster::atomLinkSet(const Atom& atom) const
227  {
228  return (atomLinkSets_[atom.id()]);
229  }
230 
231  /*
232  * Get the set of Links associated with an Atom.
233  */
234  inline
235  LinkMaster::AtomLinkSet& LinkMaster::atomLinkSet(const Atom& atom)
236  {
237  return (atomLinkSets_[atom.id()]);
238  }
239 
240  /*
241  * Initialize iterator to beginning of list of active links.
242  */
243  inline void LinkMaster::begin(LinkMaster::LinkIterator& iterator)
244  { linkSet_.begin(iterator); }
245 
249  inline void LinkMaster::begin(LinkMaster::ConstLinkIterator& iterator) const
250  { linkSet_.begin(iterator); }
251 
252  /*
253  * Get an active Link by index.
254  */
255  inline Link& LinkMaster::link(int id) const
256  { return linkSet_[id]; }
257 
258  /*
259  * Get number of active Links.
260  */
261  inline int LinkMaster::nLink() const
262  { return linkSet_.size(); }
263 
264 }
265 #endif
266 #endif
SSet< Link, 400 > AtomLinkSet
A set of links involving a particular atom.
Definition: LinkMaster.h:57
Forward iterator for a PArray.
PArrayIterator< Link > LinkIterator
Iterator for set of active links.
Definition: LinkMaster.h:49
A container for pointers to a subset of elements of an associated array.
Definition: ArraySet.h:46
A point particle within a Molecule.
Utility classes for scientific computation.
Definition: accumulators.mod:1
void begin(PArrayIterator< Data > &iterator)
Set a PArrayIterator to the beginning of this Array.
Definition: SSet.h:263
int id() const
Get global index for this Atom within the Simulation.
A stack of fixed capacity.
Definition: ArrayStack.h:25
Forward iterator for a PArray.
Definition: ArraySet.h:19
Abstract template for a notifier (or subject) in the Observer design pattern.
Definition: Notifier.h:41
Manages all Link objects in a System.
Definition: LinkMaster.h:39
ConstPArrayIterator< Link > ConstLinkIterator
Const iterator for set of active links.
Definition: LinkMaster.h:52
Dynamically allocatable contiguous array template.
Definition: DArray.h:31
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
Statically allocated array of pointers to an unordered set.
Definition: SSet.h:43
Random number generator.
Definition: Random.h:46
An object that can read multiple parameters from file.