Simpatico  v1.10
OrthoBoxExternal.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 "OrthoBoxExternal.h"
9 
10 #include <iostream>
11 
12 namespace Simp
13 {
14 
15  using namespace Util;
16 
17  /*
18  * Constructor.
19  */
21  : indConfine_(3),
22  boundaryPtr_(0),
23  nAtomType_(0),
24  isInitialized_(false)
25  { setClassName("OrthoBoxExternal"); }
26 
27  /*
28  * Copy constructor.
29  */
31  : indConfine_(other.indConfine_),
32  epsilon_(other.epsilon_),
33  sigma_(other.sigma_),
34  sigmaCb_(other.sigmaCb_),
35  cutoff_(other.cutoff_),
36  coeff_(other.coeff_),
37  boundaryPtr_(other.boundaryPtr_),
38  nAtomType_(other.nAtomType_),
39  isInitialized_(other.isInitialized_)
40  {}
41 
42  /*
43  * Assignment operator.
44  */
46  {
47  indConfine_ = other.indConfine_;
48  boundaryPtr_ = other.boundaryPtr_;
49  nAtomType_ = other.nAtomType_;
50  isInitialized_ = other.isInitialized_;
51  epsilon_ = other.epsilon_;
52  sigma_ = other.sigma_;
53  sigmaCb_ = other.sigmaCb_;
54  cutoff_ = other.cutoff_;
55  coeff_ = other.coeff_;
56  return *this;
57  }
58 
59  /*
60  * Set nAtomType
61  */
62  void OrthoBoxExternal::setNAtomType(int nAtomType)
63  {
64  if (nAtomType <= 0) {
65  UTIL_THROW("nAtomType <= 0");
66  }
67  if (nAtomType > MaxAtomType) {
68  UTIL_THROW("nAtomType > OrthoBoxExternal::MaxAtomType");
69  }
70  nAtomType_ = nAtomType;
71  }
72 
73  /*
74  * Set pointer to the Boundary.
75  */
77  { boundaryPtr_ = &boundary; }
78 
83  {
84  // Preconditions
85  if (!isInitialized_) {
86  UTIL_THROW("OrthoBoxExternal potential is not initialized");
87  }
88 
89  epsilon_ = externalParameter;
90  }
91 
92  /*
93  * Read potential parameters from file.
94  */
95  void OrthoBoxExternal::readParameters(std::istream &in)
96  {
97  if (nAtomType_ == 0) {
98  UTIL_THROW("nAtomType must be set before readParam");
99  }
100  if (!boundaryPtr_) {
101  UTIL_THROW("Boundary must be set before readParam");
102  }
103 
104  // Read parameters
105  read<int>(in, "indexConfinement", indConfine_);
106  if (indConfine_ < 0 || indConfine_ > Dimension) {
107  UTIL_THROW("Invalid index for confinement directions.");
108  }
109  read<double>(in, "epsilon", epsilon_);
110  read<double>(in, "sigma", sigma_);
111  read<double>(in, "cutoff", cutoff_);
112 
113  // Initialize dependent variables (particle number density = 0.7)
114  sigmaCb_ = sigma_ * sigma_ * sigma_;
115  coeff_ = 4.0 * epsilon_ * acos(-1.0) / 45.0 * 0.7 * sigmaCb_;
116 
117  isInitialized_ = true;
118  }
119 
120  /*
121  * Load internal state from an archive.
122  */
124  {
125  ar >> nAtomType_;
126  if (nAtomType_ <= 0) {
127  UTIL_THROW( "nAtomType must be positive");
128  }
129  if (!boundaryPtr_) {
130  UTIL_THROW("Boundary must be set before readParam");
131  }
132  loadParameter<int>(ar, "indexConfinement", indConfine_);
133  if (indConfine_ < 0 || indConfine_ > Dimension) {
134  UTIL_THROW("Invalid index for confinement directions.");
135  }
136  loadParameter<double>(ar, "epsilon", epsilon_);
137  loadParameter<double>(ar, "sigma", sigma_);
138  loadParameter<double>(ar, "cutoff", cutoff_);
139  ar >> sigmaCb_;
140  ar >> coeff_;
141  isInitialized_ = true;
142  }
143 
144  /*
145  * Save internal state to an archive.
146  */
148  {
149  ar << nAtomType_;
150  ar << indConfine_;
151  ar << epsilon_;
152  ar << sigma_;
153  ar << cutoff_;
154  ar << sigmaCb_;
155  ar << coeff_;
156  }
157 
158  /*
159  * Set a potential energy parameter, identified by a string.
160  */
161  void OrthoBoxExternal::set(std::string name, double value)
162  {
163  if (name == "epsilon") {
164  epsilon_ = value;
165  } else
166  if (name == "sigma") {
167  sigma_ = value;
168  } else
169  if (name == "cutoff") {
170  cutoff_ = value;
171  } else {
172  UTIL_THROW("Unrecognized parameter name");
173  }
174  }
175 
176  /*
177  * Get a parameter value, identified by a string.
178  */
179  double OrthoBoxExternal::get(std::string name) const
180  {
181  double value = 0.0;
182  if (name == "epsilon") {
183  value = epsilon_;
184  } else
185  if (name == "sigma") {
186  value = sigma_;
187  } else
188  if (name == "cutoff") {
189  value = cutoff_;
190  } else {
191  UTIL_THROW("Unrecognized parameter name");
192  }
193  return value;
194  }
195 
200  {
201  return epsilon_;
202  }
203 
207  std::string OrthoBoxExternal::className() const
208  { return std::string("OrthoBoxExternal"); }
209 
210 
211 }
const int Dimension
Dimensionality of space.
Definition: Dimension.h:19
A repulsive 9-3 potential confining particles inside an orthogonal box along directions specified by ...
An orthorhombic periodic unit cell.
double externalParameter() const
Returns external parameter.
Classes used by all simpatico molecular simulations.
void readParameters(std::istream &in)
Read potential parameters, and initialize other variables.
std::string className() const
Return name string "LJPair" for this evaluator class.
OrthoBoxExternal()
Default constructor.
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
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
Utility classes for scientific computation.
Definition: accumulators.mod:1
OrthoBoxExternal & operator=(const OrthoBoxExternal &other)
Assignment.
Saving archive for binary istream.
void setNAtomType(int nAtomType)
Set nAtomType value.
void setClassName(const char *className)
Set class name string.
void setBoundary(Boundary &boundary)
Set pointer to Boundary.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
void setExternalParameter(double externalParameter)
Sets external parameter.