Simpatico  v1.10
OrthoBoxExternal.h
1 #ifndef SIMP_ORTHO_BOX_EXTERNAL_H
2 #define SIMP_ORTHO_BOX_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 
47  {
48 
49  public:
50 
55 
59  OrthoBoxExternal(const OrthoBoxExternal& other);
60 
65 
67 
68 
74  void setNAtomType(int nAtomType);
75 
81  void setBoundary(Boundary &boundary);
82 
89 
98  void readParameters(std::istream &in);
99 
105  virtual void loadParameters(Serializable::IArchive &ar);
106 
112  virtual void save(Serializable::OArchive &ar);
113 
114  /*
115  * Set a potential energy parameter, identified by a string.
116  */
117  void set(std::string name, double value);
118 
119  /*
120  * Get a parameter value, identified by a string.
121  */
122  double get(std::string name) const;
123 
125 
127 
128 
132  std::string className() const;
133 
139  double externalParameter() const;
140 
148  double energy(double d, int i) const;
149 
157  double energy(const Vector& position, int i) const;
158 
169  double forceScalar(double d, int i) const;
170 
178  void getForce(const Vector& position, int type, Vector& force) const;
179 
181 
182  private:
183 
185  static const int MaxAtomType = 2;
186 
188  int indConfine_;
189 
191  double epsilon_;
192 
194  double sigma_;
195 
197  double sigmaCb_;
198 
200  double cutoff_;
201 
203  double coeff_;
204 
206  Boundary *boundaryPtr_;
207 
209  int nAtomType_;
210 
212  bool isInitialized_;
213 
214  };
215 
216  // inline methods
217 
218  /*
219  * Calculate repulsive potential energy for particle of type i.
220  *
221  * 7.905694 = 25/sqrt(10), which is the negative of the minimum of the
222  * unshifted 9-3 potential.
223  */
224  inline double OrthoBoxExternal::energy(double d, int type) const
225  {
226  if (d < cutoff_) {
227  double r3i;
228  r3i = d * d * d;
229  if (r3i < 0.129615*sigmaCb_) r3i = 0.129615 * sigmaCb_;
230  r3i = sigmaCb_ / r3i;
231  return coeff_ * (r3i*(r3i*r3i - 7.5) + 7.905694);
232  } else {
233  return 0.0;
234  }
235  }
236 
237  /*
238  * Calculate external potential energy for a single atom.
239  */
240  inline double OrthoBoxExternal::energy(const Vector& position, int type) const
241  {
242  double d, totalEnergy;
243  Vector halfL = boundaryPtr_->lengths();
244  halfL *= 0.5;
245  totalEnergy = 0.0;
246  for (int i = indConfine_; i < Dimension; ++i) {
247  d = position[i];
248  if (d > halfL[i]) d = halfL[i] + halfL[i] - d;
249  totalEnergy += energy(d, type);
250  }
251  return totalEnergy;
252  }
253 
254  /*
255  * Calculate force for a particle as a function of distance to boundary.
256  */
257  inline double OrthoBoxExternal::forceScalar(double d, int i) const
258  {
259  if (d < cutoff_) {
260  double r3i;
261  r3i = d * d * d;
262  if (r3i < 0.129615 * sigmaCb_) r3i = 0.129615 * sigmaCb_;
263  r3i = sigmaCb_ / r3i;
264  return coeff_ * (9.0*r3i*r3i - 22.5) * r3i / d;
265  } else {
266  return 0.0;
267  }
268  }
269 
270  /*
271  * Calculate external force for a single atom.
272  */
273  inline void
274  OrthoBoxExternal::getForce(const Vector& position, int type, Vector& force) const
275  {
276  double d = position[2];
277  double scalarf;
278  Vector halfL = boundaryPtr_->lengths();
279  halfL *= 0.5;
280  force.zero();
281  for (int i = indConfine_; i < Dimension; ++i) {
282  d = position[i];
283  if (d > halfL[i]) {
284  d = halfL[i] + halfL[i] - d;
285  scalarf = forceScalar(d, type);
286  force[i] = -scalarf;
287  } else {
288  scalarf = forceScalar(d, type);
289  force[i] = scalarf;
290  }
291  }
292  }
293 
294 }
295 #endif
Vector & zero()
Set all elements of a 3D vector to zero.
Definition: Vector.h:514
const int Dimension
Dimensionality of space.
Definition: Dimension.h:19
A Vector is a Cartesian vector.
Definition: Vector.h:75
A repulsive 9-3 potential confining particles inside an orthogonal box along directions specified by ...
An orthorhombic periodic unit cell.
double externalParameter() const
Returns external parameter.
File containing preprocessor macros for error handling.
Classes used by all simpatico molecular simulations.
void readParameters(std::istream &in)
Read potential parameters, and initialize other variables.
std::string className() const
Return name string "LJPair" for this evaluator class.
OrthoBoxExternal()
Default constructor.
Saving / output archive for binary ostream.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
Utility classes for scientific computation.
Definition: accumulators.mod:1
OrthoBoxExternal & operator=(const OrthoBoxExternal &other)
Assignment.
void getForce(const Vector &position, int type, Vector &force) const
Returns force caused by the external potential.
Saving archive for binary istream.
void setNAtomType(int nAtomType)
Set nAtomType value.
void setBoundary(Boundary &boundary)
Set pointer to Boundary.
An object that can read multiple parameters from file.
double forceScalar(double d, int i) const
Returns magnitude of the repulsive force.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
double energy(double d, int i) const
Returns external potential energy of a particle of type i.
void setExternalParameter(double externalParameter)
Sets external parameter.