OpenMPCD
WeeksChandlerAndersen.hpp
1 #ifndef OPENMPCD_PAIRPOTENTIALS_WEEKSCHANDLERANDERSEN_HPP
2 #define OPENMPCD_PAIRPOTENTIALS_WEEKSCHANDLERANDERSEN_HPP
3 
4 #include <OpenMPCD/PairPotentials/Base.hpp>
5 
8 
9 namespace OpenMPCD
10 {
11 namespace PairPotentials
12 {
13 
14 /**
15  * Weeks-Chandler-Andersen (WCA) potential.
16  *
17  * This potential has been introduced by Weeks, Chandler, and Andersen, in
18  * J. Chem. Phys. 54, 5237 (1971). DOI: 10.1063/1.1674820
19  *
20  * It is given, as a function of the distance \f$ r \f$ of particles, and with
21  * \f$ \epsilon \f$ and \f$ sigma \f$ being parameters, by
22  * \f[
23  * 4 * \epsilon *
24  * \left(
25  * \left( \frac{ \sigma }{ r } \right)^{12}
26  * -
27  * \left( \frac{ \sigma }{ r } \right)^{6}
28  * +
29  * \frac{ 1 }{ 4 }
30  * \right)
31  * *
32  * \theta \left( 2^{1/6} \sigma - r \right)
33  * \f]
34  * with \f$ \theta \left( x \right) \f$ being the Heaviside step function,
35  * which is \f$ 1 \f$ if \f$ x > 0 \f$, and \f$ 0 \f$ otherwise.
36  */
37 template<typename T = FP>
38 class WeeksChandlerAndersen : public Base<T>
39 {
40 public:
41  /**
42  * The constructor.
43  *
44  * @param[in] epsilon The \f$ \epsilon \f$ parameter.
45  * @param[in] sigma The \f$ \sigma \f$ parameter.
46  */
48  WeeksChandlerAndersen(const T epsilon, const T sigma)
49  : epsilon(epsilon), sigma(sigma)
50  {
51  }
52 
53  /**
54  * Returns the force vector of the interaction for a given position vector.
55  *
56  * This function returns the directional derivative
57  * \f[ - \nabla_R V \left( \vec{R} \right) \f]
58  * where \f$ \vec{R} \f$ is the `R` parameter, \f$ V \f$ is the potential
59  * as given by the `potential` function, and \f$ \nabla_R V \f$ is the
60  * gradient of \f$ V \f$ with respect to \f$ \vec{R} \f$.
61  *
62  * @throw OpenMPCD::AssertionException
63  * If `OPENMPCD_DEBUG` is defined, throws if
64  * `OpenMPCD::Scalar::isZero(R.getMagnitudeSquared())`.
65  *
66  * @param[in] R The relative position vector.
67  */
69  Vector3D<T> force(const Vector3D<T>& R) const
70  {
71  const T r2 = R.getMagnitudeSquared();
72 
74 
76 
77  const T sigma2 = sigma * sigma;
78  const T cutoff = pow(2, 1.0/3) * sigma2;
79 
80  if( r2 >= cutoff )
81  return Vector3D<T>(0, 0, 0);
82 
83  const T frac2 = sigma2 / r2;
84  const T frac6 = frac2 * frac2 * frac2;
85  const T frac12 = frac6 * frac6;
86 
87  return R * (24 * epsilon / r2 * ( 2 * frac12 - frac6 ));
88  }
89 
90  /**
91  * Returns the potential of the interaction for a given position vector.
92  *
93  * @throw OpenMPCD::AssertionException
94  * If `OPENMPCD_DEBUG` is defined, throws if
95  * `OpenMPCD::Scalar::isZero(R.getMagnitudeSquared())`.
96  *
97  * @param[in] R The relative position vector.
98  */
100  T potential(const Vector3D<T>& R) const
101  {
102  const T r2 = R.getMagnitudeSquared();
103 
105 
107 
108  const T sigma2 = sigma * sigma;
109  const T cutoff = pow(2, 1.0/3) * sigma2;
110 
111  if( r2 >= cutoff )
112  return 0;
113 
114  const T frac2 = sigma2 / r2;
115  const T frac6 = frac2 * frac2 * frac2;
116  const T frac12 = frac6 * frac6;
117 
118  return 4 * epsilon * (frac12 - frac6 + 1.0/4);
119  }
120 
121 private:
122  const T epsilon; ///< The \f$ \epsilon \f$ parameter.
123  const T sigma; ///< The \f$ \sigma \f$ parameter.
124 }; //class WeeksChandlerAndersen
125 
126 } //namespace PairPotentials
127 } //namespace OpenMPCD
128 #endif //OPENMPCD_PAIRPOTENTIALS_WEEKSCHANDLERANDERSEN_HPP
OpenMPCD::Scalar::isZero
OPENMPCD_CUDA_HOST_AND_DEVICE boost::enable_if< boost::is_floating_point< T >, bool >::type isZero(const T &val)
Returns whether the given value is zero.
Definition: Scalar.hpp:66
OpenMPCD::Vector3D
3-dimensional vector.
Definition: Vector3D.hpp:38
OpenMPCD::PairPotentials::WeeksChandlerAndersen
Weeks-Chandler-Andersen (WCA) potential.
Definition: WeeksChandlerAndersen.hpp:38
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::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.hpp:100
OpenMPCD::PairPotentials::WeeksChandlerAndersen::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.hpp:69
OPENMPCD_DEBUG_ASSERT.hpp
OpenMPCD::PairPotentials::Base
Abstract base class for pair potentials.
Definition: PairPotentials/Base.hpp:24
Utilities.hpp
OpenMPCD::PairPotentials::WeeksChandlerAndersen::WeeksChandlerAndersen
OPENMPCD_CUDA_HOST_AND_DEVICE WeeksChandlerAndersen(const T epsilon, const T sigma)
The constructor.
Definition: WeeksChandlerAndersen.hpp:48
OpenMPCD::Vector3D::getMagnitudeSquared
OPENMPCD_CUDA_HOST_AND_DEVICE RealType getMagnitudeSquared() const
Returns the square of the magnitude of this vector.
Definition: Vector3D.hpp:209