Simpatico  v1.10
SlitExternal.h
1 #ifndef SIMP_SLIT_EXTERNAL_H
2 #define SIMP_SLIT_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/param/ParamComposite.h>
13 #include <util/global.h>
14 #include <cmath>
15 
16 namespace Simp
17 {
18 
19  using namespace Util;
20 
40  class SlitExternal : public ParamComposite
41  {
42 
43  public:
44 
48  SlitExternal();
49 
53  SlitExternal(const SlitExternal& other);
54 
58  SlitExternal& operator = (const SlitExternal& other);
59 
61 
62 
68  void setNAtomType(int nAtomType);
69 
75  void setBoundary(Boundary &boundary);
76 
83 
92  void readParameters(std::istream &in);
93 
99  virtual void loadParameters(Serializable::IArchive &ar);
100 
106  virtual void save(Serializable::OArchive &ar);
107 
108  /*
109  * Set a potential energy parameter, identified by a string.
110  */
111  void set(std::string name, double value);
112 
113  /*
114  * Get a parameter value, identified by a string.
115  */
116  double get(std::string name) const;
117 
119 
121 
122 
126  std::string className() const;
127 
133  double externalParameter() const;
134 
142  double energy(double d, int i) const;
143 
151  double energy(const Vector& position, int i) const;
152 
163  double forceScalar(double d, int i) const;
164 
172  void getForce(const Vector& position, int type, Vector& force) const;
173 
175 
176  private:
177 
179  static const int MaxAtomType = 2;
180 
182  double epsilon_;
183 
185  double sigma_;
186 
188  double sigmaCb_;
189 
191  double cutoff_;
192 
194  double coeff_;
195 
197  Boundary *boundaryPtr_;
198 
200  int nAtomType_;
201 
203  bool isInitialized_;
204 
205  };
206 
207  // inline methods
208 
209  /*
210  * Calculate repulsive potential energy for particle of type i.
211  *
212  * 7.905694 = 25/sqrt(10), which is the negative of the minimum of the
213  * unshifted 9-3 potential.
214  */
215  inline double SlitExternal::energy(double d, int type) const
216  {
217  if (d < cutoff_) {
218  double r3i;
219  r3i = d * d * d;
220  if (r3i < 0.129615*sigmaCb_) r3i = 0.129615 * sigmaCb_;
221  r3i = sigmaCb_ / r3i;
222  return coeff_ * (r3i*(r3i*r3i - 7.5) + 7.905694);
223  } else {
224  return 0.0;
225  }
226  }
227 
228  /*
229  * Calculate external potential energy for a single atom.
230  */
231  inline double SlitExternal::energy(const Vector& position, int type) const
232  {
233  double d = position[2];
234  double halfL = boundaryPtr_->lengths()[2] * 0.5;
235  if (d > halfL) d = halfL + halfL - d;
236  return energy(d, type);
237  }
238 
239  /*
240  * Calculate force for a particle as a function of distance to boundary.
241  */
242  inline double SlitExternal::forceScalar(double d, int i) const
243  {
244  if (d < cutoff_) {
245  double r3i;
246  r3i = d * d * d;
247  if (r3i < 0.129615 * sigmaCb_) r3i = 0.129615 * sigmaCb_;
248  r3i = sigmaCb_ / r3i;
249  return coeff_ * (9.0*r3i*r3i - 22.5) * r3i / d;
250  } else {
251  return 0.0;
252  }
253  }
254 
255  /*
256  * Calculate external force for a single atom.
257  */
258  inline void
259  SlitExternal::getForce(const Vector& position, int type, Vector& force) const
260  {
261  double d = position[2];
262  double halfL = boundaryPtr_->lengths()[2] * 0.5;
263  double scalarf;
264  if (d > halfL) {
265  d = halfL + halfL - d;
266  scalarf = forceScalar(d, type);
267  force = Vector(0.0, 0.0, -scalarf);
268  } else {
269  scalarf = forceScalar(d, type);
270  force = Vector(0.0, 0.0, scalarf);
271  }
272  }
273 
274 }
275 #endif
double forceScalar(double d, int i) const
Returns magnitude of the repulsive force.
Definition: SlitExternal.h:242
double energy(double d, int i) const
Returns external potential energy of a particle of type i.
Definition: SlitExternal.h:215
void setExternalParameter(double externalParameter)
Sets external parameter.
A Vector is a Cartesian vector.
Definition: Vector.h:75
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.
File containing preprocessor macros for error handling.
Classes used by all simpatico molecular simulations.
Saving / output archive for binary ostream.
void setNAtomType(int nAtomType)
Set nAtomType value.
Utility classes for scientific computation.
Definition: accumulators.mod:1
void getForce(const Vector &position, int type, Vector &force) const
Returns force caused by the external potential.
Definition: SlitExternal.h:259
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.
SlitExternal()
Default constructor.
An object that can read multiple parameters from file.
SlitExternal & operator=(const SlitExternal &other)
Assignment.