12 #include <initializer_list>
17 #include <boost/math/special_functions/factorials.hpp>
18 #include <boost/random.hpp>
63 double a,
double b,
double cx,
double cy,
64 double gamma=0.1,
double tol=1e-5)
66 auto d0=[&](
double u){
return sqrt((X[0]-cx-
a*cos(u))*(X[0]-cx-
a*cos(u))+(X[1]-cy-b*sin(u))*(X[1]-cy-b*sin(u)));} ;
67 auto d1=[&](
double u){
return (2*
a*(X[0]-cx-
a*cos(u))*sin(u)-2*b*cos(u)*(X[1]-cy-b*sin(u)));} ;
71 int n=0 ;
double delta=1 ;
72 double to=atan2(X[1]-cy,X[0]-cx), tn ;
75 tn= to - gamma * d1(to) ;
79 if (n>1000) {printf(
"ERR: maximum number of iteration reached in gradient descent. gradientdescent_gamma is probably too large\n") ; break ;}
106 static void clear() ;
109 static int sgn (
double a) {
return a<0 ? -1:1 ; }
115 static void unitvec (vector <double> & v,
int n) ;
119 static double norm (
const vector <double> &
a) {
double res=0 ;
for (
uint i=0 ; i<
a.size() ; i++) res+=
a[i]*
a[i] ;
return (sqrt(res)) ; }
121 static double normdiff (
cv1d &
a,
cv1d & b) {
double res=0 ;
for (
int i=0 ; i<
d ; i++) res+=(
a[i]-b[i])*(
a[i]-b[i]) ;
return (sqrt(res)) ; }
122 static double normsq (
const vector <double> &
a) {
double res=0 ;
for (
int i=0 ; i<
d ; i++) res+=
a[i]*
a[i] ;
return (res) ; }
123 static double normdiffsq (
cv1d &
a,
cv1d & b) {
double res=0 ;
for (
int i=0 ; i<
d ; i++) res+=(
a[i]-b[i])*(
a[i]-b[i]) ;
return (res) ; }
125 static double skewnorm (
cv1d &
a) {
double res=0 ;
for (
int i=0 ; i<
d*(
d-1)/2 ; i++) res+=
a[i]*
a[i] ;
return (sqrt(res)) ; }
126 static double skewnormsq (
cv1d &
a) {
double res=0 ;
for (
int i=0 ; i<
d*(
d-1)/2 ; i++) res+=
a[i]*
a[i] ;
return (res) ; }
127 static double dot (
cv1d &
a,
cv1d & b) {
double res=0;
for (
int i=0 ; i<
d ; i++) res+=
a[i]*b[i] ;
return (res) ; }
133 if (vel_com ==
nullptr && omega_com ==
nullptr)
137 else if (omega_com ==
nullptr)
138 for (
int dd=0 ; dd<
d ; dd++)
139 res[dd] = vel_com[dd] ;
140 else if (vel_com ==
nullptr)
148 for (
int dd=0 ; dd<
d ; dd++)
149 res[dd] = vel_com[dd] - res[dd] ;
166 static double Volume (
double R) ;
195 double Tmp, Previous ;
197 for (
uint i=0 ; i<
a.size() ; i++)
199 Tmp=(
a[i]+b[i])-Corr[i] ;
202 Corr[i] = (res[i]-Previous)-Tmp ;
207 double Tmp, Previous ;
209 for (
uint i=0 ; i<
a.size() ; i++)
211 Tmp=(-
a[i]-b[i])-Corr[i] ;
214 Corr[i] = (res[i]-Previous)-Tmp ;
219 double Tmp, Previous ;
221 for (
uint i=0 ; i<
a.size() ; i++)
226 Corr[i] = (res[i]-Previous)-Tmp ;
231 double Tmp, Previous ;
233 for (
uint i=0 ; i<
a.size() ; i++)
238 Corr[i] = (res[i]-Previous)-Tmp ;
262 static double det (
double M[
d][
d]) ;
268 static int savetxt(
char path[],
const v2d & table,
char const header[]) ;
269 static void savecsv (
char path[],
cv2d & X,
cv1d &r,
const vector <uint32_t> & PBCFlags,
cv1d & Vmag,
cv1d & OmegaMag, [[maybe_unused]]
cv1d & Z) ;
270 static void savecsv (
char path[],
cv2d & X,
cv2d & V,
cv1d &r,
const vector <uint32_t> & PBCFlags,
cv1d & Vmag,
cv1d & OmegaMag, [[maybe_unused]]
cv1d & Z) ;
274 static void print (
cv1d M) {printf(
"[") ;
if (M.size()==
d*
d)
for (
int i=0 ; i<
d ; i++) {
for (
int j=0 ; j<
d ; j++) printf(
"%g ", M[i*
d+j]) ; printf(
"\n") ; }
else for (
auto v: M) printf(
"%g ", v) ; printf(
"]") ; }
282 static boost::random::mt19937
rng ;
283 static boost::random::uniform_01<boost::mt19937>
rand ;
320 MSigns.resize(
d, vector <int> (
d, 0)) ;
321 for (
int i=0 ; i<
d ; i++)
for (
int j=0 ; j<
d ; j++) MSigns[i][j]=(i<j)*(1)+(i>j)*(-1) ;
323 MIndexAS.resize(
d, vector < int > (
d,0)) ;
324 MASIndex.resize(
d*(
d-1)/2, make_pair(0,0)) ;
326 for (
int i=0 ; i<
d ; i++)
327 for (
int j=i+1 ; j<
d ; j++,n++)
329 MIndexAS[i][j]=n ; MIndexAS[j][i]=n ;
330 MASIndex[n]=make_pair(i,j) ;
334 Eye.clear() ; Eye.resize(
d*
d,0) ;
335 for (
int de=0 ; de<
d ; de++) Eye[de*
d+de]=1 ;
352 out = fopen(path,
"w") ;
if (out==NULL) {printf(
"ERR: cannot write in file %s\n", path) ;
return 1 ; }
353 fprintf(out,
"%s\n", header) ;
354 for (
uint i=0 ; i<table.size() ; i++)
356 for (
uint j=0 ; j<table[i].size() ; j++)
358 fprintf(out,
"%.6g",table[i][j]) ;
359 if (j<table[i].size()-1) fprintf(out,
",") ;
361 if (i<table.size()-1) fprintf(out,
"\n") ;
371 out = fopen(path,
"w") ;
if (out==NULL) {printf(
"ERR: cannot write in file %s\n", path) ;
return 1 ; }
372 for (
uint i=0 ; i<table.size() ; i++)
373 fprintf(out,
"%g\n", table[i]) ;
382 FILE *out ;
int dim ;
383 out=fopen(path,
"w") ;
if (out==NULL) {printf(
"Cannot open out file\n") ; return ;}
385 for (
int i=0 ; i<dim ; i++) fprintf(out,
"x%d,", i);
386 fprintf(out,
"R,PBCFlags,Vmag,Omegamag\n") ;
387 for (
uint i=0 ; i<X.size() ; i++)
389 for (
int j=0 ; j<dim ; j++)
390 fprintf(out,
"%.6g,", X[i][j]) ;
391 fprintf(out,
"%g,%d,%g,%g\n", r[i],PBCFlags[i], Vmag[i], OmegaMag[i]) ;
399 FILE *out ;
int dim ;
400 out=fopen(path,
"w") ;
if (out==NULL) {printf(
"Cannot open out file\n") ; return ;}
402 for (
int i=0 ; i<dim ; i++) fprintf(out,
"x%d,", i);
403 for (
int i=0 ; i<dim ; i++) fprintf(out,
"v%d,", i);
404 fprintf(out,
"R,PBCFlags,Vmag,Omegamag\n") ;
405 for (
uint i=0 ; i<X.size() ; i++)
407 for (
int j=0 ; j<dim ; j++) fprintf(out,
"%.6g,", X[i][j]) ;
408 for (
int j=0 ; j<dim ; j++) fprintf(out,
"%.6g,", V[i][j]) ;
409 fprintf(out,
"%g,%d,%g,%g\n", r[i],PBCFlags[i], Vmag[i], OmegaMag[i]) ;
417 FILE *out ;
int dim ;
418 out=fopen(path,
"w") ;
if (out==NULL) {printf(
"Cannot open out file\n") ; return ;}
420 for (
int i=0 ; i<dim-1 ; i++) fprintf(out,
"x%d,", i);
421 fprintf(out,
"x%d\n", dim-1) ;
422 for (
uint i=0 ; i<A.size() ; i++)
424 for (
int j=0 ; j<dim-1 ; j++)
425 fprintf(out,
"%.6g,", A[i][j]) ;
426 fprintf(out,
"%.6g", A[i][dim-1]) ;
435 FILE *out ;
static bool warn = false ;
437 vector <float> projectioncenter ;
for (
int i=3 ; i<
d ; i++) projectioncenter.push_back((
Boundaries[i][1]+
Boundaries[i][0])/2) ;
439 out=fopen(path,
"w") ;
if (out==NULL) {printf(
"Cannot open out file\n") ; return ;}
441 if (
d>3 && warn==
false) {
442 printf(
"WARN: writevtk might misbehave with dimension higher than 3. The 3d projection is always centered in all other dimensions\n") ;
445 fprintf(out,
"# vtk DataFile Version 2.0\nMost Useless DEM (tm) output file\nASCII\nDATASET POLYDATA\n") ;
447 fprintf(out,
"POINTS %ld float\n", X.size()) ;
448 for (
uint i=0 ; i<X.size() ; i++) fprintf(out,
"%g %g %g\n", X[i][0], X[i][1],
d<3?0:X[i][2]) ;
449 fprintf(out,
"VERTICES %ld %ld\n", X.size(), 2*X.size()) ;
450 for (
uint i=0 ; i<X.size() ; i++) fprintf(out,
"1 %d\n", i) ;
452 fprintf(out,
"\nPOINT_DATA %ld", X.size()) ;
454 for (
uint j=3 ; j<X[0].size() ; j++)
456 fprintf(out,
"\nSCALARS Dimension%d float 1 \nLOOKUP_TABLE default \n", j) ;
457 for (
uint i=0 ; i<X.size() ; i++)
458 fprintf(out,
"%g ", X[i][j]) ;
461 fprintf(out,
"\n\nSCALARS RadiusProjected float 1 \nLOOKUP_TABLE default\n");
462 for (
int i=0 ; i<
N ; i++)
464 float value = r[i]*r[i] ;
465 for (
int j=3 ; j<
d ; j++)
value-=(X[i][j]-projectioncenter[j-3])*(X[i][j]-projectioncenter[j-3]) ;
466 if (
value<0) fprintf(out,
"%g ", 0.0) ;
467 else fprintf(out,
"%g ", sqrt(
value)) ;
473 case TensorType::SCALAR: fprintf(out,
"\nSCALARS %s double 1 \nLOOKUP_TABLE default \n", v.name.c_str()) ;
474 for (
uint i=0 ; i<(*v.data)[0].size() ; i++)
475 fprintf(out,
"%g ", (*v.data)[0][i]) ;
478 for (
auto i : (*v.data))
479 fprintf(out,
"%g %g %g\n", i[0], i[1], i[2]) ;
482 for (
auto i : (*v.data))
483 fprintf(out,
"%g %g %g %g %g %g %g %g %g\n", i[0], i[1], i[2], i[
d], i[
d+1], i[
d+2], i[2*
d], i[2*
d+1], i[2*
d+2]) ;
486 for (
auto i : (*v.data))
487 fprintf(out,
"%g %g %g %g %g %g %g %g %g\n", i[0], i[1], i[2], i[1], i[
d], i[
d+1], i[2], i[
d+1], i[2*
d-1]) ;
490 for (
v1d i : (*v.data))
491 fprintf(out,
"%g %g %g %g %g %g %g %g %g\n", 0.0, i[0], i[1], -i[0], 0.0, i[
d-1], -i[1], -i[
d-1], 0.0) ;
510 outs.resize(list.size(), NULL) ;
512 for (
auto iter=list.begin() ; iter<list.end() ; iter++, i++)
514 sprintf(path,
"Res-%d.txt", i) ;
515 outs[i]=fopen(path,
"w") ;
516 if (outs[i]==NULL) {printf(
"Error cannot open writeinline file %d", i) ;
return (1) ; }
521 for (
auto iter=list.begin() ; iter<list.end() ; iter++, i++)
523 for (
uint j=0 ; j<iter->size() ; j++ )
524 fprintf(outs[i],
"%g ", iter->at(j)) ;
525 fprintf(outs[i],
"\n") ;
534 for (
uint i=0 ; i<outs.size() ; i++)
542 v1d res ; res.resize(v.size(),0) ;
543 for (
uint i=0 ; i<res.size() ; i++) res[i]=rand() ;
545 for (
uint i=0 ; i<res.size() ; i++) res[i]=res[i]/nr*n ;
552 double m1=v[0],m2=v[1] ;
553 if (m1<m2) {
double tmp ; tmp=m1 ; m1=m2 ; m2=tmp ;} ;
555 for (
uint i=2 ; i<v.size() ; i++)
557 if (v[i] > m1) {m1=v[i] ; continue ; }
558 if (v[i] > m2) {m2=v[i] ; }
560 return (make_pair(m1,m2)) ;
572 for (
int i=0 ; i<
d ; i++)
574 for (
int j=0 ; j<
d ; j++)
577 res[i]+= MSigns[i][j]*M[MIndexAS[i][j]]*v[j] ;
586 for (
int i=0 ; i<
d ; i++)
588 for (
int j=0 ; j<
d ; j++)
591 res[i]+= MSigns[i][j]*M[MIndexAS[i][j]]*v[j] ;
600 for (
int i=0 ; i<
d ; i++)
603 for (
int j=0 ; j<
d ; j++)
606 r[i]+= MSigns[i][j]*M[MIndexAS[i][j]]*v[j] ;
613 for (
int i=0 ; i<
d ; i++)
616 for (
int j=0 ; j<
d ; j++)
619 r[i]+= MSigns[i][j]*M[MIndexAS[i][j]]*v[j] ;
628 for (
int i=0 ; i<
d ; i++)
629 for (
int j=i ; j<
d ; j++)
631 for (
int k=0 ; k<
d ; k++)
632 res[i*
d+j]+=A[MIndexAS[i][k]]*A[MIndexAS[k][j]]*MSigns[i][k]*MSigns[k][j] ;
635 for (
int i=1 ; i<
d ; i++)
636 for (
int j=0 ; j<i ; j++)
637 res[i*
d+j]=res[j*
d+i] ;
645 for (
int i=0 ; i<
d ; i++)
646 for (
int j=i ; j<
d ; j++)
649 for (
int k=0 ; k<
d ; k++)
650 r[i*
d+j]+=A[MIndexAS[i][k]]*A[MIndexAS[k][j]]*MSigns[i][k]*MSigns[k][j] ;
653 for (
int i=1 ; i<
d ; i++)
654 for (
int j=0 ; j<i ; j++)
663 for (
int i=0 ; i<
d*
d; i++)
665 res[i]=A[MIndexAS[i/
d][i%
d]]*MSigns[i/
d][i%
d] ;
673 for (
int i=0 ; i<
d*
d; i++)
675 r[i]=A[MIndexAS[i/
d][i%
d]]*MSigns[i/
d][i%
d] ;
683 for (
int i=0 ; i<
d; i++)
684 for (
int j=0 ; j<
d ; j++)
685 for (
int k=0 ; k<
d ; k++)
686 res[i*
d+j]+=A[i*
d+k]*B[k*
d+j] ;
694 for (
int i=0 ; i<
d; i++)
695 for (
int j=0 ; j<
d ; j++)
696 for (
int k=0 ; k<
d ; k++)
697 r[i*
d+j]+=A[i*
d+k]*B[k*
d+j] ;
703 for (
int i=0 ; i<
d ; i++) res[i] = 0.0;
704 for (
int i=0 ; i<
d; i++)
705 for (
int k=0 ; k<
d ; k++)
706 res[i]+=A[i*
d+k]*v[k] ;
712 v1d res (
d*(
d-1)/2, 0) ;
size_t k ;
718 for (k=0 ; k<MASIndex.size() ; k++)
719 res[k]=
a[ MASIndex[k].first ]*b[MASIndex[k].second]-
a[MASIndex[k].second]*b[MASIndex[k].first] ;
730 for (k=0 ; k<MASIndex.size() ; k++)
731 res[k]=
a[ MASIndex[k].first ]*b[MASIndex[k].second]-
a[MASIndex[k].second]*b[MASIndex[k].first] ;
737 for (
int i=0 ; i<
d ; i++) v[i]=(i==n?1:0) ;
743 static int first = 0 ;
747 for (
int i=0 ; i<
d ; i++)
748 for (
int j=0 ; j<
d ; j++)
749 base[i][j] = A[j*
d+(i+first)%
d] ;
751 for (
int i=0 ; i<
d ; i++)
753 for (
int j=0 ; j<i ; j++)
754 base[i] -= base[j] * (dot(base[i],base[j])) ;
755 base[i] /= norm(base[i]) ;
758 for (
int i=first ; i<first+
d ; i++)
759 for (
int j=0 ; j<
d ; j++)
760 A[j*
d+(i%
d)] = base[i-first][j] ;
771 double submatrix[
d-1][
d-1] ;
772 for (
int i=0 ; i<
d ; i++)
774 for (
int j=0 ; j<
d ; j++)
775 for (
int k=0 ; k<
d-1 ; k++)
778 submatrix[k][j-(j>i?1:0)]=M[k][j] ;
793 double submatrix[
d-1][
d-1] ;
794 for (
int i=0 ; i<
d ; i++)
796 for (
int j=0 ; j<
d ; j++)
797 for (
int k=0 ; k<
d-1 ; k++)
800 submatrix[k][j-(j>i?1:0)]=M[k*
d+j] ;
815 double submatrix[
d-1][
d-1] ;
816 for (
int i=0 ; i<
d ; i++)
818 for (
int j=0 ; j<
d ; j++)
819 for (
int k=0 ; k<
d-1 ; k++)
822 submatrix[k][j-(j>i?1:0)]=M[k][j] ;
828 template <>
double Tools<2>::det (
double M[2][2] ) {
return M[0][0]*M[1][1]-M[1][0]*M[0][1] ; }
834 vector<double> res (
d*
d,0) ;
835 vector<double> submatrix (
d*
d,0) ;
836 for (
int i=0 ; i<
d ; i++)
837 for (
int j=0 ; j<
d ; j++)
840 for (
int dd=0 ; dd<
d ; dd++)
841 submatrix[i*
d+dd]=(dd==j?1:0) ;
845 for (
int i=0 ; i<
d*
d ; i++)
846 res[i] /= determinant ;
856 return (pow(boost::math::double_constants::pi,
d/2)*pow(R,
d)/( boost::math::factorial<double>(
d/2) )) ;
860 return(2* boost::math::factorial<double>(k) * pow(4*boost::math::double_constants::pi, k) *pow(R,
d) / (boost::math::factorial<double>(
d))) ;
869 printf(
"[WARN] Inertia InertiaMomentum not guaranteed for dimension > %d\n",
MAXDEFDIM) ;
876 res=pow(boost::math::double_constants::pi,k)*pow(R,
d+2) / boost::math::factorial<double>(k+1) ;
882 res=pow(2,k+2) * pow(boost::math::double_constants::pi, k) * pow(R,
d+2) / boost::math::double_factorial<double> (
d+2) ;
891 double rsqr = normsq(x) ;
892 double r= sqrt(rsqr) ;
894 phi=vector<double>(
d-1, 0) ;
895 for (j=
d-1 ; j>=0 && fabs(x[j])<1e-6 ; j--) ;
897 for (j=0 ; j<
d-1 ; j++)
901 if (x[j]<0) phi[j]=M_PI ;
905 phi[j] = acos(x[j]/sqrt(rsqr)) ;
907 if (isnan(phi[j])) {phi[j]=acos(sgn(x[j])*x[j]) ;}
911 if (x[
d-1]<0) phi[
d-2] = 2*M_PI - phi[
d-2] ;
919 for (
int i=0 ; i<
d-1 ; i++)
921 x[i] *= cos(phi[i]) ;
922 for (
int j=i+1 ; j<
d ; j++)
923 x[j] *= sin(phi[i]) ;
925 x[
d-1] *= sin(phi[
d-2]) ;
968 int NetCDFWriter::initialise (
string path, initializer_list< v2d > & list, vector <string> names)
971 int ret = nc_create((path+
".nc").c_str(), NC_CLOBBER, &ncid) ;
972 if (ret) {printf(
"An error occured creating the netCDF file\n") ;
return 0 ; }
974 nc_def_dim (ncid,
"Grains", list.begin()->size(), dimensions) ;
975 nc_def_dim (ncid,
"Scalar", 1, dimensions+1) ;
979 nc_def_dim (ncid,
"Time", NC_UNLIMITED, dimensions+5) ;
981 dimids[0]=dimensions[5] ; dimids[2]=dimensions[0] ;
982 for (
auto i=names.begin() ; i<names.end() ; i++)
984 if (list.begin()->at(0).size() == 1) dimids[1]=dimensions[1] ;
985 else if (list.begin()->at(0).size() ==
Tools<d>::getdim()) dimids[1]=dimensions[2] ;
988 else {printf(
"ERR: Unknown dimension size to write in netCDF\n") ;
return 1 ; }
990 nc_def_var(ncid, (*i).c_str() , NC_DOUBLE, 3, dimids, &(varid[varid.size()-1])) ;
997 int NetCDFWriter::saveNetCDF (initializer_list< v2d > & list)
999 size_t start[3], count[3] ;
1000 for (
auto i = varid.begin() ; i<varid.end() ; i++)
1002 auto & X=*(list.begin()) ;
1003 start[0]=timerecord ; start[1]=X.size() ; ; start[2]=0 ;
1004 count[0]=count[1]=1 ; count[2]=X[0].size() ;
1005 for (
auto j=X.begin() ; j < X.end() ; j++)
1006 nc_put_vara_double (ncid, *i , start, count, j->data());
1017 class NetCDFWriter {
1019 int initialise (
string path, initializer_list< v2d > & list, vector <string> names) ;
1020 int writeCDF (
string path, initializer_list< v2d > & list, vector <string> & names) {
if (first) {initialise(path, list, names); first=
false;} saveNetCDF(list) ;
return 0 ; }
1021 ~NetCDFWriter() {
if (!first) nc_close(ncid) ;}
1026 vector <int> varid, stride ;
1028 int saveNetCDF (initializer_list< v2d > & list) ;
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
Limited use: used to transfer data to the VTK writer.
Definition: Tools.h:50
TensorType order
Definition: Tools.h:53
string name
Definition: Tools.h:52
v2d * data
Definition: Tools.h:54
const vector< float > cv1f
Definition: Typedefs.h:16
vector< vector< double > > v2d
Definition: Typedefs.h:10
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.
Definition: Tools.h:380
static double normdiff(cv1d &a, cv1d &b)
Norm of a vector difference .
Definition: Tools.h:121
static void orthonormalise(v1d &A)
Orthonormalise A using the Gram-Shmidt process, in place.
Definition: Tools.h:741
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 void setzero(v2d &a)
Set a matrix to zero in-place.
Definition: Tools.h:117
static v1d skewmatsquare(cv1d &A)
Square the skew symetric matrix M.
Definition: Tools.h:625
static v1d wedgeproduct(cv1d &a, cv1d &b)
Wedge product of vectors.
Definition: Tools.h:710
static void unitvec(vector< double > &v, int n)
Construct a unit vector in place.
Definition: Tools.h:735
static v1d Eye
The identity matrix in dimension <d>
Definition: Tools.h:281
static v1f vsqrt(cv1f &a)
Component-wise square root.
Definition: Tools.h:128
static double dot(cv1d &a, cv1d &b)
Dot product.
Definition: Tools.h:127
static vector< FILE * > outs
Store the output file descriptors.
Definition: Tools.h:292
static v1d transpose(cv1d &a)
Transposition.
Definition: Tools.h:258
static double skewnorm(cv1d &a)
Norm of a skew-symetric matrix.
Definition: Tools.h:125
static double InertiaMomentum(double R, double rho)
Compute the hypersphere moment of inertia.
Definition: Tools.h:865
#define MAXDEFDIM
For larger number of dimension, be taken in particular for periodic boundary conditions.
Definition: Tools.h:20
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 int savetxt(char path[], const v2d &table, char const header[])
Definition: Tools.h:349
static double det(cv2d &M)
compute the matrix determinant (probably quite slow, but doesn't really really matters for the usage)
Definition: Tools.h:766
static int writeinline_close(void)
Definition: Tools.h:532
static double skewnormsq(cv1d &a)
Norm squared of a skew-symetrix matrix.
Definition: Tools.h:126
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 information...
Definition: Tools.h:433
TensorType
Definition: Tools.h:46
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 double normdiffsq(cv1d &a, cv1d &b)
Norm squared of a vector difference .
Definition: Tools.h:123
static void norm(v1d &res, cv2d &a)
Norm of a 2D-matrix, returns a 1D vector with the norms of the individual vectors.
Definition: Tools.h:120
static void setzero(v1d &a)
Set a vector to zero in-place.
Definition: Tools.h:118
static v1f vsq(cv1f &a)
Component-wise squaring.
Definition: Tools.h:129
static std::pair< double, double > two_max_element(cv1d &v)
Return the two largest elements of v.
Definition: Tools.h:550
static double normsq(const vector< double > &a)
Norm squared.
Definition: Tools.h:122
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
static v1d inverse(cv1d &M)
compute the matrix inverse (very slow and redundant calculation of the determinant for the comatrix,...
Definition: Tools.h:832
static int writeinline(initializer_list< v1d >)
Definition: Tools.h:505
static v1d skewmatvecmult(cv1d &M, cv1d &v)
Multiply the skew symetric matrix M with vector v.
Definition: Tools.h:569
const vector< double > cv1d
Definition: Typedefs.h:13
static int sgn(double a)
Sign function.
Definition: Tools.h:109
static bool check_initialised(int dd)
Definition: Tools.h:107
const vector< vector< double > > cv2d
Definition: Typedefs.h:14
static v1d matmult(cv1d &A, cv1d &B)
Multiply 2 matrix together.
Definition: Tools.h:680
static int write1D(char path[], v1d table)
Definition: Tools.h:368
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 co...
Definition: Tools.h:660
static void hyperspherical_phitox(double r, cv1d &phi, v1d &x)
Convert from hyperspherical to cartesian coordinates.
Definition: Tools.h:916
static void transpose_inplace(v1d &a)
Transpose in-place.
Definition: Tools.h:259
static void setgravity(v2d &a, v1d &g, v1d &m)
Set the gravity. .
Definition: Tools.h:154
static void print(cv1d M)
Definition: Tools.h:274
static void clear()
Get the class ready for a different dimension.
Definition: Tools.h:339
vector< double > v1d
Definition: Typedefs.h:9
static void surfacevelocity(v1d &res, cv1d &p, double *com, double *vel_com, double *omega_com)
Definition: Tools.h:131
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 int sgn(uint8_t a)
Sign function.
Definition: Tools.h:108
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
static v1d randomize_vec(cv1d v)
Produce a random vector.
Definition: Tools.h:540
v1d operator-(v1d a, double b)
static double norm(const vector< double > &a)
Norm of a vector.
Definition: Tools.h:119
static double Volume(double R)
Compute the hypersphere volume.
Definition: Tools.h:853
static v1d unitvec(int n)
Construct & return a unit vector.
Definition: Tools.h:116
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 value
Definition: pointer.h:1282
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1181
unsigned char uint8_t
Definition: stdint.h:124