Simpatico  v1.10
ddMd/storage/GroupStorage.h
1 #ifndef DDMD_GROUP_STORAGE_H
2 #define DDMD_GROUP_STORAGE_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 #include <util/global.h>
12 #include <util/param/ParamComposite.h> // base class
13 #include <ddMd/storage/GroupExchanger.h> // base class
14 #include <ddMd/communicate/GroupDistributor.h> // member
15 #include <ddMd/communicate/GroupCollector.h> // member
16 #include <ddMd/chemistry/Atom.h> // member template parameter
17 #include <ddMd/chemistry/Group.h> // member template parameter
18 #include <util/space/IntVector.h> // member template parameter
19 #include <util/containers/DArray.h> // member template
20 #include <util/containers/GPArray.h> // member template
21 #include <util/containers/FMatrix.h> // member template
22 #include <util/containers/ArraySet.h> // member template
23 #include <util/containers/ArrayStack.h> // member template
24 
25 #include "GroupIterator.h" // inline functions
26 #include "ConstGroupIterator.h" // inline functions
27 
28 namespace DdMd
29 {
30 
31  class Domain;
32  class Buffer;
33  class AtomStorage;
34  using namespace Util;
35 
41  template <int N>
42  class GroupStorage : public ParamComposite, public GroupExchanger
43  {
44 
45  public:
46 
50  GroupStorage();
51 
55  ~GroupStorage();
56 
58 
59 
67  void associate(Domain& domain, AtomStorage& atomStorage,
68  Buffer& buffer);
69 
79  void initialize(int capacity, int totalCapacity);
80 
92  virtual void readParameters(std::istream& in);
93 
101  virtual void loadParameters(Serializable::IArchive &ar);
102 
110  virtual void save(Serializable::OArchive &ar);
111 
113 
115 
133  Group<N>* newPtr();
134 
162  void add();
163 
176  Group<N>* add(int id);
177 
186  void returnPtr();
187 
195  void remove(Group<N>* groupPtr);
196 
204  void clearGroups();
205 
209  int size() const;
210 
214  int capacity() const;
215 
217 
219 
225  void begin(GroupIterator<N>& iterator);
226 
232  void begin(ConstGroupIterator<N>& iterator) const;
233 
239  Group<N>* find(int id) const;
240 
242 
244 
252  int totalCapacity() const;
253 
267  #ifdef UTIL_MPI
268  void computeNTotal(MPI::Intracomm& communicator);
269  #else
270  void computeNTotal();
271  #endif
272 
279  int nTotal() const;
280 
286  void unsetNTotal();
287 
289 
291 
300  virtual
301  void markSpanningGroups(FMatrix<double, Dimension, 2>& bound,
304  IntVector& gridFlags);
305 
306  #ifdef UTIL_MPI
307 
318  virtual
319  void pack(int i, int j, Buffer& buffer);
320 
327  virtual
328  void unpack(Buffer& buffer, AtomStorage& atomStorage);
329  #endif // endif ifdef UTIL_MPI
330 
342  virtual
343  void markGhosts(AtomStorage& atomStorage,
344  FMatrix<GPArray<Atom>, Dimension, 2>& sendArray,
345  IntVector& gridFlags);
346 
354  virtual
355  void findGhosts(AtomStorage& atomStorage);
356 
370  #ifdef UTIL_MPI
371  virtual
372  bool isValid(AtomStorage& atomStorage, MPI::Intracomm& communicator,
373  bool hasGhosts);
374  #else
375  virtual
376  bool isValid(AtomStorage& atomStorage, bool hasGhosts);
377  #endif
378 
380 
382 
388  #ifdef UTIL_MPI
389  virtual void computeStatistics(MPI::Intracomm& communicator);
390  #else
391  virtual void computeStatistics();
392  #endif
393 
397  void clearStatistics();
398 
406  void outputStatistics(std::ostream& out);
407 
413  int maxNGroup() const;
414 
416 
418 
422  GroupDistributor<N>& distributor();
423 
427  GroupCollector<N>& collector();
428 
432  bool isValid();
433 
435 
436  private:
437 
438  // Memory pool that holds all available group objects.
439  DArray< Group<N> > groups_;
440 
441  // Set of pointers to local groups.
442  ArraySet< Group<N> > groupSet_;
443 
444  // Stack of pointers to unused local Group objects.
445  ArrayStack< Group<N> > reservoir_;
446 
447  // Array of pointers to groups, indexed by global group Id.
448  // Elements corresponding to absent groups hold null pointers.
449  DArray< Group<N>* > groupPtrs_;
450 
451  // Array identifying empty groups, marked for later removal
452  GPArray< Group<N> > emptyGroups_;
453 
454  // Pointer to space for a new local Group
455  Group<N>* newPtr_;
456 
457  // Capacity for local groups on this processor.
458  int capacity_;
459 
460  // Maximum number of groups on all processors, maximum id + 1
461  int totalCapacity_;
462 
464  int maxNGroupLocal_;
465 
467  Setable<int> maxNGroup_;
468 
469  // Total number of distinct groups on all processors.
470  Setable<int> nTotal_;
471 
472  // Distributor and Collector objects
473  GroupDistributor<N> distributor_;
474  GroupCollector<N> collector_;
475 
476  /*
477  * Allocate and initialize all private containers.
478  */
479  void allocate();
480 
481  };
482 
483  // Inline member function definitions
484 
485  template <int N>
486  inline int GroupStorage<N>::size() const
487  { return groupSet_.size(); }
488 
489  template <int N>
490  inline int GroupStorage<N>::capacity() const
491  { return capacity_; }
492 
493  template <int N>
495  { return totalCapacity_; }
496 
497  template <int N>
498  inline int GroupStorage<N>::nTotal() const
499  { return nTotal_.value(); }
500 
501  /*
502  * Return pointer to Group with specified id.
503  */
504  template <int N>
505  inline Group<N>* GroupStorage<N>::find(int id) const
506  { return groupPtrs_[id]; }
507 
508  /*
509  * Set iterator to beginning of the set of local groups.
510  */
511  template <int N>
513  { groupSet_.begin(iterator); }
514 
515  /*
516  * Set const iterator to beginning of the set of local groups.
517  */
518  template <int N>
519  inline
521  { groupSet_.begin(iterator); }
522 
523  template <int N>
525  { return distributor_; }
526 
527  template <int N>
529  { return collector_; }
530 
531 }
532 #endif
GroupDistributor< N > & distributor()
Get the GroupDistributor by reference.
const int Dimension
Dimensionality of space.
Definition: Dimension.h:19
File containing preprocessor macros for error handling.
Parallel domain decomposition (DD) MD simulation.
int capacity() const
Return capacity for groups on this processor.
Saving / output archive for binary ostream.
Class for collecting Groups from processors to master processor.
Iterator for all Group < N > objects owned by a GroupStorage< N >.
Definition: GroupIterator.h:25
A container for pointers to a subset of elements of an associated array.
Definition: ArraySet.h:46
Utility classes for scientific computation.
Definition: accumulators.mod:1
Const iterator for all Group < N > objects owned by a GroupStorage < N >.
A stack of fixed capacity.
Definition: ArrayStack.h:25
void begin(GroupIterator< N > &iterator)
Set iterator to beginning of the set of groups.
GroupCollector< N > & collector()
Get the GroupCollector by reference.
int totalCapacity() const
Return maximum allowed number of groups on all processors.
int nTotal() const
Return total number of distinct groups on all processors.
Dynamically allocatable contiguous array template.
Definition: DArray.h:31
Saving archive for binary istream.
An IntVector is an integer Cartesian vector.
Definition: IntVector.h:73
A group of covalently interacting atoms.
An automatically growable PArray.
Definition: GPArray.h:28
An object that can read multiple parameters from file.
int size() const
Return current number of groups on this processor.
Class template for distributing Group<N> objects among processors.
Group< N > * find(int id) const
Find local Group<N> indexed by global id.