NDDEM
Public Member Functions | Static Public Member Functions | Static Public Attributes | Static Private Attributes | List of all members
Tools< d > Class Template Reference

Static class to handle multi-dimensional mathematics, and more. It gets specialised for speed with template parameter d:dimension. More...

#include <Tools.h>

Public Member Functions

double det (cv2d &M)
 
double det (cv2d &M)
 
double det (cv1d &M)
 
double det (cv1d &M)
 
double det (double M[2][2])
 
double det (double M[1][1])
 

Static Public Member Functions

static int getdim (void)
 Return the dimension. More...
 
static void initialise ()
 
static void clear ()
 
static void matvecmult (v1d &res, cv1d &A, cv1d &v)
 
static double hyperspherical_xtophi (cv1d &x, v1d &phi)
 
static void hyperspherical_phitox (double r, cv1d &phi, v1d &x)
 
static double normsq (const vector< double > &a)
 
static int sgn (uint8_t a)
 
static v1d transpose (cv1d &a)
 
static void transpose_inplace (v1d &a)
 
General functions
static void initialise ()
 Initialise the member variables, in particular the variables to handle skew-symmetric flattened matrix, cf. the class detailed description. More...
 
static void clear ()
 Get the class ready for a different dimension. More...
 
static bool check_initialised (int dd)
 
static int sgn (uint8_t a)
 Sign function. More...
 
static int sgn (double a)
 Sign function. More...
 
static std::pair< double, double > two_max_element (cv1d &v)
 Return the two largest elements of v. More...
 
Vector and matrix initialisation and normalisation
static void unitvec (vector< double > &v, int n)
 Construct a unit vector in place. More...
 
static v1d unitvec (int n)
 Construct & return a unit vector. More...
 
static void setzero (v2d &a)
 Set a matrix to zero in-place. More...
 
static void setzero (v1d &a)
 Set a vector to zero in-place. More...
 
static double norm (const vector< double > &a)
 Norm of a vector. More...
 
static void norm (v1d &res, cv2d &a)
 Norm of a 2D-matrix, returns a 1D vector with the norms of the individual vectors. More...
 
static double normdiff (cv1d &a, cv1d &b)
 Norm of a vector difference $|a-b|$. More...
 
static double normsq (const vector< double > &a)
 Norm squared. More...
 
static double normdiffsq (cv1d &a, cv1d &b)
 Norm squared of a vector difference $|a-b|^2$. More...
 
static void orthonormalise (v1d &A)
 Orthonormalise A using the Gram-Shmidt process, in place. More...
 
static double skewnorm (cv1d &a)
 Norm of a skew-symetric matrix. More...
 
static double skewnormsq (cv1d &a)
 Norm squared of a skew-symetrix matrix. More...
 
static double dot (cv1d &a, cv1d &b)
 Dot product. More...
 
static v1f vsqrt (cv1f &a)
 Component-wise square root. More...
 
static v1f vsq (cv1f &a)
 Component-wise squaring. More...
 
static void surfacevelocity (v1d &res, cv1d &p, double *com, double *vel_com, double *omega_com)
 
static void setgravity (v2d &a, v1d &g, v1d &m)
 Set the gravity. $\vec a_i = m_i * \vec g $. More...
 
static v1d randomize_vec (cv1d v)
 Produce a random vector. More...
 
Coordinate system change
static double hyperspherical_xtophi (cv1d &x, v1d &phi)
 Convert from cartesian to hyperspherical coordinates. More...
 
static void hyperspherical_phitox (double r, cv1d &phi, v1d &x)
 Convert from hyperspherical to cartesian coordinates. More...
 
Special physics computation
static double Volume (double R)
 Compute the hypersphere volume. More...
 
static double InertiaMomentum (double R, double rho)
 Compute the hypersphere moment of inertia. More...
 
Faster vector operations

These vector or matrix operations are working in place, and sometimes perform multiple operations at once

static void vMul (v1d &res, cv1d &a, double b)
 Multiply a vector by a scalar in-place. More...
 
static void vMul (v1d &res, cv1d &a, cv1d &b)
 Component-wise multiply 2 vectors in-place. More...
 
static void vMinus (v1d &res, cv1d &a, cv1d &b)
 Difference of 2 vectors in-place $a-b$. More...
 
static void vPlus (v1d &res, cv1d &a, double b)
 Addition of a vector by a scalar in-place. More...
 
static void vPlus (v1d &res, cv1d &a, cv1d &b)
 Addition of 2 vectors in-place. More...
 
static void vDiv (v1d &res, cv1d &a, double b)
 Division of a vector by a scalar in-place. More...
 
static void vDiv (v1d &res, cv1d &a, cv1d &b)
 Component-wise discrete of 2 vectors in-place. More...
 
static void vAddFew (v1d &res, cv1d &a, cv1d &b)
 
static void vAddScaled (v1d &res, double v, cv1d &a, cv1d &b)
 Addition of 3 vectors in-place. More...
 
static void vAddScaled (v1d &res, double v, cv1d &a)
 Addition of a scaled vector $ res := res + v*a$. More...
 
static void vSubFew (v1d &res, cv1d &a, cv1d &b)
 Subtraction of 2 vectors $ res := res - a - b$. More...
 
static void vSubScaled (v1d &res, double v, cv1d &a)
 Subtraction of a scaled vector $ res := res - v*a$. More...
 
Faster vector operations with error corrections (Kahan summation algorithm)

These vector or matrix operations are working in place, perform multiple operations at once, and are designed to use error correction across multiple calls.

static void vAddFew (v1d &res, cv1d &a, cv1d &b, v1d &Corr)
 Addition of 3 vectors in-place with error correction (Kahan summation algorithm) More...
 
static void vSubFew (v1d &res, cv1d &a, cv1d &b, v1d &Corr)
 Subtraction of 2 vectors $ res := res - a - b$ with error correction. More...
 
static void vAddOne (v1d &res, cv1d &a, v1d &Corr)
 Addition of 2 vectors in-place with error correction (Kahan summation algorithm) More...
 
static void vSubOne (v1d &res, cv1d &a, v1d &Corr)
 Subtraction of 2 vectors in-place with error correction (Kahan summation algorithm) More...
 
Matrix operations, usually operating on flattened matrices, cf. the description for more information on matrix storage
static v1d skewmatvecmult (cv1d &M, cv1d &v)
 Multiply the skew symetric matrix M with vector v. More...
 
static v1d skewmatvecmult (const double *M, cv1d &v)
 Multiply the skew symetric matrix M with vector v. More...
 
static void skewmatvecmult (v1d &r, cv1d &M, cv1d &v)
 Multiply the skew symetric matrix M with vector v in place. More...
 
static void skewmatvecmult (v1d &r, const double *M, cv1d &v)
 Multiply the skew symetric matrix M with vector v in place (overload) More...
 
static v1d skewmatsquare (cv1d &A)
 Square the skew symetric matrix M. More...
 
static void skewmatsquare (v1d &r, cv1d &A)
 Square the skew symetric matrix M in place. More...
 
static v1d skewexpand (cv1d &A)
 Return the skew symetrix matrix M stored on d(d-1)/2 component as a full flattened matrix with d^2 components. More...
 
static void skewexpand (v1d &r, cv1d &A)
 Return the skew symetrix matrix M stored on d(d-1)/2 component as a full flattened matrix with d^2 components in place. More...
 
static v1d matmult (cv1d &A, cv1d &B)
 Multiply 2 matrix together. More...
 
static void matmult (v1d &r, cv1d &A, cv1d &B)
 Multiply 2 matrix together in place. More...
 
static void matvecmult (v1d &res, cv1d &A, cv1d &B)
 Multiply a matrix with a vector, in place. More...
 
static v1d wedgeproduct (cv1d &a, cv1d &b)
 Wedge product of vectors. More...
 
static void wedgeproduct (v1d &res, cv1d &a, cv1d &b)
 Wedge product in-place. More...
 
static v1d transpose (cv1d &a)
 Transposition. More...
 
static void transpose_inplace (v1d &a)
 Transpose in-place. More...
 
static double det (cv2d &M)
 compute the matrix determinant (probably quite slow, but doesn't really really matters for the usage) More...
 
static double det (cv1d &M)
 compute the matrix determinant (probably quite slow, but shouldn't really really matters for the usage) More...
 
static double det (double M[d][d])
 compute the matrix determinant using array on the stack (avoids malloc/free) More...
 
static v1d inverse (cv1d &M)
 compute the matrix inverse (very slow and redundant calculation of the determinant for the comatrix, but shouldn't really really matters for the usage) More...
 
Saving and writing functions
static int savetxt (char path[], const v2d &table, char const header[])
 
static void savecsv (char path[], cv2d &X, cv1d &r, const vector< uint32_t > &PBCFlags, cv1d &Vmag, cv1d &OmegaMag, [[maybe_unused]] cv1d &Z)
 Save the location and a few more informations in a CSV file. More...
 
static void savecsv (char path[], cv2d &X, cv2d &V, cv1d &r, const vector< uint32_t > &PBCFlags, cv1d &Vmag, cv1d &OmegaMag, [[maybe_unused]] cv1d &Z)
 Save the location and a few more informations in a CSV file. More...
 
static void savecsv (char path[], cv2d &A)
 Save the orientation in a CSV file. More...
 
static void savevtk (char path[], int N, cv2d &Boundaries, cv2d &X, cv1d &r, vector< TensorInfos > data)
 Save as a vtk file. Dimensions higher than 3 are stored as additional scalars. Additional informations can be passed as a vector of TensorInfos. More...
 
static void print (cv1d M)
 
static int write1D (char path[], v1d table)
 
static int writeinline (initializer_list< v1d >)
 
static int writeinline_close (void)
 

Static Public Attributes

static v1d Eye
 The identity matrix in dimension <d> More...
 
static boost::random::mt19937 rng
 Random number generator. More...
 
static boost::random::uniform_01< boost::mt19937 > rand
 Returns a random number between 0 and 1. More...
 
static vector< pair< int, int > > MASIndex
 For skew symmetric matrix, make the correspondance between linear index and (row,column) index. More...
 

Static Private Attributes

static vector< vector< int > > MSigns
 For skew symetric matrix. -1 below the diagonal, 0 on the diagonal, +1 above the diagnal. More...
 
static vector< vector< int > > MIndexAS
 For skew symmetric matrix, make the correspondance between linear index of a full matrix with the linear index of the skew-symetric storage. More...
 
static vector< FILE * > outs
 Store the output file descriptors. More...
 

Detailed Description

template<int d>
class Tools< d >

Static class to handle multi-dimensional mathematics, and more. It gets specialised for speed with template parameter d:dimension.

Matrix storage
  • Arbitrary square matrix are stored as linear array, in the order x11, x12, x13 ... x21, x22 ... xdd. They have d^2 components.
  • Skew-symetric matrix only store their top right side, in the order x12, x13, x14 ... x23, x24 ... x(d-1)d. They have d(d-1)/2 components. These are handled using the specific function skewmatvecmult() and similar, and make use of the special variables MSigns, MIndexAS and MASIndex
  • Symetric matrix are not really needed anywhere, but would store only the top right side + diagonal as a linear array, in the order x11, x12 ... x22, x23, ... xdd. They have d(d+1)/2 components.

Member Function Documentation

◆ clear()

template<int d>
static void Tools< d >::clear ( )
static

◆ det() [1/6]

double Tools< 2 >::det ( cv1d M)

◆ det() [2/6]

double Tools< 1 >::det ( cv1d M)

◆ det() [3/6]

double Tools< 2 >::det ( cv2d M)

◆ det() [4/6]

double Tools< 1 >::det ( cv2d M)

◆ det() [5/6]

double Tools< 1 >::det ( double  M[1][1])

◆ det() [6/6]

double Tools< 2 >::det ( double  M[2][2])

◆ getdim()

template<int d>
static int Tools< d >::getdim ( void  )
inlinestatic

Return the dimension.

Deprecated:

◆ hyperspherical_phitox()

template<int d>
static void Tools< d >::hyperspherical_phitox ( double  r,
cv1d phi,
v1d x 
)
static

◆ hyperspherical_xtophi()

template<int d>
static double Tools< d >::hyperspherical_xtophi ( cv1d x,
v1d phi 
)
static

◆ initialise()

template<int d>
static void Tools< d >::initialise ( )
static

◆ matvecmult()

template<int d>
static void Tools< d >::matvecmult ( v1d res,
cv1d A,
cv1d v 
)
static

◆ normsq()

template<int d>
static double Tools< d >::normsq ( const vector< double > &  a)
inlinestatic

◆ sgn()

template<int d>
static int Tools< d >::sgn ( uint8_t  a)
inlinestatic

◆ transpose()

template<int d>
static v1d Tools< d >::transpose ( cv1d a)
inlinestatic

◆ transpose_inplace()

template<int d>
static void Tools< d >::transpose_inplace ( v1d a)
inlinestatic

◆ vAddFew() [1/2]

template<int d>
static void Tools< d >::vAddFew ( v1d res,
cv1d a,
cv1d b 
)
inlinestatic

◆ vAddFew() [2/2]

template<int d>
static void Tools< d >::vAddFew ( v1d res,
cv1d a,
cv1d b,
v1d Corr 
)
inlinestatic

Addition of 3 vectors in-place with error correction (Kahan summation algorithm)

◆ vAddOne()

template<int d>
static void Tools< d >::vAddOne ( v1d res,
cv1d a,
v1d Corr 
)
inlinestatic

Addition of 2 vectors in-place with error correction (Kahan summation algorithm)

◆ vAddScaled() [1/2]

template<int d>
static void Tools< d >::vAddScaled ( v1d res,
double  v,
cv1d a 
)
inlinestatic

Addition of a scaled vector $ res := res + v*a$.

◆ vAddScaled() [2/2]

template<int d>
static void Tools< d >::vAddScaled ( v1d res,
double  v,
cv1d a,
cv1d b 
)
inlinestatic

Addition of 3 vectors in-place.

Addition of two scaled vector $ res := res + v*(a+b)$

◆ vDiv() [1/2]

template<int d>
static void Tools< d >::vDiv ( v1d res,
cv1d a,
cv1d b 
)
inlinestatic

Component-wise discrete of 2 vectors in-place.

◆ vDiv() [2/2]

template<int d>
static void Tools< d >::vDiv ( v1d res,
cv1d a,
double  b 
)
inlinestatic

Division of a vector by a scalar in-place.

◆ vMinus()

template<int d>
static void Tools< d >::vMinus ( v1d res,
cv1d a,
cv1d b 
)
inlinestatic

Difference of 2 vectors in-place $a-b$.

◆ vMul() [1/2]

template<int d>
static void Tools< d >::vMul ( v1d res,
cv1d a,
cv1d b 
)
inlinestatic

Component-wise multiply 2 vectors in-place.

◆ vMul() [2/2]

template<int d>
static void Tools< d >::vMul ( v1d res,
cv1d a,
double  b 
)
inlinestatic

Multiply a vector by a scalar in-place.

◆ vPlus() [1/2]

template<int d>
static void Tools< d >::vPlus ( v1d res,
cv1d a,
cv1d b 
)
inlinestatic

Addition of 2 vectors in-place.

◆ vPlus() [2/2]

template<int d>
static void Tools< d >::vPlus ( v1d res,
cv1d a,
double  b 
)
inlinestatic

Addition of a vector by a scalar in-place.

◆ vSubFew() [1/2]

template<int d>
static void Tools< d >::vSubFew ( v1d res,
cv1d a,
cv1d b 
)
inlinestatic

Subtraction of 2 vectors $ res := res - a - b$.

◆ vSubFew() [2/2]

template<int d>
static void Tools< d >::vSubFew ( v1d res,
cv1d a,
cv1d b,
v1d Corr 
)
inlinestatic

Subtraction of 2 vectors $ res := res - a - b$ with error correction.

◆ vSubOne()

template<int d>
static void Tools< d >::vSubOne ( v1d res,
cv1d a,
v1d Corr 
)
inlinestatic

Subtraction of 2 vectors in-place with error correction (Kahan summation algorithm)

◆ vSubScaled()

template<int d>
static void Tools< d >::vSubScaled ( v1d res,
double  v,
cv1d a 
)
inlinestatic

Subtraction of a scaled vector $ res := res - v*a$.


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