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