13 #define DIMROTATIONS 24
20 #include <boost/random/mersenne_twister.hpp>
21 #include <boost/random/variate_generator.hpp>
22 #include <boost/random/normal_distribution.hpp>
23 #include <boost/array.hpp>
24 #include <Eigen/Dense>
29 typedef long double flt;
34 inline flt cbrt(
flt n){
return cbrtl(n);};
35 inline flt expm1(
flt n){
return expm1l(n);};
36 inline flt copysign(
flt n,
flt m){
return copysignl(n,m);};
37 inline flt remainder(
flt n,
flt m){
return remainderl(n,m);};
38 inline flt round(
flt n){
return roundl(n);};
48 typedef std::complex<flt>
cmplx;
53 typedef Eigen::Matrix<flt, NDIM, 1>
Vec;
54 typedef Eigen::Matrix<flt, 2, 1>
Vec2;
55 typedef Eigen::Matrix<flt, 3, 1>
Vec3;
56 typedef Eigen::Matrix<flt, NDIM, NDIM>
Matrix;
59 typedef Eigen::Matrix<flt, NDIM, 2>
VecPair;
78 inline Vec3 vec(
double x,
double y,
double z){
return Vec3(x,y,z);};
86 return r - to * ((r.dot(to)) / to.squaredNorm());
90 if(i % 4 == 0)
return v;
91 else if(i % 4 == 3)
return Vec2(v(1), -v(0));
92 else if(i % 4 == 2)
return Vec2(-v(0), -v(1));
93 else return Vec2(-v(1), v(0));
100 if((i / 4) % 2 == 1)
return rotate(
flip(v), i%4);
106 if((i / 4) % 2 == 0)
return inv;
113 else if(i == 1)
return Vec3( v(0),-v(1),-v(2));
114 else if(i == 2)
return Vec3( v(1), v(0),-v(2));
115 else if(i == 3)
return Vec3( v(2),-v(1), v(0));
116 else if(i == 4)
return Vec3(-v(2),-v(1),-v(0));
117 else if(i == 5)
return Vec3(-v(1),-v(0),-v(2));
118 else if(i == 6)
return Vec3(-v(0), v(1),-v(2));
119 else if(i == 7)
return Vec3(-v(0), v(2), v(1));
120 else if(i == 8)
return Vec3(-v(0),-v(2),-v(1));
121 else if(i == 9)
return Vec3(-v(0),-v(1), v(2));
122 else if(i == 10)
return Vec3( v(0), v(2),-v(1));
123 else if(i == 11)
return Vec3( v(1), v(2), v(0));
124 else if(i == 12)
return Vec3( v(1),-v(2),-v(0));
125 else if(i == 13)
return Vec3( v(1),-v(0), v(2));
126 else if(i == 14)
return Vec3( v(2), v(1),-v(0));
127 else if(i == 15)
return Vec3( v(2),-v(0),-v(1));
128 else if(i == 16)
return Vec3(-v(2),-v(0), v(1));
129 else if(i == 17)
return Vec3(-v(1), v(2),-v(0));
130 else if(i == 18)
return Vec3(-v(1),-v(2), v(0));
131 else if(i == 19)
return Vec3(-v(2), v(1), v(0));
132 else if(i == 20)
return Vec3(-v(1), v(0), v(2));
133 else if(i == 21)
return Vec3(-v(2), v(0),-v(1));
134 else if(i == 22)
return Vec3( v(2), v(0), v(1));
135 else if(i == 23)
return Vec3( v(0),-v(2), v(1));
136 throw std::runtime_error(
"This should be impossible to reach.");
141 if(i < 10)
return rotate(v, i);
142 else return rotate(v, 33 - i);
146 if((i / 24) % 2 == 1)
return rotate(
flip(v), i%24);
152 if((i / 24) % 2 == 0)
return inv;
163 typedef boost::variate_generator<engine&, lindistribution >
lingenerator;
186 unsigned int seed(
unsigned int n);
232 void set(
const flt s1,
const flt s2,
const flt corr);
234 Eigen::Matrix<flt, 1, 2> generate();
250 long double to_LD(
double e);
252 vector<long double>
LDVector(vector<double> dists);
254 template<
typename Derived>
258 inline bool hasNaN(
const Eigen::DenseBase<Derived> &m) {
260 return !((m.derived().array()==m.derived().array()).all());
267 template<
typename Derived>
268 inline bool allFinite(
const Eigen::DenseBase<Derived> &m){
270 return !
hasNaN(((m.derived()-m.derived())));
273 template<
typename Derived>
276 std::cerr <<
"Matrix !Finite ERROR" << std::endl;
277 std::cerr << m << std::endl;
278 throw std::invalid_argument(
"Matrix was not finite, cannot continue.");
Vec perpto(Vec r, Vec to)
Definition: vecrand.hpp:85
Vec vec()
A one-liner for creating a Vec object, occasionally useful from within Python.
Definition: vecrand.hpp:72
normgenerator gauss
Definition: vecrand.hpp:215
A class for generating two random numbers from a Gaussian distribution, with a given correlation...
Definition: vecrand.hpp:212
Vec rand_vec_boxed()
Generate a random vector inside a box with sides of length 1.
Definition: vecrand.cpp:19
Vec2 rotate_flip_inv(Vec2 v, uint i)
Definition: vecrand.hpp:104
unsigned int seed(unsigned int n)
Seed the global random number generator with a given integer.
Definition: vecrand.cpp:36
normgenerator gauss
Definition: vecrand.hpp:196
vector< long double > LDVector(vector< double > dists)
Go to and from Long Doubles.
Definition: vecrand.cpp:99
bool allFinite(const Eigen::DenseBase< Derived > &m)
Are all values finite, i.e.
Definition: vecrand.hpp:268
unsigned int uint
Definition: vec.hpp:20
double flt
The basic floating point type used in the simulations.
Definition: vecrand.hpp:45
boost::mt19937 engine
Definition: vecrand.hpp:159
Vec2 flip(Vec2 v)
Definition: vecrand.hpp:98
Definition: vecrand.hpp:193
flt x22
Definition: vecrand.hpp:218
std::complex< flt > cmplx
Definition: vecrand.hpp:48
normdistribution distro
Definition: vecrand.hpp:214
long double to_LD(double e)
Go to and from Long Doubles.
Definition: vecrand.cpp:97
Vec2 perp(Vec2 v)
Definition: vecrand.hpp:84
Vec2 rotate_inv(Vec2 v, uint i)
Definition: vecrand.hpp:95
Eigen::Matrix< flt, NDIM, NDIM > Matrix
Definition: vecrand.hpp:56
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...
Definition: vecrand.hpp:258
flt x11
Definition: vecrand.hpp:216
double from_LD(long double e)
Go to and from Long Doubles.
Definition: vecrand.cpp:98
Vec gen_vec()
Generate a single Vec.
Definition: vecrand.hpp:239
Eigen::Matrix< flt, 3, 3 > Matrix3
Definition: vecrand.hpp:58
boost::uniform_01< flt, flt > lindistribution
Definition: vecrand.hpp:161
Eigen::Matrix< flt, NDIM, 2 > VecPair
Definition: vecrand.hpp:59
flt rand01()
Generate a random number between 0 and 1, using the "global" random number generator.
Definition: vecrand.cpp:12
uint vecsize()
Definition: vecrand.hpp:157
Vec rand_vec()
Generate a random vector from a Gaussian distribution, i.e.
Definition: vecrand.cpp:15
Eigen::Matrix< flt, 2, 1 > Vec2
Definition: vecrand.hpp:54
boost::normal_distribution< flt > normdistribution
Definition: vecrand.hpp:160
unsigned int uint
Definition: vecrand.hpp:27
Vec rand_vec_sphere(flt radius=1)
Generate a random vector inside a sphere.
A 3x3 matrix, with methods for adding, subtracting, dot product, etc.
Definition: vec.hpp:360
normgenerator gauss(randengine, mynormaldistribution)
void finite_or_throw(const Eigen::DenseBase< Derived > &m)
Definition: vecrand.hpp:274
flt x21
Definition: vecrand.hpp:217
Eigen::Matrix< flt, 2, 2 > Matrix2
Definition: vecrand.hpp:57
Vec2 rotate_flip(Vec2 v, uint i)
Definition: vecrand.hpp:99
Vec generate()
Definition: vecrand.hpp:201
Matrix best_rotation_matrix(Eigen::Matrix< flt, Eigen::Dynamic, NDIM > &from, Eigen::Matrix< flt, Eigen::Dynamic, NDIM > &to)
Definition: vecrand.cpp:108
#define NDIM
Definition: vecrand.hpp:12
Vec2 rotate(Vec2 v, uint i)
Definition: vecrand.hpp:89
boost::variate_generator< engine &, normdistribution > normgenerator
Definition: vecrand.hpp:162
normdistribution distro
Definition: vecrand.hpp:195
boost::variate_generator< engine &, lindistribution > lingenerator
Definition: vecrand.hpp:163
Eigen::Matrix< flt, NDIM, 1 > Vec
The basic physics vector.
Definition: vecrand.hpp:53
Vec3 cross(Vec3 v1, Vec3 v2)
Definition: vecrand.hpp:80
Eigen::Matrix< flt, 3, 1 > Vec3
Definition: vecrand.hpp:55
const flt OVERNDIM
A constant equal to , where is the number of dimensions.
Definition: vecrand.hpp:66
void set(flt sigma)
Definition: vecrand.hpp:199