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

Go to the source code of this file.

Macros

#define T_CMB0   2.7255
 

Functions

double specialJ (const double x, const double vcmnubylight, const double nufrac_low)
 
double fslength (Cosmology *CP, const double logai, const double logaf, const double light)
 
void petaio_save_block (BigFile *bf, char *blockname, BigArray *array, int verbose)
 
int petaio_read_block (BigFile *bf, char *blockname, BigArray *array, int required)
 
void setup_cosmology (Cosmology *CP, double MNu[])
 
static void test_allocate_delta_tot_table (void **state)
 
static void test_specialJ (void **state)
 
static void test_fslength (void **state)
 
int main (void)
 

Variables

_delta_tot_table delta_tot_table
 

Macro Definition Documentation

◆ T_CMB0

#define T_CMB0   2.7255

Definition at line 14 of file test_neutrinos_lra.c.

Function Documentation

◆ fslength()

double fslength ( Cosmology CP,
const double  logai,
const double  logaf,
const double  light 
)

Free-streaming length (times Mnu/k_BT_nu, which is dimensionless) for a non-relativistic particle of momentum q = T0, from scale factor ai to af. Arguments:

Parameters
logailog of initial scale factor
logaflog of final scale factor
mnuNeutrino mass in eV
lightspeed of light in internal length units.
Returns
free-streaming length in Unit_Length/Unit_Time (same units as light parameter).

Definition at line 553 of file neutrinos_lra.c.

554 {
555  double abserr;
556  double fslength_val;
557  gsl_function F;
558  gsl_integration_workspace * w = gsl_integration_workspace_alloc (GSL_VAL);
559  F.function = &fslength_int;
560  F.params = CP;
561  if(logai >= logaf)
562  return 0;
563  gsl_integration_qag (&F, logai, logaf, 0, 1e-6,GSL_VAL,6,w,&(fslength_val), &abserr);
564  gsl_integration_workspace_free (w);
565  return light*fslength_val;
566 }
#define GSL_VAL
Definition: neutrinos_lra.c:30
double fslength_int(const double loga, void *params)
static Cosmology * CP
Definition: power.c:27

References CP, fslength_int(), and GSL_VAL.

Referenced by get_delta_nu(), and test_fslength().

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

◆ main()

int main ( void  )

Definition at line 110 of file test_neutrinos_lra.c.

110  {
111  const struct CMUnitTest tests[] = {
112  cmocka_unit_test(test_allocate_delta_tot_table),
113  cmocka_unit_test(test_specialJ),
114  cmocka_unit_test(test_fslength),
115  };
116  return cmocka_run_group_tests_mpi(tests, NULL, NULL);
117 }
static void test_fslength(void **state)
static void test_specialJ(void **state)
static void test_allocate_delta_tot_table(void **state)

References test_allocate_delta_tot_table(), test_fslength(), and test_specialJ().

Here is the call graph for this function:

◆ petaio_read_block()

int petaio_read_block ( BigFile *  bf,
char *  blockname,
BigArray *  array,
int  required 
)

Definition at line 20 of file test_neutrinos_lra.c.

21 {
22  return 0;
23 }

◆ petaio_save_block()

void petaio_save_block ( BigFile *  bf,
char *  blockname,
BigArray *  array,
int  verbose 
)

Definition at line 19 of file test_neutrinos_lra.c.

19 {};

◆ setup_cosmology()

void setup_cosmology ( Cosmology CP,
double  MNu[] 
)

Definition at line 29 of file test_neutrinos_lra.c.

30 {
31  CP->CMBTemperature = 2.7255;
32  CP->Omega0 = 0.2793;
33  CP->OmegaLambda = 1- CP->Omega0;
34  CP->OmegaBaryon = 0.0464;
35  CP->HubbleParam = 0.7;
36  CP->RadiationOn = 1;
37  CP->Omega_fld = 0;
38  CP->Omega_ur = 0;
39  int i;
40  for(i = 0; i<3; i++)
41  CP->MNu[i] = MNu[i];
42  struct UnitSystem units = get_unitsystem(3.085678e21, 1.989e43, 1e5);
43  /*Do the main cosmology initialisation*/
44  init_cosmology(CP,0.01, units);
45 }
void init_cosmology(Cosmology *CP, const double TimeBegin, const struct UnitSystem units)
Definition: cosmology.c:15
double Omega_ur
Definition: cosmology.h:18
double Omega_fld
Definition: cosmology.h:15
double Omega0
Definition: cosmology.h:10
int RadiationOn
Definition: cosmology.h:23
double HubbleParam
Definition: cosmology.h:20
double CMBTemperature
Definition: cosmology.h:9
double OmegaLambda
Definition: cosmology.h:14
double OmegaBaryon
Definition: cosmology.h:19
double MNu[3]
Definition: cosmology.h:25
struct UnitSystem get_unitsystem(double UnitLength_in_cm, double UnitMass_in_g, double UnitVelocity_in_cm_per_s)
Definition: unitsystem.c:6

References Cosmology::CMBTemperature, CP, get_unitsystem(), Cosmology::HubbleParam, init_cosmology(), Cosmology::MNu, Cosmology::Omega0, Cosmology::Omega_fld, Cosmology::Omega_ur, Cosmology::OmegaBaryon, Cosmology::OmegaLambda, and Cosmology::RadiationOn.

Referenced by test_fslength().

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

◆ specialJ()

double specialJ ( const double  x,
const double  vcmnubylight,
const double  nufrac_low 
)

Fit to the special function J(x) that is accurate to better than 3% relative and 0.07% absolute

Definition at line 616 of file neutrinos_lra.c.

617 {
618  if( qc > 0 ) {
619  return Jfrac_high(x, qc, nufrac_low);
620  }
621  return specialJ_fit(x);
622 }
static double specialJ_fit(const double x)
static double Jfrac_high(const double x, const double qc, const double nufrac_low)
double nufrac_low(const double qc)

Referenced by get_delta_nu(), get_delta_nu_int(), and test_specialJ().

Here is the caller graph for this function:

◆ test_allocate_delta_tot_table()

static void test_allocate_delta_tot_table ( void **  state)
static

Definition at line 49 of file test_neutrinos_lra.c.

50 {
51  _omega_nu omnu;
52  double MNu[3] = {0, 0, 0};
53  int i;
54  init_omega_nu(&omnu, MNu, 0.01, 0.7,T_CMB0);
55  init_neutrinos_lra(300, 0.01, 1, 0.2793, &omnu, 1, 1);
56  assert_true(delta_tot_table.ia == 0);
57  assert_true(delta_tot_table.namax > 10);
58  assert_true(delta_tot_table.scalefact);
59  assert_true(delta_tot_table.delta_nu_init);
60  assert_true(delta_tot_table.delta_tot);
61  for(i=0; i<delta_tot_table.nk_allocated; i++){
62  assert_true(delta_tot_table.delta_tot[i]);
63  }
64 }
void init_neutrinos_lra(const int nk_in, const double TimeTransfer, const double TimeMax, const double Omega0, const _omega_nu *const omnu, const double UnitTime_in_s, const double UnitLength_in_cm)
void init_omega_nu(_omega_nu *omnu, const double MNu[], const double a0, const double HubbleParam, const double tcmb0)
double ** delta_tot
Definition: neutrinos_lra.h:27
double * scalefact
Definition: neutrinos_lra.h:29
double * delta_nu_init
Definition: neutrinos_lra.h:31
#define T_CMB0
_delta_tot_table delta_tot_table
Definition: neutrinos_lra.c:75

References _delta_tot_table::delta_nu_init, _delta_tot_table::delta_tot, delta_tot_table, _delta_tot_table::ia, init_neutrinos_lra(), init_omega_nu(), _delta_tot_table::namax, _delta_tot_table::nk_allocated, _delta_tot_table::scalefact, and T_CMB0.

Referenced by main().

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

◆ test_fslength()

static void test_fslength ( void **  state)
static

Definition at line 95 of file test_neutrinos_lra.c.

96 {
97  Cosmology CP;
98  double MNu[3] = {0.15, 0.15, 0.15};
99  setup_cosmology(&CP, MNu);
100  /*Note that MNu is the mass of a single neutrino species:
101  *we use large masses so that we don't have to compute omega_nu in mathematica.*/
102  double kT = BOLEVK*TNUCMB*T_CMB0;
103  /*fslength function returns fslength * (MNu / kT)*/
104  assert_true(fabs(fslength(&CP, log(0.5), log(1), 299792.)/ 1272.92/(0.45/kT) -1 ) < 1e-5);
105  double MNu2[3] = {0.2, 0.2, 0.2};
106  setup_cosmology(&CP, MNu2);
107  assert_true(fabs(fslength(&CP, log(0.1), log(0.5),299792.)/ 5427.8/(0.6/kT) -1 ) < 1e-5);
108 }
#define TNUCMB
#define BOLEVK
Definition: physconst.h:13
void setup_cosmology(Cosmology *CP, double MNu[])
double fslength(Cosmology *CP, const double logai, const double logaf, const double light)

References BOLEVK, CP, fslength(), setup_cosmology(), T_CMB0, and TNUCMB.

Referenced by main().

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

◆ test_specialJ()

static void test_specialJ ( void **  state)
static

Definition at line 67 of file test_neutrinos_lra.c.

68 {
69  /*Check against mathematica computed values:
70  Integrate[(Sinc[q*x])*(q^2/(Exp[q] + 1)), {q, 0, Infinity}]*/
71  assert_true(specialJ(0,-1,0) == 1);
72  assert_true(fabs(specialJ(1,-1, 0) - 0.2117) < 1e-3);
73  assert_true(fabs(specialJ(2,-1, 0) - 0.0223807) < 1e-3);
74  assert_true(fabs(specialJ(0.5,-1, 0) - 0.614729) < 1e-3);
75  assert_true(fabs(specialJ(0.3,-1, 0) - 0.829763) < 1e-3);
76  /*Test that it is ok when truncated*/
77  /*Mathematica: Jfrac[x_, qc_] := NIntegrate[(Sinc[q*x])*(q^2/(Exp[q] + 1)), {q, qc, Infinity}]/(3*Zeta[3]/2) */
78  assert_true(fabs(specialJ(0,1, 0) - 0.940437) < 1e-4);
79  assert_true(fabs(specialJ(0.5,1e-2, 0.5) - 0.614729/0.5) < 1e-3);
80  assert_true(fabs(specialJ(0.5,1, 0.5) - 0.556557/0.5) < 1e-4);
81  assert_true(fabs(specialJ(1,0.1, 0.5) - 0.211662/0.5) < 1e-4);
82 }
double specialJ(const double x, const double vcmnubylight, const double nufrac_low)

References specialJ().

Referenced by main().

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

Variable Documentation

◆ delta_tot_table

_delta_tot_table delta_tot_table
extern