OpenMPCD
LennardJones.hpp
1 #ifndef OPENMPCD_PAIRPOTENTIALS_LENNARDJONES_HPP
2 #define OPENMPCD_PAIRPOTENTIALS_LENNARDJONES_HPP
3 
4 #include <OpenMPCD/PairPotentials/Base.hpp>
5 
6 namespace OpenMPCD
7 {
8 namespace PairPotentials
9 {
10 
11 /** Lennard-Jones Interaction
12  * \f[
13  * 4 \varepsilon \cdot
14  * \left(
15  * \left( \frac{\sigma}{r - r_{\textrm{offset}}} \right)^{12}
16  * -
17  * \left( \frac{\sigma}{r - r_{\textrm{offset}}} \right)^6
18  * \right)
19  * \f]
20  * If \f$ r \f$ exceeds a parameter \f$ r_{\textrm{cut}} \f$ (given to the
21  * constructor of the class), the resulting potential and force will be zero.
22  *
23  * @tparam T The numeric base type.
24  */
25 template<typename T = FP>
26 class LennardJones : public Base<T>
27 {
28 public:
29  /**
30  * The constructor
31  *
32  * @param[in] r_offset Offset for distance
33  * @param[in] r_cut Cutoff param; If distance > r_cut, potential is zero
34  * @param[in] sigma At distance sigma, inter-particle potential is zero
35  * @param[in] epsilon Depth of the potential well
36  */
38  LennardJones(const T r_offset, const T r_cut, const T sigma, const T epsilon)
39  : r_offset(r_offset), r_cut(r_cut), sigma(sigma), epsilon(epsilon)
40  {
41  }
42 
43  /**
44  * Returns the force vector of the interaction for a given position vector.
45  *
46  * This function returns the directional derivative
47  * \f[ - \nabla_R V \left( \vec{R} \right) \f]
48  * where \f$ \vec{R} \f$ is the `R` parameter, \f$ V \f$ is the potential
49  * as given by the `potential` function, and \f$ \nabla_R V \f$ is the
50  * gradient of \f$ V \f$ with respect to \f$ \vec{R} \f$.
51  *
52  * @param[in] R The relative position vector.
53  */
55  Vector3D<T> force(const Vector3D<T>& R) const
56  {
57  const T Rv = R.getMagnitude();
58 
59  if (Rv > r_cut ) {
60  return Vector3D<T>(0,0,0);
61  }
62 
63  const T oneOverRMinusROffset = 1.0 / (Rv - r_offset);
64  const T ratio = sigma * oneOverRMinusROffset;
65  const T ratio6 = pow(ratio, 6);
66  const T ratio12 = ratio6 * ratio6;
67  return 24 * epsilon * (2 * ratio12 - ratio6) * oneOverRMinusROffset*R.getNormalized();
68  }
69 
70  /**
71  * Returns the potential of the interaction for a given position vector.
72  * @param[in] R The relative position vector.
73  */
75  T potential(const Vector3D<T>& R) const
76  {
77  const T Rv = R.getMagnitude();
78 
79  if (Rv > r_cut)
80  {
81  return 0.0;
82  }
83  else
84  {
85  return 4*epsilon*(pow(sigma/(Rv-r_offset ), 12) - pow(sigma/(Rv-r_offset),6));
86  }
87  }
88 
89 private:
90  const T r_offset;
91  const T r_cut;
92  const T sigma;
93  const T epsilon;
94 }; //class LennardJones
95 
96 } //namespace PairPotentials
97 } //namespace OpenMPCD
98 #endif //OPENMPCD_PAIRPOTENTIALS_LENNARDJONES_HPP
OpenMPCD::Vector3D
3-dimensional vector.
Definition: Vector3D.hpp:38
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::LennardJones::LennardJones
OPENMPCD_CUDA_HOST_AND_DEVICE LennardJones(const T r_offset, const T r_cut, const T sigma, const T epsilon)
The constructor.
Definition: LennardJones.hpp:38
OpenMPCD::Vector3D::getNormalized
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D getNormalized() const
Returns this vector, but normalized.
Definition: Vector3D.hpp:264
OpenMPCD::PairPotentials::LennardJones::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: LennardJones.hpp:55
OpenMPCD::PairPotentials::Base
Abstract base class for pair potentials.
Definition: PairPotentials/Base.hpp:24
OpenMPCD::PairPotentials::LennardJones
Lennard-Jones Interaction.
Definition: LennardJones.hpp:26
OpenMPCD::PairPotentials::LennardJones::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: LennardJones.hpp:75
OpenMPCD::Vector3D::getMagnitude
OPENMPCD_CUDA_HOST_AND_DEVICE RealType getMagnitude() const
Returns the magnitude of this vector.
Definition: Vector3D.hpp:227