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