1 #include <gsl/gsl_integration.h>
2 #include <gsl/gsl_interp.h>
3 #include <gsl/gsl_rng.h>
11 #define BOLEVK 8.61734e-5
24 NU_V0(
const double Time,
const double kBTNubyMNu,
const double UnitVelocity_in_cm_per_s)
26 return kBTNubyMNu / Time * (
LIGHTCGS / UnitVelocity_in_cm_per_s);
30 double WDM_V0(
const double Time,
const double WDM_therm_mass,
const double Omega_CDM,
const double HubbleParam,
const double UnitVelocity_in_cm_per_s)
33 double WDM_V0 = 0.012 / Time * pow(Omega_CDM / 0.3, 1.0 / 3) * pow(HubbleParam / 0.65, 2.0 / 3) * pow(1.0 /WDM_therm_mass,4.0 / 3);
34 WDM_V0 *= 1.0e5 / UnitVelocity_in_cm_per_s;
42 return x * x / (exp(x) + 1);
51 endrun(1,
"Thermal vel called with negative interval: %g <= %g\n", max_fd, min_fd);
58 gsl_integration_workspace * w = gsl_integration_workspace_alloc (100);
71 gsl_integration_qag (&F, 0,
MAX_FERMI_DIRAC, 0, 1e-6,100,GSL_INTEG_GAUSS61, w,&(total_fd), &abserr);
72 assert(total_fd > 1.8);
74 gsl_integration_workspace_free (w);
92 unsigned int * seedtable = (
unsigned int *)
mymalloc(
"randseeds", Nmesh*Nmesh*
sizeof(
unsigned int));
93 gsl_rng * rng = gsl_rng_alloc(gsl_rng_ranlxd1);
94 gsl_rng_set(rng, Seed);
97 for(i = 0; i < Nmesh; i++)
98 for(j=0; j < Nmesh; j++)
100 seedtable[i+Nmesh*j] = gsl_rng_get(rng);
111 const double p = gsl_rng_uniform (g_rng);
116 const double phi = 2 * M_PI * gsl_rng_uniform (g_rng);
117 const double theta = acos(2 * gsl_rng_uniform (g_rng) - 1);
119 Vel[0] += v * sin(theta) * cos(phi);
120 Vel[1] += v * sin(theta) * sin(phi);
121 Vel[2] += v * cos(theta);
void endrun(int where, const char *fmt,...)
#define mymalloc(name, size)
double fermi_dirac_cumprob[LENGTH_FERMI_DIRAC_TABLE]
double fermi_dirac_vel[LENGTH_FERMI_DIRAC_TABLE]
gsl_interp_accel * fd_intp_acc
double NU_V0(const double Time, const double kBTNubyMNu, const double UnitVelocity_in_cm_per_s)
double WDM_V0(const double Time, const double WDM_therm_mass, const double Omega_CDM, const double HubbleParam, const double UnitVelocity_in_cm_per_s)
unsigned int * init_rng(int Seed, int Nmesh)
double init_thermalvel(struct thermalvel *thermals, const double v_amp, double max_fd, const double min_fd)
void add_thermal_speeds(struct thermalvel *thermals, gsl_rng *g_rng, float Vel[])
static double fermi_dirac_kernel(double x, void *params)
#define LENGTH_FERMI_DIRAC_TABLE