Simpatico  v1.10
LamellarOrderingExternal.h
1 #ifndef SIMP_LAMELLAR_ORDERING_EXTERNAL_H
2 #define SIMP_LAMELLAR_ORDERING_EXTERNAL_H
3 
4 /*
5 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
6 *
7 * Copyright 2010 - 2017, The Regents of the University of Minnesota
8 * Distributed under the terms of the GNU General Public License.
9 */
10 
11 #include <simp/boundary/Boundary.h>
12 #include <util/space/Dimension.h>
13 #include <util/param/ParamComposite.h>
14 #include <util/global.h>
15 #include <cmath>
16 
17 namespace Simp
18 {
19 
20  using namespace Util;
21 
40  {
41 
42  public:
43 
48 
53 
58 
64  void setNAtomType(int nAtomType);
65 
72 
78  void setBoundary(Boundary &boundary);
79 
88  void readParameters(std::istream &in);
89 
95  virtual void loadParameters(Serializable::IArchive &ar);
96 
102  virtual void save(Serializable::OArchive &ar);
103 
104  /*
105  * Set a potential energy parameter, identified by a string.
106  */
107  void set(std::string name, double value);
108 
109  /*
110  * Get a parameter value, identified by a string.
111  */
112  double get(std::string name) const;
113 
119  double externalParameter() const;
120 
128  double energy(double d, int i) const;
129 
137  double energy(const Vector& position, int i) const;
138 
146  double forceScalar(double d, int type) const;
147 
155  void getForce(const Vector& position, int type, Vector& force) const;
156 
160  std::string className() const;
161 
162  private:
163 
165  static const int MaxAtomType = 2;
166 
168  int perpDirection_;
169 
171  double interfaceWidth_;
172 
174  DArray<double> prefactor_;
175 
177  double externalParameter_;
178 
180  int periodicity_;
181 
183  Boundary *boundaryPtr_;
184 
186  int nAtomType_;
187 
189  bool isInitialized_;
190 
191  };
192 
193  // inline methods
194 
195 
196  inline double LamellarOrderingExternal::energy(double d, int type) const
197  {
198  double perpLength, q, clipParameter, arg, clipcos;
199  Vector lengths;
200  lengths = boundaryPtr_->lengths();
201  perpLength = lengths[perpDirection_];
202 
203  q = (2.0*M_PI*periodicity_)/perpLength;
204  clipParameter = 1.0/(q*interfaceWidth_*perpLength);
205  arg = q*d;
206  clipcos = clipParameter*cos(arg);
207 
208  return prefactor_[type]*externalParameter_*tanh(clipcos);
209  }
210 
211  /*
212  * Calculate external potential energy for a single atom.
213  */
214  inline
215  double LamellarOrderingExternal::energy(const Vector& position, int type) const
216  {
217  double d, totalEnergy;
218  totalEnergy = 0.0;
219  d = position[perpDirection_];
220  totalEnergy += energy(d, type);
221 
222  return totalEnergy;
223  }
224 
225  /*
226  * Calculate force for a particle as a function of distance to boundary.
227  */
228  inline double LamellarOrderingExternal::forceScalar(double d, int type) const
229  {
230  double perpLength, q, clipParameter, arg, clipcos, tanH, sechSq;
231  Vector lengths;
232  lengths = boundaryPtr_->lengths();
233  perpLength = lengths[perpDirection_];
234 
235  q = (2.0*M_PI*periodicity_)/perpLength;
236  clipParameter = 1.0/(q*interfaceWidth_*perpLength);
237  arg = q*d;
238  clipcos = clipParameter*cos(arg);
239  tanH = tanh(clipcos);
240  sechSq = (1.0 - tanH*tanH);
241  return prefactor_[type]*externalParameter_*sechSq*clipParameter*sin(arg)*q;
242  }
243 
244  /*
245  * Calculate external force for a single atom.
246  */
247  inline
248  void LamellarOrderingExternal::getForce(const Vector& position, int type,
249  Vector& force) const
250  {
251  double d = position[perpDirection_];
252  double scalarf;
253  force.zero();
254  scalarf = forceScalar(d, type);
255  force[perpDirection_] = scalarf;
256  }
257 
258 }
259 #endif
Vector & zero()
Set all elements of a 3D vector to zero.
Definition: Vector.h:514
A Vector is a Cartesian vector.
Definition: Vector.h:75
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.
File containing preprocessor macros for error handling.
A clipped cosine potential that induces lamellar ordering along the direction specified by perpDirect...
Classes used by all simpatico molecular simulations.
double energy(double d, int i) const
Returns external potential energy of a particle of type i.
LamellarOrderingExternal()
Default constructor.
Saving / output archive for binary ostream.
double forceScalar(double d, int type) const
Returns magnitude of the external force.
Utility classes for scientific computation.
Definition: accumulators.mod:1
Saving archive for binary istream.
void setNAtomType(int nAtomType)
Set nAtomType value.
void getForce(const Vector &position, int type, Vector &force) const
Returns force caused by the external potential.
void readParameters(std::istream &in)
Read potential parameters, and initialize other variables.
An object that can read multiple parameters from file.
std::string className() const
Return name string "LamellarOrderingExternal".