Simpatico  v1.10
BoundaryEnsemble.cpp
1 /*
2 * Util Package - C++ Utilities for Scientific Computation
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 "BoundaryEnsemble.h"
9 #ifdef UTIL_MPI
10 #include <util/mpi/MpiStructBuilder.h>
11 #endif
12 
13 namespace Simp
14 {
15 
16  using namespace Util;
17 
18  /*
19  * Constructor.
20  */
22  : pressure_(1.0),
23  type_(type)
24  { setClassName("BoundaryEnsemble"); }
25 
26  /*
27  * Destructor.
28  */
30  {}
31 
32  /*
33  * Set the target pressure.
34  */
36  {
37  if (!isIsobaric()) {
38  UTIL_THROW("Must be an isobaric ensemble");
39  }
40  pressure_ = pressure;
41  }
42 
43  /*
44  * Read the type and (if necessary) pressure from file.
45  */
46  void BoundaryEnsemble::readParameters(std::istream& in)
47  {
48  read<Type>(in, "type", type_);
49  if (isIsobaric()) {
50  read<double>(in, "pressure", pressure_);
51  }
52  }
53 
54  /*
55  * Load internal state from an archive.
56  */
58  {
59  loadParameter<Type>(ar, "type", type_);
60  if (isIsobaric()) {
61  loadParameter<double>(ar, "pressure", pressure_);
62  }
63  }
64 
65  /*
66  * Save internal state to an archive.
67  */
69  {
70  ar << type_;
71  if (isIsobaric()) {
72  ar << pressure_;
73  }
74  }
75 
76  /*
77  * Extract an BoundaryEnsemble::Type from an istream as a string.
78  */
79  std::istream& operator>>(std::istream& in, BoundaryEnsemble::Type &type)
80  {
81  std::string buffer;
82  in >> buffer;
83  if (buffer == "RIGID" || buffer == "rigid") {
84  type = BoundaryEnsemble::RIGID;
85  } else
86  if (buffer == "ISOBARIC" || buffer == "isobaric") {
87  type = BoundaryEnsemble::ISOBARIC;
88  } else {
89  UTIL_THROW("Invalid BoundaryEnsemble::Type value input");
90  }
91  return in;
92  }
93 
94  /*
95  * Insert a BoundaryEnsemble::Type to an ostream as a string.
96  */
97  std::ostream& operator<<(std::ostream& out, const BoundaryEnsemble::Type &type)
98  {
99  if (type == BoundaryEnsemble::RIGID) {
100  out << "rigid";
101  } else
102  if (type == BoundaryEnsemble::ISOBARIC) {
103  out << "isobaric";
104  } else
105  if (type == BoundaryEnsemble::UNKNOWN) {
106  out << "unknown";
107  }
108  return out;
109  }
110 
111  #ifdef UTIL_MPI
112 
116  {
117  MpiStructBuilder builder;
118  BoundaryEnsemble object;
119 
120  builder.setBase(&object);
121  builder.addMember(&object.pressure_, MPI::DOUBLE);
122  builder.addMember(&object.type_, MPI::INT);
125  }
126  #endif
127 
128 }
129 
130 #ifdef UTIL_MPI
131 namespace Util
132 {
133 
134  // Initialize Simp::BoundaryEnsemble MPI Datatype.
135  MPI::Datatype MpiTraits<Simp::BoundaryEnsemble>::type = MPI::BYTE;
137 
138  // Initialize Simp::BoundaryEnsemble::Type MPI Datatype.
139  MPI::Datatype MpiTraits<Simp::BoundaryEnsemble::Type>::type = MPI::INT;
141 
142 }
143 #endif
void addMember(void *memberAddress, MPI::Datatype type, int count=1)
Add a new member variable to the type map.
bool isIsobaric() const
Is this an Isobaric ensemble?
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
double pressure() const
Get the target pressure.
Statistical ensemble for changes in the periodic unit cell size.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
BoundaryEnsemble(Type type=UNKNOWN)
Constructor.
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.
Saving / output archive for binary ostream.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
Type
Enumeration of the allowed types of BoundaryEnsemble.
Utility classes for scientific computation.
Definition: accumulators.mod:1
Default MpiTraits class.
Definition: MpiTraits.h:39
std::ostream & operator<<(std::ostream &out, const MonoclinicBoundary &boundary)
ostream inserter for an MonoclinicBoundary.
virtual void readParameters(std::istream &in)
Read the type and (if necessary) pressure from file.
A MpiStructBuilder objects is used to create an MPI Struct datatype.
~BoundaryEnsemble()
Destructor.
Saving archive for binary istream.
void setPressure(double pressure)
Set the pressure.
void setClassName(const char *className)
Set class name string.
static void commitMpiType()
Commit associated MPI DataType.