Simpatico  v1.10
ddMd/storage/AtomStorage.h
1 #ifndef DDMD_ATOM_STORAGE_H
2 #define DDMD_ATOM_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/param/ParamComposite.h> // base class
12 
13 #include <ddMd/chemistry/AtomArray.h> // member
14 #include <ddMd/storage/AtomMap.h> // member
15 #include <ddMd/communicate/AtomDistributor.h> // member
16 #include <ddMd/communicate/AtomCollector.h> // member
17 #include <ddMd/chemistry/Atom.h> // member template argument
18 #include <ddMd/chemistry/Group.h> // in function templates
19 #include <simp/boundary/Boundary.h> // typedef
20 #include <util/containers/DArray.h> // member template
21 #include <util/containers/ArraySet.h> // member template
22 #include <util/containers/ArrayStack.h> // member template
23 #include <util/misc/Setable.h> // member template
24 #include <util/global.h>
25 
26 class AtomStorageTest;
27 
28 namespace DdMd
29 {
30 
31  class AtomIterator;
32  class ConstAtomIterator;
33  class GhostIterator;
34  class ConstGhostIterator;
35 
36  using namespace Util;
37  using namespace Simp;
38 
44  class AtomStorage : public ParamComposite
45  {
46 
47  public:
48 
52  AtomStorage();
53 
57  ~AtomStorage();
58 
66  void associate(Domain& domain, Boundary& boundary, Buffer& buffer);
67 
77  void initialize(int atomCapacity, int ghostCapacity,
78  int totalAtomCapacity);
79 
92  virtual void readParameters(std::istream& in);
93 
102  void zeroForces(bool zeroGhosts);
103 
105 
106 
112  virtual void loadParameters(Serializable::IArchive &ar);
113 
121  virtual void save(Serializable::OArchive &ar);
122 
124 
126 
157  Atom* newAtomPtr();
158 
169  void addNewAtom();
170 
189  Atom* addAtom(int id);
190 
198  void removeAtom(Atom* atomPtr);
199 
203  void clearAtoms();
204 
208  int nAtom() const;
209 
213  int atomCapacity() const;
214 
216 
218 
239  Atom* newGhostPtr();
240 
250  void addNewGhost();
251 
268  Atom* addGhost(int id);
269 
277  void removeGhost(Atom* atomPtr);
278 
282  void clearGhosts();
283 
287  int nGhost() const;
288 
292  int ghostCapacity() const;
293 
295 
297 
305  void transformCartToGen(const Boundary& boundary);
306 
314  void transformGenToCart(const Boundary& boundary);
315 
319  bool isCartesian() const;
320 
322 
324 
332  void makeSnapshot();
333 
340  void clearSnapshot();
341 
350  double maxSqDisplacement();
351 
353 
355 
361  void begin(AtomIterator& iterator);
362 
368  void begin(ConstAtomIterator& iterator) const;
369 
375  void begin(GhostIterator& iterator);
376 
382  void begin(ConstGhostIterator& iterator) const;
383 
385 
387 
395  int totalAtomCapacity() const;
396 
397  #ifdef UTIL_MPI
398 
417  void computeNAtomTotal(MPI::Intracomm& communicator);
418  #endif
419 
427  int nAtomTotal() const;
428 
436  void unsetNAtomTotal();
437 
439 
441 
445  const AtomMap& map() const;
446 
447  #ifdef UTIL_MPI
448 
451  AtomDistributor& distributor();
452 
456  AtomCollector& collector();
457  #endif
458 
460 
462 
468  bool isInitialized() const;
469 
473  bool isValid() const;
474 
475  #ifdef UTIL_MPI
476 
481  bool isValid(MPI::Intracomm& communicator) const;
482  #endif
483 
485 
487 
493  #ifdef UTIL_MPI
494  virtual void computeStatistics(MPI::Intracomm& communicator);
495  #else
496  virtual void computeStatistics();
497  #endif
498 
502  void clearStatistics();
503 
511  void outputStatistics(std::ostream& out);
512 
518  int maxNAtom() const;
519 
525  int maxNGhost() const;
526 
528 
529  private:
530 
531  // Array that holds all available local Atom objects.
532  AtomArray atoms_;
533 
534  // Set of pointers to local atoms.
535  ArraySet<Atom> atomSet_;
536 
537  // Stack of pointers to unused local Atom objects.
538  ArrayStack<Atom> atomReservoir_;
539 
540  // Array that holds all available ghost Atom objects.
541  AtomArray ghosts_;
542 
543  // Set of pointers to ghost atoms.
544  ArraySet<Atom> ghostSet_;
545 
546  // Stack of pointers to unused ghost Atom objects.
547  ArrayStack<Atom> ghostReservoir_;
548 
549  // Map of atomIds to atom pointers.
550  AtomMap map_;
551 
552  // Array of stored old positions.
553  DArray<Vector> snapshot_;
554 
555  // Pointer to space for a new local Atom
556  Atom* newAtomPtr_;
557 
558  // Pointer to space for a new ghost Atom.
559  Atom* newGhostPtr_;
560 
561  // Capacity for local atoms on this processor.
562  int atomCapacity_;
563 
564  // Capacity for ghost atoms on this processors.
565  int ghostCapacity_;
566 
567  // Maximum number of atoms on all processors, maximum id + 1
568  int totalAtomCapacity_;
569 
571  int maxNAtomLocal_;
572 
574  int maxNGhostLocal_;
575 
576  #ifdef UTIL_MPI
577  // Total number of local atoms on all processors.
578  Setable<int> nAtomTotal_;
579 
581  Setable<int> maxNAtom_;
582 
584  Setable<int> maxNGhost_;
585 
586  // Distributor and collector
587  AtomDistributor distributor_;
588  AtomCollector collector_;
589  #endif
590 
591  // Is addition or removal of atoms forbidden?
592  bool locked_;
593 
594  // Is this object initialized (has memory been allocated?).
595  bool isInitialized_;
596 
597  // Are atomic coordinates Cartesian (true) or generalized (false)?
598  bool isCartesian_;
599 
600  /*
601  * Allocate and initialize all private containers.
602  */
603  void allocate();
604 
605  friend class ::AtomStorageTest;
606 
607  };
608 
609  // Inline member function definitions
610 
611  inline int AtomStorage::nAtom() const
612  { return atomSet_.size(); }
613 
614  inline int AtomStorage::nGhost() const
615  { return ghostSet_.size(); }
616 
617  #ifdef UTIL_MPI
619  { return distributor_; }
620 
622  { return collector_; }
623  #endif
624 
625  inline int AtomStorage::atomCapacity() const
626  { return atomCapacity_; }
627 
628  inline int AtomStorage::ghostCapacity() const
629  { return ghostCapacity_; }
630 
632  { return totalAtomCapacity_; }
633 
634  inline bool AtomStorage::isCartesian() const
635  { return isCartesian_; }
636 
637  inline const AtomMap& AtomStorage::map() const
638  { return map_; }
639 
640  /*
641  * On master processor (rank=0), stored value of total number of atoms.
642  */
643  inline int AtomStorage::nAtomTotal() const
644  {
645  #ifdef UTIL_MPI
646  return nAtomTotal_.value();
647  #else
648  return atomSet_.size();
649  #endif
650  }
651 
652 }
653 #endif
int nAtomTotal() const
Get total number of atoms on all processors.
AtomDistributor & distributor()
Get the AtomDistributor by reference.
An orthorhombic periodic unit cell.
Associative container for finding atoms identified by integer id.
Definition: AtomMap.h:36
File containing preprocessor macros for error handling.
A point particle in an MD simulation.
Parallel domain decomposition (DD) MD simulation.
Classes used by all simpatico molecular simulations.
int nAtom() const
Return number of local atoms on this procesor (excluding ghosts)
AtomCollector & collector()
Get the AtomCollector by reference.
Saving / output archive for binary ostream.
Class for collecting Atoms from processors to master processor.
Definition: AtomCollector.h:57
An array of Atom objects.
Definition: AtomArray.h:40
int nGhost() const
Return current number of ghost atoms on this processor.
A container for pointers to a subset of elements of an associated array.
Definition: ArraySet.h:46
Const iterator for all atoms owned by an AtomStorage.
Utility classes for scientific computation.
Definition: accumulators.mod:1
const AtomMap & map() const
Return the AtomMap by const reference.
A stack of fixed capacity.
Definition: ArrayStack.h:25
A container for all the atoms and ghost atoms on this processor.
int atomCapacity() const
Return capacity for local atoms on this processor (excluding ghosts).
int totalAtomCapacity() const
Return maximum number of atoms on all processors.
Buffer for interprocessor communication.
Definition: Buffer.h:217
Decomposition of the system into domains associated with processors.
Definition: Domain.h:31
Dynamically allocatable contiguous array template.
Definition: DArray.h:31
Saving archive for binary istream.
int ghostCapacity() const
Return capacity for ghost atoms on this processor.
bool isCartesian() const
Are atom coordinates Cartesian (true) or generalized (false)?
Iterator for all ghost atoms owned by an AtomStorage.
Definition: GhostIterator.h:24
An object that can read multiple parameters from file.
Iterator for all atoms owned by an AtomStorage.
Definition: AtomIterator.h:24
Iterator for all ghost atoms owned by an AtomStorage.
Class for distributing Atoms among processors.