MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
Functions
test_cosmology.c File Reference
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <math.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <gsl/gsl_sf_hyperg.h>
#include <libgadget/physconst.h>
#include <libgadget/cosmology.h>
#include "stub.h"
Include dependency graph for test_cosmology.c:

Go to the source code of this file.

Functions

void init_omega_nu (_omega_nu *const omnu, const double MNu[], const double a0, const double HubbleParam, const double tcmb0)
 
double get_omega_nu (const _omega_nu *omnu, const double a)
 
double get_omega_nu_nopart (const _omega_nu *omnu, const double a)
 
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)
 
void setup_cosmology (Cosmology *CP, double Omega0, double OmegaBaryon, double H0)
 
static double radgrow (double aa, double omegar)
 
static double growth (double aa, double omegam)
 
static void test_cosmology (void **state)
 
int main (void)
 

Function Documentation

◆ get_omega_nu()

double get_omega_nu ( const _omega_nu *const  omnu,
const double  a 
)

Return the total matter density in neutrinos at scale factor a.

Definition at line 19 of file test_cosmology.c.

20 {
21  return 0;
22 }

◆ get_omega_nu_nopart()

double get_omega_nu_nopart ( const _omega_nu *const  omnu,
const double  a 
)

Return the total matter density in neutrinos at scale factor a , excluding active particles.

Definition at line 23 of file test_cosmology.c.

24 {
25  return 0;
26 }

◆ growth()

static double growth ( double  aa,
double  omegam 
)
inlinestatic

Definition at line 53 of file test_cosmology.c.

53  {
54  double omegal = 1-omegam;
55  return aa * gsl_sf_hyperg_2F1(1./3, 1, 11./6, -omegal/omegam*pow(aa,3));
56 }

Referenced by test_cosmology().

Here is the caller graph for this function:

◆ init_hybrid_nu()

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 
)

Set up parameters for the hybrid neutrinos

Parameters
hybnuinitialised structure
mnuarray of neutrino masses in eV
vcritCritical velocity above which to treat neutrinos with particles. Note this is unperturbed velocity TODAY To get velocity at redshift z, multiply by (1+z)
lightspeed of light in internal units
nu_crit_timecritical time to make neutrino particles live
kBtnuBoltzmann constant times neutrino temperature. Dimensionful factor.

Definition at line 28 of file test_cosmology.c.

28 { }

◆ init_omega_nu()

void init_omega_nu ( _omega_nu *const  omnu,
const double  MNu[],
const double  a0,
const double  HubbleParam,
const double  tcmb0 
)

Initialise the neutrino structure, do the time integration and allocate memory for the subclass rho_nu_single

Parameters
omnustructure to initialise
MNuarray of neutrino masses in eV. Three entries.
a0initial scale factor.
HubbleParamHubble parameter h0, eg, 0.7.
tcmb0Redshift zero CMB temperature.

Definition at line 17 of file test_cosmology.c.

17 {}

◆ main()

int main ( void  )

Definition at line 96 of file test_cosmology.c.

96  {
97  const struct CMUnitTest tests[] = {
98  cmocka_unit_test(test_cosmology),
99  };
100  return cmocka_run_group_tests_mpi(tests, NULL, NULL);
101 }
static void test_cosmology(void **state)

References test_cosmology().

Here is the call graph for this function:

◆ radgrow()

static double radgrow ( double  aa,
double  omegar 
)
inlinestatic

Definition at line 48 of file test_cosmology.c.

48  {
49  return omegar + 1.5 * 1. * aa;
50 }

Referenced by test_cosmology().

Here is the caller graph for this function:

◆ setup_cosmology()

void setup_cosmology ( Cosmology CP,
double  Omega0,
double  OmegaBaryon,
double  H0 
)

Definition at line 30 of file test_cosmology.c.

31 {
32  CP->CMBTemperature = 2.7255;
33  CP->Omega0 = Omega0;
34  CP->OmegaLambda = 1- CP->Omega0;
35  CP->OmegaBaryon = OmegaBaryon;
36  CP->HubbleParam = H0;
37  CP->RadiationOn = 1;
38  CP->Omega_fld = 0; /*Energy density of dark energy fluid at z=0*/
39  CP->w0_fld = -1; /*Dark energy equation of state parameter*/
40  CP->wa_fld = 0; /*Dark energy equation of state evolution parameter*/
41  CP->Omega_ur = 0;
42  CP->MNu[0] = CP->MNu[1] = CP->MNu[2] = 0;
43  struct UnitSystem units = get_unitsystem(3.085678e21, 1.989e43, 1e5);
44  /*Do the main cosmology initialisation*/
45  init_cosmology(CP,0.01, units);
46 }
void init_cosmology(Cosmology *CP, const double TimeBegin, const struct UnitSystem units)
Definition: cosmology.c:15
static Cosmology * CP
Definition: power.c:27
double wa_fld
Definition: cosmology.h:17
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
double w0_fld
Definition: cosmology.h:16
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, Cosmology::RadiationOn, Cosmology::w0_fld, and Cosmology::wa_fld.

Referenced by test_cosmology().

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

◆ test_cosmology()

static void test_cosmology ( void **  state)
static

Definition at line 58 of file test_cosmology.c.

59 {
60  Cosmology CP = {0};
61  //Check that we get the right scalings for total matter domination.
62  //Cosmology(double HubbleParam, double Omega, double OmegaLambda, double MNu, int Hierarchy, bool NoRadiation)
63  setup_cosmology(&CP, 1., 0.0455, 0.7);
64  /*Check some of the setup worked*/
65  assert_true(CP.OmegaK < 1e-5);
66  assert_true(fabs(CP.OmegaG/5.045e-5 - 1) < 2e-3);
67  /*Check the hubble function is sane*/
68  CP.RadiationOn = 0;
69  assert_true(fabs(hubble_function(&CP, 1) - CP.Hubble) < 1e-5);
70  CP.RadiationOn = 1;
71  assert_true(fabs(hubble_function(&CP, 1) - CP.Hubble* sqrt(1+CP.OmegaG)) < 1e-7);
72 
73  assert_true(fabs(CP.Hubble - 0.1) < 1e-6);
74  assert_true((hubble_function(&CP, 1) - CP.Hubble) < 1e-5);
75  assert_true(fabs(hubble_function(&CP, 0.1) - hubble_function(&CP, 1)/pow(0.1,3/2.)) < 1e-2);
76  assert_true(fabs(GrowthFactor(&CP, 0.5,1.)/0.5 -1) < 2e-4);
77  //Check that the velocity correction d ln D1/d lna is constant
78  assert_true(fabs(1.0 - F_Omega(&CP, 1.5)) < 1e-1);
79  assert_true(fabs(1.0 - F_Omega(&CP, 2)) < 1e-2);
80  //Check radiation against exact solution from gr-qc/0504089
81  assert_true(fabs(1/GrowthFactor(&CP, 0.05,1.) - radgrow(1., CP.OmegaG)/radgrow(0.05, CP.OmegaG))< 1e-3);
82  assert_true(fabs(GrowthFactor(&CP, 0.01,0.001) - radgrow(0.01, CP.OmegaG)/radgrow(0.001, CP.OmegaG))< 1e-3);
83 
84  //Check against exact solutions from gr-qc/0504089: No radiation!
85  //Note that the GSL hyperg needs the last argument to be < 1
86  double omegam = 0.5;
87  setup_cosmology(&CP, omegam, 0.0455, 0.7);
88  CP.RadiationOn = 0;
89  //Check growth factor during matter domination
90  assert_true(fabs(1/GrowthFactor(&CP, 0.5, 1.) - growth(1., omegam)/growth(0.5, omegam)) < 1e-3);
91  assert_true(fabs(GrowthFactor(&CP, 0.3, 0.15) - growth(0.3, omegam)/growth(0.15, omegam)) < 1e-3);
92  assert_true(fabs(1/GrowthFactor(&CP, 0.01, 1.) - growth(1, omegam)/growth(0.01, omegam)) < 1e-3);
93  assert_true(fabs(0.01*log(GrowthFactor(&CP, 0.01+1e-5,0.01-1e-5))/2e-5 - F_Omega(&CP, 0.01)) < 1e-3);
94 }
double GrowthFactor(Cosmology *CP, double astart, double aend)
Definition: cosmology.c:82
double hubble_function(const Cosmology *CP, double a)
Definition: cosmology.c:58
double F_Omega(Cosmology *CP, double a)
Definition: cosmology.c:148
double OmegaK
Definition: cosmology.h:13
double OmegaG
Definition: cosmology.h:12
double Hubble
Definition: cosmology.h:21
static double growth(double aa, double omegam)
static double radgrow(double aa, double omegar)
void setup_cosmology(Cosmology *CP, double Omega0, double OmegaBaryon, double H0)

References CP, F_Omega(), growth(), GrowthFactor(), Cosmology::Hubble, hubble_function(), Cosmology::OmegaG, Cosmology::OmegaK, radgrow(), Cosmology::RadiationOn, and setup_cosmology().

Referenced by main().

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