Simpatico  v1.10
mcMd/chemistry/AtomType.h
1 #ifndef MCMD_ATOM_TYPE_H
2 #define MCMD_ATOM_TYPE_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 <string>
14 #include <iostream>
15 
16 namespace McMd
17 {
18 
19  using namespace Util;
20 
30  class AtomType
31  {
32 
33  public:
34 
38  AtomType();
39 
43  virtual ~AtomType();
44 
46 
47 
53  void setId(int Id);
54 
60  void setName(std::string name);
61 
67  void setMass(double mass);
68 
69  #ifdef SIMP_COULOMB
70 
86  void setHasCharge(bool hasCharge);
87 
95  void setCharge(double charge);
96  #endif
97 
99 
101 
105  double mass() const;
106 
107  #ifdef SIMP_COULOMB
108 
111  bool hasCharge() const;
112 
116  double charge() const;
117  #endif
118 
122  const std::string& name() const;
123 
125  int id() const;
126 
128 
129  private:
130 
132  double mass_;
133 
134  #ifdef SIMP_COULOMB
135  double charge_;
137  #endif
138 
140  std::string name_;
141 
143  int id_;
144 
146  bool hasCharge_;
147 
148  //friends:
149 
150  friend
151  std::istream& operator>>(std::istream& in, AtomType &atomType);
152 
153  friend
154  std::ostream& operator<<(std::ostream& out, const AtomType &atomType);
155 
156  template <class Archive>
157  friend void
158  serialize(Archive& ar, AtomType& atomType, const unsigned int version);
159 
160  };
161 
162  // Inline member functions.
163 
164  /*
165  * Get the type id.
166  */
167  inline int AtomType::id() const
168  { return id_; }
169 
170  /*
171  * Get the name string.
172  */
173  inline const std::string& AtomType::name() const
174  { return name_; }
175 
176  /*
177  * Get the mass.
178  */
179  inline double AtomType::mass() const
180  { return mass_; }
181 
182  #ifdef SIMP_COULOMB
183  /*
184  * Get the hasCharge bool flag.
185  */
186  inline bool AtomType::hasCharge() const
187  { return hasCharge_; }
188 
189  /*
190  * Get the electrical charge.
191  */
192  inline double AtomType::charge() const
193  {
194  UTIL_ASSERT(hasCharge_);
195  return charge_;
196  }
197  #endif
198 
199  // Declarations of friend extracter and inserter functions
200 
212  std::istream& operator>>(std::istream& in, AtomType &atomType);
213 
225  std::ostream& operator<<(std::ostream& out, const AtomType &atomType);
226 
234  template <class Archive>
235  void serialize(Archive& ar, AtomType& atomType, const unsigned int version)
236  {
237  ar & atomType.name_;
238  ar & atomType.mass_;
239  #ifdef SIMP_COULOMB
240  ar & atomType.hasCharge_;
241  if (atomType.hasCharge_) {
242  ar & atomType.charge_;
243  }
244  #endif
245  }
246 
247 }
248 
249 #ifdef UTIL_MPI
250 #include <util/mpi/MpiSendRecv.h>
251 #include <util/mpi/MpiTraits.h>
252 
253 namespace Util
254 {
255 
264  template <>
265  void send<McMd::AtomType>(MPI::Comm& comm, McMd::AtomType& data, int dest, int tag);
266 
275  template <>
276  void recv<McMd::AtomType>(MPI::Comm& comm, McMd::AtomType& data, int source, int tag);
277 
285  template <>
286  void bcast<McMd::AtomType>(MPI::Intracomm& comm, McMd::AtomType& data, int root);
287 
291  template <>
292  class MpiTraits<McMd::AtomType>
293  {
294  public:
295  static MPI::Datatype type;
296  static bool hasType;
297  };
298 
299 }
300 #endif
301 
302 #endif
static bool hasType
Is the MPI type initialized?
File containing preprocessor macros for error handling.
void serialize(Archive &ar, PairSelector &selector, const unsigned int version)
Serialize a PairSelector.
Definition: PairSelector.h:167
Descriptor for a type of Atom.
std::ostream & operator<<(std::ostream &out, const PairSelector &selector)
ostream inserter (<<) for a PairSelector object.
Utility classes for scientific computation.
Definition: accumulators.mod:1
Default MpiTraits class.
Definition: MpiTraits.h:39
int id() const
Get the index.
static MPI::Datatype type
MPI Datatype.
std::istream & operator>>(std::istream &in, PairSelector &selector)
istream extractor (>>) for a PairSelector object.
double mass() const
Get the mass.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
This file contains templates for global functions send<T>, recv<T> and bcast<T>.
double charge() const
Get the electrical charge value.
const std::string & name() const
Get the name string.
bool hasCharge() const
Does this type have a charge value?
#define UTIL_ASSERT(condition)
Assertion macro suitable for debugging serial or parallel code.
Definition: global.h:75