Simpatico  v1.10
BoxExternal.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 "BoxExternal.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("BoxExternal"); }
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 BoxExternal::setNAtomType(int nAtomType)
60  {
61  if (nAtomType <= 0) {
62  UTIL_THROW("nAtomType <= 0");
63  }
64  if (nAtomType > MaxAtomType) {
65  UTIL_THROW("nAtomType > BoxExternal::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("BoxExternal potential is not initialized");
84  }
85 
86  epsilon_ = externalParameter;
87  }
88 
89  /*
90  * Read potential parameters from file.
91  */
92  void BoxExternal::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 << epsilon_;
139  ar << sigma_;
140  ar << cutoff_;
141  ar << sigmaCb_;
142  ar << coeff_;
143  }
144 
145  /*
146  * Set a potential energy parameter, identified by a string.
147  */
148  void BoxExternal::set(std::string name, double value)
149  {
150  if (name == "epsilon") {
151  epsilon_ = value;
152  } else
153  if (name == "sigma") {
154  sigma_ = value;
155  } else
156  if (name == "cutoff") {
157  cutoff_ = value;
158  } else {
159  UTIL_THROW("Unrecognized parameter name");
160  }
161  }
162 
163  /*
164  * Get a parameter value, identified by a string.
165  */
166  double BoxExternal::get(std::string name) const
167  {
168  double value = 0.0;
169  if (name == "epsilon") {
170  value = epsilon_;
171  } else
172  if (name == "sigma") {
173  value = sigma_;
174  } else
175  if (name == "cutoff") {
176  value = cutoff_;
177  } else {
178  UTIL_THROW("Unrecognized parameter name");
179  }
180  return value;
181  }
182 
187  {
188  return epsilon_;
189  }
190 
194  std::string BoxExternal::className() const
195  { return std::string("BoxExternal"); }
196 
197 
198 }
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
An orthorhombic periodic unit cell.
void readParameters(std::istream &in)
Read potential parameters, and initialize other variables.
Definition: BoxExternal.cpp:92
void setExternalParameter(double externalParameter)
Sets external parameter.
Definition: BoxExternal.cpp:79
Classes used by all simpatico molecular simulations.
BoxExternal & operator=(const BoxExternal &other)
Assignment.
Definition: BoxExternal.cpp:43
Saving / output archive for binary ostream.
std::string className() const
Return name string "LJPair" for this evaluator class.
#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.
BoxExternal()
Default constructor.
Definition: BoxExternal.cpp:20
Utility classes for scientific computation.
Definition: accumulators.mod:1
double externalParameter() const
Returns external parameter.
A repulsive 9-3 potential confining particles within a box.
Definition: BoxExternal.h:42
Saving archive for binary istream.
void setClassName(const char *className)
Set class name string.
void setNAtomType(int nAtomType)
Set nAtomType value.
Definition: BoxExternal.cpp:59
void setBoundary(Boundary &boundary)
Set pointer to Boundary.
Definition: BoxExternal.cpp:73