1 // A class for managing the data associated with sets of molecules
2 
3 #ifndef PER_MOLECULE_SET_H
4 #define PER_MOLECULE_SET_H
5 
6 // ATC_Method headers
7 #include "LammpsInterface.h"
8 #include "DependencyManager.h"
9 #include <map>
10 #include <set>
11 #include <vector>
12 
13 namespace ATC {
14 
15   // forward declarations
16   class ATC_Method;
17   template <typename T> class PerAtomQuantity;
18 
19   /**
20    *  @class  MoleculeSet
21    *  @brief  A class for handling all the data associated with sets of molecules
22    */
23 
24   class MoleculeSet : public DependencyManager {
25 
26   public:
27 
28     MoleculeSet(ATC_Method * atc, int groupBit);
29 
30     virtual ~MoleculeSet();
31 
32     /** reset all data */
33     virtual void clear();
34 
35     /** initialize global data */
36     virtual void initialize(std::map<int, double> * globalAtomsPerMolecule = nullptr);
37 
38     /** reset the number of atoms/molecules on this processor */
reset_nlocal()39     void reset_nlocal() {this->set_reset();};
40 
41     /** recompute data when atoms cross processors */
post_exchange()42     void post_exchange() {this->set_reset();};
43 
44     /** access the number of total molecules */
global_molecule_count()45     int global_molecule_count() const {return nMoleculesTotal_;};
46 
47     /** access the number of local molecules */
local_molecule_count()48     int local_molecule_count() const {if (need_reset()) reset(); return moleculeToAtoms_.size();};
49 
50     /** access molecule atoms by lammps id */
51     std::set<int> atoms_by_global_molecule(int id) const;
52 
53     /** access molecules by local indexing */
54     const std::set<int> & atoms_by_local_molecule(int id) const;
55 
56     /** access fraction of a locally indexed molecule on this processor */
57     virtual double local_fraction(int id) const = 0;
58 
59     /** use global index to get local index */
60     //int global_to_local(int id) const;
61 
62     /** use local index to get global index */
local_to_global(int id)63     int local_to_global(int id) const {return (*localMoleculeToAtoms_[id]).first;};
64 
65   protected:
66 
67     /** pointer for access to atc data */
68     ATC_Method * atc_;
69 
70     /** lammps group bit corresponding to desired molecules */
71     int groupBit_;
72 
73     /** pointer to lammps interface */
74     const LammpsInterface * lammps_;
75 
76     /** total number of molecules in this group */
77     // see Compute::molecules_in_group
78     int nMoleculesTotal_;
79 
80     /** multimap from lammps molecule id to ids of consituent atoms, all atoms are real */
81     // multiple map to account for periodic images
82     mutable std::multimap<int, std::set<int> > moleculeToAtoms_;
83 
84     /** vector in processor-local molecule order to constituent atom sets, atoms include ghosts */
85     mutable std::vector< std::map<int, std::set<int> >::const_iterator > localMoleculeToAtoms_;
86 
87     /** resets the quantity based on the latest data */
88     virtual void reset() const = 0;
89 
90     /** creates the ordered list of local molecules */
91     void set_local_molecules_to_atoms() const;
92 
93   private:
94 
95     // do not define this
96     MoleculeSet();
97 
98   };
99 
100 
101   /**
102    *  @class  SmallMoleculeSet
103    *  @brief  A class for handling data for small molecules, i.e., molecules with maximum distance between atoms less than the lammps cutoff radius.  Atom ids are in [0,nlocalTotal-1].
104    */
105 
106   class SmallMoleculeSet : public MoleculeSet {
107 
108   public:
109 
110     SmallMoleculeSet(ATC_Method * atc, int groupBit,
111                      PerAtomQuantity<int> * bondList = nullptr,
112                      PerAtomQuantity<int> * numBond = nullptr);
113 
114     virtual ~SmallMoleculeSet();
115 
116     /** reset all data */
117     virtual void clear();
118 
119     /** initialize global data */
120     virtual void initialize(std::map<int, double> * globalAtomsPerMolecule = nullptr);
121 
122     /** access molecule atoms by lammps id */
123     std::set<int> atoms_by_global_molecule(int id) const;
124 
125     /** access fraction of a locally indexed molecule on this processor */
126     virtual double local_fraction(int id) const;
127 
128   protected:
129 
130     /** store the number of atoms in a molecule on this processor */
131     //std::map<int, int> localAtomsPerMolecule_;
132 
133     /** resets the quantity based on the latest data */
134     virtual void reset() const;
135 
136     /** data structure containing bond list information, forces parallel communication of bond lists */
137     PerAtomQuantity<int> * bondList_;
138 
139     /** data structure containing bond list information, forces parallel communication of bond lists */
140     PerAtomQuantity<int> * numBond_;
141 
142     /** removes processor ghosts from a set of atom ids */
143     void remove_proc_ghosts(std::set<int> & atomSet) const;
144 
145     // workspace variable for determining if we've hit an internal atom already
146     mutable Array<bool> _atomFound_;
147 
148   private:
149 
150     // do not define this
151     SmallMoleculeSet();
152 
153   };
154 
155 
156 };
157 
158 #endif
159