OpenMPCD
Vector2D_Implementation2.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  * Implementation details for the Vector2D class.
4  */
5 
6 #ifndef OPENMPCD_VECTOR2D_IMPLEMENTATION2_HPP
7 #define OPENMPCD_VECTOR2D_IMPLEMENTATION2_HPP
8 
9 #include <OpenMPCD/Vector2D.hpp>
10 
11 #include <boost/type_traits/is_floating_point.hpp>
12 
13 namespace OpenMPCD
14 {
15 namespace Implementation_Vector2D
16 {
17 
18 /**
19  * Helper class to allow partial template specialization of
20  * `OpenMPCD::Vector2D::dot`, for the case where `T` is a floating-point type.
21  *
22  * @see OpenMPCD::Implementation_Vector2D::Dot
23  *
24  * @tparam T The underlying scalar type.
25  */
26 template<typename T>
27 class Dot<T, typename boost::enable_if<boost::is_floating_point<T> >::type>
28 {
29  private:
30  Dot();
31 
32  public:
33 
34  /**
35  * Returns the scalar product two real-valued vectors.
36  *
37  * @see OpenMPCD::Implementation_Vector2D::Dot::dot
38  *
39  * @param[in] lhs The left-hand-side.
40  * @param[in] rhs The right-hand-side.
41  */
42  static
44  const T dot(const Vector2D<T>& lhs, const Vector2D<T>& rhs)
45  {
46  BOOST_STATIC_ASSERT(boost::is_floating_point<T>::value);
47 
48  return lhs.getX()*rhs.getX() + lhs.getY()*rhs.getY();
49  }
50 }; //class Dot, partial template specialization for floating point types
51 
52 /**
53  * Helper class to allow partial template specialization of
54  * `OpenMPCD::Vector2D::dot`, for the case where `T` is an instance of
55  * `std::complex`.
56  *
57  * @see OpenMPCD::Implementation_Vector2D::Dot
58  *
59  * @tparam T The underlying scalar type.
60  */
61 template<typename T>
62 class Dot<std::complex<T> >
63 {
64  private:
65  Dot();
66 
67  public:
68 
69  /**
70  * Returns the scalar product two vectors.
71  *
72  * The scalar product is defined such that the left-hand-side's components
73  * are complex-conjugated prior to multiplication with the right-hand-side's
74  * components.
75  *
76  * @see OpenMPCD::Implementation_Vector2D::Dot::dot
77  *
78  * @param[in] lhs The left-hand-side.
79  * @param[in] rhs The right-hand-side.
80  */
81  static
83  const std::complex<T> dot(
84  const Vector2D<std::complex<T> >& lhs,
85  const Vector2D<std::complex<T> >& rhs)
86  {
87  BOOST_STATIC_ASSERT(boost::is_floating_point<T>::value);
88 
89  return
90  std::conj(lhs.getX())*rhs.getX() +
91  std::conj(lhs.getY())*rhs.getY();
92  }
93 }; //class Dot, partial template specialization for std::complex<T>
94 } //namespace Implementation_Vector2D
95 } //namespace OpenMPCD
96 
97 #endif //OPENMPCD_VECTOR2D_IMPLEMENTATION2_HPP
OpenMPCD::Vector2D::getY
OPENMPCD_CUDA_HOST_AND_DEVICE T getY() const
Returns the y coordinate.
Definition: Vector2D.hpp:75
OpenMPCD::Vector2D::getX
OPENMPCD_CUDA_HOST_AND_DEVICE T getX() const
Returns the x coordinate.
Definition: Vector2D.hpp:66
OpenMPCD::Implementation_Vector2D::Dot< T, typename boost::enable_if< boost::is_floating_point< T > >::type >::dot
static const OPENMPCD_CUDA_HOST_AND_DEVICE T dot(const Vector2D< T > &lhs, const Vector2D< T > &rhs)
Returns the scalar product two real-valued vectors.
Definition: Vector2D_Implementation2.hpp:44
Vector2D.hpp
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::Vector2D
2-dimensional vector.
Definition: Vector2D.hpp:34
OpenMPCD::Implementation_Vector2D::Dot
Helper class to allow partial template specialization of OpenMPCD::Vector2D::dot.
Definition: Vector2D_Implementation1.hpp:28
OpenMPCD::Implementation_Vector2D::Dot< std::complex< T > >::dot
static const OPENMPCD_CUDA_HOST_AND_DEVICE std::complex< T > dot(const Vector2D< std::complex< T > > &lhs, const Vector2D< std::complex< T > > &rhs)
Returns the scalar product two vectors.
Definition: Vector2D_Implementation2.hpp:83