OpenMPCD
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
OpenMPCD::Vector3D< T > Class Template Reference

3-dimensional vector. More...

#include <Vector3D.hpp>

Public Types

typedef TypeTraits< T >::RealType RealType
 The real-value type matching T. More...
 

Public Member Functions

OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D (const T x_, const T y_, const T z_)
 Constructs a vector from its coordinates. More...
 
OPENMPCD_CUDA_HOST_AND_DEVICEgetX () const
 Returns the x coordinate. More...
 
OPENMPCD_CUDA_HOST_AND_DEVICE void setX (const T val)
 Sets the x coordinate. More...
 
OPENMPCD_CUDA_HOST_AND_DEVICE void addToX (const T val)
 Adds the given value to the x coordinate. More...
 
OPENMPCD_CUDA_HOST_AND_DEVICEgetY () const
 Returns the y coordinate. More...
 
OPENMPCD_CUDA_HOST_AND_DEVICE void setY (const T val)
 Sets the y coordinate. More...
 
OPENMPCD_CUDA_HOST_AND_DEVICE void addToY (const T val)
 Adds the given value to the y coordinate. More...
 
OPENMPCD_CUDA_HOST_AND_DEVICEgetZ () const
 Returns the z coordinate. More...
 
OPENMPCD_CUDA_HOST_AND_DEVICE void setZ (const T val)
 Sets the z coordinate. More...
 
OPENMPCD_CUDA_HOST_AND_DEVICE void addToZ (const T val)
 Adds the given value to the z coordinate. More...
 
OPENMPCD_CUDA_HOST_AND_DEVICE void set (const T x_, const T y_, const T z_)
 Sets the coordinates. More...
 
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D cross (const Vector3D &rhs) const
 Returns the cross product of this vector with the given vector. More...
 
const OPENMPCD_CUDA_HOST_AND_DEVICEdot (const Vector3D &rhs) const
 Returns the scalar product of this vector with the given vector. More...
 
getCosineOfAngle (const Vector3D &rhs) const
 Returns the cosine of the angle between this vector and the given one. More...
 
getAngle (const Vector3D &rhs) const
 Returns the the angle between this vector and the given one. More...
 
OPENMPCD_CUDA_HOST_AND_DEVICE RealType getMagnitudeSquared () const
 Returns the square of the magnitude of this vector. More...
 
OPENMPCD_CUDA_HOST_AND_DEVICE RealType magnitudeSquared () const
 Returns the square of the magnitude of this vector. More...
 
OPENMPCD_CUDA_HOST_AND_DEVICE RealType getMagnitude () const
 Returns the magnitude of this vector. More...
 
OPENMPCD_CUDA_HOST_AND_DEVICE RealType magnitude () const
 Returns the magnitude of this vector. More...
 
OPENMPCD_CUDA_HOST_AND_DEVICE void normalize ()
 Normalizes this vector. More...
 
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D getNormalized () const
 Returns this vector, but normalized. More...
 
const Vector3D getProjectedOnto (const Vector3D &onto) const
 Returns the projection of this vector onto the given one. More...
 
const Vector3D getPerpendicularTo (const Vector3D &rhs) const
 Returns the part of this vector that is perpendicular to the given vector. More...
 
const Vector3D< std::complex< T > > getComplexVector () const
 Returns the complex version of this vector. More...
 
OPENMPCD_CUDA_HOST_AND_DEVICE void rotateAroundNormalizedAxis (const Vector3D &axis, const T angle)
 Rotates this vector about the given axis by the given angle. More...
 
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D getRotatedAroundNormalizedAxis (const Vector3D &axis, const T angle) const
 Returns this vector, but rotated about the given axis by the given angle. More...
 
bool hasNegativeComponent () const
 Returns whether at least one of the components of this vector is negative. More...
 
OPENMPCD_CUDA_HOST_AND_DEVICE bool isFinite () const
 Returns whether all components are finite, i.e. More...
 
OPENMPCD_CUDA_HOST_AND_DEVICE bool operator== (const Vector3D &rhs) const
 Equality operator. More...
 
OPENMPCD_CUDA_HOST_AND_DEVICE bool operator!= (const Vector3D &rhs) const
 Inequality operator. More...
 
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3Doperator+= (const Vector3D &rhs)
 Addition-and-assignment operator. More...
 
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D operator+ (const Vector3D &rhs) const
 Addition operator. More...
 
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3Doperator-= (const Vector3D &rhs)
 Subtraction-and-assignment operator. More...
 
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D operator- (const Vector3D &rhs) const
 Subtraction operator. More...
 
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D operator- () const
 The negation operator. More...
 
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3Doperator*= (const T scale)
 Scalar multiplication and assignment operator. More...
 
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D operator* (const T scale) const
 Scalar multiplication operator. More...
 
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3Doperator/= (const T divisor)
 Scalar division and assignment operator. More...
 
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D operator/ (const T divisor) const
 Scalar division operator. More...
 
bool operator< (const Vector3D &rhs) const
 Less-than operator. More...
 

Static Public Member Functions

template<typename RNG >
static const OPENMPCD_CUDA_HOST Vector3D getRandomUnitVector (RNG &rng)
 Returns a random vector with unit length; all directions are equally likely. More...
 
static const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D getUnitVectorFromRandom01 (const T X_1, const T X_2)
 Constructs a unit vector from the two given random variables. More...
 

Friends

OPENMPCD_CUDA_HOST_AND_DEVICE const friend Vector3D operator* (const T scale, const Vector3D &vec)
 Scalar multiplication operator. More...
 
std::ostream & operator<< (std::ostream &stream, const Vector3D &vector)
 Output operator for streams. More...
 

Detailed Description

template<typename T>
class OpenMPCD::Vector3D< T >

3-dimensional vector.

Template Parameters
TThe underlying floating-point type.

Definition at line 38 of file Vector3D.hpp.

Member Typedef Documentation

◆ RealType

template<typename T >
typedef TypeTraits<T>::RealType OpenMPCD::Vector3D< T >::RealType

The real-value type matching T.

Definition at line 41 of file Vector3D.hpp.

Constructor & Destructor Documentation

◆ Vector3D()

template<typename T >
OPENMPCD_CUDA_HOST_AND_DEVICE OpenMPCD::Vector3D< T >::Vector3D ( const T  x_,
const T  y_,
const T  z_ 
)
inline

Constructs a vector from its coordinates.

Parameters
[in]x_The x-coordinate.
[in]y_The y-coordinate.
[in]z_The z-coordinate.

Definition at line 51 of file Vector3D.hpp.

Member Function Documentation

◆ addToX()

template<typename T >
OPENMPCD_CUDA_HOST_AND_DEVICE void OpenMPCD::Vector3D< T >::addToX ( const T  val)
inline

Adds the given value to the x coordinate.

Parameters
[in]valThe value to add

Definition at line 81 of file Vector3D.hpp.

◆ addToY()

template<typename T >
OPENMPCD_CUDA_HOST_AND_DEVICE void OpenMPCD::Vector3D< T >::addToY ( const T  val)
inline

Adds the given value to the y coordinate.

Parameters
[in]valThe value to add

Definition at line 110 of file Vector3D.hpp.

◆ addToZ()

template<typename T >
OPENMPCD_CUDA_HOST_AND_DEVICE void OpenMPCD::Vector3D< T >::addToZ ( const T  val)
inline

Adds the given value to the z coordinate.

Parameters
[in]valThe value to add

Definition at line 139 of file Vector3D.hpp.

◆ cross()

template<typename T >
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D OpenMPCD::Vector3D< T >::cross ( const Vector3D< T > &  rhs) const
inline

Returns the cross product of this vector with the given vector.

Parameters
[in]rhsThe right-hand-side vector.

Definition at line 164 of file Vector3D.hpp.

◆ dot()

template<typename T >
const OPENMPCD_CUDA_HOST_AND_DEVICE T OpenMPCD::Vector3D< T >::dot ( const Vector3D< T > &  rhs) const
inline

Returns the scalar product of this vector with the given vector.

The scalar product is defines such that the left-hand-side's components are complex-conjugated prior to multiplication with the right-hand-side's components.

Parameters
[in]rhsThe right-hand-side.

Definition at line 181 of file Vector3D.hpp.

◆ getAngle()

template<typename T >
T OpenMPCD::Vector3D< T >::getAngle ( const Vector3D< T > &  rhs) const
inline

Returns the the angle between this vector and the given one.

Parameters
[in]rhsThe right-hand-side vector.

Definition at line 200 of file Vector3D.hpp.

◆ getComplexVector()

template<typename T >
const Vector3D<std::complex<T> > OpenMPCD::Vector3D< T >::getComplexVector ( ) const
inline

Returns the complex version of this vector.

This function only works if this vector has a real-value type.

Definition at line 295 of file Vector3D.hpp.

◆ getCosineOfAngle()

template<typename T >
T OpenMPCD::Vector3D< T >::getCosineOfAngle ( const Vector3D< T > &  rhs) const
inline

Returns the cosine of the angle between this vector and the given one.

Template Parameters
ResultThe result type.
Parameters
[in]rhsThe right-hand-side vector.

Definition at line 191 of file Vector3D.hpp.

◆ getMagnitude()

template<typename T >
OPENMPCD_CUDA_HOST_AND_DEVICE RealType OpenMPCD::Vector3D< T >::getMagnitude ( ) const
inline

Returns the magnitude of this vector.

Definition at line 227 of file Vector3D.hpp.

◆ getMagnitudeSquared()

template<typename T >
OPENMPCD_CUDA_HOST_AND_DEVICE RealType OpenMPCD::Vector3D< T >::getMagnitudeSquared ( ) const
inline

Returns the square of the magnitude of this vector.

Definition at line 209 of file Vector3D.hpp.

◆ getNormalized()

template<typename T >
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D OpenMPCD::Vector3D< T >::getNormalized ( ) const
inline

Returns this vector, but normalized.

Definition at line 264 of file Vector3D.hpp.

◆ getPerpendicularTo()

template<typename T >
const Vector3D OpenMPCD::Vector3D< T >::getPerpendicularTo ( const Vector3D< T > &  rhs) const
inline

Returns the part of this vector that is perpendicular to the given vector.

Parameters
[in]rhsThe vector the result should be perpendicular to.

Definition at line 285 of file Vector3D.hpp.

◆ getProjectedOnto()

template<typename T >
const Vector3D OpenMPCD::Vector3D< T >::getProjectedOnto ( const Vector3D< T > &  onto) const
inline

Returns the projection of this vector onto the given one.

Parameters
[in]ontoThe vector to project onto.

Definition at line 275 of file Vector3D.hpp.

◆ getRandomUnitVector()

template<typename T >
template<typename RNG >
static const OPENMPCD_CUDA_HOST Vector3D OpenMPCD::Vector3D< T >::getRandomUnitVector ( RNG rng)
inlinestatic

Returns a random vector with unit length; all directions are equally likely.

Template Parameters
RNGThe random-number-generator type.
Parameters
[in]rngThe random-number-generator.

Definition at line 367 of file Vector3D.hpp.

◆ getRotatedAroundNormalizedAxis()

template<typename T >
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D OpenMPCD::Vector3D< T >::getRotatedAroundNormalizedAxis ( const Vector3D< T > &  axis,
const T  angle 
) const
inline

Returns this vector, but rotated about the given axis by the given angle.

Parameters
[in]axisThe axis to rotate about, which is assumed to be normalized.
[in]angleThe angle to rotate with.

Definition at line 322 of file Vector3D.hpp.

◆ getUnitVectorFromRandom01()

template<typename T >
static const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D OpenMPCD::Vector3D< T >::getUnitVectorFromRandom01 ( const T  X_1,
const T  X_2 
)
inlinestatic

Constructs a unit vector from the two given random variables.

Parameters
[in]X_1A variable drawn from the uniform distribution on the closed interval \( \left[ 0, 1 \right] \).
[in]X_2A variable drawn from the uniform distribution on either the half-open interval \( \left[ 0, 1 \right) \) or the half-open interval \( \left( 0, 1 \right] \).

Definition at line 408 of file Vector3D.hpp.

◆ getX()

template<typename T >
OPENMPCD_CUDA_HOST_AND_DEVICE T OpenMPCD::Vector3D< T >::getX ( ) const
inline

Returns the x coordinate.

Definition at line 61 of file Vector3D.hpp.

◆ getY()

template<typename T >
OPENMPCD_CUDA_HOST_AND_DEVICE T OpenMPCD::Vector3D< T >::getY ( ) const
inline

Returns the y coordinate.

Definition at line 90 of file Vector3D.hpp.

◆ getZ()

template<typename T >
OPENMPCD_CUDA_HOST_AND_DEVICE T OpenMPCD::Vector3D< T >::getZ ( ) const
inline

Returns the z coordinate.

Definition at line 119 of file Vector3D.hpp.

◆ hasNegativeComponent()

template<typename T >
bool OpenMPCD::Vector3D< T >::hasNegativeComponent ( ) const
inline

Returns whether at least one of the components of this vector is negative.

Definition at line 332 of file Vector3D.hpp.

◆ isFinite()

template<typename T >
OPENMPCD_CUDA_HOST_AND_DEVICE bool OpenMPCD::Vector3D< T >::isFinite ( ) const
inline

Returns whether all components are finite, i.e.

neither infinite nor NaN.

Definition at line 341 of file Vector3D.hpp.

◆ magnitude()

template<typename T >
OPENMPCD_CUDA_HOST_AND_DEVICE RealType OpenMPCD::Vector3D< T >::magnitude ( ) const
inline

Returns the magnitude of this vector.

Definition at line 236 of file Vector3D.hpp.

◆ magnitudeSquared()

template<typename T >
OPENMPCD_CUDA_HOST_AND_DEVICE RealType OpenMPCD::Vector3D< T >::magnitudeSquared ( ) const
inline

Returns the square of the magnitude of this vector.

Definition at line 218 of file Vector3D.hpp.

◆ normalize()

template<typename T >
OPENMPCD_CUDA_HOST_AND_DEVICE void OpenMPCD::Vector3D< T >::normalize ( )
inline

Normalizes this vector.

Exceptions
OpenMPCD::DivisionByZeroExceptionFor Host code, throws if magnitude() == 0.

Definition at line 248 of file Vector3D.hpp.

◆ operator!=()

template<typename T >
OPENMPCD_CUDA_HOST_AND_DEVICE bool OpenMPCD::Vector3D< T >::operator!= ( const Vector3D< T > &  rhs) const
inline

Inequality operator.

Parameters
[in]rhsThe right-hand-side vector.

Definition at line 445 of file Vector3D.hpp.

◆ operator*()

template<typename T >
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D OpenMPCD::Vector3D< T >::operator* ( const T  scale) const
inline

Scalar multiplication operator.

Parameters
[in]scaleThe scaling factor.

Definition at line 533 of file Vector3D.hpp.

◆ operator*=()

template<typename T >
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D& OpenMPCD::Vector3D< T >::operator*= ( const T  scale)
inline

Scalar multiplication and assignment operator.

Parameters
[in]scaleThe scaling factor.
Returns
Returns this instance.

Definition at line 519 of file Vector3D.hpp.

◆ operator+()

template<typename T >
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D OpenMPCD::Vector3D< T >::operator+ ( const Vector3D< T > &  rhs) const
inline

Addition operator.

Parameters
[in]rhsThe right-hand-side vector.
Returns
Returns this instance.

Definition at line 471 of file Vector3D.hpp.

◆ operator+=()

template<typename T >
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D& OpenMPCD::Vector3D< T >::operator+= ( const Vector3D< T > &  rhs)
inline

Addition-and-assignment operator.

Parameters
[in]rhsThe right-hand-side vector.
Returns
Returns this instance.

Definition at line 456 of file Vector3D.hpp.

◆ operator-() [1/2]

template<typename T >
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D OpenMPCD::Vector3D< T >::operator- ( ) const
inline

The negation operator.

Definition at line 508 of file Vector3D.hpp.

◆ operator-() [2/2]

template<typename T >
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D OpenMPCD::Vector3D< T >::operator- ( const Vector3D< T > &  rhs) const
inline

Subtraction operator.

Parameters
[in]rhsThe right-hand-side vector.
Returns
Returns this instance.

Definition at line 498 of file Vector3D.hpp.

◆ operator-=()

template<typename T >
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D& OpenMPCD::Vector3D< T >::operator-= ( const Vector3D< T > &  rhs)
inline

Subtraction-and-assignment operator.

Parameters
[in]rhsThe right-hand-side vector.
Returns
Returns this instance.

Definition at line 483 of file Vector3D.hpp.

◆ operator/()

template<typename T >
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D OpenMPCD::Vector3D< T >::operator/ ( const T  divisor) const
inline

Scalar division operator.

Exceptions
DivisionByZeroExcpetionFor Host code, throws if divisor is 0.
Parameters
[in]divisorThe divisor.

Definition at line 578 of file Vector3D.hpp.

◆ operator/=()

template<typename T >
const OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D& OpenMPCD::Vector3D< T >::operator/= ( const T  divisor)
inline

Scalar division and assignment operator.

Exceptions
OpenMPCD::DivisionByZeroExceptionFor Host code, throws if divisor is 0.
Parameters
[in]divisorThe divisor.
Returns
Returns this instance.

Definition at line 558 of file Vector3D.hpp.

◆ operator<()

template<typename T >
bool OpenMPCD::Vector3D< T >::operator< ( const Vector3D< T > &  rhs) const
inline

Less-than operator.

Compares, in this order, the x, y, and z components.

Parameters
[in]rhsThe right-hand-side instance.

Definition at line 589 of file Vector3D.hpp.

◆ operator==()

template<typename T >
OPENMPCD_CUDA_HOST_AND_DEVICE bool OpenMPCD::Vector3D< T >::operator== ( const Vector3D< T > &  rhs) const
inline

Equality operator.

Parameters
[in]rhsThe right-hand-side vector.

Definition at line 433 of file Vector3D.hpp.

◆ rotateAroundNormalizedAxis()

template<typename T >
OPENMPCD_CUDA_HOST_AND_DEVICE void OpenMPCD::Vector3D< T >::rotateAroundNormalizedAxis ( const Vector3D< T > &  axis,
const T  angle 
)
inline

Rotates this vector about the given axis by the given angle.

Parameters
[in]axisThe axis to rotate about, which is assumed to be normalized.
[in]angleThe angle to rotate with.

Definition at line 308 of file Vector3D.hpp.

◆ set()

template<typename T >
OPENMPCD_CUDA_HOST_AND_DEVICE void OpenMPCD::Vector3D< T >::set ( const T  x_,
const T  y_,
const T  z_ 
)
inline

Sets the coordinates.

Parameters
[in]x_The x coordinate.
[in]y_The y coordinate.
[in]z_The z coordinate.

Definition at line 151 of file Vector3D.hpp.

◆ setX()

template<typename T >
OPENMPCD_CUDA_HOST_AND_DEVICE void OpenMPCD::Vector3D< T >::setX ( const T  val)
inline

Sets the x coordinate.

Parameters
[in]valThe new value.

Definition at line 71 of file Vector3D.hpp.

◆ setY()

template<typename T >
OPENMPCD_CUDA_HOST_AND_DEVICE void OpenMPCD::Vector3D< T >::setY ( const T  val)
inline

Sets the y coordinate.

Parameters
[in]valThe new value.

Definition at line 100 of file Vector3D.hpp.

◆ setZ()

template<typename T >
OPENMPCD_CUDA_HOST_AND_DEVICE void OpenMPCD::Vector3D< T >::setZ ( const T  val)
inline

Sets the z coordinate.

Parameters
[in]valThe new value.

Definition at line 129 of file Vector3D.hpp.

Friends And Related Function Documentation

◆ operator*

template<typename T >
OPENMPCD_CUDA_HOST_AND_DEVICE const friend Vector3D operator* ( const T  scale,
const Vector3D< T > &  vec 
)
friend

Scalar multiplication operator.

Parameters
[in]scaleThe scaling factor.
[in]vecThe vector to multiply.

Definition at line 545 of file Vector3D.hpp.

◆ operator<<

template<typename T >
std::ostream& operator<< ( std::ostream &  stream,
const Vector3D< T > &  vector 
)
friend

Output operator for streams.

Parameters
[in]streamThe stream to print to.
[in]vectorThe vector to print.

Definition at line 614 of file Vector3D.hpp.


The documentation for this class was generated from the following file: