MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
Macros | Functions
test_omega_nu_single.c File Reference
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <stdio.h>
#include <math.h>
#include <gsl/gsl_integration.h>
#include "stub.h"
#include "../omega_nu_single.h"
#include "../physconst.h"
Include dependency graph for test_omega_nu_single.c:

Go to the source code of this file.

Macros

#define T_CMB0   2.7255 /* present-day CMB temperature, from Fixsen 2009 */
 
#define STEFAN_BOLTZMANN   5.670373e-5
 
#define OMEGAR   (4*STEFAN_BOLTZMANN*8*M_PI*GRAVITY/(3*LIGHTCGS*LIGHTCGS*LIGHTCGS*HUBBLE*HUBBLE*HubbleParam*HubbleParam)*pow(T_CMB0,4))
 
#define GSL_VAL   200
 

Functions

static void test_rho_nu_init (void **state)
 
static void test_omega_nu_single (void **state)
 
double get_rho_nu_conversion ()
 
double rho_nu_int (double q, void *params)
 
double do_exact_rho_nu_integration (double a, double mnu, double rhocrit)
 
static void test_omega_nu_single_exact (void **state)
 
static void test_omega_nu_init_degenerate (void **state)
 
static void test_omega_nu_init_nondeg (void **state)
 
static void test_get_omega_nu (void **state)
 
static void test_get_omegag (void **state)
 
static void test_nufrac_low (void **state)
 
static void test_hybrid_neutrinos (void **state)
 
int main (void)
 

Macro Definition Documentation

◆ GSL_VAL

#define GSL_VAL   200

Definition at line 36 of file test_omega_nu_single.c.

◆ OMEGAR

#define OMEGAR   (4*STEFAN_BOLTZMANN*8*M_PI*GRAVITY/(3*LIGHTCGS*LIGHTCGS*LIGHTCGS*HUBBLE*HUBBLE*HubbleParam*HubbleParam)*pow(T_CMB0,4))

Definition at line 35 of file test_omega_nu_single.c.

◆ STEFAN_BOLTZMANN

#define STEFAN_BOLTZMANN   5.670373e-5

Definition at line 34 of file test_omega_nu_single.c.

◆ T_CMB0

#define T_CMB0   2.7255 /* present-day CMB temperature, from Fixsen 2009 */

Definition at line 12 of file test_omega_nu_single.c.

Function Documentation

◆ do_exact_rho_nu_integration()

double do_exact_rho_nu_integration ( double  a,
double  mnu,
double  rhocrit 
)

Definition at line 77 of file test_omega_nu_single.c.

78 {
79  gsl_function F;
80  gsl_integration_workspace * w = gsl_integration_workspace_alloc (GSL_VAL);
81  double abserr;
82  F.function = &rho_nu_int;
83  double kTnu = BOLEVK*TNUCMB*T_CMB0;
84  double param[2] = {mnu * a, kTnu};
85  F.params = &param;
86  double result;
87  gsl_integration_qag (&F, 0, 500*kTnu,0 , 1e-9,GSL_VAL,6,w,&result, &abserr);
88  result*=get_rho_nu_conversion()/pow(a,4)/rhocrit;
89  gsl_integration_workspace_free (w);
90  return result;
91 }
#define TNUCMB
#define BOLEVK
Definition: physconst.h:13
#define GSL_VAL
#define T_CMB0
double get_rho_nu_conversion()
double rho_nu_int(double q, void *params)

References BOLEVK, get_rho_nu_conversion(), GSL_VAL, rho_nu_int(), T_CMB0, and TNUCMB.

Referenced by test_omega_nu_single_exact().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_rho_nu_conversion()

double get_rho_nu_conversion ( )

Definition at line 102 of file omega_nu_single.c.

103 {
104  /*q has units of eV/c, so rho_nu now has units of (eV/c)^4*/
105  double convert=4*M_PI*2; /* The factor of two is for antineutrinos*/
106  /*rho_nu_val now has units of eV^4*/
107  /*To get units of density, divide by (c*hbar)**3 in eV s and cm/s */
108  const double chbar=1./(2*M_PI*LIGHTCGS*HBAR);
109  convert*=(chbar*chbar*chbar);
110  /*Now has units of (eV)/(cm^3)*/
111  /* 1 eV = 1.60217646 × 10-12 g cm^2 s^(-2) */
112  /* So 1eV/c^2 = 1.7826909604927859e-33 g*/
113  /*So this is rho_nu_val in g /cm^3*/
114  convert*=(1.60217646e-12/LIGHTCGS/LIGHTCGS);
115  return convert;
116 }
#define HBAR
#define LIGHTCGS
Definition: physconst.h:18

References HBAR, and LIGHTCGS.

Referenced by do_exact_rho_nu_integration(), non_rel_rho_nu(), rel_rho_nu(), and rho_nu_init().

Here is the caller graph for this function:

◆ main()

int main ( void  )

Definition at line 196 of file test_omega_nu_single.c.

196  {
197  const struct CMUnitTest tests[] = {
198  cmocka_unit_test(test_rho_nu_init),
199  cmocka_unit_test(test_omega_nu_single),
200  cmocka_unit_test(test_omega_nu_init_degenerate),
201  cmocka_unit_test(test_omega_nu_init_nondeg),
202  cmocka_unit_test(test_get_omega_nu),
203  cmocka_unit_test(test_get_omegag),
204  cmocka_unit_test(test_omega_nu_single_exact),
205  cmocka_unit_test(test_nufrac_low),
206  cmocka_unit_test(test_hybrid_neutrinos),
207  };
208  return cmocka_run_group_tests_mpi(tests, NULL, NULL);
209 }
static void test_omega_nu_single_exact(void **state)
static void test_omega_nu_init_nondeg(void **state)
static void test_omega_nu_single(void **state)
static void test_rho_nu_init(void **state)
static void test_get_omega_nu(void **state)
static void test_nufrac_low(void **state)
static void test_omega_nu_init_degenerate(void **state)
static void test_get_omegag(void **state)
static void test_hybrid_neutrinos(void **state)

References test_get_omega_nu(), test_get_omegag(), test_hybrid_neutrinos(), test_nufrac_low(), test_omega_nu_init_degenerate(), test_omega_nu_init_nondeg(), test_omega_nu_single(), test_omega_nu_single_exact(), and test_rho_nu_init().

Here is the call graph for this function:

◆ rho_nu_int()

double rho_nu_int ( double  q,
void *  params 
)

Definition at line 91 of file omega_nu_single.c.

92 {
93  double amnu = *((double *)params);
94  double kT = *((double *)params+1);
95  double epsilon = sqrt(q*q+amnu*amnu);
96  double f0 = 1./(exp(q/kT)+1);
97  return q*q*epsilon*f0;
98 }

Referenced by do_exact_rho_nu_integration(), and rho_nu_init().

Here is the caller graph for this function:

◆ test_get_omega_nu()

static void test_get_omega_nu ( void **  state)
static

Definition at line 143 of file test_omega_nu_single.c.

143  {
144  /*Check that we get the right answer from get_omega_nu, in terms of rho_nu*/
145  _omega_nu omnu;
146  /*Initialise*/
147  double MNu[3] = {0.2,0.1,0.3};
148  init_omega_nu(&omnu, MNu, 0.01, 0.7,T_CMB0);
149  double total =0;
150  int i;
151  for(i=0; i<3; i++) {
152  total += omega_nu_single(&omnu, 0.5, i);
153  }
154  assert_true(fabs(get_omega_nu(&omnu, 0.5) - total) < 1e-6*total);
155 }
void init_omega_nu(_omega_nu *omnu, const double MNu[], const double a0, const double HubbleParam, const double tcmb0)
double omega_nu_single(const _omega_nu *const omnu, const double a, int i)
double get_omega_nu(const _omega_nu *const omnu, const double a)

References get_omega_nu(), init_omega_nu(), omega_nu_single(), and T_CMB0.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_get_omegag()

static void test_get_omegag ( void **  state)
static

Definition at line 157 of file test_omega_nu_single.c.

157  {
158  /*Check that we get the right answer from get_omegag*/
159  _omega_nu omnu;
160  /*Initialise*/
161  double MNu[3] = {0.2,0.1,0.3};
162  const double HubbleParam = 0.7;
163  init_omega_nu(&omnu, MNu, 0.01, HubbleParam,T_CMB0);
164  const double omegag = OMEGAR/pow(0.5,4);
165  assert_true(fabs(get_omegag(&omnu, 0.5)/omegag -1)< 1e-6);
166 }
double get_omegag(const _omega_nu *const omnu, const double a)
#define OMEGAR

References get_omegag(), init_omega_nu(), OMEGAR, and T_CMB0.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_hybrid_neutrinos()

static void test_hybrid_neutrinos ( void **  state)
static

Definition at line 177 of file test_omega_nu_single.c.

178 {
179  /*Check that we get the right answer from get_omegag*/
180  _omega_nu omnu;
181  /*Initialise*/
182  double MNu[3] = {0.2,0.2,0.2};
183  const double HubbleParam = 0.7;
184  init_omega_nu(&omnu, MNu, 0.01, HubbleParam,T_CMB0);
185  init_hybrid_nu(&omnu.hybnu, MNu, 700, 299792, 0.5,omnu.kBtnu);
186  /*Check that the fraction of omega change over the jump*/
187  double nufrac_part = nufrac_low(700/299792.*0.2/omnu.kBtnu);
188  assert_true(fabs(particle_nu_fraction(&omnu.hybnu, 0.50001, 0)/nufrac_part -1) < 1e-5);
189  assert_true(particle_nu_fraction(&omnu.hybnu, 0.49999, 0) == 0);
190  assert_true(fabs(get_omega_nu_nopart(&omnu, 0.499999)*(1-nufrac_part)/get_omega_nu_nopart(&omnu, 0.500001)-1) < 1e-4);
191  /*Ditto omega_nu_single*/
192  assert_true(fabs(omega_nu_single(&omnu, 0.499999, 0)*(1-nufrac_part)/omega_nu_single(&omnu, 0.500001, 0)-1) < 1e-4);
193 }
void init_hybrid_nu(_hybrid_nu *const hybnu, const double mnu[], const double vcrit, const double light, const double nu_crit_time, const double kBtnu)
double particle_nu_fraction(const _hybrid_nu *const hybnu, const double a, const int i)
double nufrac_low(const double qc)
double get_omega_nu_nopart(const _omega_nu *const omnu, const double a)
_hybrid_nu hybnu

References get_omega_nu_nopart(), _omega_nu::hybnu, init_hybrid_nu(), init_omega_nu(), _omega_nu::kBtnu, nufrac_low(), omega_nu_single(), particle_nu_fraction(), and T_CMB0.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_nufrac_low()

static void test_nufrac_low ( void **  state)
static

Definition at line 169 of file test_omega_nu_single.c.

170 {
171  assert_true(nufrac_low(0) == 0);
172  /*Mathematica integral: 1.*Integrate[x*x/(Exp[x] + 1), {x, 0, 0.5}]/(3*Zeta[3]/2)*/
173  assert_true(fabs(nufrac_low(1)/0.0595634-1)< 1e-5);
174  assert_true(fabs(nufrac_low(0.5)/0.00941738-1)< 1e-5);
175 }

References nufrac_low().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_omega_nu_init_degenerate()

static void test_omega_nu_init_degenerate ( void **  state)
static

Definition at line 116 of file test_omega_nu_single.c.

116  {
117  /*Check we correctly initialise omega_nu with degenerate neutrinos*/
118  _omega_nu omnu;
119  /*Initialise*/
120  double MNu[3] = {0.2,0.2,0.2};
121  init_omega_nu(&omnu, MNu, 0.01, 0.7,T_CMB0);
122  /*Check that we initialised the right number of arrays*/
123  assert_int_equal(omnu.nu_degeneracies[0], 3);
124  assert_int_equal(omnu.nu_degeneracies[1], 0);
125  assert_true(omnu.RhoNuTab[0].loga);
126  assert_false(omnu.RhoNuTab[1].loga);
127 }
int nu_degeneracies[NUSPECIES]
_rho_nu_single RhoNuTab[NUSPECIES]

References init_omega_nu(), _rho_nu_single::loga, _omega_nu::nu_degeneracies, _omega_nu::RhoNuTab, and T_CMB0.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_omega_nu_init_nondeg()

static void test_omega_nu_init_nondeg ( void **  state)
static

Definition at line 129 of file test_omega_nu_single.c.

129  {
130  /*Now check that it works with a non-degenerate set*/
131  _omega_nu omnu;
132  /*Initialise*/
133  double MNu[3] = {0.2,0.1,0.3};
134  int i;
135  init_omega_nu(&omnu, MNu, 0.01, 0.7,T_CMB0);
136  /*Check that we initialised the right number of arrays*/
137  for(i=0; i<3; i++) {
138  assert_int_equal(omnu.nu_degeneracies[i], 1);
139  assert_true(omnu.RhoNuTab[i].loga);
140  }
141 }

References init_omega_nu(), _rho_nu_single::loga, _omega_nu::nu_degeneracies, _omega_nu::RhoNuTab, and T_CMB0.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_omega_nu_single()

static void test_omega_nu_single ( void **  state)
static

Definition at line 40 of file test_omega_nu_single.c.

40  {
41  (void) state; /* unused */
42  double mnu = 0.5;
43  double HubbleParam = 0.7;
44  _omega_nu omnu;
45  /*Initialise*/
46  double MNu[3] = {mnu, mnu, 0};
47  init_omega_nu(&omnu, MNu, 0.01, 0.7,T_CMB0);
48  assert_true(omnu.RhoNuTab[0].mnu == mnu);
49  /*This is the critical density at z=0:
50  * we allow it to change by what is (at the time of writing) the uncertainty on G.*/
51  assert_true(fabs(omnu.rhocrit - 1.8784e-29*HubbleParam*HubbleParam) < 5e-3*omnu.rhocrit);
52  /*Check everything initialised ok*/
53  double omnuz0 = omega_nu_single(&omnu, 1, 0);
54  /*Check redshift scaling*/
55  assert_true(fabs(omnuz0/pow(0.5,3) - omega_nu_single(&omnu, 0.5, 0)) < 5e-3*omnuz0);
56  /*Check not just a^-3 scaling*/
57  assert_true(omnuz0/pow(0.01,3) < omega_nu_single(&omnu, 0.01, 0));
58  /*Check that we have correctly accounted for neutrino decoupling*/
59  assert_true(fabs(omnuz0 - mnu/93.14/HubbleParam/HubbleParam) < 1e-3*omnuz0);
60  /*Check degenerate species works*/
61  assert_true(omega_nu_single(&omnu, 0.1, 1) == omega_nu_single(&omnu, 0.1, 0));
62  /*Check we get it right for massless neutrinos*/
63  double omnunomassz0 = omega_nu_single(&omnu, 1, 2);
64  assert_true(omnunomassz0 - OMEGAR*7./8.*pow(pow(4/11.,1/3.)*1.00381,4)< 1e-5*omnunomassz0);
65  assert_true(omnunomassz0/pow(0.5,4) == omega_nu_single(&omnu, 0.5, 2));
66  /*Check that we return something vaguely sensible for very early times*/
67  assert_true(omega_nu_single(&omnu,1e-4,0) > omega_nu_single(&omnu, 1,0)/pow(1e-4,3));
68 }
double rhocrit

References init_omega_nu(), _rho_nu_single::mnu, omega_nu_single(), OMEGAR, _omega_nu::rhocrit, _omega_nu::RhoNuTab, and T_CMB0.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_omega_nu_single_exact()

static void test_omega_nu_single_exact ( void **  state)
static

Definition at line 94 of file test_omega_nu_single.c.

95 {
96  double mnu = 0.05;
97  double hubble = 0.7;
98  int i;
99  _omega_nu omnu;
100  /*Initialise*/
101  double MNu[3] = {mnu, mnu, mnu};
102  init_omega_nu(&omnu, MNu, 0.01, hubble,T_CMB0);
103  double omnuz0 = omega_nu_single(&omnu, 1, 0);
104  double rhocrit = omnu.rhocrit;
105  assert_true(fabs(1 - do_exact_rho_nu_integration(1, mnu, rhocrit)/omnuz0) < 1e-6);
106  for(i=1; i< 123; i++) {
107  double a = 0.01 + i/123.;
108  omnuz0 = omega_nu_single(&omnu, a, 0);
109  double omexact = do_exact_rho_nu_integration(a, mnu, rhocrit);
110  if(fabs(omnuz0 - omexact) > 1e-6 * omnuz0)
111  printf("a=%g %g %g %g\n",a, omnuz0, omexact, omnuz0/omexact-1);
112  assert_true(fabs(1 - omexact/omnuz0) < 1e-6);
113  }
114 }
double do_exact_rho_nu_integration(double a, double mnu, double rhocrit)

References do_exact_rho_nu_integration(), init_omega_nu(), omega_nu_single(), _omega_nu::rhocrit, and T_CMB0.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_rho_nu_init()

static void test_rho_nu_init ( void **  state)
static

Definition at line 15 of file test_omega_nu_single.c.

15  {
16  (void) state; /* unused */
17  double mnu = 0.06;
18  _rho_nu_single rho_nu_tab;
19  /*Initialise*/
20  rho_nu_init(&rho_nu_tab, 0.01, mnu, BOLEVK*TNUCMB*T_CMB0);
21  /*Check everything initialised ok*/
22  assert_true(rho_nu_tab.mnu == mnu);
23  assert_true(rho_nu_tab.acc);
24  assert_true(rho_nu_tab.interp);
25  assert_true(rho_nu_tab.loga);
26  assert_true(rho_nu_tab.rhonu);
27  /*Check that loga is correctly ordered (or interpolation won't work)*/
28  int i;
29  for(i=1; i<200; i++){
30  assert_true(rho_nu_tab.loga[i] > rho_nu_tab.loga[i-1]);
31  }
32 }
void rho_nu_init(_rho_nu_single *const rho_nu_tab, double a0, const double mnu, const double kBtnu)
gsl_interp * interp
gsl_interp_accel * acc

References _rho_nu_single::acc, BOLEVK, _rho_nu_single::interp, _rho_nu_single::loga, _rho_nu_single::mnu, rho_nu_init(), _rho_nu_single::rhonu, T_CMB0, and TNUCMB.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function: