Skip to content

Commit

Permalink
less zs
Browse files Browse the repository at this point in the history
  • Loading branch information
JaimeRZP committed Apr 18, 2024
1 parent 7fdf6ce commit 60457fc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 31 deletions.
37 changes: 12 additions & 25 deletions src/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ Constructor of settings structure constructor.
Kwargs:
- `nz::Int=300` : number of nodes in the general redshift array.
- `nz_chi::Int=1000` : number of nodes in the redshift array used to compute matter power spectrum grid.
- `nz_t::Int=350` : number of nodes in the general redshift array.
- `nk::Int=500`: number of nodes in the k-scale array used to compute matter power spectrum grid.
- `nℓ::Int=300`: number of nodes in the multipoles array.
- `using_As::Bool=false`: `True` if using the `As` parameter.
Expand All @@ -20,14 +18,11 @@ Returns:
```
mutable struct Settings
nz::Int
nz_chi::Int
nz_t::Int
nk::Int
nℓ::Int
xs
zs
zs_t
ks
ℓs
logk
Expand All @@ -44,15 +39,11 @@ end
"""
mutable struct Settings
nz::Int
nz_chi::Int
nz_t::Int
nk::Int
nℓ::Int

xs
zs
zs_chi
zs_t
ks
ℓs
logk
Expand All @@ -68,16 +59,12 @@ end

Settings(;kwargs...) = begin
nz = get(kwargs, :nz, 300)
nz_chi = get(kwargs, :nz_chi, 1000)
nz_t = get(kwargs, :nz_t, 350)
nk = get(kwargs, :nk, 500)
nℓ = get(kwargs, :nℓ, 300)

z_max = get(kwargs, :z_max, 3)
z_max = get(kwargs, :z_max, 3.0)
xs = LinRange(0, log(1+z_max), nz)
zs = @.(exp(xs) - 1)
zs_chi = 10 .^ Vector(LinRange(-3, log10(1100), nz_chi))
zs_t = range(0.00001, stop=3.0, length=nz_t)
logk = range(log(0.0001), stop=log(100.0), length=nk)
ks = exp.(logk)
dlogk = log(ks[2]/ks[1])
Expand All @@ -89,8 +76,8 @@ Settings(;kwargs...) = begin
tk_mode = get(kwargs, :tk_mode, :EisHu)
Dz_mode = get(kwargs, :Dz_mode, :RK2)
pk_mode = get(kwargs, :pk_mode, :linear)
Settings(nz, nz_chi, nz_t, nk, nℓ,
xs, zs, zs_chi, zs_t, ks, ℓs, logk, dlogk,
Settings(nz, nk, nℓ,
xs, zs, ks, ℓs, logk, dlogk,
using_As,
cosmo_type, tk_mode, Dz_mode, pk_mode)
end
Expand Down Expand Up @@ -244,28 +231,28 @@ end
Cosmology(cpar::CosmoPar, settings::Settings; kwargs...) = begin
# Load settings
cosmo_type = settings.cosmo_type
zs_chi, nz_chi = settings.zs_chi, settings.nz_chi
zs, nz = settings.zs, settings.nz
logk, nk = settings.logk, settings.nk
ks = settings.ks
dlogk = settings.dlogk
pk0, pki = lin_Pk0(cpar, settings; kwargs...)
# Compute redshift-distance relation
chis = zeros(cosmo_type, nz_chi)
ts = zeros(cosmo_type, nz_chi)
for i in 1:nz_chi
zz = zs_chi[i]
chis = zeros(cosmo_type, nz)
ts = zeros(cosmo_type, nz)
for i in 1:nz
zz = zs[i]
chis[i] = quadgk(z -> 1.0/Ez(cpar, z), 0.0, zz, rtol=1E-5)[1]
chis[i] *= CLIGHT_HMPC / cpar.h
ts[i] = quadgk(z -> 1.0/((1+z)*Ez(cpar, z)), 0.0, zz, rtol=1E-5)[1]
ts[i] *= cpar.h*(18.356164383561644*10^9)
end
# Distance to LSS
chi_LSS = chis[end]
chi_LSS = quadgk(z -> 1.0/Ez(cpar, z), 0.0, 1100., rtol=1E-5)[1]
chi_LSS *= CLIGHT_HMPC / cpar.h
# OPT: tolerances, interpolation method
chii = linear_interpolation(zs_chi, Vector(chis), extrapolation_bc=Line())
ti = linear_interpolation(zs_chi, Vector(ts), extrapolation_bc=Line())
zi = linear_interpolation(chis, Vector(zs_chi), extrapolation_bc=Line())
chii = linear_interpolation(zs, Vector(chis), extrapolation_bc=Line())
ti = linear_interpolation(zs, Vector(ts), extrapolation_bc=Line())
zi = linear_interpolation(chis, Vector(zs), extrapolation_bc=Line())
Dzs, Dzi, fs8zi = get_growth(cpar, settings; kwargs...)

if settings.pk_mode == :linear
Expand Down
11 changes: 5 additions & 6 deletions src/tracers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ Kwargs:
Returns:
- `NumberCountsTracer::NumberCountsTracer` : Number counts tracer structure.
"""
NumberCountsTracer(cosmo::Cosmology, z_n, nz; b=1.0) = begin
NumberCountsTracer(cosmo::Cosmology, z_n, nz; b=1.0, res=1000) = begin
nz_int = linear_interpolation(z_n, nz, extrapolation_bc=0)
res = cosmo.settings.nz_t
z_w = range(0.00001, stop=z_n[end], length=res)
nz_w = nz_int(z_w)
nz_norm = integrate(z_w, nz_w, SimpsonEven())
Expand Down Expand Up @@ -62,10 +61,10 @@ struct WeakLensingTracer <: Tracer
F::Function
end

WeakLensingTracer(cosmo::Cosmology, z_n, nz; IA_params = [0.0, 0.0], m=0.0, kwargs...) = begin
WeakLensingTracer(cosmo::Cosmology, z_n, nz;
IA_params = [0.0, 0.0], m=0.0, res=350, kwargs...) = begin
nz_int = linear_interpolation(z_n, nz, extrapolation_bc=0)
cosmo_type = cosmo.settings.cosmo_type
res =cosmo.settings.nz_t
z_w = range(0.00001, stop=z_n[end], length=res)
dz_w = (z_w[end]-z_w[1])/res
nz_w = nz_int(z_w)
Expand Down Expand Up @@ -127,9 +126,9 @@ Arguments:
Returns:
- `CMBLensingTracer::CMBLensingTracer` : CMB lensing tracer structure.
"""
CMBLensingTracer(cosmo::Cosmology) = begin
CMBLensingTracer(cosmo::Cosmology; res=350) = begin
# chi array
chis = range(0.0, stop=cosmo.chi_max, length=cosmo.settings.nz_t)
chis = range(0.0, stop=cosmo.chi_max, length=res)
zs = cosmo.z_of_chi(chis)
# Prefactor
H0 = cosmo.cpar.h/CLIGHT_HMPC
Expand Down
Binary file modified test/test_output.npz
Binary file not shown.

0 comments on commit 60457fc

Please sign in to comment.