PLUTO  4.4-patch2
math_tools.h
Go to the documentation of this file.
1 /* ///////////////////////////////////////////////////////////////////// */
22 /* ///////////////////////////////////////////////////////////////////// */
23 
24 /* ---- ODE solver labels ---- */
25 
26 #define ODE_RK2 2
27 #define ODE_RK4 4
28 #define ODE_CK45 45
29 
30 #define MAXITS 200
31 #define EPS_FD_JAC 1.0e-7
32 #define TOLF EPS_FD_JAC
33 #define TOLX EPS_FD_JAC
34 #define STPMX 100.0
35 #define TOLMIN 1.0e-6
36 #define ALF 1.0e-4
37 #define MAX_ROOT_EQNS 8
38 
39 /* ***********************************************************
40  \cond REPEAT_FUNCTION_DOCUMENTATION_IN_HEADER_FILES
41  Function prototyping
42  *********************************************************** */
43 
44 /* ------------------------------------------------------------
45  Functions containd in math_lu_decomp.c
46  ------------------------------------------------------------ */
47 
48 int LUDecompose (double **, int, int *, double *);
49 void LUBackSubst (double **, int, int *, double b[]);
50 void MatrixInverse (double **, double **, int);
51 void MatrixMultiply (double **, double **, double **, int);
52 void TridiagonalSolve(double *, double *, double *, double *, double *, int);
53 
54 /* -----------------------------------------------------------
55  Functions contained in math_misc.c
56  ----------------------------------------------------------- */
57 
58 double BesselJ0(double);
59 double BesselJ1(double);
60 double BesselIO(double);
61 double BesselI1(double);
62 double BesselKO(double);
63 double BesselK1(double);
64 double BesselKn(int, double);
65 void QuickSort(int *, int, int);
66 void SortArray (double *, int);
67 void VectorCartesianComponents(double *, double, double, double);
68 
69 /* -------------------------------------------------------
70  Functions contained in math_ode.c
71  ------------------------------------------------------- */
72 
73 void ODE_Solve(double *, int, double, double, double,
74  void (*rhs)(double, double *, double *), int method);
75 
76 /* --------------------------------------------------------
77  Functions contained in math_qr_decomp.c
78  -------------------------------------------------------- */
79 
80 void QRUpdate(double **, double **, int , double *, double *);
81 void RSolve(double **, int , double *, double *);
82 void QRSolve(double **, int , double *, double *, double *);
83 void QRDecompose (double **, int , double *, double *, int *);
84 void rotate(double **, double **, int , int , double , double );
85 
86 /* -------------------------------------------------------
87  Functions contained in math_quadrature.c
88  ------------------------------------------------------- */
89 
90 double GaussQuadrature(double (*func)(double, void *), void *, double, double,
91  int, int);
92 
93 /* ------------------------------------------------
94  Functions contained in math_random.c
95  ------------------------------------------------ */
96 
97 #define PRNG_DEFAULT 0 /* Standard drand48() */
98 #define PRNG_ECUYER 1 /* prng of L'Ecuyer */
99 #define PRNG_MT 2 /* Mersenne Twister pseudorandom number */
100 
101 #ifndef PRNG
102  #define PRNG PRNG_DEFAULT
103 #endif
104 
105 void RandomSeed (long int, long int);
106 double RandomNumber (double, double);
107 double GaussianRandomNumber(double, double);
108 double PowerLawRandomNumber(double, double, double);
109 unsigned int SeedGenerator(long);
110 #if PRNG == PRNG_ECUYER
111 double NR_ran2(long int *);
112 #elif PRNG == PRNG_MT
113 void init_genrand64(unsigned long long);
114 unsigned long long genrand64_int64(void);
115 double genrand64_real1(void);
116 #endif
117 
118 /* ------------------------------------------------
119  Functions contained in math_root_finders.c
120  ------------------------------------------------ */
121 
122 int CubicSolve (double, double, double, double *z);
123 int Brent(double (*func)(double, void *), void *, double, double,
124  double, double, double *);
125 void Broyden(double *, int , int *, void (*vecfunc)(int, double *, double *));
126 void FDJacobian(int , double *, double *, double **,
127  void (*vecfunc)(int , double *, double *));
128 void LineSearch (int , double *, double , double *,
129  double *, double *, double *, double *, double ,
130  int *, void ( *vecfunc)(int , double *, double *));
131 int QuadraticSolve(double, double, double, double *);
132 int QuarticSolve (double, double, double, double, double *);
133 int Ridder(double (*func)(double, void *), void *,
134  double, double, double, double, double *);
135 
136 /* ---------------------------------------------------
137  Functions contained in math_table2D.c
138  --------------------------------------------------- */
139 
140 void InitializeTable2D (Table2D *, double, double, int, double, double, int);
141 void FinalizeTable2D (Table2D *);
142 int Table2DInterpolate (Table2D *, double, double, double *);
143 int InverseLookupTable2D (Table2D *, double, double, double *);
144 void WriteBinaryTable2D (char *, Table2D *);
145 
146 /* -----------------------------------------------------------
147  Functions contained in math_interp.c
148  ----------------------------------------------------------- */
149 
150 void MonotoneSplineCoeffs (double *x, double *y, double *dydx, int n,
151  double *a, double *b, double *c, double *d);
152 
153 
154 void SplineCoeffs (double *x, double *f, double dfL, double dfR, int n,
155  double *a, double *b, double *c, double *d);
156 
157 /* \endcond */
void MatrixMultiply(double **A, double **B, double **C, int n)
Definition: math_lu_decomp.c:163
double BesselK1(double x)
Definition: math_misc.c:159
void RandomSeed(long int seed, long int offset)
Definition: math_random.c:105
double BesselI1(double x)
Definition: math_misc.c:107
double BesselJ0(double x)
Definition: math_misc.c:13
void TridiagonalSolve(double *am, double *a0, double *ap, double *b, double *y, int n)
Definition: math_lu_decomp.c:182
double RandomNumber(double rmin, double rmax)
Definition: math_random.c:36
void MatrixInverse(double **A, double **Ainv, int n)
Definition: math_lu_decomp.c:137
double PowerLawRandomNumber(double xmin, double xmax, double n)
Definition: math_random.c:242
void SplineCoeffs(double *x, double *f, double dfL, double dfR, int n, double *a, double *b, double *c, double *d)
Definition: math_interp.c:95
void WriteBinaryTable2D(char *fname, Table2D *tab)
Definition: math_table2D.c:528
void LUBackSubst(double **a, int n, int *indx, double b[])
Definition: math_lu_decomp.c:92
int Brent(double(*Func)(double, void *), void *param, double x1, double x2, double abs_acc, double rel_acc, double *xroot)
Definition: math_root_finders.c:14
int InverseLookupTable2D(Table2D *tab, double y, double f, double *x)
Definition: math_table2D.c:196
void ODE_Solve(double *y0, int nvar, double xbeg, double xend, double dx, void(*rhs)(double, double *, double *), int method)
Definition: math_ode.c:25
void MonotoneSplineCoeffs(double *x, double *y, double *dydx, int n, double *a, double *b, double *c, double *d)
Definition: math_interp.c:13
double NR_ran2(long int *idum)
Definition: math_random.c:306
int Table2DInterpolate(Table2D *tab, double x, double y, double *f)
Definition: math_table2D.c:430
int CubicSolve(double b, double c, double d, double z[])
Definition: math_root_finders.c:591
int QuarticSolve(double b, double c, double d, double e, double *z)
Definition: math_root_finders.c:694
void QuickSort(int *x, int first, int last)
Definition: math_misc.c:210
double BesselJ1(double x)
Definition: math_misc.c:45
void VectorCartesianComponents(double *v, double x1, double x2, double x3)
Definition: math_misc.c:275
double GaussianRandomNumber(double mu, double sigma)
Definition: math_random.c:212
void SortArray(double *z, int n)
Definition: math_misc.c:249
void InitializeTable2D(Table2D *tab, double xmin, double xmax, int nx, double ymin, double ymax, int ny)
Definition: math_table2D.c:15
double BesselKn(int n, double x)
Definition: math_misc.c:184
int Ridder(double(*Func)(double, void *), void *param, double x1, double x2, double abs_acc, double rel_acc, double *xroot)
Definition: math_root_finders.c:120
double GaussQuadrature(double(*func)(double, void *), void *par, double xb, double xe, int nstep, int order)
Definition: math_quadrature.c:20
int LUDecompose(double **a, int n, int *indx, double *d)
Definition: math_lu_decomp.c:12
int QuadraticSolve(double a, double b, double c, double *x)
Definition: math_root_finders.c:545