OpenMPCD
MagneticDipoleDipoleInteraction_ConstantEqualDipolesAlongZ.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  * Defines the
4  * `OpenMPCD::PairPotentials::MagneticDipoleDipoleInteraction_ConstantEqualDipolesAlongZ`
5  * class.
6  */
7 
8 #ifndef OPENMPCD_PAIRPOTENTIALS_MAGNETICDIPOLEDIPOLEINTERACTION_CONSTANTEQUALDIPOLESALONGZ_HPP
9 #define OPENMPCD_PAIRPOTENTIALS_MAGNETICDIPOLEDIPOLEINTERACTION_CONSTANTEQUALDIPOLESALONGZ_HPP
10 
11 #include <OpenMPCD/PairPotentials/Base.hpp>
12 
14 
15 namespace OpenMPCD
16 {
17 namespace PairPotentials
18 {
19 
20 /**
21  * Interactions between two constant and equal magnetic dipoles oriented along
22  * the Z axis.
23  *
24  * The general magnetic dipole-dipole interaction potential is given by
25  * \f[
26  * - \frac{ \mu_0 }{ 4 \pi r^3 }
27  * \left(
28  * 3
29  * \left(\vec{m_1} \cdot \hat{r} \right)
30  * \left(\vec{m_2} \cdot \hat{r} \right)
31  * -
32  * \vec{m_1} \cdot \vec{m_2}
33  * \right)
34  * \f]
35  * where \f$ \mu_0 \f$ is the vacuum permeability, \f$ \hat{r} \f$ and \f$ r \f$
36  * are, respectively, the unit vector and length of the vector \f$ \vec{r} \f$
37  * that points from one dipole's position to the other's, \f$ \vec{m_1} \f$ and
38  * \f$ \vec{m_2} \f$ are the magnetic dipole moments, and \f$ \cdot \f$ denotes
39  * the inner product.
40  *
41  * In the special case treated in this class, the magnetic dipole moments are
42  * assumed to be constant throughout time in size and orientation, with the
43  * latter being along the \f$ z \f$ axis. Therefore, with \f$ m \f$ being the
44  * magnitude of the individual dipole moments and with \f$ R_z \f$ being the
45  * \f$ z \f$ component of \f$ \hat{r} \f$, the interaction potential is given by
46  * \f[
47  * - \frac{ \mu_0 m^2 }{ 4 \pi r^3 }
48  * \left( 3 R_z^2 - 1 \right)
49  * \f]
50  *
51  * @tparam T The numeric data type.
52  */
53 template<typename T = FP>
55  : public Base<T>
56 {
57 public:
58  /**
59  * The constructor.
60  *
61  * @param[in] prefactor The term \f$ \frac{\mu_0 m^2}{4 \pi} \f$.
62  */
65  const T prefactor)
66  : prefactor(prefactor)
67  {
68  }
69 
70  /**
71  * Returns the force vector of the interaction for a given position vector.
72  *
73  * This function returns the directional derivative
74  * \f[ - \nabla_R V \left( \vec{R} \right) \f]
75  * where \f$ \vec{R} \f$ is the `R` parameter, \f$ V \f$ is the potential
76  * as given by the `potential` function, and \f$ \nabla_R V \f$ is the
77  * gradient of \f$ V \f$ with respect to \f$ \vec{R} \f$.
78  *
79  * @throw OpenMPCD::AssertionException
80  * If `OPENMPCD_DEBUG` is defined, throws if
81  * `OpenMPCD::Scalar::isZero(R.getMagnitudeSquared())`.
82  *
83  * @param[in] R The relative position vector.
84  */
86  Vector3D<T> force(const Vector3D<T>& R) const
87  {
88  const T r2 = R.getMagnitudeSquared();
89 
91 
92  const T r_m2 = 1 / r2;
93  const T r_m3 = r_m2 / sqrt(r2);
94  const T r_m5 = r_m2 * r_m3;
95  const T r_m7 = r_m5 * r_m2;
96 
97  const T r_x = R.getX();
98  const T r_y = R.getY();
99  const T r_z = R.getZ();
100  const T r_z_squared = r_z * r_z;
101  const T F_x = - 5 * r_x * r_z_squared * r_m7 + r_x * r_m5;
102  const T F_y = - 5 * r_y * r_z_squared * r_m7 + r_y * r_m5;
103  const T F_z = - 5 * r_z * r_z_squared * r_m7 + 3 * r_z * r_m5;
104 
105  const Vector3D<T> F(F_x, F_y, F_z);
106  return (3 * prefactor) * F;
107  }
108 
109  /**
110  * Returns the potential of the interaction for a given position vector.
111  *
112  * @throw OpenMPCD::AssertionException
113  * If `OPENMPCD_DEBUG` is defined, throws if
114  * `OpenMPCD::Scalar::isZero(R.getMagnitudeSquared())`.
115  *
116  * @param[in] R The relative position vector.
117  */
119  T potential(const Vector3D<T>& R) const
120  {
121  const T r2 = R.getMagnitudeSquared();
122 
124 
125  const T r_m2 = 1 / r2;
126  const T r_m3 = r_m2 / sqrt(r2);
127  const T r_z_squared = R.getZ() * R.getZ();
128 
129  return - prefactor * r_m3 * (3 * r_z_squared * r_m2 - 1);
130  }
131 
132  /**
133  * Returns the term \f$ \frac{\mu_0 m^2}{4 \pi} \f$.
134  */
136  T getPrefactor() const
137  {
138  return prefactor;
139  }
140 
141 private:
142  const T prefactor; ///< The term \f$ \frac{\mu_0 m^2}{4 \pi} \f$.
143 }; //class MagneticDipoleDipoleInteraction_ConstantEqualDipolesAlongZ
144 
145 } //namespace PairPotentials
146 } //namespace OpenMPCD
147 #endif //OPENMPCD_PAIRPOTENTIALS_MAGNETICDIPOLEDIPOLEINTERACTION_CONSTANTEQUALDIPOLESALONGZ_HPP
OpenMPCD::PairPotentials::MagneticDipoleDipoleInteraction_ConstantEqualDipolesAlongZ::getPrefactor
OPENMPCD_CUDA_HOST_AND_DEVICE T getPrefactor() const
Returns the term .
Definition: MagneticDipoleDipoleInteraction_ConstantEqualDipolesAlongZ.hpp:136
OpenMPCD::PairPotentials::MagneticDipoleDipoleInteraction_ConstantEqualDipolesAlongZ
Interactions between two constant and equal magnetic dipoles oriented along the Z axis.
Definition: MagneticDipoleDipoleInteraction_ConstantEqualDipolesAlongZ.hpp:54
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::getZ
OPENMPCD_CUDA_HOST_AND_DEVICE T getZ() const
Returns the z coordinate.
Definition: Vector3D.hpp:119
OpenMPCD::Vector3D
3-dimensional vector.
Definition: Vector3D.hpp:38
OpenMPCD::Vector3D::getX
OPENMPCD_CUDA_HOST_AND_DEVICE T getX() const
Returns the x coordinate.
Definition: Vector3D.hpp:61
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_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::Vector3D::getY
OPENMPCD_CUDA_HOST_AND_DEVICE T getY() const
Returns the y coordinate.
Definition: Vector3D.hpp:90
OPENMPCD_DEBUG_ASSERT.hpp
OpenMPCD::PairPotentials::MagneticDipoleDipoleInteraction_ConstantEqualDipolesAlongZ::MagneticDipoleDipoleInteraction_ConstantEqualDipolesAlongZ
OPENMPCD_CUDA_HOST_AND_DEVICE MagneticDipoleDipoleInteraction_ConstantEqualDipolesAlongZ(const T prefactor)
The constructor.
Definition: MagneticDipoleDipoleInteraction_ConstantEqualDipolesAlongZ.hpp:64
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::MagneticDipoleDipoleInteraction_ConstantEqualDipolesAlongZ::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: MagneticDipoleDipoleInteraction_ConstantEqualDipolesAlongZ.hpp:119
OpenMPCD::Vector3D::getMagnitudeSquared
OPENMPCD_CUDA_HOST_AND_DEVICE RealType getMagnitudeSquared() const
Returns the square of the magnitude of this vector.
Definition: Vector3D.hpp:209
OpenMPCD::PairPotentials::MagneticDipoleDipoleInteraction_ConstantEqualDipolesAlongZ::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: MagneticDipoleDipoleInteraction_ConstantEqualDipolesAlongZ.hpp:86