Simpatico  v1.10
SpeciesGroup.h
1 #ifndef SIMP_SPECIES_GROUP_H
2 #define SIMP_SPECIES_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 #include <util/global.h>
12 
13 #include <iostream>
14 
15 namespace Simp
16 {
17 
18  // Forward declarations of templates required for friend declarations.
19 
20  template <int NAtom> class SpeciesGroup;
21 
22  template <int NAtom> std::istream&
23  operator >> (std::istream& in, SpeciesGroup<NAtom> &speciesGroup);
24 
25  template <int NAtom> std::ostream&
26  operator << (std::ostream& out, const SpeciesGroup<NAtom>& speciesGroup);
27 
28  template <int NAtom> std::ostream&
29  operator << (std::ostream& out, const SpeciesGroup<NAtom>& speciesGroup);
30 
41  template <class Archive, int NAtom>
42  void serialize(Archive& ar, SpeciesGroup<NAtom>& speciesGroup,
43  const unsigned int version);
44 
74  template <int NAtom>
75  class SpeciesGroup
76  {
77 
78  public:
79 
83  static const int NullIndex = -1;
84 
88  SpeciesGroup();
89 
96  void setAtomId(int i, int atomId);
97 
103  void setTypeId(int typeId);
104 
110  int atomId(int i) const;
111 
115  int typeId() const;
116 
117  #ifdef UTIL_MPI
118 
121  static void commitMpiType();
122  #endif
123 
124  private:
125 
127  int atomIds_[NAtom];
128 
130  int typeId_;
131 
132  //friends:
133 
134  friend
135  std::istream&
136  operator >> <> (std::istream& in, SpeciesGroup<NAtom>& speciesGroup);
137 
138  friend
139  std::ostream&
140  operator << <> (std::ostream& out, const SpeciesGroup<NAtom>& speciesGroup);
141 
142  template <class Archive> friend
143  void serialize(Archive& ar, SpeciesGroup<NAtom>& speciesGroup,
144  const unsigned int version);
145 
146  template <class Archive> friend
147  void serialize(Archive& ar, SpeciesGroup<NAtom>& speciesGroup,
148  const unsigned int version);
149 
150  };
151 
152  /*
153  * Constructor.
154  */
155  template <int NAtom>
157  : typeId_(NullIndex)
158  {
159  for (int i=0; i < NAtom; ++i) {
160  atomIds_[i] = NullIndex;
161  }
162  }
163 
164  /*
165  * Set index for one atom in the group.
166  */
167  template <int NAtom>
168  inline void SpeciesGroup<NAtom>::setAtomId(int i, int atomId)
169  { atomIds_[i] = atomId; }
170 
171  /*
172  * Set the group type id for this group.
173  */
174  template <int NAtom>
176  { typeId_ = typeId; }
177 
178  /*
179  * Get the local id for a specific Atom.
180  */
181  template <int NAtom>
182  inline int SpeciesGroup<NAtom>::atomId(int i) const
183  { return atomIds_[i]; }
184 
185  /*
186  * Get the type id for this covalent group.
187  */
188  template <int NAtom>
189  inline int SpeciesGroup<NAtom>::typeId() const
190  { return typeId_; }
191 
192  // Inserter and extractor operator declarations
193 
205  template <int NAtom>
206  std::istream&
207  operator >> (std::istream& in, SpeciesGroup<NAtom> &speciesGroup);
208 
220  template <int NAtom>
221  std::ostream&
222  operator << (std::ostream& out, const SpeciesGroup<NAtom> &speciesGroup);
223 
224  // Serialize definitions
225 
226  template <class Archive>
227  void serialize(Archive& ar, SpeciesGroup<2>& speciesGroup, const unsigned int version)
228  {
229  for (int i = 0; i < 2; ++i) {
230  ar & speciesGroup.atomIds_[i];
231  }
232  ar & speciesGroup.typeId_;
233  }
234 
235  template <class Archive>
236  void serialize(Archive& ar, SpeciesGroup<3>& speciesGroup, const unsigned int version)
237  {
238  for (int i = 0; i < 3; ++i) {
239  ar & speciesGroup.atomIds_[i];
240  }
241  ar & speciesGroup.typeId_;
242  }
243 
244  template <class Archive>
245  void serialize(Archive& ar, SpeciesGroup<4>& speciesGroup, const unsigned int version)
246  {
247  for (int i = 0; i < 4; ++i) {
248  ar & speciesGroup.atomIds_[i];
249  }
250  ar & speciesGroup.typeId_;
251  }
252 
253 }
254 
255 #ifdef UTIL_MPI
256 #include <util/mpi/MpiTraits.h>
257 
258 namespace Util
259 {
260 
264  template <>
266  {
267  public:
268  static MPI::Datatype type;
269  static bool hasType;
270  };
271 
275  template <>
277  {
278  public:
279  static MPI::Datatype type;
280  static bool hasType;
281  };
282 
286  template <>
288  {
289  public:
290  static MPI::Datatype type;
291  static bool hasType;
292  };
293 
294 }
295 
296 namespace Simp
297 {
298 
303 
304 }
305 #endif // ifdef UTIL_MPI
306 
307 #endif
void serialize(Archive &ar, BoundaryEnsemble::Type &data, const unsigned int version)
Serialize a BoundaryEnsemble::Type enum value.
friend void serialize(Archive &ar, SpeciesGroup< NAtom > &speciesGroup, const unsigned int version)
Serialize one SpeciesGroup<NAtom>.
A Group of covalently interacting atoms within any molecule of one Species.
Definition: SpeciesGroup.h:20
static void commitMpiType()
Commit associated MPI DataType.
static bool hasType
Is the MPI type initialized?
Definition: SpeciesGroup.h:269
static bool hasType
Is the MPI type initialized?
Definition: SpeciesGroup.h:280
static MPI::Datatype type
MPI Datatype.
Definition: SpeciesGroup.h:290
File containing preprocessor macros for error handling.
Classes used by all simpatico molecular simulations.
std::istream & operator>>(std::istream &in, MonoclinicBoundary &boundary)
istream extractor for a MonoclinicBoundary.
friend std::istream & operator>>(std::istream &in, SpeciesGroup< NAtom > &speciesGroup)
istream extractor for a SpeciesGroup.
static const int NullIndex
Null (unknown) value for non-negative atom and group type indices.
Definition: SpeciesGroup.h:83
Utility classes for scientific computation.
Definition: accumulators.mod:1
SpeciesGroup()
Constructor.
Definition: SpeciesGroup.h:156
Default MpiTraits class.
Definition: MpiTraits.h:39
int typeId() const
Get the type id for this covalent group.
Definition: SpeciesGroup.h:189
void setAtomId(int i, int atomId)
Set index for one atom in the group.
Definition: SpeciesGroup.h:168
static MPI::Datatype type
MPI Datatype.
Definition: SpeciesGroup.h:279
void commitMpiSpeciesGroupTypes()
Commit all MPI SpeciesGroup data types.
static MPI::Datatype type
MPI Datatype.
Definition: SpeciesGroup.h:268
int atomId(int i) const
Get the local id for a specific Atom.
Definition: SpeciesGroup.h:182
void setTypeId(int typeId)
Set the group type id for this group.
Definition: SpeciesGroup.h:175
static bool hasType
Is the MPI type initialized?
Definition: SpeciesGroup.h:291