OpenMD 3.2
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"

Inheritance diagram for OpenMD::Vector< Real, Dim >:

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) const
 Copy the internal data to an array.
const Real * getArrayPointer () const
 Returns the pointer of internal array.
Real * getArrayPointer ()
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 () const
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 () const
 Returns the sum of all elements of this vector.
Real componentProduct () const
 Returns the product of all elements of this vector.
Real length () const
 Returns the length of this vector.
Real lengthSquare () const
 Returns the squared length of this vector.
void normalize ()
 Normalizes this vector in place.
bool isNormalized () const
 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 81 of file Vector.hpp.

Member Typedef Documentation

◆ ElemPoinerType

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

Definition at line 84 of file Vector.hpp.

◆ ElemType

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

Definition at line 83 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 87 of file Vector.hpp.

Referenced by OpenMD::Vector2< int >::Vector2(), and OpenMD::Vector3< int >::Vector3().

◆ 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 93 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 115 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 121 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 294 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 222 of file Vector.hpp.

Referenced by OpenMD::operator+(), and OpenMD::Vector< RealType, N_INTERACTION_FAMILIES >::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 232 of file Vector.hpp.

◆ componentProduct()

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

Returns the product of all elements of this vector.

Returns
the product of all elements of this vector

Definition at line 385 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 326 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 315 of file Vector.hpp.

Referenced by OpenMD::operator/(), and OpenMD::Vector< RealType, N_INTERACTION_FAMILIES >::operator/=().

◆ getArray()

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

Copy the internal data to an array.

Definition at line 167 of file Vector.hpp.

◆ getArrayPointer() [1/2]

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

Definition at line 175 of file Vector.hpp.

◆ getArrayPointer() [2/2]

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

◆ isNormalized()

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

Tests if this vector is normalized.

Returns
true if this vector is normalized, otherwise return false

Definition at line 418 of file Vector.hpp.

◆ length()

◆ lengthSquare()

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

Returns the squared length of this vector.

Returns
the squared length of this vector

Definition at line 403 of file Vector.hpp.

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

◆ max()

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

Definition at line 302 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 274 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 263 of file Vector.hpp.

Referenced by OpenMD::operator*(), OpenMD::operator*(), and OpenMD::Vector< RealType, N_INTERACTION_FAMILIES >::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 204 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 213 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 195 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 141 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 161 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 358 of file Vector.hpp.

◆ 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 346 of file Vector.hpp.

◆ 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 352 of file Vector.hpp.

◆ operator/=()

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

Definition at line 364 of file Vector.hpp.

◆ 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 106 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 96 of file Vector.hpp.

Referenced by OpenMD::Quaternion< RealType >::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 182 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 131 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 151 of file Vector.hpp.

◆ size()

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

Definition at line 420 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 242 of file Vector.hpp.

Referenced by OpenMD::operator-(), and OpenMD::Vector< RealType, N_INTERACTION_FAMILIES >::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 253 of file Vector.hpp.

◆ sum()

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

Returns the sum of all elements of this vector.

Returns
the sum of all elements of this vector

Definition at line 373 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 340 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 288 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 198 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 423 of file Vector.hpp.


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