Simpatico  v1.10
SpeciesGroup.tpp
1 #ifndef SIMP_SPECIES_GROUP_TPP
2 #define SIMP_SPECIES_GROUP_TPP
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 "SpeciesGroup.h"
12 #include <util/param/Parameter.h>
13 
14 #ifdef UTIL_MPI
15 #include <util/mpi/MpiStructBuilder.h>
16 #endif
17 
18 namespace Simp
19 {
20 
21  using namespace Util;
22 
23  /*
24  * Input a SpeciesGroup<N> from an istream, without line breaks.
25  */
26  template <int NAtom>
27  std::istream& operator >> (std::istream& in, SpeciesGroup<NAtom>& speciesGroup)
28  {
29  for (int i = 0; i < NAtom; ++i) {
30  in >> speciesGroup.atomIds_[i];
31  }
32  in >> speciesGroup.typeId_;
33  return in;
34  }
35 
36  /*
37  * Output a SpeciesGroup<N> to an ostream, without line breaks.
38  */
39  template <int NAtom>
40  std::ostream&
41  operator << (std::ostream& out, const SpeciesGroup<NAtom>& speciesGroup)
42  {
43  for (int i = 0; i < NAtom; ++i) {
44  out.width(5);
45  out << speciesGroup.atomIds_[i];
46  }
47  out.width(6);
48  out << speciesGroup.typeId_;
49  return out;
50  }
51 
52  #ifdef UTIL_MPI
53 
56  template <int NAtom>
58  {
59  if (!Util::MpiTraits< SpeciesGroup<NAtom> >::hasType) {
60  MpiStructBuilder builder;
61  SpeciesGroup<NAtom> object;
62 
63  builder.setBase(&object);
64  for (int i = 0; i < NAtom; ++i) {
65  builder.addMember(&(object.atomIds_[i]), MPI::INT);
66  }
67  builder.addMember(&object.typeId_, MPI::INT);
68  builder.commit(Util::MpiTraits< SpeciesGroup<NAtom> >::type);
69  Util::MpiTraits< SpeciesGroup<NAtom> >::hasType = true;
70  }
71  }
72  #endif
73 
74 }
75 #endif
void addMember(void *memberAddress, MPI::Datatype type, int count=1)
Add a new member variable to the type map.
A Group of covalently interacting atoms within any molecule of one Species.
Definition: SpeciesGroup.h:20
static void commitMpiType()
Commit associated MPI DataType.
Classes used by all simpatico molecular simulations.
std::istream & operator>>(std::istream &in, MonoclinicBoundary &boundary)
istream extractor for a MonoclinicBoundary.
void setBase(void *objectAddress)
Set address of an class instance.
void commit(MPI::Datatype &newType)
Build and commit a user-defined MPI Struct datatype.
Utility classes for scientific computation.
Definition: accumulators.mod:1
Default MpiTraits class.
Definition: MpiTraits.h:39
A MpiStructBuilder objects is used to create an MPI Struct datatype.