ParM  parm
A molecular dynamics library
Classes | Macros | Typedefs | Functions | Variables
vecrand.hpp File Reference
#include <iostream>
#include <ctime>
#include <vector>
#include <cmath>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/variate_generator.hpp>
#include <boost/random/normal_distribution.hpp>
#include <boost/array.hpp>
#include <Eigen/Dense>

Go to the source code of this file.

Classes

class  GaussVec
 
class  BivariateGauss
 A class for generating two random numbers from a Gaussian distribution, with a given correlation. More...
 

Macros

#define NDIM   2
 
#define DIMROTATIONS   4
 
#define NDIM   3
 
#define DIMROTATIONS   24
 

Typedefs

typedef unsigned int uint
 
typedef double flt
 The basic floating point type used in the simulations. More...
 
typedef std::complex< fltcmplx
 
typedef Eigen::Matrix< flt, NDIM, 1 > Vec
 The basic physics vector. More...
 
typedef Eigen::Matrix< flt, 2, 1 > Vec2
 
typedef Eigen::Matrix< flt, 3, 1 > Vec3
 
typedef Eigen::Matrix< flt, NDIM, NDIMMatrix
 
typedef Eigen::Matrix< flt, 2, 2 > Matrix2
 
typedef Eigen::Matrix< flt, 3, 3 > Matrix3
 
typedef Eigen::Matrix< flt, NDIM, 2 > VecPair
 
typedef boost::mt19937 engine
 
typedef boost::normal_distribution< fltnormdistribution
 
typedef boost::uniform_01< flt, fltlindistribution
 
typedef boost::variate_generator< engine &, normdistributionnormgenerator
 
typedef boost::variate_generator< engine &, lindistributionlingenerator
 

Functions

Vec vec ()
 A one-liner for creating a Vec object, occasionally useful from within Python. More...
 
Vec2 vec (double x, double y)
 
Vec3 vec (double x, double y, double z)
 
Vec3 cross (Vec3 v1, Vec3 v2)
 
flt cross (Vec2 v1, Vec2 v2)
 
Vec2 cross (Vec2 v, flt n)
 
Vec2 perp (Vec2 v)
 
Vec perpto (Vec r, Vec to)
 
Vec2 rotate (Vec2 v, uint i)
 
Vec2 rotate_inv (Vec2 v, uint i)
 
Vec2 flip (Vec2 v)
 
Vec2 rotate_flip (Vec2 v, uint i)
 
Vec2 rotate_flip_inv (Vec2 v, uint i)
 
Vec3 rotate (Vec3 v, uint i)
 
Vec3 rotate_inv (Vec3 v, uint i)
 
Vec3 flip (Vec3 v)
 
Vec3 rotate_flip (Vec3 v, uint i)
 
Vec3 rotate_flip_inv (Vec3 v, uint i)
 
uint vecsize ()
 
flt rand01 ()
 Generate a random number between 0 and 1, using the "global" random number generator. More...
 
Vec rand_vec ()
 Generate a random vector from a Gaussian distribution, i.e. More...
 
Vec rand_vec_boxed ()
 Generate a random vector inside a box with sides of length 1. More...
 
Vec rand_vec_sphere (flt radius=1)
 Generate a random vector inside a sphere. More...
 
unsigned int seed (unsigned int n)
 Seed the global random number generator with a given integer. More...
 
unsigned int seed ()
 Seed the global random number generator with the current time. More...
 
long double to_LD (double e)
 Go to and from Long Doubles. More...
 
double from_LD (long double e)
 Go to and from Long Doubles. More...
 
vector< long double > LDVector (vector< double > dists)
 Go to and from Long Doubles. More...
 
template<typename Derived >
bool hasNaN (const Eigen::DenseBase< Derived > &m)
 Is there a NaN in this matrix? Eigen has an allFinite and hasNan function as of version 3.2, but Ubuntu libeigen3-dev is not up that far. More...
 
template<typename Derived >
bool allFinite (const Eigen::DenseBase< Derived > &m)
 Are all values finite, i.e. More...
 
template<typename Derived >
void finite_or_throw (const Eigen::DenseBase< Derived > &m)
 
Matrix best_rotation_matrix (Eigen::Matrix< flt, Eigen::Dynamic, NDIM > &from, Eigen::Matrix< flt, Eigen::Dynamic, NDIM > &to)
 

Variables

const flt OVERNDIM = ((flt) 1.0)/NDIM
 A constant equal to \(\frac{1}{d}\), where \(d\) is the number of dimensions. More...
 

Macro Definition Documentation

#define DIMROTATIONS   4
#define DIMROTATIONS   24
#define NDIM   2
#define NDIM   3

Typedef Documentation

typedef std::complex<flt> cmplx
typedef boost::mt19937 engine
typedef double flt

The basic floating point type used in the simulations.

The entire package can be compiled with LONGFLOAT defined to use long doubles.

Examples:
hardspheres.cpp, and packer.cpp.
typedef boost::uniform_01<flt, flt> lindistribution
typedef boost::variate_generator<engine&, lindistribution > lingenerator
typedef Eigen::Matrix<flt, NDIM, NDIM> Matrix
typedef Eigen::Matrix<flt, 2, 2> Matrix2
typedef Eigen::Matrix<flt, 3, 3> Matrix3
typedef boost::normal_distribution<flt> normdistribution
typedef boost::variate_generator<engine&, normdistribution > normgenerator
typedef unsigned int uint
typedef Eigen::Matrix<flt, NDIM, 1> Vec

The basic physics vector.

See Vector3 for full methods.

typedef Eigen::Matrix<flt, 2, 1> Vec2
typedef Eigen::Matrix<flt, 3, 1> Vec3
typedef Eigen::Matrix<flt, NDIM, 2> VecPair

Function Documentation

template<typename Derived >
bool allFinite ( const Eigen::DenseBase< Derived > &  m)
inline

Are all values finite, i.e.

not NaN and not +/- Inf? Eigen has an allFinite and hasNan function as of version 3.2, but Ubuntu libeigen3-dev is not up that far.

Matrix best_rotation_matrix ( Eigen::Matrix< flt, Eigen::Dynamic, NDIM > &  from,
Eigen::Matrix< flt, Eigen::Dynamic, NDIM > &  to 
)
Vec3 cross ( Vec3  v1,
Vec3  v2 
)
inline
flt cross ( Vec2  v1,
Vec2  v2 
)
inline
Vec2 cross ( Vec2  v,
flt  n 
)
inline
template<typename Derived >
void finite_or_throw ( const Eigen::DenseBase< Derived > &  m)
Vec2 flip ( Vec2  v)
inline
Vec3 flip ( Vec3  v)
inline
double from_LD ( long double  e)

Go to and from Long Doubles.

Useful from Python.

template<typename Derived >
bool hasNaN ( const Eigen::DenseBase< Derived > &  m)
inline

Is there a NaN in this matrix? Eigen has an allFinite and hasNan function as of version 3.2, but Ubuntu libeigen3-dev is not up that far.

vector<long double> LDVector ( vector< double >  dists)

Go to and from Long Doubles.

Useful from Python.

Vec2 perp ( Vec2  v)
inline
Vec perpto ( Vec  r,
Vec  to 
)
inline
flt rand01 ( )

Generate a random number between 0 and 1, using the "global" random number generator.

Vec rand_vec ( )

Generate a random vector from a Gaussian distribution, i.e.

\ \(P(x)=\frac{1}{\sqrt{2 \pi}} e^{\frac{-x^2}{2\pi}}\), and similarly for \(y\) and \(z\).

In terms of spherical coordinates, directionality is uniform on a sphere, and the radial distribution is a Chi Distribution with \(\sigma=1\).

Vec rand_vec_boxed ( )

Generate a random vector inside a box with sides of length 1.

Vec rand_vec_sphere ( flt  radius = 1)

Generate a random vector inside a sphere.

Vec2 rotate ( Vec2  v,
uint  i 
)
inline
Vec3 rotate ( Vec3  v,
uint  i 
)
inline
Vec2 rotate_flip ( Vec2  v,
uint  i 
)
inline
Vec3 rotate_flip ( Vec3  v,
uint  i 
)
inline
Vec2 rotate_flip_inv ( Vec2  v,
uint  i 
)
inline
Vec3 rotate_flip_inv ( Vec3  v,
uint  i 
)
inline
Vec2 rotate_inv ( Vec2  v,
uint  i 
)
inline
Vec3 rotate_inv ( Vec3  v,
uint  i 
)
inline
unsigned int seed ( unsigned int  n)

Seed the global random number generator with a given integer.

unsigned int seed ( )

Seed the global random number generator with the current time.

Returns
the seed used.
long double to_LD ( double  e)

Go to and from Long Doubles.

Useful from Python.

Vec vec ( )
inline

A one-liner for creating a Vec object, occasionally useful from within Python.

Vec2 vec ( double  x,
double  y 
)
inline
Vec3 vec ( double  x,
double  y,
double  z 
)
inline
uint vecsize ( )
inline

Variable Documentation

const flt OVERNDIM = ((flt) 1.0)/NDIM

A constant equal to \(\frac{1}{d}\), where \(d\) is the number of dimensions.

Examples:
hardspheres.cpp, LJatoms.cpp, and packer.cpp.