Fast Methods for Cosmological Simulations
FastSim serves as a tool for quick N-body simulations in modified gravity.
ccl_neutrinos.h File Reference
#include <gsl/gsl_spline.h>
#include <gsl/gsl_const_mksa.h>
Include dependency graph for ccl_neutrinos.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define CCL_MAX_NU_SPECIES   3
 
#define CCL_NU_MNUT_MIN   1e-4
 
#define CCL_NU_MNUT_MAX   500
 
#define CCL_NU_MNUT_N   1000
 
#define NU_CONST   (8. * pow(M_PI,5) *pow((KBOLTZ/ HPLANCK),3)* KBOLTZ/(15. *pow( CLIGHT,3))* (8. * M_PI * GNEWT) / (3. * 100.*100.*1000.*1000. /MPC_TO_METER /MPC_TO_METER * CLIGHT * CLIGHT))
 

Typedefs

typedef CCL_BEGIN_DECLS enum ccl_neutrino_mass_splits ccl_neutrino_mass_splits
 

Enumerations

enum  ccl_neutrino_mass_splits { ccl_nu_normal =0, ccl_nu_inverted =1, ccl_nu_equal =2, ccl_nu_sum =3 }
 

Functions

gsl_spline * calculate_nu_phasespace_spline (int *status)
 
double ccl_Omeganuh2 (double a, int N_nu_mass, double *mnu, double T_CMB, gsl_interp_accel *accel, int *status)
 
doubleccl_nu_masses (double OmNuh2, ccl_neutrino_mass_splits mass_split, double T_CMB, int *status)
 

Macro Definition Documentation

#define CCL_MAX_NU_SPECIES   3

Definition at line 9 of file ccl_neutrinos.h.

#define CCL_NU_MNUT_MAX   500

Definition at line 13 of file ccl_neutrinos.h.

Referenced by calculate_nu_phasespace_spline(), and nu_phasespace_intg().

#define CCL_NU_MNUT_MIN   1e-4

Definition at line 12 of file ccl_neutrinos.h.

Referenced by calculate_nu_phasespace_spline(), and nu_phasespace_intg().

#define CCL_NU_MNUT_N   1000

Definition at line 15 of file ccl_neutrinos.h.

Referenced by calculate_nu_phasespace_spline().

#define NU_CONST   (8. * pow(M_PI,5) *pow((KBOLTZ/ HPLANCK),3)* KBOLTZ/(15. *pow( CLIGHT,3))* (8. * M_PI * GNEWT) / (3. * 100.*100.*1000.*1000. /MPC_TO_METER /MPC_TO_METER * CLIGHT * CLIGHT))

Definition at line 18 of file ccl_neutrinos.h.

Referenced by ccl_Omeganuh2().

Typedef Documentation

Enumeration Type Documentation

Enumerator
ccl_nu_normal 
ccl_nu_inverted 
ccl_nu_equal 
ccl_nu_sum 

Definition at line 22 of file ccl_neutrinos.h.

Function Documentation

gsl_spline* calculate_nu_phasespace_spline ( int *  status)

Spline for the phasespace integral required for getting the fractional energy density of massive neutrinos. Returns a gsl spline for the phase space integral needed for massive neutrinos.

Parameters
statusStatus flag. 0 if there are no errors, nonzero otherwise. For specific cases see documentation for ccl_error.c
Returns
spl, the gsl spline for the phasespace integral required for massive neutrino calculations.

Definition at line 33 of file ccl_neutrinos.c.

References A_SPLINE_TYPE, ccl_cosmology_read_config(), CCL_ERROR_MISSING_CONFIG_FILE, CCL_ERROR_NU_INT, ccl_gsl, ccl_linear_spacing(), CCL_NU_MNUT_MAX, CCL_NU_MNUT_MIN, CCL_NU_MNUT_N, ccl_raise_exception(), ccl_raise_gsl_warning(), ccl_splines, ccl_gsl_params::INTEGRATION_NU_EPSABS, ccl_gsl_params::INTEGRATION_NU_EPSREL, ccl_gsl_params::N_ITERATION, and nu_integrand().

Referenced by nu_phasespace_intg().

33  {
34  int N=CCL_NU_MNUT_N;
35  double *mnut = ccl_linear_spacing(log(CCL_NU_MNUT_MIN),log(CCL_NU_MNUT_MAX),N);
36  double *y=malloc(sizeof(double)*CCL_NU_MNUT_N);
37  if (y ==NULL) {
38  // Not setting a status_message here because we can't easily pass a cosmology to this function - message printed in ccl_error.c.
39  *status = CCL_ERROR_NU_INT;
40  }
41 
42  // Check whether ccl_splines and ccl_gsl exist; exit gracefully if they
43  // can't be loaded
44  if(ccl_splines==NULL || ccl_gsl==NULL) ccl_cosmology_read_config();
45  if(ccl_splines==NULL || ccl_gsl==NULL) {
47  "ccl_neutrinos.c: Failed to read config file.");
49  return NULL;
50  }
51 
52  int stat=0, gslstatus;
53  gsl_integration_cquad_workspace * workspace = \
54  gsl_integration_cquad_workspace_alloc(ccl_gsl->N_ITERATION);
55  gsl_function F;
56  F.function = &nu_integrand;
57  for (int i=0; i<CCL_NU_MNUT_N; i++) {
58  double mnut_=exp(mnut[i]);
59  F.params = &(mnut_);
60  gslstatus = gsl_integration_cquad(&F, 0, 1000.0,
63  workspace,&y[i], NULL, NULL);
64  if(gslstatus != GSL_SUCCESS) {
65  ccl_raise_gsl_warning(gslstatus, "ccl_neutrinos.c: calculate_nu_phasespace_spline():");
66  stat |= gslstatus;
67  }
68  }
69  gsl_integration_cquad_workspace_free(workspace);
70  double renorm=1./y[0];
71  for (int i=0; i<CCL_NU_MNUT_N; i++)
72  y[i]*=renorm;
73  gsl_spline* spl = gsl_spline_alloc(A_SPLINE_TYPE, CCL_NU_MNUT_N);
74  stat |= gsl_spline_init(spl, mnut, y, CCL_NU_MNUT_N);
75 
76  // Check for errors in creating the spline
77  if (stat) {
78  // Not setting a status_message here because we can't easily pass a cosmology to this function - message printed in ccl_error.c.
79  *status = CCL_ERROR_NU_INT;
80  free(mnut);
81  free(y);
82  gsl_spline_free(spl);
83  }
84  free(mnut);
85  free(y);
86  return spl;
87 }
double INTEGRATION_NU_EPSREL
Definition: ccl_params.h:70
void ccl_raise_gsl_warning(int gslstatus, const char *msg,...)
Definition: ccl_error.c:75
#define CCL_NU_MNUT_MAX
Definition: ccl_neutrinos.h:13
#define CCL_NU_MNUT_N
Definition: ccl_neutrinos.h:15
#define CCL_ERROR_MISSING_CONFIG_FILE
Definition: ccl_error.h:28
static double nu_integrand(double x, void *r)
Definition: ccl_neutrinos.c:23
#define A_SPLINE_TYPE
Definition: ccl_constants.h:7
ccl_spline_params * ccl_splines
Definition: ccl_core.c:47
CCL_BEGIN_DECLS double * ccl_linear_spacing(double xmin, double xmax, int N)
Definition: ccl_utils.c:14
#define CCL_ERROR_NU_INT
Definition: ccl_error.h:22
double INTEGRATION_NU_EPSABS
Definition: ccl_params.h:71
ccl_gsl_params * ccl_gsl
Definition: ccl_core.c:48
void ccl_cosmology_read_config(void)
Definition: ccl_core.c:50
size_t N_ITERATION
Definition: ccl_params.h:55
#define CCL_NU_MNUT_MIN
Definition: ccl_neutrinos.h:12
void ccl_raise_exception(int err, const char *msg,...)
Definition: ccl_error.c:35
double* ccl_nu_masses ( double  OmNuh2,
ccl_neutrino_mass_splits  mass_split,
double  T_CMB,
int *  status 
)

Returns mass of one neutrino species at a scale factor a.

Parameters
aScale factor
NeffThe effective number of species with neutrino mass mnu.
OmNuh2Fractional energy density of neutrions with mass mnu, multiplied by h squared. (can be 0).
T_CMBTemperature of the CMB
accel- Interpolation accelerator to be used with phasespace spline. If not set yet, pass NULL.
statusStatus flag. 0 if there are no errors, nonzero otherwise. For specific cases see documentation for ccl_error.c
Returns
Mnu Neutrino mass [eV].

Definition at line 168 of file ccl_neutrinos.c.

References ccl_check_status_nocosmo(), CCL_ERROR_MNU_UNPHYSICAL, ccl_nu_equal, ccl_nu_inverted, ccl_nu_normal, ccl_nu_sum, DELTAM12_sq, DELTAM13_sq_neg, DELTAM13_sq_pos, ccl_test_distances::mnu, and pow().

Referenced by __attribute__().

168  {
169 
170  double sumnu;
171 
172  sumnu = 93.14 * OmNuh2;
173 
174  // Now split the sum up into three masses depending on the label given:
175 
176  if(mass_split==ccl_nu_normal){
177 
178  double *mnu;
179  mnu = malloc(3*sizeof(double));
180 
181  // See CCL note for how we get these expressions for the neutrino masses in normal and inverted hierarchy.
182  mnu[0] = 2./3.* sumnu - 1./6. * pow(-6. * DELTAM12_sq + 12. * DELTAM13_sq_pos + 4. * sumnu*sumnu, 0.5)
183  - 0.25 * DELTAM12_sq / (2./3.* sumnu - 1./6. * pow(-6. * DELTAM12_sq + 12. * DELTAM13_sq_pos + 4. * sumnu*sumnu, 0.5));
184  mnu[1] = 2./3.* sumnu - 1./6. * pow(-6. * DELTAM12_sq + 12. * DELTAM13_sq_pos + 4. * sumnu*sumnu, 0.5)
185  + 0.25 * DELTAM12_sq / (2./3.* sumnu - 1./6. * pow(-6. * DELTAM12_sq + 12. * DELTAM13_sq_pos + 4. * sumnu*sumnu, 0.5));
186  mnu[2] = -1./3. * sumnu + 1./3 * pow(-6. * DELTAM12_sq + 12. * DELTAM13_sq_pos + 4. * sumnu*sumnu, 0.5);
187  if (mnu[0]<0 || mnu[1]<0 || mnu[2]<0){
188  // The user has provided a sum that is below the physical limit.
189  if (sumnu<1e-14){
190  mnu[0] = 0.;
191  mnu[1] = 0.;
192  mnu[2] = 0.;
193  }else{
194  *status = CCL_ERROR_MNU_UNPHYSICAL;
195  }
196  }
197  ccl_check_status_nocosmo(status);
198  return mnu;
199 
200  } else if (mass_split==ccl_nu_inverted){
201 
202  double *mnu;
203  mnu = malloc(3*sizeof(double));
204  mnu[0] = 2./3.* sumnu - 1./6. * pow(-6. * DELTAM12_sq + 12. * DELTAM13_sq_neg + 4. * sumnu * sumnu, 0.5)
205  - 0.25 * DELTAM12_sq / (2./3.* sumnu - 1./6. * pow(-6. * DELTAM12_sq + 12. * DELTAM13_sq_neg + 4. * sumnu * sumnu, 0.5));
206  mnu[1] = 2./3.* sumnu - 1./6. * pow(-6. * DELTAM12_sq + 12. * DELTAM13_sq_neg + 4. * sumnu*sumnu, 0.5)
207  + 0.25 * DELTAM12_sq / (2./3.* sumnu - 1./6. * pow(-6. * DELTAM12_sq + 12. * DELTAM13_sq_neg + 4. * sumnu*sumnu, 0.5));
208  mnu[2] = -1./3. * sumnu + 1./3 * pow(-6. * DELTAM12_sq + 12. * DELTAM13_sq_neg + 4. * sumnu*sumnu, 0.5);
209  if(mnu[0]<0 || mnu[1]<0 || mnu[2]<0){
210  // The user has provided a sum that is below the physical limit.
211  if (sumnu<1e-14){
212  mnu[0] = 0.;
213  mnu[1] = 0.;
214  mnu[2] = 0.;;
215  }else{
216  *status = CCL_ERROR_MNU_UNPHYSICAL;
217  }
218  }
219 
220  ccl_check_status_nocosmo(status);
221  return mnu;
222 
223  } else if (mass_split==ccl_nu_equal){
224  double *mnu;
225  mnu = malloc(3*sizeof(double));
226  mnu[0] = sumnu/3.;
227  mnu[1] = sumnu/3.;
228  mnu[2] = sumnu/3.;
229 
230  return mnu;
231 
232  } else if (mass_split == ccl_nu_sum){
233 
234  double *mnu;
235  mnu = malloc(sizeof(double));
236 
237  mnu[0] = sumnu;
238 
239  return mnu;
240 
241  } else{
242 
243  printf("WARNING: mass option = %d not yet supported\n continuing with normal hierarchy\n", mass_split);
244  double *mnu;
245  mnu = malloc(3*sizeof(double));
246 
247  if (sumnu>0.59){
248  mnu[0] = (sumnu - 0.59) / 3.;
249  mnu[1] = mnu[0] + 0.009;
250  mnu[2] = mnu[0] + 0.05;
251  }else{
252  *status = CCL_ERROR_MNU_UNPHYSICAL;
253  }
254 
255  ccl_check_status_nocosmo(status);
256  return mnu;
257  }
258 }
#define DELTAM12_sq
#define DELTAM13_sq_pos
#define DELTAM13_sq_neg
void ccl_check_status_nocosmo(int *status)
Definition: ccl_error.c:116
#define CCL_ERROR_MNU_UNPHYSICAL
Definition: ccl_error.h:26
float pow(float base, unsigned long int exp)
Definition: precision.hpp:39
double ccl_Omeganuh2 ( double  a,
int  N_nu_mass,
double mnu,
double  T_CMB,
gsl_interp_accel *  accel,
int *  status 
)

Returns density of one neutrino species at a scale factor a. Users are encouraged to access this quantity via the function ccl_omega_x.

Parameters
aScale factor
NeffThe effective number of species with neutrino mass mnu.
mnuPointer to array containing neutrino mass (can be 0).
T_CMBTemperature of the CMB
accel- Interpolation accelerator to be used with phasespace spline. If not set yet, pass NULL.
statusStatus flag. 0 if there are no errors, nonzero otherwise. For specific cases see documentation for ccl_error.c
Returns
OmNuh2 Fractional energy density of neutrions with mass mnu, multiplied by h squared.

Definition at line 125 of file ccl_neutrinos.c.

References EV_IN_J, KBOLTZ, NU_CONST, nu_phasespace_intg(), pow(), and TNCDM.

Referenced by ccl_cosmology_compute_power_emu(), ccl_omega_x(), ccl_parameters_fill_initial(), and h_over_h0().

126 {
127  double Tnu, a4, prefix_massless, mnuone, OmNuh2;
128  double Tnu_eff, mnuOT, intval, prefix_massive;
129  double total_mass; // To check if this is the massless or massive case.
130 
131  // First check if N_nu_mass is 0
132  if (N_nu_mass==0) return 0.0;
133 
134  Tnu=T_CMB*pow(4./11.,1./3.);
135  a4=a*a*a*a;
136  // Check if mnu=0. We assume that in the massless case mnu is a pointer to a single element and that element is 0. This should in principle never be called.
137  if (mnu[0] < 0.00017) { // Limit taken from Lesgourges et al. 2012
138  prefix_massless = NU_CONST * Tnu * Tnu * Tnu * Tnu;
139  return N_nu_mass*prefix_massless*7./8./a4;
140  }
141 
142  // And the remaining massive case.
143  // Tnu_eff is used in the massive case because CLASS uses an effective temperature of nonLCDM components to match to mnu / Omeganu =93.14eV. Tnu_eff = T_ncdm * T_CMB = 0.71611 * T_CMB
144  Tnu_eff = Tnu * TNCDM / (pow(4./11.,1./3.));
145 
146  // Define the prefix using the effective temperature (to get mnu / Omega = 93.14 eV) for the massive case:
147  prefix_massive = NU_CONST * Tnu_eff * Tnu_eff * Tnu_eff * Tnu_eff;
148 
149  OmNuh2 = 0.; // Initialize to 0 - we add to this for each massive neutrino species.
150  for(int i=0; i<N_nu_mass; i++){
151  // Get mass over T (mass (eV) / ((kb eV/s/K) Tnu_eff (K))
152  // This returns the density normalized so that we get nuh2 at a=0
153  mnuOT = mnu[i] / (Tnu_eff/a) * (EV_IN_J / (KBOLTZ));
154 
155  // Get the value of the phase-space integral
156  intval=nu_phasespace_intg(accel,mnuOT, status);
157  OmNuh2 = intval*prefix_massive/a4 + OmNuh2;
158  }
159 
160  return OmNuh2;
161 }
#define NU_CONST
Definition: ccl_neutrinos.h:18
#define KBOLTZ
Definition: ccl_constants.h:67
double nu_phasespace_intg(gsl_interp_accel *accel, double mnuOT, int *status)
Definition: ccl_neutrinos.c:94
#define TNCDM
#define EV_IN_J
Definition: ccl_constants.h:90
float pow(float base, unsigned long int exp)
Definition: precision.hpp:39