OpenMD 3.1
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
OpenMD::Vector< Real, Dim > Class Template Reference

Fix length vector class. More...

#include "math/Vector.hpp"

Public Types

using ElemType = Real
 
using ElemPoinerType = Real*
 

Public Member Functions

 Vector ()
 default constructor
 
 Vector (const Vector< Real, Dim > &v)
 Constructs and initializes a Vector from a vector.
 
Vector< Real, Dim > & operator= (const Vector< Real, Dim > &v)
 copy assignment operator
 
Vector< Real, Dim > & operator= (const Real *v)
 array assignment operator
 
 Vector (const Real &s)
 
 Vector (Real *v)
 Constructs and initializes a Vector from an array.
 
Real & operator[] (unsigned int i)
 Returns reference of ith element.
 
Real & operator() (unsigned int i)
 Returns reference of ith element.
 
const Real & operator[] (unsigned int i) const
 Returns constant reference of ith element.
 
const Real & operator() (unsigned int i) const
 Returns constant reference of ith element.
 
void getArray (Real *array)
 Copy the internal data to an array.
 
Real * getArrayPointer ()
 Returns the pointer of internal array.
 
bool operator== (const Vector< Real, Dim > &v)
 Tests if this vetor is equal to other vector.
 
bool operator!= (const Vector< Real, Dim > &v)
 Tests if this vetor is not equal to other vector.
 
void zero ()
 Zeros out the values in this vector in place.
 
void negate ()
 Negates the value of this vector in place.
 
void negate (const Vector< Real, Dim > &v1)
 Sets the value of this vector to the negation of vector v1.
 
void add (const Vector< Real, Dim > &v1)
 Sets the value of this vector to the sum of itself and v1 (*this += v1).
 
void add (const Vector< Real, Dim > &v1, const Vector< Real, Dim > &v2)
 Sets the value of this vector to the sum of v1 and v2 (*this = v1 + v2).
 
void sub (const Vector< Real, Dim > &v1)
 Sets the value of this vector to the difference of itself and v1 (*this -= v1).
 
void sub (const Vector< Real, Dim > &v1, const Vector &v2)
 Sets the value of this vector to the difference of vector v1 and v2 (*this = v1 - v2).
 
void mul (Real s)
 Sets the value of this vector to the scalar multiplication of itself (*this *= s).
 
void mul (const Vector< Real, Dim > &v1, Real s)
 Sets the value of this vector to the scalar multiplication of vector v1 (*this = s * v1).
 
void Vmul (const Vector< Real, Dim > &v1, const Vector< Real, Dim > &v2)
 Sets the elements of this vector to the multiplication of elements of two other vectors.
 
Vector< Real, Dim > & abs ()
 
Real max ()
 
void div (Real s)
 Sets the value of this vector to the scalar division of itself (*this /= s ).
 
void div (const Vector< Real, Dim > &v1, Real s)
 Sets the value of this vector to the scalar division of vector v1 (*this = v1 / s ).
 
void Vdiv (const Vector< Real, Dim > &v1, const Vector< Real, Dim > &v2)
 Sets the elements of this vector to the division of elements of two other vectors.
 
Vector< Real, Dim > & operator+= (const Vector< Real, Dim > &v1)
 
Vector< Real, Dim > & operator-= (const Vector< Real, Dim > &v1)
 
Vector< Real, Dim > & operator*= (Real s)
 
Vector< Real, Dim > & operator/= (Real s)
 
Real sum ()
 Returns the sum of all elements of this vector.
 
Real componentProduct ()
 Returns the product of all elements of this vector.
 
Real length ()
 Returns the length of this vector.
 
Real lengthSquare ()
 Returns the squared length of this vector.
 
void normalize ()
 Normalizes this vector in place.
 
bool isNormalized ()
 Tests if this vector is normalized.
 
unsigned int size () const
 

Protected Attributes

Real data_ [Dim] {}
 

Detailed Description

template<typename Real, unsigned int Dim>
class OpenMD::Vector< Real, Dim >

Fix length vector class.

Definition at line 78 of file Vector.hpp.

Member Typedef Documentation

◆ ElemPoinerType

template<typename Real , unsigned int Dim>
using OpenMD::Vector< Real, Dim >::ElemPoinerType = Real*

Definition at line 81 of file Vector.hpp.

◆ ElemType

template<typename Real , unsigned int Dim>
using OpenMD::Vector< Real, Dim >::ElemType = Real

Definition at line 80 of file Vector.hpp.

Constructor & Destructor Documentation

◆ Vector() [1/4]

template<typename Real , unsigned int Dim>
OpenMD::Vector< Real, Dim >::Vector ( )
inline

default constructor

Definition at line 84 of file Vector.hpp.

◆ Vector() [2/4]

template<typename Real , unsigned int Dim>
OpenMD::Vector< Real, Dim >::Vector ( const Vector< Real, Dim > & v)
inline

Constructs and initializes a Vector from a vector.

Definition at line 90 of file Vector.hpp.

◆ Vector() [3/4]

template<typename Real , unsigned int Dim>
OpenMD::Vector< Real, Dim >::Vector ( const Real & s)
inline

Definition at line 112 of file Vector.hpp.

◆ Vector() [4/4]

template<typename Real , unsigned int Dim>
OpenMD::Vector< Real, Dim >::Vector ( Real * v)
inline

Constructs and initializes a Vector from an array.

Definition at line 118 of file Vector.hpp.

Member Function Documentation

◆ abs()

template<typename Real , unsigned int Dim>
Vector< Real, Dim > & OpenMD::Vector< Real, Dim >::abs ( )
inline

Definition at line 290 of file Vector.hpp.

◆ add() [1/2]

template<typename Real , unsigned int Dim>
void OpenMD::Vector< Real, Dim >::add ( const Vector< Real, Dim > & v1)
inline

Sets the value of this vector to the sum of itself and v1 (*this += v1).

Parameters
v1the other vector

Definition at line 218 of file Vector.hpp.

Referenced by OpenMD::operator+(), and OpenMD::Vector< Real, Dim >::operator+=().

◆ add() [2/2]

template<typename Real , unsigned int Dim>
void OpenMD::Vector< Real, Dim >::add ( const Vector< Real, Dim > & v1,
const Vector< Real, Dim > & v2 )
inline

Sets the value of this vector to the sum of v1 and v2 (*this = v1 + v2).

Parameters
v1the first vector
v2the second vector

Definition at line 228 of file Vector.hpp.

◆ componentProduct()

template<typename Real , unsigned int Dim>
Real OpenMD::Vector< Real, Dim >::componentProduct ( )
inline

Returns the product of all elements of this vector.

Returns
the product of all elements of this vector

Definition at line 381 of file Vector.hpp.

◆ div() [1/2]

template<typename Real , unsigned int Dim>
void OpenMD::Vector< Real, Dim >::div ( const Vector< Real, Dim > & v1,
Real s )
inline

Sets the value of this vector to the scalar division of vector v1 (*this = v1 / s ).

Parameters
v1the source vector
sthe scalar value

Definition at line 322 of file Vector.hpp.

◆ div() [2/2]

template<typename Real , unsigned int Dim>
void OpenMD::Vector< Real, Dim >::div ( Real s)
inline

Sets the value of this vector to the scalar division of itself (*this /= s ).

Parameters
sthe scalar value

Definition at line 311 of file Vector.hpp.

Referenced by OpenMD::operator/(), and OpenMD::Vector< Real, Dim >::operator/=().

◆ getArray()

template<typename Real , unsigned int Dim>
void OpenMD::Vector< Real, Dim >::getArray ( Real * array)
inline

Copy the internal data to an array.

Definition at line 164 of file Vector.hpp.

◆ getArrayPointer()

template<typename Real , unsigned int Dim>
Real * OpenMD::Vector< Real, Dim >::getArrayPointer ( )
inline

◆ isNormalized()

template<typename Real , unsigned int Dim>
bool OpenMD::Vector< Real, Dim >::isNormalized ( )
inline

Tests if this vector is normalized.

Returns
true if this vector is normalized, otherwise return false

Definition at line 417 of file Vector.hpp.

References OpenMD::equal(), and OpenMD::Vector< Real, Dim >::lengthSquare().

◆ length()

template<typename Real , unsigned int Dim>
Real OpenMD::Vector< Real, Dim >::length ( )
inline

◆ lengthSquare()

template<typename Real , unsigned int Dim>
Real OpenMD::Vector< Real, Dim >::lengthSquare ( )
inline

Returns the squared length of this vector.

Returns
the squared length of this vector

Definition at line 399 of file Vector.hpp.

References OpenMD::dot().

Referenced by OpenMD::distanceSquare(), OpenMD::Cuboctahedron::getPoints(), OpenMD::Vector< Real, Dim >::isNormalized(), and OpenMD::Vector< Real, Dim >::length().

◆ max()

template<typename Real , unsigned int Dim>
Real OpenMD::Vector< Real, Dim >::max ( )
inline

Definition at line 298 of file Vector.hpp.

◆ mul() [1/2]

template<typename Real , unsigned int Dim>
void OpenMD::Vector< Real, Dim >::mul ( const Vector< Real, Dim > & v1,
Real s )
inline

Sets the value of this vector to the scalar multiplication of vector v1 (*this = s * v1).

Parameters
v1the vector
sthe scalar value

Definition at line 270 of file Vector.hpp.

◆ mul() [2/2]

template<typename Real , unsigned int Dim>
void OpenMD::Vector< Real, Dim >::mul ( Real s)
inline

Sets the value of this vector to the scalar multiplication of itself (*this *= s).

Parameters
sthe scalar value

Definition at line 259 of file Vector.hpp.

Referenced by OpenMD::operator*(), OpenMD::operator*(), and OpenMD::Vector< Real, Dim >::operator*=().

◆ negate() [1/2]

template<typename Real , unsigned int Dim>
void OpenMD::Vector< Real, Dim >::negate ( )
inline

Negates the value of this vector in place.

Definition at line 200 of file Vector.hpp.

Referenced by OpenMD::operator-().

◆ negate() [2/2]

template<typename Real , unsigned int Dim>
void OpenMD::Vector< Real, Dim >::negate ( const Vector< Real, Dim > & v1)
inline

Sets the value of this vector to the negation of vector v1.

Parameters
v1the source vector

Definition at line 209 of file Vector.hpp.

◆ normalize()

template<typename Real , unsigned int Dim>
void OpenMD::Vector< Real, Dim >::normalize ( )
inline

◆ operator!=()

template<typename Real , unsigned int Dim>
bool OpenMD::Vector< Real, Dim >::operator!= ( const Vector< Real, Dim > & v)
inline

Tests if this vetor is not equal to other vector.

Returns
true if equal, otherwise return false
Parameters
vvector to be compared

Definition at line 191 of file Vector.hpp.

◆ operator()() [1/2]

template<typename Real , unsigned int Dim>
Real & OpenMD::Vector< Real, Dim >::operator() ( unsigned int i)
inline

Returns reference of ith element.

Returns
reference of ith element
Parameters
iindex

Definition at line 138 of file Vector.hpp.

◆ operator()() [2/2]

template<typename Real , unsigned int Dim>
const Real & OpenMD::Vector< Real, Dim >::operator() ( unsigned int i) const
inline

Returns constant reference of ith element.

Returns
reference of ith element
Parameters
iindex

Definition at line 158 of file Vector.hpp.

◆ operator*=()

template<typename Real , unsigned int Dim>
Vector< Real, Dim > & OpenMD::Vector< Real, Dim >::operator*= ( Real s)
inline
See also
mul

Definition at line 354 of file Vector.hpp.

References OpenMD::Vector< Real, Dim >::mul().

◆ operator+=()

template<typename Real , unsigned int Dim>
Vector< Real, Dim > & OpenMD::Vector< Real, Dim >::operator+= ( const Vector< Real, Dim > & v1)
inline
See also
add

Definition at line 342 of file Vector.hpp.

References OpenMD::Vector< Real, Dim >::add().

◆ operator-=()

template<typename Real , unsigned int Dim>
Vector< Real, Dim > & OpenMD::Vector< Real, Dim >::operator-= ( const Vector< Real, Dim > & v1)
inline
See also
sub

Definition at line 348 of file Vector.hpp.

References OpenMD::Vector< Real, Dim >::sub().

◆ operator/=()

template<typename Real , unsigned int Dim>
Vector< Real, Dim > & OpenMD::Vector< Real, Dim >::operator/= ( Real s)
inline
See also
div

Definition at line 360 of file Vector.hpp.

References OpenMD::Vector< Real, Dim >::div().

◆ operator=() [1/2]

template<typename Real , unsigned int Dim>
Vector< Real, Dim > & OpenMD::Vector< Real, Dim >::operator= ( const Real * v)
inline

array assignment operator

Definition at line 103 of file Vector.hpp.

◆ operator=() [2/2]

template<typename Real , unsigned int Dim>
Vector< Real, Dim > & OpenMD::Vector< Real, Dim >::operator= ( const Vector< Real, Dim > & v)
inline

copy assignment operator

Definition at line 93 of file Vector.hpp.

Referenced by OpenMD::Quaternion< Real >::operator=().

◆ operator==()

template<typename Real , unsigned int Dim>
bool OpenMD::Vector< Real, Dim >::operator== ( const Vector< Real, Dim > & v)
inline

Tests if this vetor is equal to other vector.

Returns
true if equal, otherwise return false
Parameters
vvector to be compared

Definition at line 178 of file Vector.hpp.

References OpenMD::equal().

◆ operator[]() [1/2]

template<typename Real , unsigned int Dim>
Real & OpenMD::Vector< Real, Dim >::operator[] ( unsigned int i)
inline

Returns reference of ith element.

Returns
reference of ith element
Parameters
iindex

Definition at line 128 of file Vector.hpp.

◆ operator[]() [2/2]

template<typename Real , unsigned int Dim>
const Real & OpenMD::Vector< Real, Dim >::operator[] ( unsigned int i) const
inline

Returns constant reference of ith element.

Returns
reference of ith element
Parameters
iindex

Definition at line 148 of file Vector.hpp.

◆ size()

template<typename Real , unsigned int Dim>
unsigned int OpenMD::Vector< Real, Dim >::size ( ) const
inline

Definition at line 419 of file Vector.hpp.

◆ sub() [1/2]

template<typename Real , unsigned int Dim>
void OpenMD::Vector< Real, Dim >::sub ( const Vector< Real, Dim > & v1)
inline

Sets the value of this vector to the difference of itself and v1 (*this -= v1).

Parameters
v1the other vector

Definition at line 238 of file Vector.hpp.

Referenced by OpenMD::operator-(), and OpenMD::Vector< Real, Dim >::operator-=().

◆ sub() [2/2]

template<typename Real , unsigned int Dim>
void OpenMD::Vector< Real, Dim >::sub ( const Vector< Real, Dim > & v1,
const Vector< Real, Dim > & v2 )
inline

Sets the value of this vector to the difference of vector v1 and v2 (*this = v1 - v2).

Parameters
v1the first vector
v2the second vector

Definition at line 249 of file Vector.hpp.

◆ sum()

template<typename Real , unsigned int Dim>
Real OpenMD::Vector< Real, Dim >::sum ( )
inline

Returns the sum of all elements of this vector.

Returns
the sum of all elements of this vector

Definition at line 369 of file Vector.hpp.

◆ Vdiv()

template<typename Real , unsigned int Dim>
void OpenMD::Vector< Real, Dim >::Vdiv ( const Vector< Real, Dim > & v1,
const Vector< Real, Dim > & v2 )
inline

Sets the elements of this vector to the division of elements of two other vectors.

Not to be confused with scalar division (div)

(*this.data_[i] = v1.data_[i] / v2.data_[i]).

Parameters
v1the first vector
v2the second vector

Definition at line 336 of file Vector.hpp.

◆ Vmul()

template<typename Real , unsigned int Dim>
void OpenMD::Vector< Real, Dim >::Vmul ( const Vector< Real, Dim > & v1,
const Vector< Real, Dim > & v2 )
inline

Sets the elements of this vector to the multiplication of elements of two other vectors.

Not to be confused with scalar multiplication (mul) or dot products.

(*this.data_[i] = v1.data_[i] * v2.data_[i]).

Parameters
v1the first vector
v2the second vector

Definition at line 284 of file Vector.hpp.

◆ zero()

template<typename Real , unsigned int Dim>
void OpenMD::Vector< Real, Dim >::zero ( )
inline

Zeros out the values in this vector in place.

Definition at line 194 of file Vector.hpp.

Member Data Documentation

◆ data_

template<typename Real , unsigned int Dim>
Real OpenMD::Vector< Real, Dim >::data_[Dim] {}
protected

Definition at line 422 of file Vector.hpp.


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