Simpatico  v1.10
ddMd/chemistry/AtomType.cpp
1 /*
2 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
3 *
4 * Copyright 2010 - 2017, The Regents of the University of Minnesota
5 * Distributed under the terms of the GNU General Public License.
6 */
7 
8 #include "AtomType.h"
9 #include <util/param/Parameter.h>
10 
11 namespace DdMd
12 {
13 
14  using namespace Util;
15 
16  /*
17  * Constructor
18  */
20  : mass_(1.0),
21  name_(),
22  id_(-1)
23  {}
24 
25  /*
26  * Set the index.
27  */
28  void AtomType::setId(int id)
29  { id_ = id; }
30 
31  /*
32  * Input a AtomType from an istream, without line breaks.
33  */
34  std::istream& operator>>(std::istream& in, AtomType &atomType)
35  {
36  in >> atomType.name_;
37  in >> atomType.mass_;
38  return in;
39  }
40 
41  /*
42  * Output a AtomType to an ostream, without line breaks.
43  */
44  std::ostream& operator<<(std::ostream& out, const AtomType &atomType)
45  {
46  out.width(Parameter::Width);
47  out << atomType.name_;
48  out.setf(std::ios::scientific);
49  out.width(Parameter::Width);
50  out.precision(Parameter::Precision);
51  out << atomType.mass_;
52  return out;
53  }
54 
55  #ifdef UTIL_MPI
56  /*
57  * Call to guarantee initialization of static data.
58  */
60  {
63  }
64  #endif
65 
66 }
67 
68 #ifdef UTIL_MPI
69 namespace Util
70 {
71 
72  template <>
73  void send<DdMd::AtomType>(MPI::Comm& comm, DdMd::AtomType& data, int dest, int tag)
74  {
75  std::string name = data.name();
76  double mass = data.mass();
77  send<std::string>(comm, name, dest, tag);
78  send<double>(comm, mass, dest, tag);
79  }
80 
81  template <>
82  void recv<DdMd::AtomType>(MPI::Comm& comm, DdMd::AtomType& data, int source, int tag)
83  {
84  std::string name;
85  double mass;
86  recv<std::string>(comm, name, source, tag);
87  recv<double>(comm, mass, source, tag);
88  data.setName(name);
89  data.setMass(mass);
90  }
91 
92  template <>
93  void bcast<DdMd::AtomType>(MPI::Intracomm& comm, DdMd::AtomType& data, int root)
94  {
95  std::string name;
96  double mass;
97  int rank = comm.Get_rank();
98  if (rank == root) {
99  name = data.name();
100  mass = data.mass();
101  }
102  bcast<std::string>(comm, name, root);
103  bcast<double>(comm, mass, root);
104  if (rank != root) {
105  data.setName(name);
106  data.setMass(mass);
107  }
108  }
109 
113  MPI::Datatype MpiTraits<DdMd::AtomType>::type = MPI::BYTE;
115 
116 }
117 #endif // ifdef UTIL_MPI
static void initStatic()
Call this to guarantee initialization of static data.
const std::string & name() const
Get the name string.
double mass() const
Get the mass.
Parallel domain decomposition (DD) MD simulation.
friend std::istream & operator>>(std::istream &in, AtomType &atomType)
istream extractor (>>) for an AtomType.
Utility classes for scientific computation.
Definition: accumulators.mod:1
Default MpiTraits class.
Definition: MpiTraits.h:39
static const int Precision
Precision for io of floating point data field.
Definition: Parameter.h:56
static const int Width
Width of output field for a scalar variable.
Definition: Parameter.h:53
friend std::ostream & operator<<(std::ostream &out, const AtomType &atomType)
ostream inserter (<<) for an AtomType.
Descriptor for a type of Atom.
void setId(int Id)
Set the type index.
int id() const
Get the index.