MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
timefac.c
Go to the documentation of this file.
1 #include <mpi.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <math.h>
6 #include <gsl/gsl_math.h>
7 #include <gsl/gsl_integration.h>
8 
9 #include "physconst.h"
10 #include "timefac.h"
11 #include "timebinmgr.h"
12 #include "utils.h"
13 
14 #define WORKSIZE 10000
15 
16 /* Integrand for the drift table*/
17 static double drift_integ(double a, void *param)
18 {
19  Cosmology * CP = (Cosmology *) param;
20  double h = hubble_function(CP, a);
21  return 1 / (h * a * a * a);
22 }
23 
24 /* Integrand for the gravkick table*/
25 static double gravkick_integ(double a, void *param)
26 {
27  Cosmology * CP = (Cosmology *) param;
28  double h = hubble_function(CP, a);
29 
30  return 1 / (h * a * a);
31 }
32 
33 /* Integrand for the hydrokick table.
34  * Note this is the same function as drift.*/
35 static double hydrokick_integ(double a, void *param)
36 {
37  double h;
38 
39  Cosmology * CP = (Cosmology *) param;
40  h = hubble_function(CP, a);
41 
42  return 1 / (h * pow(a, 3 * GAMMA_MINUS1) * a);
43 }
44 
45 /*Do the integral required to get a factor.*/
46 static double get_exact_factor(Cosmology * CP, inttime_t t0, inttime_t t1, double (*factor) (double, void *))
47 {
48  double result, abserr;
49  if(t0 == t1)
50  return 0;
51  double a0 = exp(loga_from_ti(t0));
52  double a1 = exp(loga_from_ti(t1));
53  gsl_function F;
54  gsl_integration_workspace *workspace;
55  workspace = gsl_integration_workspace_alloc(WORKSIZE);
56  F.function = factor;
57  F.params = CP;
58  gsl_integration_qag(&F, a0, a1, 0, 1.0e-8, WORKSIZE, GSL_INTEG_GAUSS61, workspace, &result, &abserr);
59  gsl_integration_workspace_free(workspace);
60  return result;
61 }
62 
63 /*Get the exact drift factor*/
65 {
66  return get_exact_factor(CP, ti0, ti1, &drift_integ);
67 }
68 
69 /*Get the exact drift factor*/
71 {
72  return get_exact_factor(CP, ti0, ti1, &gravkick_integ);
73 }
74 
76 {
77  return get_exact_factor(CP, ti0, ti1, &hydrokick_integ);
78 }
double hubble_function(const Cosmology *CP, double a)
Definition: cosmology.c:58
#define GAMMA_MINUS1
Definition: physconst.h:35
static Cosmology * CP
Definition: power.c:27
double loga_from_ti(int ti)
Definition: test_timefac.c:51
static double drift_integ(double a, void *param)
Definition: timefac.c:17
#define WORKSIZE
Definition: timefac.c:14
double get_exact_hydrokick_factor(Cosmology *CP, inttime_t ti0, inttime_t ti1)
Definition: timefac.c:75
static double gravkick_integ(double a, void *param)
Definition: timefac.c:25
double get_exact_drift_factor(Cosmology *CP, inttime_t ti0, inttime_t ti1)
Definition: timefac.c:64
static double hydrokick_integ(double a, void *param)
Definition: timefac.c:35
double get_exact_gravkick_factor(Cosmology *CP, inttime_t ti0, inttime_t ti1)
Definition: timefac.c:70
static double get_exact_factor(Cosmology *CP, inttime_t t0, inttime_t t1, double(*factor)(double, void *))
Definition: timefac.c:46
int32_t inttime_t
Definition: types.h:8