MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
Classes | Macros | Typedefs | Functions | Variables
power.c File Reference
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stddef.h>
#include <mpi.h>
#include <gsl/gsl_integration.h>
#include <gsl/gsl_interp.h>
#include <bigfile-mpi.h>
#include <libgadget/cosmology.h>
#include <libgadget/utils.h>
#include <libgadget/physconst.h>
#include "power.h"
#include "proto.h"
Include dependency graph for power.c:

Go to the source code of this file.

Classes

struct  table
 

Macros

#define NUGGET   1e-30
 
#define MAXCOLS   9
 

Typedefs

typedef void(* _parse_fn) (int i, double k, char *line, struct table *, int *InputInLog10, const double InitTime, int NumCol)
 

Functions

static double Delta_EH (double k)
 
static double Delta_Tabulated (double k, enum TransferType Type)
 
static double sigma2_int (double k, void *params)
 
static double TopHatSigma2 (double R)
 
static double tk_eh (double k)
 
double DeltaSpec (double k, enum TransferType Type)
 
static double get_Tabulated (double k, enum TransferType Type, double oobval)
 
double dlogGrowth (double kmag, enum TransferType Type)
 
static void save_transfer (BigFile *bf, int ncol, struct table *ttable, const char *bname, int ThisTask, const char *colnames[])
 
void save_all_transfer_tables (BigFile *bf, int ThisTask)
 
void parse_power (int i, double k, char *line, struct table *out_tab, int *InputInLog10, const double InitTime, int NumCol)
 
void parse_transfer (int i, double k, char *line, struct table *out_tab, int *InputInLog10, const double InitTime, int NumCol)
 
void read_power_table (int ThisTask, const char *inputfile, const int ncols, struct table *out_tab, const double InitTime, _parse_fn parse_line)
 
int init_transfer_table (int ThisTask, double InitTime, const struct power_params *const ppar)
 
int init_powerspectrum (int ThisTask, double InitTime, double UnitLength_in_cm_in, Cosmology *CPin, struct power_params *ppar)
 

Variables

static double Norm
 
static int WhichSpectrum
 
static double PrimordialIndex
 
static double UnitLength_in_cm
 
static CosmologyCP
 
static struct table power_table
 
static struct table transfer_table
 
static const char * tnames [MAXCOLS] = {"DELTA_BAR", "DELTA_CDM", "DELTA_NU", "DELTA_CB", "VEL_BAR", "VEL_CDM", "VEL_NU", "VEL_CB", "VEL_TOT"}
 

Macro Definition Documentation

◆ MAXCOLS

#define MAXCOLS   9

Definition at line 32 of file power.c.

◆ NUGGET

#define NUGGET   1e-30

Definition at line 31 of file power.c.

Typedef Documentation

◆ _parse_fn

typedef void(* _parse_fn) (int i, double k, char *line, struct table *, int *InputInLog10, const double InitTime, int NumCol)

Definition at line 43 of file power.c.

Function Documentation

◆ Delta_EH()

double Delta_EH ( double  k)
static

Definition at line 432 of file power.c.

433 {
434  return sqrt(k * pow(tk_eh(k), 2)* pow(k, PrimordialIndex - 1.0));
435 }
static double PrimordialIndex
Definition: power.c:25
static double tk_eh(double k)
Definition: power.c:438

References PrimordialIndex, and tk_eh().

Referenced by DeltaSpec().

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

◆ Delta_Tabulated()

double Delta_Tabulated ( double  k,
enum TransferType  Type 
)
static

Definition at line 93 of file power.c.

94 {
95  if(Type >= VEL_BAR && Type <= VEL_TOT)
96  endrun(1, "Velocity Type %d passed to Delta_Tabulated\n", Type);
97 
98  return get_Tabulated(k, Type, 0);
99 }
void endrun(int where, const char *fmt,...)
Definition: endrun.c:147
static double get_Tabulated(double k, enum TransferType Type, double oobval)
Definition: power.c:69
@ VEL_TOT
Definition: power.h:50
@ VEL_BAR
Definition: power.h:46

References endrun(), get_Tabulated(), VEL_BAR, and VEL_TOT.

Referenced by DeltaSpec().

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

◆ DeltaSpec()

double DeltaSpec ( double  k,
enum TransferType  Type 
)

Definition at line 52 of file power.c.

53 {
54  double power;
55 
56  if(WhichSpectrum == 2)
57  power = Delta_Tabulated(k, Type);
58  else
59  power = Delta_EH(k);
60 
61  /*Normalise the power spectrum*/
62  power *= Norm;
63 
64  return power;
65 }
static int WhichSpectrum
Definition: power.c:23
static double Delta_Tabulated(double k, enum TransferType Type)
Definition: power.c:93
static double Delta_EH(double k)
Definition: power.c:432
static double Norm
Definition: power.c:22

References Delta_EH(), Delta_Tabulated(), Norm, and WhichSpectrum.

Referenced by density_transfer(), disp_transfer(), print_spec(), sigma2_int(), test_growth_numerical(), test_read_no_rescale(), and test_read_rescale_sigma8().

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

◆ dlogGrowth()

double dlogGrowth ( double  kmag,
enum TransferType  Type 
)

Definition at line 101 of file power.c.

102 {
103  /*Default to total growth: type 3 is cdm + baryons.*/
104  if(Type < DELTA_BAR || Type > DELTA_CB)
105  Type = VEL_TOT;
106  else
107  /*Type should be an offset from the first velocity*/
108  Type = (enum TransferType) ((int) VEL_BAR + ((int) Type - (int) DELTA_BAR));
109  return get_Tabulated(kmag, Type, 1);
110 }
TransferType
Definition: power.h:41
@ DELTA_CB
Definition: power.h:45
@ DELTA_BAR
Definition: power.h:42

References DELTA_BAR, DELTA_CB, get_Tabulated(), VEL_BAR, and VEL_TOT.

Referenced by disp_transfer(), and test_growth_numerical().

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

◆ get_Tabulated()

static double get_Tabulated ( double  k,
enum TransferType  Type,
double  oobval 
)
static

Definition at line 69 of file power.c.

70 {
71  /*Convert k to Mpc/h*/
72  const double scale = (CM_PER_MPC / UnitLength_in_cm);
73  const double logk = log10(k*scale);
74 
75  if(logk < power_table.logk[0] || logk > power_table.logk[power_table.Nentry - 1])
76  return oobval;
77 
78  double logD = gsl_interp_eval(power_table.mat_intp[0], power_table.logk, power_table.logD[0], logk, NULL);
79  double trans = 1;
80  /*Transfer table stores (T_type(k) / T_tot(k))*/
81  if(transfer_table.Nentry > 0)
82  if(Type >= DELTA_BAR && Type < DELTA_TOT)
83  trans = gsl_interp_eval(transfer_table.mat_intp[Type], transfer_table.logk, transfer_table.logD[Type], logk, NULL);
84 
85  /*Convert delta from (Mpc/h)^3/2 to kpc/h^3/2*/
86  logD += 1.5 * log10(scale);
87  double delta = (pow(10.0, logD)-NUGGET) * trans;
88  if(!isfinite(delta))
89  endrun(1,"infinite delta or growth: %g for k = %g, Type = %d (tk = %g, logD = %g)\n",delta, k, Type, trans, logD);
90  return delta;
91 }
#define CM_PER_MPC
Definition: physconst.h:20
static struct table power_table
Definition: power.c:46
static struct table transfer_table
Definition: power.c:48
#define NUGGET
Definition: power.c:31
static double UnitLength_in_cm
Definition: power.c:26
@ DELTA_TOT
Definition: power.h:52
int Nentry
Definition: power.c:36
double * logD[MAXCOLS]
Definition: power.c:38
double * logk
Definition: power.c:37
gsl_interp * mat_intp[MAXCOLS]
Definition: power.c:39

References CM_PER_MPC, DELTA_BAR, DELTA_TOT, endrun(), table::logD, table::logk, table::mat_intp, table::Nentry, NUGGET, power_table, transfer_table, and UnitLength_in_cm.

Referenced by Delta_Tabulated(), and dlogGrowth().

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

◆ init_powerspectrum()

int init_powerspectrum ( int  ThisTask,
double  InitTime,
double  UnitLength_in_cm_in,
Cosmology CPin,
struct power_params ppar 
)

Definition at line 394 of file power.c.

395 {
397  /*Used only for tk_eh*/
399  UnitLength_in_cm = UnitLength_in_cm_in;
400  CP = CPin;
401 
402  if(ppar->WhichSpectrum == 2) {
404  /*Initialise the interpolation*/
407  if(ppar->DifferentTransferFunctions || ppar->ScaleDepVelocity) {
408  init_transfer_table(ThisTask, InitTime, ppar);
409  }
410  }
411 
412  Norm = 1.0;
413  if(ppar->InputPowerRedshift >= 0 || ppar->Sigma8 > 0) {
414  const double R8 = 8 * (CM_PER_MPC / UnitLength_in_cm); /* 8 Mpc/h */
415  if(ppar->Sigma8 > 0) {
416  double res = TopHatSigma2(R8);
417  if(isfinite(res) && res > 0)
418  Norm = ppar->Sigma8 / sqrt(res);
419  else
420  endrun(1, "Could not normalize P(k) to Sigma8=%g! Measured Sigma8^2 is %g\n", ppar->Sigma8, res);
421  }
422  double Dplus = GrowthFactor(CP, InitTime, 1/(1+ppar->InputPowerRedshift));
423  if(ppar->InputPowerRedshift >= 0) {
424  Norm *= Dplus;
425  message(0,"Growth factor from z=%g (InputPowerRedshift) to z=%g (Init): %g \n", ppar->InputPowerRedshift, 1. / InitTime - 1, Dplus);
426  }
427  message(0, "Normalization adjusted to Sigma8=%g (at z=0) (Normfac=%g). \n", sqrt(TopHatSigma2(R8))/Dplus, Norm);
428  }
429  return power_table.Nentry;
430 }
double GrowthFactor(Cosmology *CP, double astart, double aend)
Definition: cosmology.c:82
void message(int where, const char *fmt,...)
Definition: endrun.c:175
int init_transfer_table(int ThisTask, double InitTime, const struct power_params *const ppar)
Definition: power.c:322
void read_power_table(int ThisTask, const char *inputfile, const int ncols, struct table *out_tab, const double InitTime, _parse_fn parse_line)
Definition: power.c:238
static Cosmology * CP
Definition: power.c:27
void parse_power(int i, double k, char *line, struct table *out_tab, int *InputInLog10, const double InitTime, int NumCol)
Definition: power.c:158
static double TopHatSigma2(double R)
Definition: power.c:470
int ScaleDepVelocity
Definition: power.h:11
int DifferentTransferFunctions
Definition: power.h:10
double PrimordialIndex
Definition: power.h:16
int WhichSpectrum
Definition: power.h:9
double Sigma8
Definition: power.h:14
char * FileWithInputSpectrum
Definition: power.h:13
double InputPowerRedshift
Definition: power.h:15
int ThisTask
Definition: test_exchange.c:23

References CM_PER_MPC, CP, power_params::DifferentTransferFunctions, endrun(), power_params::FileWithInputSpectrum, GrowthFactor(), init_transfer_table(), power_params::InputPowerRedshift, table::logD, table::logk, table::mat_intp, message(), table::Nentry, Norm, parse_power(), power_table, PrimordialIndex, power_params::PrimordialIndex, read_power_table(), power_params::ScaleDepVelocity, power_params::Sigma8, ThisTask, TopHatSigma2(), transfer_table, UnitLength_in_cm, WhichSpectrum, and power_params::WhichSpectrum.

Referenced by main(), test_growth_numerical(), test_read_no_rescale(), and test_read_rescale_sigma8().

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

◆ init_transfer_table()

int init_transfer_table ( int  ThisTask,
double  InitTime,
const struct power_params *const  ppar 
)

Definition at line 322 of file power.c.

323 {
324  int i, t;
325  const int nnu = (CP->MNu[0] > 0) + (CP->MNu[1] > 0) + (CP->MNu[2] > 0);
326  if(strlen(ppar->FileWithTransferFunction) > 0) {
328  }
329  if(transfer_table.Nentry == 0) {
330  endrun(1, "Could not read transfer table at: '%s'\n",ppar->FileWithTransferFunction);
331  }
332  /*Normalise the transfer functions.*/
333 
334  /*Now normalise the velocity transfer functions: divide by a * hubble, where hubble is the hubble function in Mpc^-1, so H0/c*/
335  const double fac = InitTime * hubble_function(CP, InitTime)/CP->Hubble * 100 * CP->HubbleParam/(LIGHTCGS / 1e5);
336  const double onu = get_omega_nu(&CP->ONu, InitTime)*pow(InitTime,3);
337  double meangrowth[VEL_TOT-VEL_BAR+1] = {0};
338  /* At this point the transfer table contains: (3,4,5) t_b, 0.5 * h_prime, t_ncdm.
339  * After, if t_cdm = 0.5 h_prime / (a H(a) / H0 /c) we need:
340  * (t_b + t_cdm) / d_b, t_cdm/d_cdm, (t_ncdm + t_cdm) / d_ncdm*/
341  for(i=0; i< transfer_table.Nentry; i++) {
342  /* Now row 4 is t_cdm*/
343  transfer_table.logD[VEL_CDM][i] /= fac;
346 
347  /*Set up the CDM + baryon rows*/
350  /*total growth and delta: start as CDM + baryon and then add nu if needed.*/
352  double T_tot = transfer_table.logD[DELTA_CB][i];
353  /*Normalise the cb rows*/
354  double Omega0a3 = CP->OmegaBaryon + CP->OmegaCDM;
355  transfer_table.logD[DELTA_CB][i] /= Omega0a3;
356  transfer_table.logD[VEL_CB][i] /= Omega0a3;
357  /*Total matter density in T_tot. Neutrinos may be slightly relativistic, so
358  * Omega0a3 >= CP->Omega0 if neutrinos are massive.*/
359  if(nnu > 0) {
360  /*Add neutrino growth to total growth*/
362  T_tot += onu * transfer_table.logD[DELTA_NU][i];
363  Omega0a3 += onu;
364  }
365  /*Normalise the totals now we have neutrinos*/
366  transfer_table.logD[VEL_TOT][i] /= Omega0a3;
367  T_tot /= Omega0a3;
368  /*Normalize growth_i and delta_i by delta_tot */
369  for(t = DELTA_BAR; t <= VEL_TOT; t++) {
370  transfer_table.logD[t][i] /= T_tot;
371  }
372  }
373 
374  /*Now compute mean growths*/
375  for(t = VEL_BAR; t <= VEL_TOT; t++) {
376  int nmean=0;
377  for(i=0; i< transfer_table.Nentry; i++)
378  if(transfer_table.logk[i] > power_table.logk[0]) {
379  meangrowth[t-VEL_BAR] += transfer_table.logD[t][i];
380  nmean++;
381  }
382  if(nmean > 0)
383  meangrowth[t-VEL_BAR]/= nmean;
384  }
385  /*Initialise the interpolation*/
386  for(t = 0; t < MAXCOLS; t++)
388 
389  message(0,"Scale-dependent growth calculated. Mean = %g %g %g %g %g\n",meangrowth[0], meangrowth[1], meangrowth[2], meangrowth[3], meangrowth[4]);
390  message(0, "Power spectrum rows: %d, Transfer: %d (%g -> %g)\n", power_table.Nentry, transfer_table.Nentry, transfer_table.logD[DELTA_BAR][0],transfer_table.logD[DELTA_BAR][transfer_table.Nentry-1]);
391  return transfer_table.Nentry;
392 }
double hubble_function(const Cosmology *CP, double a)
Definition: cosmology.c:58
double get_omega_nu(const _omega_nu *const omnu, const double a)
#define LIGHTCGS
Definition: physconst.h:18
#define MAXCOLS
Definition: power.c:32
void parse_transfer(int i, double k, char *line, struct table *out_tab, int *InputInLog10, const double InitTime, int NumCol)
Definition: power.c:180
@ VEL_CB
Definition: power.h:49
@ DELTA_CDM
Definition: power.h:43
@ VEL_CDM
Definition: power.h:47
@ DELTA_NU
Definition: power.h:44
@ VEL_NU
Definition: power.h:48
double HubbleParam
Definition: cosmology.h:20
double OmegaCDM
Definition: cosmology.h:11
double OmegaBaryon
Definition: cosmology.h:19
double MNu[3]
Definition: cosmology.h:25
_omega_nu ONu
Definition: cosmology.h:24
double Hubble
Definition: cosmology.h:21
char * FileWithTransferFunction
Definition: power.h:12

References CP, DELTA_BAR, DELTA_CB, DELTA_CDM, DELTA_NU, endrun(), power_params::FileWithTransferFunction, get_omega_nu(), Cosmology::Hubble, hubble_function(), Cosmology::HubbleParam, LIGHTCGS, table::logD, table::logk, table::mat_intp, MAXCOLS, message(), Cosmology::MNu, table::Nentry, Cosmology::OmegaBaryon, Cosmology::OmegaCDM, Cosmology::ONu, parse_transfer(), power_table, read_power_table(), ThisTask, transfer_table, VEL_BAR, VEL_CB, VEL_CDM, VEL_NU, and VEL_TOT.

Referenced by init_powerspectrum().

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

◆ parse_power()

void parse_power ( int  i,
double  k,
char *  line,
struct table out_tab,
int *  InputInLog10,
const double  InitTime,
int  NumCol 
)

Definition at line 158 of file power.c.

159 {
160  char * retval;
161  if((*InputInLog10) == 0) {
162  if(k < 0) {
163  message(1, "some input k is negative, guessing the file is in log10 units\n");
164  *InputInLog10 = 1;
165  }
166  else
167  k = log10(k);
168  }
169  out_tab->logk[i] = k;
170  retval = strtok(NULL, " \t");
171  if(!retval)
172  endrun(1,"Incomplete line in power spectrum: %s\n",line);
173  double p = atof(retval);
174  if ((*InputInLog10) == 0)
175  p = log10(p+NUGGET);
176  /*Store delta, square root of power*/
177  out_tab->logD[0][i] = p/2;
178 }

References endrun(), table::logD, table::logk, message(), and NUGGET.

Referenced by init_powerspectrum().

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

◆ parse_transfer()

void parse_transfer ( int  i,
double  k,
char *  line,
struct table out_tab,
int *  InputInLog10,
const double  InitTime,
int  NumCol 
)

Definition at line 180 of file power.c.

181 {
182  int j;
183  int ncols = NumCol - 1; /* The first column k is already read in read_power_table. */
184  int nnu = round((ncols - 15)/2);
185  double * transfers = (double *) mymalloc("transfers", sizeof(double) * ncols);
186  k = log10(k);
187  out_tab->logk[i] = k;
188  /* Note: the ncdm entries change depending on the number of neutrino species. The first row, k,
189  * is read in read_power_table and passed as a parameter.
190  * but only the first is used for particles.
191  * 1:k (h/Mpc) 2:d_g 3:d_b 4:d_cdm 5:d_ur
192  * 6:d_ncdm[0] 7:d_ncdm[1] 8:d_ncdm[2] 9:d_tot 10:phi
193  * 11:psi 12:h 13:h_prime 14:eta 15:eta_prime
194  * 16:t_g 17:t_b 18:t_ur
195  * 19:t_ncdm[0] 20:t_ncdm[1] 21:t_ncdm[2] 22:t_tot*/
196  for(j = 0; j< ncols; j++) {
197  char * retval = strtok(NULL, " \t");
198  /*This happens if we do not have as many neutrino species as we expect, or we don't find h_prime.*/
199  if(!retval)
200  endrun(1,"Incomplete line in power spectrum: only %d columns, expecting %d. Did you remember to set extra metric transfer functions=y?\n",j, ncols);
201  transfers[j] = atof(retval);
202  }
203  /*Order of the transfer table matches the particle types:
204  * 0 is baryons, 1 is CDM, 2 is massive neutrinos (we use the most massive neutrino species).
205  * 3 is growth function for baryons, 4 is growth function for CDM, 5 is growth function for massive neutrinos.
206  * We use the formulae for velocities from fastpm in synchronous gauge:
207  * https://github.com/rainwoodman/fastpm-python/blob/02ce2ff87897f713c7b9204630f4e0257d703784/fastpm/multi.py#L185
208  * CDM = - h_prime / 2 / d_cdm
209  * bar = - (h_prime / 2 + t_b) / d_b
210  * nu = - (h_prime / 2 + t_ncdm) / d_ncdm
211  * and there is a normalisation factor of (1+z)/ hubble applied later on.
212  *
213  * See http://adsabs.harvard.edu/abs/1995ApJ...455....7M
214  * Eq. 42 (cdm), not using 49(ur), eq. 66 (baryons, and ncdm, truncation at the same order as baryon).
215  * These are in CLASS units: they are converted to Gadget units in init_transfer_table().
216  * */
217  out_tab->logD[DELTA_BAR][i] = -1*transfers[1];
218  out_tab->logD[DELTA_CDM][i] = -1*transfers[2];
219  /*This should be the weighted average sum of the three neutrino species*/
220  const _omega_nu * Onu = &CP->ONu;
221  out_tab->logD[DELTA_NU][i] = 0;
222  for(j=0; j < nnu; j++)
223  out_tab->logD[DELTA_NU][i] = -1*transfers[4+j] * omega_nu_single(Onu, InitTime, j);
224  const double onu = get_omega_nu(&CP->ONu, InitTime);
225  /*Should be weighted by omega_nu*/
226  out_tab->logD[DELTA_NU][i] /= onu;
227  /*h_prime is entry 8 + nnu. t_b is 12 + nnu, t_ncdm[2] is 13 + nnu * 2.*/
228  out_tab->logD[VEL_BAR][i] = transfers[12+nnu];
229  out_tab->logD[VEL_CDM][i] = transfers[8+nnu] * 0.5;
230  out_tab->logD[VEL_NU][i] = 0;
231  for(j=0; j < nnu; j++)
232  out_tab->logD[VEL_NU][i] = transfers[13 + nnu + j] * omega_nu_single(Onu, InitTime, j);
233  /*Should be weighted by omega_nu*/
234  out_tab->logD[VEL_NU][i] /= onu;
235  myfree(transfers);
236 }
#define mymalloc(name, size)
Definition: mymalloc.h:15
#define myfree(x)
Definition: mymalloc.h:19
double omega_nu_single(const _omega_nu *const omnu, const double a, int i)

References CP, DELTA_BAR, DELTA_CDM, DELTA_NU, endrun(), get_omega_nu(), table::logD, table::logk, myfree, mymalloc, omega_nu_single(), Cosmology::ONu, VEL_BAR, VEL_CDM, and VEL_NU.

Referenced by init_transfer_table().

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

◆ read_power_table()

void read_power_table ( int  ThisTask,
const char *  inputfile,
const int  ncols,
struct table out_tab,
const double  InitTime,
_parse_fn  parse_line 
)

Definition at line 238 of file power.c.

239 {
240  FILE *fd = NULL;
241  int j;
242  int InputInLog10 = 0;
243 
244  if(ThisTask == 0) {
245  if(!(fd = fopen(inputfile, "r")))
246  endrun(1, "can't read input spectrum in file '%s' on task %d\n", inputfile, ThisTask);
247 
248  out_tab->Nentry = 0;
249  do
250  {
251  char buffer[1024];
252  char * retval = fgets(buffer, 1024, fd);
253  /*Happens on end of file*/
254  if(!retval)
255  break;
256  retval = strtok(buffer, " \t");
257  if(!retval || retval[0] == '#')
258  continue;
259  out_tab->Nentry++;
260  }
261  while(1);
262  rewind(fd);
263  }
264  MPI_Bcast(&(out_tab->Nentry), 1, MPI_INT, 0, MPI_COMM_WORLD);
265 
266  if(out_tab->Nentry < 2)
267  endrun(1, "Input spectrum too short\n");
268  out_tab->logk = (double *) mymalloc("Powertable", (ncols+1)*out_tab->Nentry * sizeof(double));
269  for(j=0; j<ncols; j++)
270  out_tab->logD[j] = out_tab->logk + (j+1)*out_tab->Nentry;
271 
272  if(ThisTask == 0)
273  {
274  /* detect the columns of the input file */
275  char line1[1024];
276 
277  while(fgets(line1,1024,fd))
278  {
279  char * content = strtok(line1, " \t");
280  if(content[0] != '#') /*Find the first line*/
281  break;
282  }
283  int Ncolumns = 0;
284  char *c;
285  do
286  {
287  Ncolumns++;
288  c = strtok(NULL," \t");
289  }
290  while(c != NULL);
291 
292  rewind(fd);
293  message(0, "Detected %d columns in file '%s'. \n", Ncolumns, inputfile);
294 
295  int i = 0;
296  do
297  {
298  char buffer[1024];
299  char * line = fgets(buffer, 1024, fd);
300  /*Happens on end of file*/
301  if(!line)
302  break;
303  char * retval = strtok(line, " \t");
304  if(!retval || retval[0] == '#')
305  continue;
306  double k = atof(retval);
307  parse_line(i, k, line, out_tab, &InputInLog10, InitTime, Ncolumns);
308  i++;
309  }
310  while(1);
311 
312  fclose(fd);
313  }
314 
315  MPI_Bcast(out_tab->logk, (ncols+1)*out_tab->Nentry, MPI_DOUBLE, 0, MPI_COMM_WORLD);
316  for(j=0; j<ncols; j++) {
317  out_tab->mat_intp[j] = gsl_interp_alloc(gsl_interp_cspline,out_tab->Nentry);
318  }
319 }

References endrun(), table::logD, table::logk, table::mat_intp, message(), mymalloc, table::Nentry, and ThisTask.

Referenced by init_powerspectrum(), and init_transfer_table().

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

◆ save_all_transfer_tables()

void save_all_transfer_tables ( BigFile *  bf,
int  ThisTask 
)

Definition at line 150 of file power.c.

151 {
152  const char * pname = "DELTA_MAT";
153  save_transfer(bf, 1, &power_table, "ICPower", ThisTask, &pname);
154  save_transfer(bf, MAXCOLS, &transfer_table, "ICTransfers", ThisTask, tnames);
155 }
static const char * tnames[MAXCOLS]
Definition: power.c:50
static void save_transfer(BigFile *bf, int ncol, struct table *ttable, const char *bname, int ThisTask, const char *colnames[])
Definition: power.c:113

References MAXCOLS, power_table, save_transfer(), ThisTask, tnames, and transfer_table.

Referenced by main().

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

◆ save_transfer()

static void save_transfer ( BigFile *  bf,
int  ncol,
struct table ttable,
const char *  bname,
int  ThisTask,
const char *  colnames[] 
)
static

Definition at line 113 of file power.c.

114 {
115  BigBlock btransfer;
116  int i;
117  if(0 != big_file_mpi_create_block(bf, &btransfer, bname, NULL, 0, 0, 0, MPI_COMM_WORLD)) {
118  endrun(0, "failed to create block %s:%s", bname,
119  big_file_get_error_message());
120  }
121 
122  if ( (0 != big_block_set_attr(&btransfer, "Nentry", &(ttable->Nentry), "u8", 1)) ) {
123  endrun(0, "Failed to write table size %s\n",
124  big_file_get_error_message());
125  }
126  if(0 != big_block_mpi_close(&btransfer, MPI_COMM_WORLD)) {
127  endrun(0, "Failed to close block %s\n",
128  big_file_get_error_message());
129  }
130  size_t dims[2] = {0 , 1};
131  /*The transfer state is shared between all processors,
132  *so only write on master task*/
133  if(ThisTask == 0) {
134  dims[0] = ttable->Nentry;
135  }
136 
137  char buf[100];
138  snprintf(buf, 100, "%s/logk", bname);
139 
140  _bigfile_utils_create_block_from_c_array(bf, ttable->logk, buf, "f8", dims, sizeof(double), 1, 1, MPI_COMM_WORLD);
141 
142  for(i = 0; i < ncol; i++)
143  {
144  snprintf(buf, 100, "%s/%s", bname, colnames[i]);
145  _bigfile_utils_create_block_from_c_array(bf, ttable->logD[i], buf, "f8", dims, sizeof(double), 1, 1, MPI_COMM_WORLD);
146  }
147 }
void _bigfile_utils_create_block_from_c_array(BigFile *bf, void *baseptr, const char *name, const char *dtype, size_t dims[], ptrdiff_t elsize, int NumFiles, int NumWriters, MPI_Comm comm)
Definition: save.c:18

References _bigfile_utils_create_block_from_c_array(), endrun(), table::logD, table::logk, table::Nentry, and ThisTask.

Referenced by save_all_transfer_tables().

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

◆ sigma2_int()

double sigma2_int ( double  k,
void *  params 
)
static

Definition at line 486 of file power.c.

487 {
488  double w, x;
489 
490  double r_tophat = *(double *) params;
491  const double kr = r_tophat * k;
492  const double kr2 = kr * kr;
493 
494  /*Series expansion; actually good until kr~1*/
495  if(kr < 1e-3)
496  w = 1./3. - kr2/30. +kr2*kr2/840.;
497  else
498  w = 3 * (sin(kr) / kr - cos(kr)) / kr2;
499  x = 4 * M_PI / (2 * M_PI * 2 * M_PI * 2 * M_PI) * k * k * w * w * pow(DeltaSpec(k, DELTA_TOT),2);
500 
501  return x;
502 
503 }
double DeltaSpec(double k, enum TransferType Type)
Definition: power.c:52

References DELTA_TOT, and DeltaSpec().

Referenced by TopHatSigma2().

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

◆ tk_eh()

double tk_eh ( double  k)
static

Definition at line 438 of file power.c.

439 {
440  double q, theta, ommh2, a, s, gamma, L0, C0;
441  double tmp;
442  double omegam, ombh2, hubble;
443 
444  /* other input parameters */
445  hubble = CP->HubbleParam;
446 
447  omegam = CP->Omega0;
448  ombh2 = CP->OmegaBaryon * CP->HubbleParam * CP->HubbleParam;
449 
450  if(CP->OmegaBaryon == 0)
451  ombh2 = 0.044 * CP->HubbleParam * CP->HubbleParam;
452 
453  k *= (CM_PER_MPC / UnitLength_in_cm); /* convert to h/Mpc */
454 
455  theta = 2.728 / 2.7;
456  ommh2 = omegam * hubble * hubble;
457  s = 44.5 * log(9.83 / ommh2) / sqrt(1. + 10. * exp(0.75 * log(ombh2))) * hubble;
458  a = 1. - 0.328 * log(431. * ommh2) * ombh2 / ommh2
459  + 0.380 * log(22.3 * ommh2) * (ombh2 / ommh2) * (ombh2 / ommh2);
460  gamma = a + (1. - a) / (1. + exp(4 * log(0.43 * k * s)));
461  gamma *= omegam * hubble;
462  q = k * theta * theta / gamma;
463  L0 = log(2. * exp(1.) + 1.8 * q);
464  C0 = 14.2 + 731. / (1. + 62.5 * q);
465  tmp = L0 / (L0 + C0 * q * q);
466  return (tmp);
467 }
double Omega0
Definition: cosmology.h:10

References CM_PER_MPC, CP, Cosmology::HubbleParam, Cosmology::Omega0, Cosmology::OmegaBaryon, and UnitLength_in_cm.

Referenced by Delta_EH().

Here is the caller graph for this function:

◆ TopHatSigma2()

double TopHatSigma2 ( double  R)
static

Definition at line 470 of file power.c.

471 {
472  gsl_integration_workspace * w = gsl_integration_workspace_alloc (1000);
473  double result,abserr;
474  gsl_function F;
475  F.function = &sigma2_int;
476  F.params = &R;
477 
478  /* note: 500/R is here chosen as integration boundary (infinity) */
479  gsl_integration_qags (&F, 0, 500. / R, 0, 1e-4,1000,w,&result, &abserr);
480 /* printf("gsl_integration_qng in TopHatSigma2. Result %g, error: %g, intervals: %lu\n",result, abserr,w->size); */
481  gsl_integration_workspace_free (w);
482  return result;
483 }
static double sigma2_int(double k, void *params)
Definition: power.c:486

References sigma2_int().

Referenced by init_powerspectrum().

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

Variable Documentation

◆ CP

Cosmology* CP
static

Definition at line 27 of file power.c.

Referenced by apply_half_kick(), apply_PM_half_kick(), atime_integ(), atime_to_myr(), blackhole(), blackhole_accretion_postprocess(), check_density_entropy(), check_omega(), check_units(), compute_mass(), cooling_and_starformation(), delta_nu_from_power(), density(), displacement_fields(), do_density_test(), do_force_test(), do_heiii_reionization(), drift_all_particles(), drift_integ(), dump_snapshot(), exact_drift_factor(), F_Omega(), find_timesteps(), fof_save_groups(), fof_save_particles(), fof_write_header(), force_tree_build(), fslength(), fslength_int(), get_delta_nu(), get_delta_nu_combined(), get_exact_drift_factor(), get_exact_factor(), get_exact_gravkick_factor(), get_exact_hydrokick_factor(), get_long_range_timestep_dloga(), get_PM_timestep_ti(), gravkick_integ(), gravpm_force(), growth(), growth_ode(), GrowthFactor(), hubble_function(), hybrid_nu_tracer(), hydro_force(), hydrokick_integ(), init(), init_cooling(), init_cooling_and_star_formation(), init_cooling_rates(), init_cosmology(), init_powerspectrum(), init_transfer_table(), kernel(), lightcone_compute(), lightcone_init(), lightcone_init_entry(), main(), metal_return(), metal_return_init(), OmegaFLD(), parse_transfer(), petaio_read_header_internal(), petaio_read_snapshot(), petaio_save_snapshot(), petaio_write_header(), print_spec(), read_parameterfile(), run_gravity_test(), saveheader(), setup_cosmology(), setup_density_indep_entropy(), setup_smoothinglengths(), test_cosmology(), test_DoCooling(), test_drift_factor(), test_fslength(), test_growth_numerical(), test_heatingcooling_rate(), test_rate_network(), test_read_no_rescale(), test_read_rescale_sigma8(), test_recomb_rates(), test_uvbg_loader(), tk_eh(), turn_on_quasars(), and write_checkpoint().

◆ Norm

double Norm
static

Definition at line 22 of file power.c.

Referenced by DeltaSpec(), and init_powerspectrum().

◆ power_table

struct table power_table
static

◆ PrimordialIndex

double PrimordialIndex
static

Definition at line 25 of file power.c.

Referenced by Delta_EH(), and init_powerspectrum().

◆ tnames

const char* tnames[MAXCOLS] = {"DELTA_BAR", "DELTA_CDM", "DELTA_NU", "DELTA_CB", "VEL_BAR", "VEL_CDM", "VEL_NU", "VEL_CB", "VEL_TOT"}
static

Definition at line 50 of file power.c.

Referenced by save_all_transfer_tables().

◆ transfer_table

struct table transfer_table
static

◆ UnitLength_in_cm

double UnitLength_in_cm
static

◆ WhichSpectrum

int WhichSpectrum
static

Definition at line 23 of file power.c.

Referenced by DeltaSpec(), and init_powerspectrum().