MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
Functions
test_thermal.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 <string.h>
#include "stub.h"
#include <libgadget/config.h>
#include <libgenic/thermal.h>
Include dependency graph for test_thermal.c:

Go to the source code of this file.

Functions

static void test_mean_velocity (void **state)
 
static void test_thermal_vel (void **state)
 
int main (void)
 

Function Documentation

◆ main()

int main ( void  )

Definition at line 72 of file test_thermal.c.

72  {
73  const struct CMUnitTest tests[] = {
74  cmocka_unit_test(test_mean_velocity),
75  cmocka_unit_test(test_thermal_vel)
76  };
77  return cmocka_run_group_tests_mpi(tests, NULL, NULL);
78 }
static void test_thermal_vel(void **state)
Definition: test_thermal.c:29
static void test_mean_velocity(void **state)
Definition: test_thermal.c:18

References test_mean_velocity(), and test_thermal_vel().

Here is the call graph for this function:

◆ test_mean_velocity()

static void test_mean_velocity ( void **  state)
static

Definition at line 18 of file test_thermal.c.

19 {
20  /*Check has units of velocity*/
21  assert_true(fabs(NU_V0(1, 1, 1e3) - 100*NU_V0(1, 1, 1e5)) < 1e-6);
22  /*Check scales linearly with neutrino mass*/
23  assert_true(fabs(10*NU_V0(1, 0.1, 1e5) - NU_V0(1, 1, 1e5)) < 1e-6);
24  /*Check scales as z (gadget's cosmological velocity unit is accounted for outside)*/
25  assert_true(fabs(0.5*NU_V0(0.5, 1, 1e5) - NU_V0(1, 1, 1e5)) < 1e-6);
26 }
double NU_V0(const double Time, const double kBTNubyMNu, const double UnitVelocity_in_cm_per_s)
Definition: thermal.c:24

References NU_V0().

Referenced by main().

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

◆ test_thermal_vel()

static void test_thermal_vel ( void **  state)
static

Definition at line 29 of file test_thermal.c.

30 {
31  /*Seed table with velocity of 100 km/s*/
32  struct thermalvel nu_vels;
33  init_thermalvel(&nu_vels, 100, 5000/100, 0);
34 
35  /*Test getting the distribution*/
36  assert_true(fabs(nu_vels.fermi_dirac_vel[0]) < 1e-6);
37  assert_true(fabs(nu_vels.fermi_dirac_vel[LENGTH_FERMI_DIRAC_TABLE - 1] - MAX_FERMI_DIRAC) < 1e-3);
38 
39  /*Number verified by mathematica*/
40  int ii = 0;
41  while(nu_vels.fermi_dirac_cumprob[ii] < 0.5) {
42  ii++;
43  }
44  assert_true(fabs(nu_vels.fermi_dirac_vel[ii] - 2.839075) < 0.002);
45  /*Check some statistical properties (max, min, mean)*/
46  double mean = 0;
47  double max = 0;
48  double min = 1e10;
49  int nsample;
50  float Vel[3] = {0};
51  int64_t MaxID = 100000;
52  gsl_rng * g_rng = gsl_rng_alloc(gsl_rng_ranlxd1);
53  for (nsample=0; nsample < MaxID; nsample++)
54  {
55  add_thermal_speeds(&nu_vels, g_rng, Vel);
56  double v2 = sqrt(Vel[0]*Vel[0]+Vel[1]*Vel[1]+Vel[2]*Vel[2]);
57  if(v2 > max)
58  max = v2;
59  if(v2 < min)
60  min = v2;
61  mean+=v2;
62  memset(Vel, 0, 3*sizeof(float));
63  }
64  gsl_rng_free(g_rng);
65  mean/=nsample;
66  /*Mean should be roughly 3*zeta(4)/zeta(3)*7/8/(3/4)* m_vamp*/
67  assert_true(fabs(mean - 3*pow(M_PI,4)/90./1.202057*(7./8)/(3/4.)*100) < 1);
68  assert_true(min > 0);
69  assert_true( max < MAX_FERMI_DIRAC*100);
70 }
double init_thermalvel(struct thermalvel *thermals, const double v_amp, double max_fd, const double min_fd)
Definition: thermal.c:47
void add_thermal_speeds(struct thermalvel *thermals, gsl_rng *g_rng, float Vel[])
Definition: thermal.c:109
#define MAX_FERMI_DIRAC
Definition: thermal.h:7
#define LENGTH_FERMI_DIRAC_TABLE
Definition: thermal.h:8

References add_thermal_speeds(), thermalvel::fermi_dirac_cumprob, thermalvel::fermi_dirac_vel, init_thermalvel(), LENGTH_FERMI_DIRAC_TABLE, and MAX_FERMI_DIRAC.

Referenced by main().

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