-
Notifications
You must be signed in to change notification settings - Fork 30
Code1:philosophy and structure
This part is based on https://lesgourg.github.io/class-tour/Tokyo2014/lecture1_philosophy.pdf, https://lesgourg.github.io/class-tour/Tokyo2014/lecture2_structure.pdf and https://workshops.ift.uam-csic.es/files/208/hi_class_course_IFT.pdf
-
Notation from Ma & Bertschinger (astro-ph/9506072)
-
Distinct modules with separate physical tasks: 1.
input.c
, 2.background.c
, 3.thermodynamics.c
, 4.perturbations.c
, 5.primordial.c
, 6.nonlinear.c
, 7.transfer.c
, 8.spectra.c
, 9.lensing.c
, 10.output.c
-
Each module associated with a structure
xx
, containing all what other modules need to know, and nothing else. -
Documentation + Version history
-
Structure for approximations, always chosen in terms of dimensionless ratios
-
All precision variables grouped in one single place (
input.c
) -
No duplicate equations
-
No hard-coding: dynamical indexing (ρ_b->
vec[index_bg_rho_b]
) -
Component-specific blocks
-
if (has xxx) { (xxx physics) }
-
Easy to add new components:
- Search for inspirational ingredient
- Copy, paste & adapt
- interpret parameters (
input.c
) - implement equations (
background.c
,perturbations.c
)
This part is extracted from https://lesgourg.github.io/class-tour/Tokyo2014/lecture2_structure.pdf
A CLASS module is:
- a file
include/xxx.h
containing some declarations - a file
source/xxx.c
containing some functions each module is a associated with a structurexx
- each module is a associated with a structure
xx
, containing all what other modules need to know, and nothing else some fields in this structure are filled in theinput.c
module - some fields in this structure are filled in the
input.c
module (input parameters relevant for this module) - all other fields are filled by a function
xxx_init(...)
- "executing a module” ≡ calling
xxx_init(...)
Schematically:
module | structure | ab. | * | main content |
---|---|---|---|---|
input.c | precision | pr | ppr | all precision parameters |
background.c | background | ba | pba | background quantities as funct. of conformal time (tau). |
thermodynamics.c | thermodynamics | th | pth | thermo. quantities as funct. of conformal time (tau). |
perturbation.c | perturb | pt | ppt | source functions S(k,t) |
primordial.c | primordial | pm | ppm | primordial spectra P(k) |
nonlinear.c | nonlinear | nl | pnl | non-linear corrections α_NL(k,tau) |
transfer.c | tranfers | tr | ptr | transfer functions ∆_l(k) |
spectra.c | spectra | sp | psp | linear and/or non-linear P(k,z), cl's |
lensing.c | lensing | le | ple | lensed cl's |
output.c | output | op | pop | description of output format |
Note: "*" stands for "pointer". See that all pointers have the same name as the structure abreviated names with a prefixed "p".
It is important to remark that each module depends on the previous one and needs to be sourced the associated strctures (as pointers); except input.c
that needs to be called with all the pointer to structures in order to fill them with the input/default values. main/class.c
is a good example.
Another important issue is that CLASS runs as less modules as possible; i.e. if you only request background output, it will only run input.c, background.c, thermodynamics.c and output.c (all these are mandatory). The following ./class
output is really informative:
Running CLASS version v2.4.5
Computing background
-> age = 13.795359 Gyr
-> conformal age = 14165.045412 Mpc
Computing thermodynamics with Y_He=0.2477
-> recombination at z = 1089.267451
corresponding to conformal time = 280.576042 Mpc
with comoving sound horizon = 144.695940 Mpc
angular diameter distance = 12.734921 Mpc
and sound horizon angle 100*theta_s = 1.042142
-> baryon drag stops at z = 1059.171266
corresponding to conformal time = 286.488461 Mpc
with comoving sound horizon rs = 147.376600 Mpc
-> reionization with optical depth = 0.092473
corresponding to conformal time = 4255.316282 Mpc
-> free-streaming approximation can be turned on as soon as tau=364.763 Mpc
No sources requested. Perturbation module skipped.
No perturbations requested. Primordial module skipped.
No non-linear spectra requested. Nonlinear module skipped.
No harmonic space transfer functions to compute. Transfer module skipped.
No spectra requested. Spectra module skipped.
No lensing requested. Lensing module skipped.
No output files requested. Output module skipped.
The ini-file was just:
background_verbose = 10
thermodynamics_verbose = 10
perturbations_verbose = 10
bessels_verbose = 10
transfer_verbose = 10
primordial_verbose = 10
spectra_verbose = 10
nonlinear_verbose = 10
lensing_verbose = 10
output_verbose = 10
Each module contains, in this order:
-
some functions
xxx_external_1(...)
, ...,xxx_external_n(...)
that can be called from other modules (e.g. to read correctly or interpolate the content of the structurexx
) -
a function
xxx_init(...)
filling the structurexx
-
a function
xxx_free(...)
freeing all the memory all the memory allocated to this structure -
some functions
xxx_internal_1(...)
, ...,xxx_internal_m(...)
that are called only inside the module, withinxxx_init(...)
CLASS uses the following convention:
-
c = 1
. - The Planck Mass,
M_P = 1/\sqrt{8\piG} = 1
. - All quantities are in some power of Mpc..
- The energy densities and pressures are scaled by
1/(3*M_P^2) = 1/3
; e.g.rho_CLASS = rho_physical/3
. ThenH^2 = \sum_i rho_i - K/a^2
.
Important remark: in hi_class, for the time being, modified gravity models have K = 0.
Home
Installation
Basic usage
classy: the python wrapper
Introducing new models
The code:
- Code 1: Philosophy and structure
- Code 2: Indexing
- Code 3: Errors
- Code 4: input.c
- Code 5: background.c
- Code 6: thermodynamics.c
- Code 7: perturbations.c
- Code 8: primordial.c
- Code 10: output.c
- Other modules
- classy: classy.pyx and classy.pxd
Examples: