8 #include "../Dem/Typedefs.h"
9 #include <boost/math/special_functions/factorials.hpp>
10 #include <boost/random.hpp>
22 static double normsq (
const vector <double> &
a) {
double res=0 ;
for (
int i=0 ; i<
d ; i++) res+=
a[i]*
a[i] ;
return (res) ; }
28 static boost::random::mt19937
rng ;
29 static boost::random::uniform_01<boost::mt19937>
rand ;
32 static vector < vector <int> >
MSigns ;
33 static vector < vector <int> >
MIndexAS ;
34 static vector < pair <int,int> >
MASIndex ;
35 static vector <FILE *>
outs ;
82 MSigns.resize(
d, vector <int> (
d, 0)) ;
83 for (
int i=0 ; i<
d ; i++)
for (
int j=0 ; j<
d ; j++) MSigns[i][j]=(i<j)*(1)+(i>j)*(-1) ;
85 MIndexAS.resize(
d, vector < int > (
d,0)) ;
86 MASIndex.resize(
d*(
d-1)/2, make_pair(0,0)) ;
88 for (
int i=0 ; i<
d ; i++)
89 for (
int j=i+1 ; j<
d ; j++,n++)
91 MIndexAS[i][j]=n ; MIndexAS[j][i]=n ;
92 MASIndex[n]=make_pair(i,j) ;
96 Eye.clear() ; Eye.resize(
d*
d,0) ;
97 for (
int de=0 ; de<
d ; de++) Eye[de*
d+de]=1 ;
112 for (
int i=0 ; i<
d ; i++) res[i] = 0.0;
113 for (
int i=0 ; i<
d; i++)
114 for (
int k=0 ; k<
d ; k++)
115 res[i]+=A[i*
d+k]*v[k] ;
121 double rsqr = normsq(x) ;
122 double r= sqrt(rsqr) ;
124 phi=vector<double>(
d-1, 0) ;
125 for (j=
d-1 ; j>=0 && fabs(x[j])<1e-6 ; j--) ;
127 for (j=0 ; j<
d-1 ; j++)
131 if (x[j]<0) phi[j]=M_PI ;
135 phi[j] = acos(x[j]/sqrt(rsqr)) ;
137 if (isnan(phi[j])) {phi[j]=acos(sgn(x[j])*x[j]) ;}
141 if (x[
d-1]<0) phi[
d-2] = 2*M_PI - phi[
d-2] ;
149 for (
int i=0 ; i<
d-1 ; i++)
151 x[i] *= cos(phi[i]) ;
152 for (
int j=i+1 ; j<
d ; j++)
153 x[j] *= sin(phi[i]) ;
155 x[
d-1] *= sin(phi[
d-2]) ;
boost::random::mt19937 rng(static_cast< unsigned int >(std::time(nullptr)))
v1d & operator+=(v1d &a, cv1d &b)
Definition: Tools.h:64
v1d & operator-=(v1d &a, cv1d &b)
Definition: Tools.h:61
v1f & operator/=(v1f &a, cv1f &b)
Definition: Tools.h:66
v1d operator/(v1d a, double b)
Definition: Tools.h:60
v1d & operator*=(v1d &a, double b)
Definition: Tools.h:62
v1d operator*(v1d a, double b)
Definition: Tools.h:49
v1d operator+(v1d a, double b)
Definition: Tools.h:53
const vector< float > cv1f
Definition: Typedefs.h:16
static vector< pair< int, int > > MASIndex
For skew symmetric matrix, make the correspondance between linear index and (row,column) index.
Definition: Tools.h:287
static v1d Eye
The identity matrix in dimension <d>
Definition: Tools.h:281
static vector< FILE * > outs
Store the output file descriptors.
Definition: Tools.h:292
static vector< vector< int > > MSigns
For skew symetric matrix. -1 below the diagonal, 0 on the diagonal, +1 above the diagnal.
Definition: Tools.h:290
vector< float > v1f
Definition: Typedefs.h:12
static boost::random::uniform_01< boost::mt19937 > rand
Returns a random number between 0 and 1.
Definition: Tools.h:283
unsigned int uint
Definition: Typedefs.h:8
static void matvecmult(v1d &res, cv1d &A, cv1d &B)
Multiply a matrix with a vector, in place.
Definition: Tools.h:701
static double hyperspherical_xtophi(cv1d &x, v1d &phi)
Convert from cartesian to hyperspherical coordinates.
Definition: Tools.h:889
const vector< double > cv1d
Definition: Typedefs.h:13
static void hyperspherical_phitox(double r, cv1d &phi, v1d &x)
Convert from hyperspherical to cartesian coordinates.
Definition: Tools.h:916
static void clear()
Get the class ready for a different dimension.
Definition: Tools.h:339
vector< double > v1d
Definition: Typedefs.h:9
static vector< vector< int > > MIndexAS
For skew symmetric matrix, make the correspondance between linear index of a full matrix with the lin...
Definition: Tools.h:291
static void initialise()
Initialise the member variables, in particular the variables to handle skew-symmetric flattened matri...
Definition: Tools.h:318
static boost::random::mt19937 rng
Random number generator.
Definition: Tools.h:282
v1d operator-(v1d a, double b)
NLOHMANN_BASIC_JSON_TPL_DECLARATION void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL &j1, nlohmann::NLOHMANN_BASIC_JSON_TPL &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name, cert-dcl58-cpp) is_nothrow_move_constructible< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression, cppcoreguidelines-noexcept-swap, performance-noexcept-swap) is_nothrow_move_assignable< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
Definition: json.hpp:25399
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1181
unsigned char uint8_t
Definition: stdint.h:124