CLASS MANUAL
spectra.c File Reference
#include "spectra.h"
+ Include dependency graph for spectra.c:

Functions

int spectra_cl_at_l (struct spectra *psp, double l, double *cl_tot, double **cl_md, double **cl_md_ic)
 
int spectra_pk_at_z (struct background *pba, struct spectra *psp, enum linear_or_logarithmic mode, double z, double *output_tot, double *output_ic)
 
int spectra_pk_at_k_and_z (struct background *pba, struct primordial *ppm, struct spectra *psp, double k, double z, double *pk_tot, double *pk_ic)
 
int spectra_pk_nl_at_z (struct background *pba, struct spectra *psp, enum linear_or_logarithmic mode, double z, double *output_tot)
 
int spectra_pk_nl_at_k_and_z (struct background *pba, struct primordial *ppm, struct spectra *psp, double k, double z, double *pk_tot)
 
int spectra_tk_at_z (struct background *pba, struct spectra *psp, double z, double *output)
 
int spectra_tk_at_k_and_z (struct background *pba, struct spectra *psp, double k, double z, double *output)
 
int spectra_init (struct precision *ppr, struct background *pba, struct perturbs *ppt, struct primordial *ppm, struct nonlinear *pnl, struct transfers *ptr, struct spectra *psp)
 
int spectra_free (struct spectra *psp)
 
int spectra_indices (struct background *pba, struct perturbs *ppt, struct transfers *ptr, struct primordial *ppm, struct spectra *psp)
 
int spectra_cls (struct background *pba, struct perturbs *ppt, struct transfers *ptr, struct primordial *ppm, struct spectra *psp)
 
int spectra_compute_cl (struct background *pba, struct perturbs *ppt, struct transfers *ptr, struct primordial *ppm, struct spectra *psp, int index_md, int index_ic1, int index_ic2, int index_l, int cl_integrand_num_columns, double *cl_integrand, double *primordial_pk, double *transfer_ic1, double *transfer_ic2)
 
int spectra_k_and_tau (struct background *pba, struct perturbs *ppt, struct spectra *psp)
 
int spectra_pk (struct background *pba, struct perturbs *ppt, struct primordial *ppm, struct nonlinear *pnl, struct spectra *psp)
 
int spectra_sigma (struct background *pba, struct primordial *ppm, struct spectra *psp, double R, double z, double *sigma)
 
int spectra_matter_transfers (struct background *pba, struct perturbs *ppt, struct spectra *psp)
 
int spectra_output_tk_data (struct background *pba, struct perturbs *ppt, struct spectra *psp, enum file_format output_format, double z, int number_of_titles, double *data)
 

Detailed Description

Documented spectra module

Julien Lesgourgues, 25.08.2010

This module computes the anisotropy and Fourier power spectra $ C_l^{X}, P(k), ... $'s given the transfer and Bessel functions (for anisotropy spectra), the source functions (for Fourier spectra) and the primordial spectra.

The following functions can be called from other modules:

  1. spectra_init() at the beginning (but after transfer_init())
  2. spectra_cl_at_l() at any time for computing $ C_l $ at any l
  3. spectra_spectrum_at_z() at any time for computing P(k) at any z
  4. spectra_spectrum_at_k_and z() at any time for computing P at any k and z
  5. spectra_free() at the end

Function Documentation

int spectra_cl_at_l ( struct spectra psp,
double  l,
double *  cl_tot,
double **  cl_md,
double **  cl_md_ic 
)

Anisotropy power spectra $ C_l$'s for all types, modes and initial conditions.

This routine evaluates all the $C_l$'s at a given value of l by interpolating in the pre-computed table. When relevant, it also sums over all initial conditions for each mode, and over all modes.

This function can be called from whatever module at whatever time, provided that spectra_init() has been called before, and spectra_free() has not been called yet.

Parameters
pspInput: pointer to spectra structure (containing pre-computed table)
lInput: multipole number
cl_totOutput: total $C_l$'s for all types (TT, TE, EE, etc..)
cl_mdOutput: $C_l$'s for all types (TT, TE, EE, etc..) decomposed mode by mode (scalar, tensor, ...) when relevant
cl_md_icOutput: $C_l$'s for all types (TT, TE, EE, etc..) decomposed by pairs of initial conditions (adiabatic, isocurvatures) for each mode (usually, only for the scalar mode) when relevant
Returns
the error status

Summary:

  • define local variables
  • (a) treat case in which there is only one mode and one initial condition. Then, only cl_tot needs to be filled.
  • (b) treat case in which there is only one mode with several initial condition. Fill cl_md_ic[index_md=0] and sum it to get cl_tot.
  • (c) loop over modes
  • –> (c.1.) treat case in which the mode under consideration has only one initial condition. Fill cl_md[index_md].
  • –> (c.2.) treat case in which the mode under consideration has several initial conditions. Fill cl_md_ic[index_md] and sum it to get cl_md[index_md]
  • –> (c.3.) add contribution of cl_md[index_md] to cl_tot

+ Here is the caller graph for this function:

int spectra_pk_at_z ( struct background pba,
struct spectra psp,
enum linear_or_logarithmic  mode,
double  z,
double *  output_tot,
double *  output_ic 
)

Matter power spectrum for arbitrary redshift and for all initial conditions.

This routine evaluates the matter power spectrum at a given value of z by interpolating in the pre-computed table (if several values of z have been stored) or by directly reading it (if it only contains values at z=0 and we want P(k,z=0))

Can be called in two modes: linear or logarithmic.

  • linear: returns P(k) (units: $ Mpc^3$)
  • logarithmic: returns $\ln{P(k)}$

One little subtlety: in case of several correlated initial conditions, the cross-correlation spectrum can be negative. Then, in logarithmic mode, the non-diagonal elements contain the cross-correlation angle $ P_{12}/\sqrt{P_{11} P_{22}}$ (from -1 to 1) instead of $\ln{P_{12}}$

This function can be called from whatever module at whatever time, provided that spectra_init() has been called before, and spectra_free() has not been called yet.

Parameters
pbaInput: pointer to background structure (used for converting z into tau)
pspInput: pointer to spectra structure (containing pre-computed table)
modeInput: linear or logarithmic
zInput: redshift
output_totOutput: total matter power spectrum P(k) in $ Mpc^3 $ (linear mode), or its logarithms (logarithmic mode)
output_icOutput: for each pair of initial conditions, matter power spectra P(k) in $ Mpc^3 $ (linear mode), or their logarithms and cross-correlation angles (logarithmic mode)
Returns
the error status

Summary:

  • define local variables
  • first step: convert z into $\ln{\tau}$
  • second step: for both modes (linear or logarithmic), store the spectrum in logarithmic format in the output array(s)
  • –> (a) if only values at tau=tau_today are stored and we want $ P(k,z=0)$, no need to interpolate
  • –> (b) if several values of tau have been stored, use interpolation routine to get spectra at correct redshift
  • third step: if there are several initial conditions, compute the total P(k) and set back all uncorrelated coefficients to exactly zero. Check positivity of total P(k).
  • fourth step: depending on requested mode (linear or logarithmic), apply necessary transformation to the output arrays
  • –> (a) linear mode: if only one initial condition, convert output_pk to linear format; if several initial conditions, convert output_ic to linear format, output_tot is already in this format
  • –> (b) logarithmic mode: if only one initial condition, nothing to be done; if several initial conditions, convert output_tot to logarithmic format, output_ic is already in this format

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int spectra_pk_at_k_and_z ( struct background pba,
struct primordial ppm,
struct spectra psp,
double  k,
double  z,
double *  pk_tot,
double *  pk_ic 
)

Matter power spectrum for arbitrary wavenumber, redshift and initial condition.

This routine evaluates the matter power spectrum at a given value of k and z by interpolating in a table of all P(k)'s computed at this z by spectra_pk_at_z() (when kmin <= k <= kmax), or eventually by using directly the primordial spectrum (when 0 <= k < kmin): the latter case is an approximation, valid when kmin << comoving Hubble scale today. Returns zero when k=0. Returns an error when k<0 or k > kmax.

This function can be called from whatever module at whatever time, provided that spectra_init() has been called before, and spectra_free() has not been called yet.

Parameters
pbaInput: pointer to background structure (used for converting z into tau)
ppmInput: pointer to primordial structure (used only in the case 0 < k < kmin)
pspInput: pointer to spectra structure (containing pre-computed table)
kInput: wavenumber in 1/Mpc
zInput: redshift
pk_totOutput: total matter power spectrum P(k) in $ Mpc^3 $
pk_icOutput: for each pair of initial conditions, matter power spectra P(k) in $ Mpc^3$
Returns
the error status

Summary:

  • define local variables
  • first step: check that k is in valid range [0:kmax] (the test for z will be done when calling spectra_pk_at_z())
  • deal with case 0 <= k < kmin
  • –> (a) subcase k=0: then P(k)=0
  • –> (b) subcase 0<k<kmin: in this case we know that on super-Hubble scales: P(k) = [some number] * k * P_primordial(k) so P(k) = P(kmin) * (k P_primordial(k)) / (kmin P_primordial(kmin)) (note that the result is accurate only if kmin is such that [a0 kmin] << H0)
  • deal with case kmin <= k <= kmax
  • last step: if more than one condition, sum over pk_ic to get pk_tot, and set back coefficients of non-correlated pairs to exactly zero.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int spectra_pk_nl_at_z ( struct background pba,
struct spectra psp,
enum linear_or_logarithmic  mode,
double  z,
double *  output_tot 
)

Non-linear total matter power spectrum for arbitrary redshift.

This routine evaluates the non-linear matter power spectrum at a given value of z by interpolating in the pre-computed table (if several values of z have been stored) or by directly reading it (if it only contains values at z=0 and we want P(k,z=0))

Can be called in two modes: linear or logarithmic.

  • linear: returns P(k) (units: Mpc^3)
  • logarithmic: returns ln(P(k))

This function can be called from whatever module at whatever time, provided that spectra_init() has been called before, and spectra_free() has not been called yet.

Parameters
pbaInput: pointer to background structure (used for converting z into tau)
pspInput: pointer to spectra structure (containing pre-computed table)
modeInput: linear or logarithmic
zInput: redshift
output_totOutput: total matter power spectrum P(k) in $ Mpc^3$ (linear mode), or its logarithms (logarithmic mode)
Returns
the error status

Summary:

  • define local variables
  • first step: convert z into ln(tau)
  • second step: for both modes (linear or logarithmic), store the spectrum in logarithmic format in the output array(s)
  • –> (a) if only values at tau=tau_today are stored and we want P(k,z=0), no need to interpolate
  • –> (b) if several values of tau have been stored, use interpolation routine to get spectra at correct redshift
  • fourth step: eventually convert to linear format

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int spectra_pk_nl_at_k_and_z ( struct background pba,
struct primordial ppm,
struct spectra psp,
double  k,
double  z,
double *  pk_tot 
)

Non-linear total matter power spectrum for arbitrary wavenumber and redshift.

This routine evaluates the matter power spectrum at a given value of k and z by interpolating in a table of all P(k)'s computed at this z by spectra_pk_nl_at_z() (when kmin <= k <= kmax), or eventually by using directly the primordial spectrum (when 0 <= k < kmin): the latter case is an approximation, valid when kmin << comoving Hubble scale today. Returns zero when k=0. Returns an error when k<0 or k > kmax.

This function can be called from whatever module at whatever time, provided that spectra_init() has been called before, and spectra_free() has not been called yet.

Parameters
pbaInput: pointer to background structure (used for converting z into tau)
ppmInput: pointer to primordial structure (used only in the case 0 < k < kmin)
pspInput: pointer to spectra structure (containing pre-computed table)
kInput: wavenumber in 1/Mpc
zInput: redshift
pk_totOutput: total matter power spectrum P(k) in $ Mpc^3$
Returns
the error status

Summary:

  • define local variables
  • check that k is in valid range [0:kmax] (the test for z will be done when calling spectra_pk_at_z())
  • compute P(k,z) (in logarithmic format for more accurate interpolation)
  • get its second derivatives with spline, then interpolate, then convert to linear format

+ Here is the call graph for this function:

int spectra_tk_at_z ( struct background pba,
struct spectra psp,
double  z,
double *  output 
)

Matter transfer functions $ T_i(k) $ for arbitrary redshift and for all initial conditions.

This routine evaluates the matter transfer functions at a given value of z by interpolating in the pre-computed table (if several values of z have been stored) or by directly reading it (if it only contains values at z=0 and we want $ T_i(k,z=0)$)

This function can be called from whatever module at whatever time, provided that spectra_init() has been called before, and spectra_free() has not been called yet.

Parameters
pbaInput: pointer to background structure (used for converting z into tau)
pspInput: pointer to spectra structure (containing pre-computed table)
zInput: redshift
outputOutput: matter transfer functions
Returns
the error status

Summary:

  • define local variables
  • first step: convert z into ln(tau)
  • second step: store the matter transfer functions in the output array
  • –> (a) if only values at tau=tau_today are stored and we want $ T_i(k,z=0)$, no need to interpolate
  • –> (b) if several values of tau have been stored, use interpolation routine to get spectra at correct redshift

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int spectra_tk_at_k_and_z ( struct background pba,
struct spectra psp,
double  k,
double  z,
double *  output 
)

Matter transfer functions $ T_i(k)$ for arbitrary wavenumber, redshift and initial condition.

This routine evaluates the matter transfer functions at a given value of k and z by interpolating in a table of all $ T_i(k,z)$'s computed at this z by spectra_tk_at_z() (when kmin <= k <= kmax). Returns an error when k<kmin or k > kmax.

This function can be called from whatever module at whatever time, provided that spectra_init() has been called before, and spectra_free() has not been called yet.

Parameters
pbaInput: pointer to background structure (used for converting z into tau)
pspInput: pointer to spectra structure (containing pre-computed table)
kInput: wavenumber in 1/Mpc
zInput: redshift
outputOutput: matter transfer functions
Returns
the error status

Summary:

  • define local variables
  • check that k is in valid range [0:kmax] (the test for z will be done when calling spectra_tk_at_z())
  • compute T_i(k,z)
  • get its second derivatives w.r.t. k with spline, then interpolate

+ Here is the call graph for this function:

int spectra_init ( struct precision ppr,
struct background pba,
struct perturbs ppt,
struct primordial ppm,
struct nonlinear pnl,
struct transfers ptr,
struct spectra psp 
)

This routine initializes the spectra structure (in particular, computes table of anisotropy and Fourier spectra $ C_l^{X}, P(k), ... $)

Parameters
pprInput: pointer to precision structure
pbaInput: pointer to background structure (will provide H, Omega_m at redshift of interest)
pptInput: pointer to perturbation structure
ptrInput: pointer to transfer structure
ppmInput: pointer to primordial structure
pnlInput: pointer to nonlinear structure
pspOutput: pointer to initialized spectra structure
Returns
the error status

Summary:

  • check that we really want to compute at least one spectrum
  • initialize indices and allocate some of the arrays in the spectra structure
  • deal with $ C_l$'s, if any
  • deal with $ P(k,\tau)$ and $ T_i(k,\tau)$

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int spectra_free ( struct spectra psp)

This routine frees all the memory space allocated by spectra_init().

To be called at the end of each run, only when no further calls to spectra_cls_at_l(), spectra_pk_at_z(), spectra_pk_at_k_and_z() are needed.

Parameters
pspInput: pointer to spectra structure (which fields must be freed)
Returns
the error status

+ Here is the caller graph for this function:

int spectra_indices ( struct background pba,
struct perturbs ppt,
struct transfers ptr,
struct primordial ppm,
struct spectra psp 
)

This routine defines indices and allocates tables in the spectra structure

Parameters
pbaInput: pointer to background structure
pptInput: pointer to perturbation structure
ptrInput: pointer to transfers structure
ppmInput: pointer to primordial structure
pspInput/output: pointer to spectra structure
Returns
the error status

+ Here is the caller graph for this function:

int spectra_cls ( struct background pba,
struct perturbs ppt,
struct transfers ptr,
struct primordial ppm,
struct spectra psp 
)

This routine computes a table of values for all harmonic spectra $ C_l $'s, given the transfer functions and primordial spectra.

Parameters
pbaInput: pointer to background structure
pptInput: pointer to perturbation structure
ptrInput: pointer to transfers structure
ppmInput: pointer to primordial structure
pspInput/Output: pointer to spectra structure
Returns
the error status

Summary:

  • define local variables
  • allocate pointers to arrays where results will be stored
  • store values of l
  • loop over modes (scalar, tensors, etc). For each mode:
  • –> (a) store number of l values for this mode
  • –> (b) allocate arrays where results will be stored
  • –> (c) loop over initial conditions
  • —> loop over l values defined in the transfer module. For each l, compute the $ C_l$'s for all types (TT, TE, ...) by convolving primordial spectra with transfer functions. This elementary task is assigned to spectra_compute_cl()
  • –> (d) now that for a given mode, all possible $ C_l$'s have been computed, compute second derivative of the array in which they are stored, in view of spline interpolation.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int spectra_compute_cl ( struct background pba,
struct perturbs ppt,
struct transfers ptr,
struct primordial ppm,
struct spectra psp,
int  index_md,
int  index_ic1,
int  index_ic2,
int  index_l,
int  cl_integrand_num_columns,
double *  cl_integrand,
double *  primordial_pk,
double *  transfer_ic1,
double *  transfer_ic2 
)

This routine computes the $ C_l$'s for a given mode, pair of initial conditions and multipole, but for all types (TT, TE...), by convolving the transfer functions with the primordial spectra.

Parameters
pbaInput: pointer to background structure
pptInput: pointer to perturbation structure
ptrInput: pointer to transfers structure
ppmInput: pointer to primordial structure
pspInput/Output: pointer to spectra structure (result stored here)
index_mdInput: index of mode under consideration
index_ic1Input: index of first initial condition in the correlator
index_ic2Input: index of second initial condition in the correlator
index_lInput: index of multipole under consideration
cl_integrand_num_columnsInput: number of columns in cl_integrand
cl_integrandInput: an allocated workspace
primordial_pkInput: table of primordial spectrum values
transfer_ic1Input: table of transfer function values for first initial condition
transfer_ic2Input: table of transfer function values for second initial condition
Returns
the error status

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int spectra_k_and_tau ( struct background pba,
struct perturbs ppt,
struct spectra psp 
)

This routine computes the values of k and tau at which the matter power spectra $ P(k,\tau)$ and the matter transfer functions $ T_i(k,\tau)$ will be stored.

Parameters
pbaInput: pointer to background structure (for z to tau conversion)
pptInput: pointer to perturbation structure (contain source functions)
pspInput/Output: pointer to spectra structure
Returns
the error status

Summary:

  • define local variables
  • check the presence of scalar modes
  • check the maximum redshift z_max_pk at which $P(k,z)$ and $ T_i(k,z)$ should be computable by interpolation. If it is equal to zero, only $ P(k,z=0)$ needs to be computed. If it is higher, we will store in a table various P(k,tau) at several values of tau generously encompassing the range 0<z<z_max_pk
  • allocate and fill table of tau values at which $P(k,\tau)$ and $T_i(k,\tau)$ are stored
  • allocate and fill table of k values at which $ P(k,\tau)$ is stored

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int spectra_pk ( struct background pba,
struct perturbs ppt,
struct primordial ppm,
struct nonlinear pnl,
struct spectra psp 
)

This routine computes a table of values for all matter power spectra P(k), given the source functions and primordial spectra.

Parameters
pbaInput: pointer to background structure (will provide H, Omega_m at redshift of interest)
pptInput: pointer to perturbation structure (contain source functions)
ppmInput: pointer to primordial structure
pnlInput: pointer to nonlinear structure
pspInput/Output: pointer to spectra structure
Returns
the error status

Summary:

  • define local variables
  • check the presence of scalar modes
  • allocate temporary vectors where the primordial spectrum and the background quantities will be stored
  • allocate and fill array of $P(k,\tau)$ values
  • if interpolation of $P(k,\tau)$ will be needed (as a function of tau), compute array of second derivatives in view of spline interpolation
  • if interpolation of $ P_{NL}(k,\tau)$ will be needed (as a function of tau), compute array of second derivatives in view of spline interpolation

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int spectra_sigma ( struct background pba,
struct primordial ppm,
struct spectra psp,
double  R,
double  z,
double *  sigma 
)

This routine computes sigma(R) given P(k) (does not check that k_max is large enough)

Parameters
pbaInput: pointer to background structure
ppmInput: pointer to primordial structure
pspInput: pointer to spectra structure
zInput: redshift
RInput: radius in Mpc
sigmaOutput: variance in a sphere of radius R (dimensionless)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int spectra_matter_transfers ( struct background pba,
struct perturbs ppt,
struct spectra psp 
)

This routine computes a table of values for all matter power spectra P(k), given the source functions and primordial spectra.

Parameters
pbaInput: pointer to background structure (will provide density of each species)
pptInput: pointer to perturbation structure (contain source functions)
pspInput/Output: pointer to spectra structure
Returns
the error status

Summary:

  • define local variables
  • check the presence of scalar modes
  • allocate and fill array of $ T_i(k,\tau)$ values
  • allocate temporary vectors where the background quantities will be stored
  • if interpolation of $ P(k,\tau)$ will be needed (as a function of tau), compute array of second derivatives in view of spline interpolation

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int spectra_output_tk_data ( struct background pba,
struct perturbs ppt,
struct spectra psp,
enum file_format  output_format,
double  z,
int  number_of_titles,
double *  data 
)
  • compute $T_i(k)$ for each k (if several ic's, compute it for each ic; if z_pk = 0, this is done by directly reading inside the pre-computed table; if not, this is done by interpolating the table at the correct value of tau.
  • store data

+ Here is the call graph for this function:

+ Here is the caller graph for this function: