-
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 to:
- 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 and output.c
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(...)
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: