MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
Classes | Functions
cosmology.h File Reference
#include <stddef.h>
#include "omega_nu_single.h"
#include "utils/unitsystem.h"
Include dependency graph for cosmology.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Cosmology
 
struct  FunctionOfK
 

Functions

void function_of_k_normalize_sigma (FunctionOfK *fk, double R, double sigma)
 
double function_of_k_eval (FunctionOfK *fk, double k)
 
double function_of_k_tophat_sigma (FunctionOfK *fk, double R)
 
double hubble_function (const Cosmology *CP, double a)
 
double GrowthFactor (Cosmology *CP, double astart, double aend)
 
double F_Omega (Cosmology *CP, double a)
 
int hybrid_nu_tracer (const Cosmology *CP, double atime)
 
void init_cosmology (Cosmology *CP, double TimeBegin, const struct UnitSystem units)
 
void check_units (const Cosmology *CP, const struct UnitSystem units)
 

Function Documentation

◆ check_units()

void check_units ( const Cosmology CP,
const struct UnitSystem  units 
)

Check and print properties of the cosmological unit system.

Definition at line 260 of file cosmology.c.

261 {
262  /* Detect cosmologies that are likely to be typos in the parameter files*/
263  if(CP->HubbleParam < 0.1 || CP->HubbleParam > 10 ||
264  CP->OmegaLambda < 0 || CP->OmegaBaryon < 0 || CP->OmegaG < 0 || CP->OmegaCDM < 0)
265  endrun(5, "Bad cosmology: H0 = %g OL = %g Ob = %g Og = %g Ocdm = %g\n",
267 
268  message(0, "Hubble (internal units) = %g\n", CP->Hubble);
269  message(0, "G (internal units) = %g\n", CP->GravInternal);
270  message(0, "UnitLength_in_cm = %g \n", units.UnitLength_in_cm);
271  message(0, "UnitMass_in_g = %g \n", units.UnitMass_in_g);
272  message(0, "UnitTime_in_s = %g \n", units.UnitTime_in_s);
273  message(0, "UnitVelocity_in_cm_per_s = %g \n", units.UnitVelocity_in_cm_per_s);
274  message(0, "UnitDensity_in_cgs = %g \n", units.UnitDensity_in_cgs);
275  message(0, "UnitEnergy_in_cgs = %g \n", units.UnitEnergy_in_cgs);
276  message(0, "Dark energy model: OmegaL = %g OmegaFLD = %g\n",CP->OmegaLambda, CP->Omega_fld);
277  message(0, "Photon density OmegaG = %g\n",CP->OmegaG);
278  if(!CP->MassiveNuLinRespOn)
279  message(0, "Massless Neutrino density OmegaNu0 = %g\n",get_omega_nu(&CP->ONu, 1));
280  message(0, "Curvature density OmegaK = %g\n",CP->OmegaK);
281  if(CP->RadiationOn) {
282  /* note that this value is inaccurate if there is a massive neutrino. */
283  double OmegaTot = CP->OmegaG + CP->OmegaK + CP->Omega0 + CP->OmegaLambda;
284  if(!CP->MassiveNuLinRespOn)
285  OmegaTot += get_omega_nu(&CP->ONu, 1);
286  message(0, "Radiation is enabled in Hubble(a). "
287  "Following CAMB convention: Omega_Tot - 1 = %g\n", OmegaTot - 1);
288  }
289  message(0, "\n");
290 }
void message(int where, const char *fmt,...)
Definition: endrun.c:175
void endrun(int where, const char *fmt,...)
Definition: endrun.c:147
double get_omega_nu(const _omega_nu *const omnu, const double a)
static Cosmology * CP
Definition: power.c:27
double GravInternal
Definition: cosmology.h:32
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 OmegaK
Definition: cosmology.h:13
double OmegaCDM
Definition: cosmology.h:11
double OmegaLambda
Definition: cosmology.h:14
double OmegaBaryon
Definition: cosmology.h:19
int MassiveNuLinRespOn
Definition: cosmology.h:26
double OmegaG
Definition: cosmology.h:12
_omega_nu ONu
Definition: cosmology.h:24
double Hubble
Definition: cosmology.h:21
double UnitEnergy_in_cgs
Definition: unitsystem.h:13
double UnitMass_in_g
Definition: unitsystem.h:8
double UnitTime_in_s
Definition: unitsystem.h:11
double UnitLength_in_cm
Definition: unitsystem.h:10
double UnitDensity_in_cgs
Definition: unitsystem.h:12
double UnitVelocity_in_cm_per_s
Definition: unitsystem.h:9

References CP, endrun(), get_omega_nu(), Cosmology::GravInternal, Cosmology::Hubble, Cosmology::HubbleParam, Cosmology::MassiveNuLinRespOn, message(), Cosmology::Omega0, Cosmology::Omega_fld, Cosmology::OmegaBaryon, Cosmology::OmegaCDM, Cosmology::OmegaG, Cosmology::OmegaK, Cosmology::OmegaLambda, Cosmology::ONu, Cosmology::RadiationOn, UnitSystem::UnitDensity_in_cgs, UnitSystem::UnitEnergy_in_cgs, UnitSystem::UnitLength_in_cm, UnitSystem::UnitMass_in_g, UnitSystem::UnitTime_in_s, and UnitSystem::UnitVelocity_in_cm_per_s.

Referenced by begrun().

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

◆ F_Omega()

double F_Omega ( Cosmology CP,
double  a 
)

Definition at line 148 of file cosmology.c.

149 {
150  double dD1da=0;
151  double D1 = growth(CP, a, &dD1da);
152  return a / D1 * dD1da;
153 }
static double growth(Cosmology *CP, double a, double *dDda)
Definition: cosmology.c:111

References CP, and growth().

Referenced by displacement_fields(), test_cosmology(), and test_growth_numerical().

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

◆ function_of_k_eval()

double function_of_k_eval ( FunctionOfK fk,
double  k 
)

Definition at line 191 of file cosmology.c.

192 {
193  /* ignore the 0 mode */
194 
195  if(k == 0) return 1;
196 
197  int l = 0;
198  int r = fk->size - 1;
199 
200  while(r - l > 1) {
201  int m = (r + l) / 2;
202  if(k < fk->table[m].k)
203  r = m;
204  else
205  l = m;
206  }
207  double k2 = fk->table[r].k,
208  k1 = fk->table[l].k;
209  double p2 = fk->table[r].Pk,
210  p1 = fk->table[l].Pk;
211 
212  if(l == r) {
213  return fk->table[l].Pk;
214  }
215 
216  if(p1 == 0 || p2 == 0 || k1 == 0 || k2 == 0) {
217  /* if any of the p is zero, use linear interpolation */
218  double p = (k - k1) * p2 + (k2 - k) * p1;
219  p /= (k2 - k1);
220  return p;
221  } else {
222  k = log(k);
223  p1 = log(p1);
224  p2 = log(p2);
225  k1 = log(k1);
226  k2 = log(k2);
227  double p = (k - k1) * p2 + (k2 - k) * p1;
228  p /= (k2 - k1);
229  return exp(p);
230  }
231 }
size_t size
Definition: cosmology.h:38
double k
Definition: cosmology.h:40
double Pk
Definition: cosmology.h:41
struct FunctionOfK::@2 table[]
Definition: power.c:35

References sigma2_params::fk, FunctionOfK::k, FunctionOfK::Pk, FunctionOfK::size, and FunctionOfK::table.

Referenced by sigma2_int().

Here is the caller graph for this function:

◆ function_of_k_normalize_sigma()

void function_of_k_normalize_sigma ( FunctionOfK fk,
double  R,
double  sigma 
)

Definition at line 249 of file cosmology.c.

249  {
250  double old = function_of_k_tophat_sigma(fk, R);
251  size_t i;
252  for(i = 0; i < fk->size; i ++) {
253  fk->table[i].Pk *= sigma / old;
254  };
255 }
double function_of_k_tophat_sigma(FunctionOfK *fk, double R)
Definition: cosmology.c:233
double sigma[3]
Definition: densitykernel.c:97

References sigma2_params::fk, function_of_k_tophat_sigma(), FunctionOfK::Pk, sigma2_params::R, sigma, FunctionOfK::size, and FunctionOfK::table.

Here is the call graph for this function:

◆ function_of_k_tophat_sigma()

double function_of_k_tophat_sigma ( FunctionOfK fk,
double  R 
)

Definition at line 233 of file cosmology.c.

234 {
235  gsl_integration_workspace * w = gsl_integration_workspace_alloc (1000);
236  struct sigma2_params params = {fk, R};
237  double result,abserr;
238  gsl_function F;
239  F.function = &sigma2_int;
240  F.params = &params;
241 
242  /* note: 500/R is here chosen as integration boundary (infinity) */
243  gsl_integration_qags (&F, 0, 500. / R, 0, 1e-4,1000,w,&result, &abserr);
244  // printf("gsl_integration_qng in TopHatSigma2. Result %g, error: %g, intervals: %lu\n",result, abserr,w->size);
245  gsl_integration_workspace_free (w);
246  return sqrt(result);
247 }
static double sigma2_int(double k, void *p)
Definition: cosmology.c:171
FunctionOfK * fk
Definition: cosmology.c:167

References sigma2_params::fk, sigma2_params::R, and sigma2_int().

Referenced by function_of_k_normalize_sigma().

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

◆ GrowthFactor()

double GrowthFactor ( Cosmology CP,
double  astart,
double  aend 
)

Definition at line 82 of file cosmology.c.

83 {
84  return growth(CP, astart, NULL) / growth(CP, aend, NULL);
85 }

References CP, and growth().

Referenced by gravpm_force(), init_powerspectrum(), print_spec(), and test_cosmology().

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

◆ hubble_function()

double hubble_function ( const Cosmology CP,
double  a 
)

Definition at line 58 of file cosmology.c.

59 {
60 
61  double hubble_a;
62 
63  /* first do the terms in SQRT */
64  hubble_a = CP->OmegaLambda;
65 
66  hubble_a += OmegaFLD(CP, a);
67  hubble_a += CP->OmegaK / (a * a);
68  hubble_a += (CP->OmegaCDM + CP->OmegaBaryon) / (a * a * a);
69 
70  if(CP->RadiationOn) {
71  hubble_a += CP->OmegaG / (a * a * a * a);
72  hubble_a += get_omega_nu(&CP->ONu, a);
73  }
74  hubble_a += CP->Omega_ur/(a*a*a*a);
75  /* Now finish it up. */
76  hubble_a = CP->Hubble * sqrt(hubble_a);
77  return (hubble_a);
78 }
static double OmegaFLD(const Cosmology *CP, const double a)
Definition: cosmology.c:158
double Omega_ur
Definition: cosmology.h:18

References CP, get_omega_nu(), Cosmology::Hubble, Cosmology::Omega0, Cosmology::Omega_ur, Cosmology::OmegaBaryon, Cosmology::OmegaCDM, OmegaFLD(), Cosmology::OmegaG, Cosmology::OmegaK, Cosmology::OmegaLambda, Cosmology::ONu, and Cosmology::RadiationOn.

Referenced by atime_integ(), blackhole(), cooling_and_starformation(), displacement_fields(), drift_integ(), fac_integ(), find_timesteps(), fof_save_particles(), fof_write_header(), fslength_int(), get_delta_nu(), get_delta_nu_int(), get_long_range_timestep_dloga(), gravkick_integ(), growth(), growth_ode(), hydro_force(), hydrokick_integ(), init_transfer_table(), kernel(), petaio_read_snapshot(), petaio_save_snapshot(), petaio_write_header(), and test_cosmology().

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

◆ hybrid_nu_tracer()

int hybrid_nu_tracer ( const Cosmology CP,
double  atime 
)

Definition at line 53 of file cosmology.c.

54 {
55  return CP->HybridNeutrinosOn && (atime <= CP->HybridNuPartTime);
56 }
int HybridNeutrinosOn
Definition: cosmology.h:28
double HybridNuPartTime
Definition: cosmology.h:31

References CP, Cosmology::HybridNeutrinosOn, and Cosmology::HybridNuPartTime.

Referenced by run(), runfof(), and runpower().

Here is the caller graph for this function:

◆ init_cosmology()

void init_cosmology ( Cosmology CP,
double  TimeBegin,
const struct UnitSystem  units 
)

Definition at line 15 of file cosmology.c.

16 {
17  CP->Hubble = HUBBLE * units.UnitTime_in_s;
19  CP->GravInternal = GRAVITY / pow(units.UnitLength_in_cm, 3) * units.UnitMass_in_g * pow(units.UnitTime_in_s, 2);
20 
21  /*With slightly relativistic massive neutrinos, for consistency we need to include radiation.
22  * A note on normalisation (as of 08/02/2012):
23  * CAMB appears to set Omega_Lambda + Omega_Matter+Omega_K = 1,
24  * calculating Omega_K in the code and specifying Omega_Lambda and Omega_Matter in the paramfile.
25  * This means that Omega_tot = 1+ Omega_r + Omega_g, effectively
26  * making h0 (very) slightly larger than specified, and the Universe is no longer flat!
27  */
29  CP->OmegaK = 1.0 - CP->Omega0 - CP->OmegaLambda;
30 
31  /* Omega_g = 4 \sigma_B T_{CMB}^4 8 \pi G / (3 c^3 H^2) */
32 
34  * pow(CP->CMBTemperature, 4)
35  * (8 * M_PI * GRAVITY)
36  / (3*pow(LIGHTCGS, 3)*HUBBLE*HUBBLE)
38 
39  init_omega_nu(&CP->ONu, CP->MNu, TimeBegin, CP->HubbleParam, CP->CMBTemperature);
40  /*Initialise the hybrid neutrinos, after Omega_nu*/
43 
44  /* Neutrinos will be included in Omega0, if massive.
45  * This ensures that OmegaCDM contains only non-relativistic species.*/
46  if(CP->MNu[0] + CP->MNu[1] + CP->MNu[2] > 0) {
47  CP->OmegaCDM -= get_omega_nu(&CP->ONu, 1);
48  }
49 }
#define STEFAN_BOLTZMANN
Definition: cosmology.c:11
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 init_omega_nu(_omega_nu *omnu, const double MNu[], const double a0, const double HubbleParam, const double tcmb0)
#define HUBBLE
Definition: physconst.h:25
#define GRAVITY
Definition: physconst.h:5
#define LIGHTCGS
Definition: physconst.h:18
double HybridVcrit
Definition: cosmology.h:29
double CMBTemperature
Definition: cosmology.h:9
double UnitTime_in_s
Definition: cosmology.h:22
double MNu[3]
Definition: cosmology.h:25
_hybrid_nu hybnu

References Cosmology::CMBTemperature, CP, get_omega_nu(), Cosmology::GravInternal, GRAVITY, Cosmology::Hubble, HUBBLE, Cosmology::HubbleParam, _omega_nu::hybnu, Cosmology::HybridNeutrinosOn, Cosmology::HybridNuPartTime, Cosmology::HybridVcrit, init_hybrid_nu(), init_omega_nu(), _omega_nu::kBtnu, LIGHTCGS, Cosmology::MNu, Cosmology::Omega0, Cosmology::OmegaBaryon, Cosmology::OmegaCDM, Cosmology::OmegaG, Cosmology::OmegaK, Cosmology::OmegaLambda, Cosmology::ONu, STEFAN_BOLTZMANN, UnitSystem::UnitLength_in_cm, UnitSystem::UnitMass_in_g, Cosmology::UnitTime_in_s, and UnitSystem::UnitTime_in_s.

Referenced by begrun(), do_density_test(), do_force_test(), main(), setup(), and setup_cosmology().

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