Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
PLMD::VectorGeneric< n > Class Template Reference

#include <Vector.h>

Inheritance diagram for PLMD::VectorGeneric< n >:
Inheritance graph
[legend]

Public Member Functions

 VectorGeneric ()
 create it null More...
 
template<typename... Args>
 VectorGeneric (double first, Args... arg)
 Constructor accepting n double parameters. More...
 
double modulo () const
 Compute the modulo. More...
 
double modulo2 () const
 compute the squared modulo More...
 
double & operator() (unsigned i)
 parenthesis access (i) More...
 
const double & operator() (unsigned i) const
 parenthesis access (i) More...
 
VectorGenericoperator*= (double s)
 multiply More...
 
VectorGeneric operator+ () const
 sign + More...
 
VectorGenericoperator+= (const VectorGeneric &b)
 increment More...
 
VectorGeneric operator- () const
 sign - More...
 
VectorGenericoperator-= (const VectorGeneric &b)
 decrement More...
 
VectorGenericoperator/= (double s)
 divide More...
 
double & operator[] (unsigned i)
 array-like access [i] More...
 
const double & operator[] (unsigned i) const
 array-like access [i] More...
 
void zero ()
 set it to zero More...
 

Private Member Functions

void auxiliaryConstructor ()
 Auxiliary private function for constructor. More...
 
template<typename... Args>
void auxiliaryConstructor (double first, Args... arg)
 Auxiliary private function for constructor. More...
 

Private Attributes

std::array< double, n > d
 

Friends

VectorGeneric< 3 > crossProduct (const VectorGeneric< 3 > &, const VectorGeneric< 3 > &)
 return v1 .vector. More...
 
template<unsigned m>
VectorGeneric< m > delta (const VectorGeneric< m > &v1, const VectorGeneric< m > &v2)
 return v2-v1 More...
 
template<unsigned m>
double dotProduct (const VectorGeneric< m > &, const VectorGeneric< m > &)
 return v1 .scalar. v2 More...
 
template<unsigned m>
double modulo (const VectorGeneric< m > &)
 friend version of modulo (to simplify some syntax) More...
 
template<unsigned m>
double modulo2 (const VectorGeneric< m > &)
 friend version of modulo2 (to simplify some syntax) More...
 
template<unsigned m>
VectorGeneric< m > operator* (const VectorGeneric< m > &, double)
 return v*s More...
 
template<unsigned m>
VectorGeneric< m > operator* (double, const VectorGeneric< m > &)
 return s*v More...
 
template<unsigned m>
VectorGeneric< m > operator+ (const VectorGeneric< m > &, const VectorGeneric< m > &)
 return v1+v2 More...
 
template<unsigned m>
VectorGeneric< m > operator- (const VectorGeneric< m > &, const VectorGeneric< m > &)
 return v1-v2 More...
 
template<unsigned m>
VectorGeneric< m > operator/ (const VectorGeneric< m > &, double)
 return v/s More...
 
template<unsigned m>
std::ostream & operator<< (std::ostream &os, const VectorGeneric< m > &)
 << operator. More...
 

Detailed Description

template<unsigned n>
class PLMD::VectorGeneric< n >

Class implementing fixed size vectors of doubles

Template Parameters
nThe number of elements of the vector.

This class implements a vector of doubles with size fixed at compile time. It is useful for small fixed size objects (e.g. 3d vectors) as it does not waste space to store the vector size. Moreover, as the compiler knows the size, it can be completely opimized inline. All the methods are inlined for better optimization and all the loops are explicitly unrolled using PLMD::LoopUnroller class. Vector elements are initialized to zero by default. Notice that this means that constructor is a bit slow. This point might change in future if we find performance issues. Accepts both [] and () syntax for access. Several functions are declared as friends even if not necessary so as to properly appear in Doxygen documentation.

Aliases are defined to simplify common declarations (Vector, Vector2d, Vector3d, Vector4d). Also notice that some operations are only available for 3 dimensional vectors.

Example of usage

#include "Vector.h"

using namespace PLMD;

int main(){
  VectorGeneric<3> v1;
  v1[0]=3.0;
// use equivalently () and [] syntax:
  v1(1)=5.0;
// initialize with components
  VectorGeneric<3> v2=VectorGeneric<3>(1.0,2.0,3.0);
  VectorGeneric<3> v3=crossProduct(v1,v2);
  double d=dotProduct(v1,v2);
  v3+=v1;
  v2=v1+2.0*v3;
}

Constructor & Destructor Documentation

◆ VectorGeneric() [1/2]

template<unsigned n>
template<typename... Args>
PLMD::VectorGeneric< n >::VectorGeneric ( double  first,
Args...  arg 
)

Constructor accepting n double parameters.

Can be used as Vector<3>(1.0,2.0,3.0) or Vector<2>(2.0,3.0). In case a wrong number of parameters is given, a static assertion will fail.

◆ VectorGeneric() [2/2]

template<unsigned n>
PLMD::VectorGeneric< n >::VectorGeneric

create it null

Member Function Documentation

◆ auxiliaryConstructor() [1/2]

template<unsigned n>
void PLMD::VectorGeneric< n >::auxiliaryConstructor
private

Auxiliary private function for constructor.

◆ auxiliaryConstructor() [2/2]

template<unsigned n>
template<typename... Args>
void PLMD::VectorGeneric< n >::auxiliaryConstructor ( double  first,
Args...  arg 
)
private

Auxiliary private function for constructor.

◆ modulo()

template<unsigned n>
double PLMD::VectorGeneric< n >::modulo

Compute the modulo.

Shortcut for sqrt(v.modulo2())

◆ modulo2()

template<unsigned n>
double PLMD::VectorGeneric< n >::modulo2

compute the squared modulo

◆ operator()() [1/2]

template<unsigned n>
double & PLMD::VectorGeneric< n >::operator() ( unsigned  i)

parenthesis access (i)

◆ operator()() [2/2]

template<unsigned n>
const double & PLMD::VectorGeneric< n >::operator() ( unsigned  i) const

parenthesis access (i)

◆ operator*=()

template<unsigned n>
VectorGeneric< n > & PLMD::VectorGeneric< n >::operator*= ( double  s)

multiply

◆ operator+()

template<unsigned n>
VectorGeneric< n > PLMD::VectorGeneric< n >::operator+

sign +

◆ operator+=()

template<unsigned n>
VectorGeneric< n > & PLMD::VectorGeneric< n >::operator+= ( const VectorGeneric< n > &  b)

increment

◆ operator-()

template<unsigned n>
VectorGeneric< n > PLMD::VectorGeneric< n >::operator-

sign -

◆ operator-=()

template<unsigned n>
VectorGeneric< n > & PLMD::VectorGeneric< n >::operator-= ( const VectorGeneric< n > &  b)

decrement

◆ operator/=()

template<unsigned n>
VectorGeneric< n > & PLMD::VectorGeneric< n >::operator/= ( double  s)

divide

◆ operator[]() [1/2]

template<unsigned n>
double & PLMD::VectorGeneric< n >::operator[] ( unsigned  i)

array-like access [i]

◆ operator[]() [2/2]

template<unsigned n>
const double & PLMD::VectorGeneric< n >::operator[] ( unsigned  i) const

array-like access [i]

◆ zero()

template<unsigned n>
void PLMD::VectorGeneric< n >::zero

set it to zero

Friends And Related Function Documentation

◆ crossProduct

template<unsigned n>
VectorGeneric<3> crossProduct ( const VectorGeneric< 3 > &  v1,
const VectorGeneric< 3 > &  v2 
)
friend

return v1 .vector.

v2 Only available for size 3

◆ delta

template<unsigned n>
template<unsigned m>
VectorGeneric<m> delta ( const VectorGeneric< m > &  v1,
const VectorGeneric< m > &  v2 
)
friend

return v2-v1

◆ dotProduct

template<unsigned n>
template<unsigned m>
double dotProduct ( const VectorGeneric< m > &  ,
const VectorGeneric< m > &   
)
friend

return v1 .scalar. v2

◆ modulo

template<unsigned n>
template<unsigned m>
double modulo ( const VectorGeneric< m > &  )
friend

friend version of modulo (to simplify some syntax)

◆ modulo2

template<unsigned n>
template<unsigned m>
double modulo2 ( const VectorGeneric< m > &  )
friend

friend version of modulo2 (to simplify some syntax)

◆ operator* [1/2]

template<unsigned n>
template<unsigned m>
VectorGeneric<m> operator* ( const VectorGeneric< m > &  ,
double   
)
friend

return v*s

◆ operator* [2/2]

template<unsigned n>
template<unsigned m>
VectorGeneric<m> operator* ( double  ,
const VectorGeneric< m > &   
)
friend

return s*v

◆ operator+

template<unsigned n>
template<unsigned m>
VectorGeneric<m> operator+ ( const VectorGeneric< m > &  ,
const VectorGeneric< m > &   
)
friend

return v1+v2

◆ operator-

template<unsigned n>
template<unsigned m>
VectorGeneric<m> operator- ( const VectorGeneric< m > &  ,
const VectorGeneric< m > &   
)
friend

return v1-v2

◆ operator/

template<unsigned n>
template<unsigned m>
VectorGeneric<m> operator/ ( const VectorGeneric< m > &  ,
double   
)
friend

return v/s

◆ operator<<

template<unsigned n>
template<unsigned m>
std::ostream& operator<< ( std::ostream &  os,
const VectorGeneric< m > &   
)
friend

<< operator.

Allows printing vector v with std::cout<<v;

Member Data Documentation

◆ d

template<unsigned n>
std::array<double,n> PLMD::VectorGeneric< n >::d
private

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