抱歉,您的瀏覽器無法訪問本站
本頁面需要瀏覽器支持(啟用)JavaScript
了解詳情 >

今天再補一個關於camb計算線性/非線性功率譜的坑。

camb在初始化時會有一個 pars.NonLinear 設置,設為 model.NonLinear_both 表示同時計算線性/非線性功率譜, model.NonLinear_none 表示計算線性功率譜,起初我以為設為 model.NonLinear_none 就可以得到的 results.get_matter_power_interpolator(k_hunit=True, hubble_units=True) 這樣得到的功率譜是線性功率譜,結果畫圖一對比發現和非線性功率譜結果相差不大($k>0.2$)。經過一番研究發現:計算功率譜結果的函數 results.get_matter_power_interpolator 裡面還有一個參數 nonlinear = True/False ,不論上述 pars.NonLinear 怎麼設置,只有當 nonlinear 取False輸出才是線性功率譜。代碼如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import camb
import numpy as np
import matplotlib.pyplot as plt
from astropy.cosmology import Planck18
from camb import model, initialpower
from matplotlib.gridspec import GridSpec
from matplotlib.ticker import FuncFormatter

k = np.linspace(1.e-2,1, 10)
rz_center = 0.3

# 線性
pars = camb.read_ini('./planck18.ini')
pars.Transfer.kmin = 0
pars.Transfer.kmax = 1
pars.set_matter_power(redshifts=[rz_center])
pars.NonLinear = model.NonLinear_none


# 計算結果
results = camb.get_results(pars)

# 物質功率譜
PK = results.get_matter_power_interpolator(k_hunit=True, hubble_units=True, nonlinear=False) # 單位(Mpc/h)^3
ps_matter = PK.P(rz_center, k)

np.save(h5_path+'matter_ps_linear.npy', ps_matter)
print(ps_matter)

# 非線性
pars = camb.read_ini('./planck18.ini')
pars.Transfer.kmin = 0
pars.Transfer.kmax = 1
pars.set_matter_power(redshifts=[rz_center])
pars.NonLinear = model.NonLinear_both


# 計算結果
results = camb.get_results(pars)

# 物質功率譜
PK = results.get_matter_power_interpolator(k_hunit=True, hubble_units=True, nonlinear=True) # 單位(Mpc/h)^3
ps_matter = PK.P(rz_center, k)

np.save(h5_path+'matter_ps_nonlinear.npy', ps_matter)
print(ps_matter)

評論



Powered by Hexo | Theme keep Volantis

本站總訪問量 總訪客數 🌎