Skip to content

Commit e8184bb

Browse files
committed
Update constants, nnu=3.044, Mpc, Gyr, BBN model default to PRIMAT2021
1 parent 758c6c2 commit e8184bb

File tree

15 files changed

+90
-92
lines changed

15 files changed

+90
-92
lines changed

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ jobs:
3434
- PYDIST="ANACONDA"
3535
- FORTRAN="test"
3636
python: "3.10"
37+
- name: "Ubuntu 22.04 + Python 3.11"
38+
dist: jammy
39+
addons:
40+
apt:
41+
packages:
42+
- gfortran
43+
env:
44+
- CHANNEL="defaults"
45+
python: "3.11"
3746
- name: "GCC trunk cosmobox"
3847
language: shell
3948
services:

camb/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
__author__ = "Antony Lewis"
88
__contact__ = "antony at cosmologist dot info"
99
__url__ = "https://camb.readthedocs.io"
10-
__version__ = "1.3.8"
10+
__version__ = "1.4.0"
1111

1212
from . import baseconfig
1313

camb/bbn.py

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,23 @@
22
# Fitting formula for Parthenelope via Julien Lesgourgues Dec 2014
33
# General interpolation tables, with defaults from Parthenope May 2017 (thanks Ofelia Pesanti)
44
# Use PRIMAT_Yp_DH_Error.dat table for latest from the PRIMAT code (arXiv: 1801.08023, thanks Cyril Pitrou)
5+
# from 1.4.0, delta_nnu values are relative to 3.044, not 3.046
56

67
import numpy as np
78
import os
89
from scipy.interpolate import RectBivariateSpline
10+
from .constants import m_H, m_He4, default_nnu
911

10-
# Various useful constants
11-
hbar = 1.05457e-34
12-
c = 299792458.
13-
kB = 1.380650e-23
14-
MeV = 1.6021764e-13
15-
eV = MeV / 1e6
16-
G = 6.6738e-11
17-
TCMB = 2.7255
18-
mP = np.sqrt(hbar * c / G)
19-
Mpc = 3.0856776e22
20-
21-
m_proton = 1.672621637e-27
22-
m_H = 1.673575e-27
23-
not4 = 3.9715
24-
m_He = m_H * not4
25-
26-
zeta3 = 1.202056903
27-
28-
n_photon = (kB * TCMB / hbar / c) ** 3 * zeta3 * 2 / np.pi ** 2
29-
omegafac = (1e5 / Mpc) ** 2 / (8 * np.pi * G) * 3
30-
31-
default_interpolation_table = 'PArthENoPE_880.2_standard.dat'
12+
# previously (< 1.4.0) default_interpolation_table = 'PArthENoPE_880.2_standard.dat'
13+
default_interpolation_table = 'PRIMAT_Yp_DH_ErrorMC_2021.dat'
3214

3315

3416
def yhe_to_ypBBN(Yp):
35-
return -4 * m_H * Yp / (Yp * m_He - 4 * Yp * m_H - m_He)
17+
return -4 * m_H * Yp / (Yp * m_He4 - 4 * Yp * m_H - m_He4)
3618

3719

3820
def ypBBN_to_yhe(YBBN):
39-
return -YBBN * m_He / (-YBBN * m_He + 4 * YBBN * m_H - 4 * m_H)
21+
return -YBBN * m_He4 / (-YBBN * m_He4 + 4 * YBBN * m_H - 4 * m_H)
4022

4123

4224
class BBNIterpolator(RectBivariateSpline):
@@ -53,7 +35,7 @@ def Y_p(self, ombh2, delta_neff=0.):
5335
Get BBN helium nucleon fraction. Must be implemented by extensions.
5436
5537
:param ombh2: :math:`\Omega_b h^2`
56-
:param delta_neff: additional N_eff relative to standard value (of 3.046)
38+
:param delta_neff: additional N_eff relative to standard value (of 3.044)
5739
:return: Y_p helium nucleon fraction predicted by BBN
5840
"""
5941
raise Exception('Not implemented')
@@ -63,7 +45,7 @@ def Y_He(self, ombh2, delta_neff=0.):
6345
Get BBN helium mass fraction for CMB code.
6446
6547
:param ombh2: :math:`\Omega_b h^2`
66-
:param delta_neff: additional N_eff relative to standard value (of 3.046)
48+
:param delta_neff: additional N_eff relative to standard value (of 3.044)
6749
:return: Y_He helium mass fraction predicted by BBN
6850
"""
6951
return ypBBN_to_yhe(self.Y_p(ombh2, delta_neff))
@@ -125,7 +107,7 @@ def Y_p(self, ombh2, delta_neff=0., grid=False):
125107
Get BBN helium nucleon fraction by intepolation in table.
126108
127109
:param ombh2: :math:`\Omega_b h^2` (or, more generally, value of function_of[0])
128-
:param delta_neff: additional N_eff relative to standard value (of 3.046) (or value of function_of[1])
110+
:param delta_neff: additional N_eff relative to standard value (of 3.044) (or value of function_of[1])
129111
:param grid: parameter for :class:`~scipy:scipy.interpolate.RectBivariateSpline` (whether to evaluate the
130112
results on a grid spanned by the input arrays, or at points specified by the input arrays)
131113
:return: Y_p helium nucleon fraction predicted by BBN. Call Y_He() to get mass fraction instead.
@@ -137,7 +119,7 @@ def DH(self, ombh2, delta_neff=0., grid=False):
137119
Get deuterium ratio D/H by interpolation in table
138120
139121
:param ombh2: :math:`\Omega_b h^2` (or, more generally, value of function_of[0])
140-
:param delta_neff: additional N_eff relative to standard value (of 3.046) (or value of function_of[1])
122+
:param delta_neff: additional N_eff relative to standard value (of 3.044) (or value of function_of[1])
141123
:param grid: parameter for :class:`~scipy:scipy.interpolate.RectBivariateSpline` (whether to evaluate the
142124
results on a grid spanned by the input arrays, or at points specified by the input arrays)
143125
:return: D/H
@@ -151,7 +133,7 @@ def get(self, name, ombh2, delta_neff=0., grid=False):
151133
152134
:param name: string name of the parameter, as given in header of interpolation table
153135
:param ombh2: :math:`\Omega_b h^2` (or, more generally, value of function_of[0])
154-
:param delta_neff: additional N_eff relative to standard value (of 3.046) (or value of function_of[1])
136+
:param delta_neff: additional N_eff relative to standard value (of 3.044) (or value of function_of[1])
155137
:param grid: parameter for :class:`~scipy:scipy.interpolate.RectBivariateSpline` (whether to evaluate the
156138
results on a grid spanned by the input arrays, or at points specified by the input arrays)
157139
:return: Interpolated value (or grid)
@@ -184,23 +166,25 @@ def Y_p(self, ombh2, delta_neff=0., tau_neutron=None):
184166
# Parthenope fits, as in Planck 2015 papers
185167
186168
:param ombh2: :math:`\Omega_b h^2`
187-
:param delta_neff: additional N_eff relative to standard value (of 3.046)
169+
:param delta_neff: additional N_eff relative to standard value (of 3.046 for consistency with Planck)
188170
:param tau_neutron: neutron lifetime
189171
:return: :math:`Y_p^{\rm BBN}` helium nucleon fraction predicted by BBN
190172
"""
173+
delta_neff = default_nnu + delta_neff - 3.046
191174
return (
192-
0.2311 + 0.9502 * ombh2 - 11.27 * ombh2 * ombh2
193-
+ delta_neff * (0.01356 + 0.008581 * ombh2 - 0.1810 * ombh2 * ombh2)
194-
+ delta_neff * delta_neff * (-0.0009795 - 0.001370 * ombh2 + 0.01746 * ombh2 * ombh2)
195-
) * pow((tau_neutron or self.taun) / 880.3, 0.728)
175+
0.2311 + 0.9502 * ombh2 - 11.27 * ombh2 * ombh2
176+
+ delta_neff * (0.01356 + 0.008581 * ombh2 - 0.1810 * ombh2 * ombh2)
177+
+ delta_neff * delta_neff * (-0.0009795 - 0.001370 * ombh2 + 0.01746 * ombh2 * ombh2)
178+
) * pow((tau_neutron or self.taun) / 880.3, 0.728)
196179

197180
def DH(self, ombh2, delta_neff, tau_neutron=None):
181+
delta_neff = default_nnu + delta_neff - 3.046
198182
return (
199-
18.754 - 1534.4 * ombh2 + 48656. * ombh2 * ombh2 - 552670. * ombh2 ** 3
200-
+ delta_neff * (2.4914 - 208.11 * ombh2 + 6760.9 * ombh2 ** 2 - 78007. * ombh2 ** 3)
201-
+ delta_neff * delta_neff * (
202-
0.012907 - 1.3653 * ombh2 + 37.388 * ombh2 ** 2 - 267.78 * ombh2 ** 3)
203-
) * pow((tau_neutron or self.taun) / 880.3, 0.418) * 1e-5
183+
18.754 - 1534.4 * ombh2 + 48656. * ombh2 * ombh2 - 552670. * ombh2 ** 3
184+
+ delta_neff * (2.4914 - 208.11 * ombh2 + 6760.9 * ombh2 ** 2 - 78007. * ombh2 ** 3)
185+
+ delta_neff * delta_neff * (
186+
0.012907 - 1.3653 * ombh2 + 37.388 * ombh2 ** 2 - 267.78 * ombh2 ** 3)
187+
) * pow((tau_neutron or self.taun) / 880.3, 0.418) * 1e-5
204188

205189

206190
_predictors = {}

camb/camb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def get_age(params):
7676
Get age of universe for given set of parameters
7777
7878
:param params: :class:`.model.CAMBparams` instance
79-
:return: age of universe in gigayears
79+
:return: age of universe in Julian gigayears
8080
"""
8181
return CAMB_GetAge(byref(params))
8282

camb/cambdll.dll

0 Bytes
Binary file not shown.

camb/constants.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,31 @@
66
zeta5 = 1.0369277551433699263313
77
zeta7 = 1.0083492773819228268397
88

9+
# Constants from particle data book 2022
910
c = 2.99792458e8
10-
h_p = 6.62606896e-34
11+
h_p = 6.62607015e-34
1112
hbar = h_p / 2 / const_pi
1213

13-
G = 6.6738e-11 # data book 2012, last digit +/-8
14-
sigma_thomson = 6.6524616e-29
15-
sigma_boltz = 5.6704e-8
16-
k_B = 1.3806504e-23
17-
eV = 1.60217646e-19
14+
G = 6.67430e-11
15+
sigma_thomson = 6.6524587321e-29
16+
sigma_boltz = 5.670374419e-8
17+
k_B = 1.380649e-23
18+
eV = 1.602176634e-19
19+
20+
m_p = 1.67262192369e-27
21+
m_e = 9.1093837015e-31
1822

19-
m_p = 1.672621637e-27 # 1.672623e-27
2023
m_H = 1.673575e-27 # av. H atom
21-
m_e = 9.10938215e-31
22-
mass_ratio_He_H = 3.9715
24+
m_He4 = 6.646479073e-27 # He4
25+
mass_ratio_He_H = m_He4 / m_H
2326

24-
Gyr = 3.1556926e16
25-
Mpc = 3.085678e22 # seem to be different definitions of this?
27+
Gyr = 365.25 * 86400 * 1e9
28+
Mpc = 3.085677581e22
2629
MPc_in_sec = Mpc / c # Mpc/c = 1.029272d14 in SI units
2730

2831
barssc0 = k_B / m_p / c ** 2
2932
kappa = 8. * const_pi * G
3033
a_rad = 8. * const_pi ** 5 * k_B ** 4 / 15 / c ** 3 / h_p ** 3
31-
# 7.565914e-16 #radiation constant for u=aT^4
32-
3334

3435
compton_cT = MPc_in_sec * (8. / 3.) * (sigma_thomson / (m_e * c)) * a_rad
3536
# compton_cT is cT in Mpc units, (8./3.)*(sigma_T/(m_e*c))*a_R in Mpc
@@ -45,7 +46,7 @@
4546
line21_const = 3 * l_21cm ** 2 * c * h_p / 32 / const_pi / k_B * A10 * MPc_in_sec * 1000
4647
# 1000 to get in MilliKelvin
4748
COBE_CMBTemp = 2.7255 # (Fixsen 2009) used as default value
48-
default_nnu = 3.046
49+
default_nnu = 3.044
4950

5051
inv_neutrino_mass_fac = zeta3 * 3. / 2 / const_pi ** 2 * 4. / 11 * \
5152
((k_B * COBE_CMBTemp / hbar / c) ** 3 * kappa / 3 / (100 * 1000 / Mpc) ** 2 / (c ** 2 / eV))

camb/model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ def get_Y_p(self, ombh2=None, delta_neff=None):
628628
(or the default one, if `Y_He` has not been set).
629629
630630
:param ombh2: :math:`\Omega_b h^2` (default: value passed to :meth:`set_cosmology`)
631-
:param delta_neff: additional :math:`N_{\rm eff}` relative to standard value (of 3.046)
631+
:param delta_neff: additional :math:`N_{\rm eff}` relative to standard value (of 3.044)
632632
(default: from values passed to :meth:`set_cosmology`)
633633
:return: :math:`Y_p^{\rm BBN}` helium nucleon fraction predicted by BBN.
634634
"""
@@ -646,7 +646,7 @@ def get_DH(self, ombh2=None, delta_neff=None):
646646
(or the default one, if `Y_He` has not been set).
647647
648648
:param ombh2: :math:`\Omega_b h^2` (default: value passed to :meth:`set_cosmology`)
649-
:param delta_neff: additional :math:`N_{\rm eff}` relative to standard value (of 3.046)
649+
:param delta_neff: additional :math:`N_{\rm eff}` relative to standard value (of 3.044)
650650
(default: from values passed to :meth:`set_cosmology`)
651651
:return: BBN helium nucleon fraction D/H
652652
"""

camb/results.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,7 +1503,7 @@ def hubble_parameter(self, z):
15031503

15041504
def physical_time_a1_a2(self, a1, a2):
15051505
"""
1506-
Get physical time between two scalar factors in Gigayears
1506+
Get physical time between two scalar factors in Julian Gigayears
15071507
15081508
Must have called :meth:`calc_background`, :meth:`calc_background_no_thermo` or calculated transfer functions
15091509
or power spectra.
@@ -1522,7 +1522,7 @@ def physical_time_a1_a2(self, a1, a2):
15221522

15231523
def physical_time(self, z):
15241524
"""
1525-
Get physical time from hot big bang to redshift z in Gigayears.
1525+
Get physical time from hot big bang to redshift z in Julian Gigayears.
15261526
15271527
:param z: redshift
15281528
:return: t(z)/Gigayear

camb/tests/camb_test.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def testBackground(self):
124124
t1 = data.conformal_time(11.5)
125125
t2 = data.comoving_radial_distance(11.5)
126126
self.assertAlmostEqual(t2, t0 - t1, 2)
127-
self.assertAlmostEqual(t1, 4200.78, 2)
127+
self.assertAlmostEqual(t1, 4200.809, 2)
128128
chistar = data.conformal_time(0) - data.tau_maxvis
129129
chis = np.linspace(0, chistar, 197)
130130
zs = data.redshift_at_comoving_radial_distance(chis)
@@ -136,25 +136,25 @@ def testBackground(self):
136136

137137
derived = data.get_derived_params()
138138
self.assertAlmostEqual(derived['age'], age, 2)
139-
self.assertAlmostEqual(derived['rdrag'], 146.976, 2)
139+
self.assertAlmostEqual(derived['rdrag'], 146.986, 2)
140140
self.assertAlmostEqual(derived['rstar'], data.sound_horizon(derived['zstar']), 2)
141141

142142
# Test BBN consistency, base_plikHM_TT_lowTEB best fit model
143143
pars.set_cosmology(H0=67.31, ombh2=0.022242, omch2=0.11977, mnu=0.06, omk=0)
144-
self.assertAlmostEqual(pars.YHe, 0.245347, 5)
144+
self.assertAlmostEqual(pars.YHe, 0.2458, 5)
145145
data.calc_background(pars)
146-
self.assertAlmostEqual(data.cosmomc_theta(), 0.010408566, 7)
146+
self.assertAlmostEqual(data.cosmomc_theta(), 0.0104090741, 7)
147147
self.assertAlmostEqual(data.get_derived_params()['kd'], 0.14055, 4)
148148

149149
pars.set_cosmology(H0=67.31, ombh2=0.022242, omch2=0.11977, mnu=0.06, omk=0,
150150
bbn_predictor=bbn.BBN_table_interpolator())
151-
self.assertAlmostEqual(pars.YHe, 0.2453469, 5)
151+
self.assertAlmostEqual(pars.YHe, 0.2458, 5)
152152
self.assertAlmostEqual(pars.get_Y_p(), bbn.BBN_table_interpolator().Y_p(0.022242, 0), 5)
153153

154154
# test massive sterile models as in Planck papers
155155
pars.set_cosmology(H0=68.0, ombh2=0.022305, omch2=0.11873, mnu=0.06, nnu=3.073, omk=0, meffsterile=0.013)
156156
self.assertAlmostEqual(pars.omnuh2, 0.00078, 5)
157-
self.assertAlmostEqual(pars.YHe, 0.24573, 5)
157+
self.assertAlmostEqual(pars.YHe, 0.246218, 5)
158158
self.assertAlmostEqual(pars.N_eff, 3.073, 4)
159159

160160
data.calc_background(pars)
@@ -175,7 +175,7 @@ def testBackground(self):
175175

176176
# test theta
177177
pars.set_cosmology(cosmomc_theta=0.0104085, ombh2=0.022271, omch2=0.11914, mnu=0.06, omk=0)
178-
self.assertAlmostEqual(pars.H0, 67.5512, 2)
178+
self.assertAlmostEqual(pars.H0, 67.537, 2)
179179
with self.assertRaises(CAMBParamRangeError):
180180
pars.set_cosmology(cosmomc_theta=0.0204085, ombh2=0.022271, omch2=0.11914, mnu=0.06, omk=0)
181181
pars = camb.set_params(cosmomc_theta=0.0104077, ombh2=0.022, omch2=0.122, w=-0.95)
@@ -185,7 +185,7 @@ def testBackground(self):
185185
self.assertAlmostEqual(camb.get_background(pars).get_derived_params()['thetastar'] / 100, 0.010311, 7)
186186
pars = camb.set_params(thetastar=0.010311, ombh2=0.022, omch2=0.122, omk=-0.05)
187187
self.assertAlmostEqual(camb.get_background(pars).get_derived_params()['thetastar'] / 100, 0.010311, 7)
188-
self.assertAlmostEqual(pars.H0, 49.7148, places=3)
188+
self.assertAlmostEqual(pars.H0, 49.70624, places=3)
189189

190190
pars = camb.set_params(cosmomc_theta=0.0104077, ombh2=0.022, omch2=0.122, w=-0.95, wa=0,
191191
dark_energy_model='ppf')
@@ -328,9 +328,9 @@ def testPowers(self):
328328

329329
data.calc_power_spectra(pars)
330330
kh3, z3, pk3 = data.get_matter_power_spectrum(1e-4, 1, 20)
331-
self.assertAlmostEqual(pk[-1][-3], 51.909, 2)
332-
self.assertAlmostEqual(pk3[-1][-3], 57.709, 2)
333-
self.assertAlmostEqual(pk2[-2][-4], 56.436, 2)
331+
self.assertAlmostEqual(pk[-1][-3], 51.924, 2)
332+
self.assertAlmostEqual(pk3[-1][-3], 57.723, 2)
333+
self.assertAlmostEqual(pk2[-2][-4], 56.454, 2)
334334
camb.set_feedback_level(0)
335335

336336
PKnonlin = camb.get_matter_power_interpolator(pars, nonlinear=True)
@@ -457,10 +457,11 @@ def testSigmaR(self):
457457
self.assertAlmostEqual(sigma8, results.get_sigmaR(np.array([8]), z_indices=-1)[-1], places=3)
458458
self.assertAlmostEqual(results.get_sigmaR(8)[-1], results.get_sigmaR(8, z_indices=-1))
459459
pars.set_matter_power(nonlinear=False, k_per_logint=0, kmax=2)
460+
460461
results = camb.get_results(pars)
461462
P, z, k = results.get_matter_power_interpolator(nonlinear=False, hubble_units=False, k_hunit=False,
462463
return_z_k=True, extrap_kmax=100, silent=True)
463-
truth = 0.800629 # from high kmax, high accuracy boost
464+
truth = 0.800679 # from high kmax, high accuracy boost
464465
self.assertTrue(abs(results.get_sigmaR(8)[-1] / sigma8 - 1) < 1e-3)
465466

466467
def get_sigma(_ks, dlogk):
@@ -657,7 +658,7 @@ def testSources(self):
657658
results = camb.get_results(pars)
658659
cls = results.get_source_cls_dict()
659660
self.assertAlmostEqual(np.sum(cls['PxW1'][10:3000:20]), 0.00020001, places=5)
660-
self.assertAlmostEqual(np.sum(cls['W1xW1'][10:3000:20]), 2.26348, places=3)
661+
self.assertAlmostEqual(np.sum(cls['W1xW1'][10:3000:20]), 2.26413, places=3)
661662
self.assertAlmostEqual(np.sum(cls['W1xW1'][10]), 0.0001097, places=6)
662663

663664
def testSymbolic(self):

fortran/DarkEnergyFluid.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ subroutine TAxionEffectiveFluid_Init(this, State)
203203
!get (very) approximate result for sound speed parameter; arXiv:1806.10608 Eq 30 (but mu may not exactly agree with what they used)
204204
n = nint((1+this%w_n)/(1-this%w_n))
205205
!Assume radiation domination, standard neutrino model; H0 factors cancel
206-
grho_rad = (kappa/c**2*4*sigma_boltz/c**3*State%CP%tcmb**4*Mpc**2*(1+3.046*7._dl/8*(4._dl/11)**(4._dl/3)))
206+
grho_rad = (kappa/c**2*4*sigma_boltz/c**3*State%CP%tcmb**4*Mpc**2*(1+default_nnu*7._dl/8*(4._dl/11)**(4._dl/3)))
207207
xc = this%a_c**2/2/sqrt(grho_rad/3)
208208
F=7./8
209209
p=1./2

fortran/camb.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ subroutine CAMB_GetCls(State, Cls, lmax,GC_conventions)
185185
end subroutine CAMB_GetCls
186186

187187
function CAMB_GetAge(P)
188-
!Return age in gigayears, returns -1 on error
188+
!Return age in Julian gigayears, returns -1 on error
189189
type(CAMBparams), intent(in) :: P
190190
real(dl) CAMB_GetAge
191191
integer error

fortran/config.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module config
33
use constants, only: const_twopi
44
implicit none
55

6-
character(LEN=*), parameter :: version = '1.3.8'
6+
character(LEN=*), parameter :: version = '1.4.0'
77

88
integer :: FeedbackLevel = 0 !if >0 print out useful information about the model
99

0 commit comments

Comments
 (0)