Simpatico  v1.10
LamellarOrderingExternal.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 "LamellarOrderingExternal.h"
9 
10 #include <iostream>
11 
12 namespace Simp
13 {
14 
15  using namespace Util;
16 
17  /*
18  * Constructor.
19  */
21  : perpDirection_(0),
22  interfaceWidth_(),
23  externalParameter_(),
24  periodicity_(),
25  boundaryPtr_(0),
26  nAtomType_(0),
27  isInitialized_(false)
28  { setClassName("LamellarOrderingExternal"); }
29 
30  /*
31  * Copy constructor.
32  */
34  : perpDirection_(other.perpDirection_),
35  interfaceWidth_(other.interfaceWidth_),
36  externalParameter_(other.externalParameter_),
37  periodicity_(other.periodicity_),
38  boundaryPtr_(other.boundaryPtr_),
39  nAtomType_(other.nAtomType_),
40  isInitialized_(other.isInitialized_)
41  {
42  prefactor_.allocate(nAtomType_);
43  for (int i=0; i < nAtomType_; ++i) {
44  prefactor_[i] = other.prefactor_[i];
45  }
46  }
47 
48  /*
49  * Assignment operator.
50  */
52  {
53  perpDirection_ = other.perpDirection_;
54  interfaceWidth_ = other.interfaceWidth_;
55  externalParameter_ = other.externalParameter_;
56  periodicity_ = other.periodicity_;
57  boundaryPtr_ = other.boundaryPtr_;
58  nAtomType_ = other.nAtomType_;
59  isInitialized_ = other.isInitialized_;
60  for (int i=0; i < nAtomType_; ++i) {
61  prefactor_[i] = other.prefactor_[i];
62  }
63  return *this;
64  }
65 
66  /*
67  * Set nAtomType
68  */
70  {
71  if (nAtomType <= 0) {
72  UTIL_THROW("nAtomType <= 0");
73  }
74  if (nAtomType > MaxAtomType) {
75  UTIL_THROW("nAtomType > LamellarOrderingExternal::MaxAtomType");
76  }
77  nAtomType_ = nAtomType;
78  }
79 
81  {
82  UTIL_CHECK(isInitialized_);
83  externalParameter_ = externalParameter;
84  }
85 
86 
87  /*
88  * Set pointer to the Boundary.
89  */
91  { boundaryPtr_ = &boundary; }
92 
93  /*
94  * Read potential parameters from file.
95  */
97  {
98  if (nAtomType_ <= 0) {
99  UTIL_THROW("nAtomType must be set before readParam");
100  }
101  if (!boundaryPtr_) {
102  UTIL_THROW("Boundary must be set before readParam");
103  }
104 
105  // Read parameters
106  read<int>(in, "perpDirection", perpDirection_);
107  if (perpDirection_ < 0 || perpDirection_ >= Dimension) {
108  UTIL_THROW("Invalid index for perpendicular direction.");
109  }
110  prefactor_.allocate(nAtomType_);
111  readDArray<double>(in, "prefactor", prefactor_, nAtomType_);
112  read<double>(in, "externalParameter", externalParameter_);
113  read<double>(in, "interfaceWidth", interfaceWidth_);
114  read<int>(in, "periodicity", periodicity_);
115  isInitialized_ = true;
116  }
117 
118  /*
119  * Load internal state from an archive.
120  */
122  {
123  UTIL_CHECK(nAtomType_ > 0);
124  loadParameter<int>(ar, "perpDirection", perpDirection_);
125  if (perpDirection_ < 0 || perpDirection_ >= Dimension) {
126  UTIL_THROW("Invalid index for perpendicular direction.");
127  }
128  prefactor_.allocate(nAtomType_);
129  loadDArray<double>(ar, "prefactor", prefactor_, nAtomType_);
130  loadParameter<double>(ar, "externalParameter", externalParameter_);
131  loadParameter<double>(ar, "interfaceWidth", interfaceWidth_);
132  loadParameter<int>(ar, "periodicity", periodicity_);
133  isInitialized_ = true;
134  }
135 
136  /*
137  * Save internal state to an archive.
138  */
140  {
141  UTIL_CHECK(nAtomType_ > 0);
142  UTIL_CHECK(isInitialized_);
143  ar << perpDirection_;
144  ar << prefactor_;
145  ar << externalParameter_;
146  ar << interfaceWidth_;
147  ar << periodicity_;
148  }
149 
150  /*
151  * Set a potential energy parameter, identified by a string.
152  */
153  void LamellarOrderingExternal::set(std::string name, double value)
154  {
155  if (name == "externalParameter") {
156  externalParameter_ = value;
157  } else
158  if (name == "interfaceWidth") {
159  interfaceWidth_ = value;
160  } else
161  if (name == "periodicity") {
162  periodicity_ = value;
163  } else {
164  UTIL_THROW("Unrecognized parameter name");
165  }
166  }
167 
168  /*
169  * Get a parameter value, identified by a string.
170  */
171  double LamellarOrderingExternal::get(std::string name) const
172  {
173  double value = 0.0;
174  if (name == "externalParameter") {
175  value = externalParameter_;
176  } else
177  if (name == "interfaceWidth") {
178  value = interfaceWidth_;
179  } else
180  if (name == "periodicity") {
181  value = periodicity_;
182  } else {
183  UTIL_THROW("Unrecognized parameter name");
184  }
185  return value;
186  }
187 
188  /*
189  * Return external parameter.
190  */
192  { return externalParameter_; }
193 
194  /*
195  * Return name string "LamellarOrderingExternal".
196  */
198  { return std::string("LamellarOrderingExternal"); }
199 
200 }
const int Dimension
Dimensionality of space.
Definition: Dimension.h:19
void setExternalParameter(double externalParameter)
Sets external parameter.
void setBoundary(Boundary &boundary)
Set pointer to Boundary.
double externalParameter() const
Returns external parameter.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
LamellarOrderingExternal & operator=(const LamellarOrderingExternal &other)
Assignment.
An orthorhombic periodic unit cell.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
A clipped cosine potential that induces lamellar ordering along the direction specified by perpDirect...
Classes used by all simpatico molecular simulations.
LamellarOrderingExternal()
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
Utility classes for scientific computation.
Definition: accumulators.mod:1
Saving archive for binary istream.
void setNAtomType(int nAtomType)
Set nAtomType value.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition: global.h:68
void setClassName(const char *className)
Set class name string.
void allocate(int capacity)
Allocate the underlying C array.
Definition: DArray.h:191
void readParameters(std::istream &in)
Read potential parameters, and initialize other variables.
std::string className() const
Return name string "LamellarOrderingExternal".