OpenMPCD
WeeksChandlerAndersen_DistanceOffset.hpp
1 #ifndef OPENMPCD_PAIRPOTENTIALS_WEEKSCHANDLERANDERSEN_DISTANCEOFFSET_HPP
2 #define OPENMPCD_PAIRPOTENTIALS_WEEKSCHANDLERANDERSEN_DISTANCEOFFSET_HPP
3 
4 #include <OpenMPCD/PairPotentials/Base.hpp>
5 
8 
9 namespace OpenMPCD
10 {
11 namespace PairPotentials
12 {
13 
14 /**
15  * A generalization of the Weeks-Chandler-Andersen (WCA) potential.
16  *
17  * The Weeks-Chandler-Andersen potential has been introduced by Weeks, Chandler,
18  * and Andersen, in J. Chem. Phys. 54, 5237 (1971). DOI: 10.1063/1.1674820
19  *
20  * This generalization introduces an offset \f$ D \f$ of the particle distance
21  * \f$ r \f$. With \f$ \epsilon \f$ and \f$ sigma \f$ being parameters, the
22  * interaction potential is given by
23  * \f[
24  * 4 * \epsilon *
25  * \left(
26  * \left( \frac{ \sigma }{ r - D } \right)^{12}
27  * -
28  * \left( \frac{ \sigma }{ r - D } \right)^{6}
29  * +
30  * \frac{ 1 }{ 4 }
31  * \right)
32  * *
33  * \theta \left( 2^{1/6} \sigma - r + D \right)
34  * \f]
35  * with \f$ \theta \left( x \right) \f$ being the Heaviside step function,
36  * which is \f$ 1 \f$ if \f$ x > 0 \f$, and \f$ 0 \f$ otherwise.
37  */
38 template<typename T = FP>
40 {
41 public:
42  /**
43  * The constructor.
44  *
45  * @throw OpenMPCD::AssertionException
46  * If `OPENMPCD_DEBUG` is defined, throws if either
47  * `epsilon < 0`, `sigma < 0`, or `d < 0`.
48  *
49  * @param[in] epsilon The \f$ \epsilon \f$ parameter.
50  * @param[in] sigma The \f$ \sigma \f$ parameter.
51  * @param[in] d The \f$ D \f$ parameter.
52  */
55  const T epsilon, const T sigma, const T d)
56  : epsilon(epsilon), sigma(sigma), d(d)
57  {
58  OPENMPCD_DEBUG_ASSERT(!(epsilon < 0));
59  OPENMPCD_DEBUG_ASSERT(!(sigma < 0));
60  OPENMPCD_DEBUG_ASSERT(!(d < 0));
61  }
62 
63  /**
64  * Returns the force vector of the interaction for a given position vector.
65  *
66  * This function returns the directional derivative
67  * \f[ - \nabla_R V \left( \vec{R} \right) \f]
68  * where \f$ \vec{R} \f$ is the `R` parameter, \f$ V \f$ is the potential
69  * as given by the `potential` function, and \f$ \nabla_R V \f$ is the
70  * gradient of \f$ V \f$ with respect to \f$ \vec{R} \f$.
71  *
72  * @throw OpenMPCD::AssertionException
73  * If `OPENMPCD_DEBUG` is defined, throws if
74  * `R.getMagnitudeSquared() - d * d <= 0`.
75  *
76  * @param[in] R The relative position vector.
77  */
79  Vector3D<T> force(const Vector3D<T>& R) const
80  {
81  const T r2 = R.getMagnitudeSquared();
82 
83  OPENMPCD_DEBUG_ASSERT(r2 - d * d > 0);
84 
86 
87  const T sigma2 = sigma * sigma;
88  const T cutoff = pow(2, 1.0/6) * sigma;
89 
90  const T r = sqrt(r2);
91  if(r - d >= cutoff)
92  return Vector3D<T>(0, 0, 0);
93 
94  const T denominator2 = (r - d) * (r - d);
95  const T frac2 = sigma2 / denominator2;
96  const T frac6 = frac2 * frac2 * frac2;
97  const T frac12 = frac6 * frac6;
98 
99  return R * (24 * epsilon / (r * (r - d)) * ( 2 * frac12 - frac6 ));
100  }
101 
102  /**
103  * Returns the potential of the interaction for a given position vector.
104  *
105  * @throw OpenMPCD::AssertionException
106  * If `OPENMPCD_DEBUG` is defined, throws if
107  * `R.getMagnitudeSquared() - d * d <= 0`.
108  *
109  * @param[in] R The relative position vector.
110  */
112  T potential(const Vector3D<T>& R) const
113  {
114  const T r2 = R.getMagnitudeSquared();
115  const T d2 = d * d;
116 
117  OPENMPCD_DEBUG_ASSERT(r2 - d2 > 0);
118 
120 
121  const T sigma2 = sigma * sigma;
122  const T cutoff = pow(2, 1.0/6) * sigma;
123 
124  const T r = sqrt(r2);
125  if(r - d >= cutoff)
126  return 0;
127  const T denominator2 = (r - d) * (r - d);
128  const T frac2 = sigma2 / denominator2;
129  const T frac6 = frac2 * frac2 * frac2;
130  const T frac12 = frac6 * frac6;
131 
132  return 4 * epsilon * (frac12 - frac6 + 1.0/4);
133  }
134 
135  /**
136  * Returns the \f$ \epsilon \f$ parameter.
137  */
139  T getEpsilon() const
140  {
141  return epsilon;
142  }
143 
144  /**
145  * Returns the \f$ \sigma \f$ parameter.
146  */
148  T getSigma() const
149  {
150  return sigma;
151  }
152 
153  /**
154  * Returns the \f$ D \f$ parameter.
155  */
157  T getD() const
158  {
159  return d;
160  }
161 
162 private:
163  const T epsilon; ///< The \f$ \epsilon \f$ parameter.
164  const T sigma; ///< The \f$ \sigma \f$ parameter.
165  const T d; ///< The \f$ D \f$ parameter.
166 }; //class WeeksChandlerAndersen_DistanceOffset
167 
168 } //namespace PairPotentials
169 } //namespace OpenMPCD
170 #endif //OPENMPCD_PAIRPOTENTIALS_WEEKSCHANDLERANDERSEN_DISTANCEOFFSET_HPP
OpenMPCD::PairPotentials::WeeksChandlerAndersen_DistanceOffset
A generalization of the Weeks-Chandler-Andersen (WCA) potential.
Definition: WeeksChandlerAndersen_DistanceOffset.hpp:39
OpenMPCD::Vector3D
3-dimensional vector.
Definition: Vector3D.hpp:38
OpenMPCD::PairPotentials::WeeksChandlerAndersen_DistanceOffset::getSigma
OPENMPCD_CUDA_HOST_AND_DEVICE T getSigma() const
Returns the parameter.
Definition: WeeksChandlerAndersen_DistanceOffset.hpp:148
OPENMPCD_DEBUG_ASSERT
#define OPENMPCD_DEBUG_ASSERT(assertion)
Asserts that the given expression evaluates to true, but only if OPENMPCD_DEBUG is defined.
Definition: OPENMPCD_DEBUG_ASSERT.hpp:88
OpenMPCD::CUDA::DeviceCode::pow
OPENMPCD_CUDA_HOST_AND_DEVICE boost::enable_if< boost::is_integral< B >, double >::type pow(const B base, const double exponent)
The power function.
Definition: Utilities.hpp:50
OPENMPCD_CUDA_HOST_AND_DEVICE
#define OPENMPCD_CUDA_HOST_AND_DEVICE
Denotes a function to be callable both from the Host and from a CUDA Device.
Definition: Macros.hpp:15
OpenMPCD::PairPotentials::WeeksChandlerAndersen_DistanceOffset::force
OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D< T > force(const Vector3D< T > &R) const
Returns the force vector of the interaction for a given position vector.
Definition: WeeksChandlerAndersen_DistanceOffset.hpp:79
OPENMPCD_DEBUG_ASSERT.hpp
OpenMPCD::PairPotentials::WeeksChandlerAndersen_DistanceOffset::getD
OPENMPCD_CUDA_HOST_AND_DEVICE T getD() const
Returns the parameter.
Definition: WeeksChandlerAndersen_DistanceOffset.hpp:157
OpenMPCD::PairPotentials::WeeksChandlerAndersen_DistanceOffset::WeeksChandlerAndersen_DistanceOffset
OPENMPCD_CUDA_HOST_AND_DEVICE WeeksChandlerAndersen_DistanceOffset(const T epsilon, const T sigma, const T d)
The constructor.
Definition: WeeksChandlerAndersen_DistanceOffset.hpp:54
OpenMPCD::PairPotentials::WeeksChandlerAndersen_DistanceOffset::potential
OPENMPCD_CUDA_HOST_AND_DEVICE T potential(const Vector3D< T > &R) const
Returns the potential of the interaction for a given position vector.
Definition: WeeksChandlerAndersen_DistanceOffset.hpp:112
OpenMPCD::Utility::MathematicalFunctions::sqrt
OPENMPCD_CUDA_HOST_AND_DEVICE T sqrt(const T x)
Returns the sqaure root of the argument.
OpenMPCD::PairPotentials::Base
Abstract base class for pair potentials.
Definition: PairPotentials/Base.hpp:24
OpenMPCD::PairPotentials::WeeksChandlerAndersen_DistanceOffset::getEpsilon
OPENMPCD_CUDA_HOST_AND_DEVICE T getEpsilon() const
Returns the parameter.
Definition: WeeksChandlerAndersen_DistanceOffset.hpp:139
Utilities.hpp
OpenMPCD::Vector3D::getMagnitudeSquared
OPENMPCD_CUDA_HOST_AND_DEVICE RealType getMagnitudeSquared() const
Returns the square of the magnitude of this vector.
Definition: Vector3D.hpp:209