Skip to content

Commit 993d17b

Browse files
authored
Merge pull request #42 from hersle/nicer_sources
Interpolate smoother polarization source function
2 parents 0ffc702 + 4ee30d6 commit 993d17b

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

docs/src/comparison.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ l = 20:20:2000 # CLASS default is lmax = 2500
409409
Dl1 = Dl_class([:TT, :TE, :EE], l, pars)
410410
jl = SphericalBesselCache(l)
411411
Dl2 = Dl_symboltz([:TT, :TE, :EE], jl, pars)
412-
plot_compare(l, l, Dl1[:, 1], Dl2[:, 1], "l", "Dₗ(TT)"; tol = 1e-12)
412+
plot_compare(l, l, Dl1[:, 1], Dl2[:, 1], "l", "Dₗ(TT)"; tol = 9e-13)
413413
```
414414
```@example class
415415
plot_compare(l, l, Dl1[:, 2], Dl2[:, 2], "l", "Dₗ(TE)"; tol = 2e-14)

src/models/cosmologies.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function ΛCDM(;
5555
ST0_SW(τ, k),
5656
ST0_ISW(τ, k), ST1_ISW(τ, k),
5757
ST0_Doppler(τ, k), ST1_Doppler(τ, k),
58-
ST0_polarization(τ, k), ST1_polarization(τ, k), ST2_polarization(τ, k)
58+
ST0_polarization(τ, k), ST1_polarization(τ, k), ST2_polarization(τ, k), SE_kχ²(τ, k)
5959
end
6060
defs = Dict(
6161
C => 1//2,
@@ -100,6 +100,7 @@ function ΛCDM(;
100100
ST2_polarization ~ 3/16 * b.v*γ.Π / (k*χ)^2
101101
ST0 ~ ST0_SW + ST0_ISW + ST0_Doppler + ST0_polarization
102102
ST1 ~ 0
103+
SE_kχ² ~ 3/16 * b.v*γ.Π
103104
])
104105
# TODO: do various initial condition types (adiabatic, isocurvature, ...) from here?
105106
# TODO: automatically solve for initial conditions following e.g. https://arxiv.org/pdf/1012.0569 eq. (1)?

src/observables/angular.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,12 @@ function spectrum_cmb(ΘlAs::AbstractMatrix, ΘlBs::AbstractMatrix, P0s::Abstrac
181181
end
182182

183183
"""
184-
spectrum_cmb(modes::AbstractVector, prob::CosmologyProblem, jl::SphericalBesselCache; normalization = :Cl, unit = nothing, kτ0s = 0.1*jl.l[begin]:2π/2:2*jl.l[end], u = (τ->tanh(τ)), u⁻¹ = (u->atanh(u)), Nlos = 768, integrator = TrapezoidalRule(), bgopts = (alg = Rodas4P(), reltol = 1e-9, abstol = 1e-9), ptopts = (alg = KenCarp4(), reltol = 1e-8, abstol = 1e-8), sourceopts = (atol = 1e0,), verbose = false, kwargs...)
184+
spectrum_cmb(modes::AbstractVector, prob::CosmologyProblem, jl::SphericalBesselCache; normalization = :Cl, unit = nothing, kτ0s = 0.1*jl.l[begin]:2π/2:2*jl.l[end], u = (τ->tanh(τ)), u⁻¹ = (u->atanh(u)), Nlos = 768, integrator = TrapezoidalRule(), bgopts = (alg = Rodas4P(), reltol = 1e-9, abstol = 1e-9), ptopts = (alg = KenCarp4(), reltol = 1e-8, abstol = 1e-8), sourceopts = (rtol = 1e-2,), verbose = false, kwargs...)
185185
186186
Compute the CMB power spectra `modes` (`:TT`, `:EE`, `:TE` or an array thereof) ``C_l^{AB}``'s at angular wavenumbers `ls` from the cosmological solution `sol`.
187187
If `unit` is `nothing` the spectra are of dimensionless temperature fluctuations relative to the present photon temperature; while if `unit` is a temperature unit the spectra are of dimensionful temperature fluctuations.
188188
"""
189-
function spectrum_cmb(modes::AbstractVector, prob::CosmologyProblem, jl::SphericalBesselCache; normalization = :Cl, unit = nothing, kτ0s = 0.1*jl.l[begin]:2π/2:2*jl.l[end], u =->tanh(τ)), u⁻¹ = (u->atanh(u)), Nlos = 768, integrator = TrapezoidalRule(), bgopts = (alg = Rodas4P(), reltol = 1e-9, abstol = 1e-9), ptopts = (alg = KenCarp4(), reltol = 1e-8, abstol = 1e-8), sourceopts = (atol = 1e0,), verbose = false, kwargs...)
189+
function spectrum_cmb(modes::AbstractVector, prob::CosmologyProblem, jl::SphericalBesselCache; normalization = :Cl, unit = nothing, kτ0s = 0.1*jl.l[begin]:2π/2:2*jl.l[end], u =->tanh(τ)), u⁻¹ = (u->atanh(u)), Nlos = 768, integrator = TrapezoidalRule(), bgopts = (alg = Rodas4P(), reltol = 1e-9, abstol = 1e-9), ptopts = (alg = KenCarp4(), reltol = 1e-8, abstol = 1e-8), sourceopts = (rtol = 1e-2,), verbose = false, kwargs...)
190190
ls = jl.l
191191
sol = solve(prob; bgopts, verbose)
192192
τ0 = getsym(sol, prob.M.τ0)(sol)
@@ -207,13 +207,17 @@ function spectrum_cmb(modes::AbstractVector, prob::CosmologyProblem, jl::Spheric
207207
iE = 'E' in join(modes) ? iT + 1 : 0
208208
Ss = Num[]
209209
iT > 0 && push!(Ss, prob.M.ST0)
210-
iE > 0 && push!(Ss, prob.M.ST2_polarization)
210+
iE > 0 && push!(Ss, prob.M.SE_kχ²)
211211
ks_coarse = range(ks_fine[begin], ks_fine[end]; length = 2)
212212
ks_coarse, Ss_coarse = source_grid_adaptive(prob, Ss, τs, ks_coarse; bgopts, ptopts, verbose, sourceopts...) # TODO: thread flag # TODO: pass kτ0 and x # TODO: pass bgsol
213213

214214
# Interpolate source function to finer k-grid
215215
Ss_fine = source_grid(Ss_coarse, ks_coarse, ks_fine)
216-
Ss_fine[:, end, :] .= 0.0
216+
if iE > 0
217+
χs = τs[end] .- τs
218+
Ss_fine[iE, :, :] ./= (ks_fine' .* χs) .^ 2
219+
end
220+
Ss_fine[:, end, :] .= 0.0 # can be Inf, but is always weighted by zero-valued spherical Bessel function in LOS integration
217221

218222
ΘlTs = iT > 0 ? los_integrate(@view(Ss_fine[iT, :, :]), ls, τs, ks_fine, jl; integrator, verbose, kwargs...) : nothing
219223
ΘlEs = iE > 0 ? los_integrate(@view(Ss_fine[iE, :, :]), ls, τs, ks_fine, jl; integrator, verbose, kwargs...) .* transpose(@. ((ls+2)*(ls+1)*(ls+0)*(ls-1))) : nothing

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,3 +452,9 @@ using SpecialFunctions: zeta as ζ
452452
end
453453
end
454454
end
455+
456+
@testset "CMB spectra" begin
457+
jl = SphericalBesselCache(20:20:3000)
458+
DlTT = spectrum_cmb(:TT, prob, jl; normalization = :Dl)
459+
DlEE = spectrum_cmb(:EE, prob, jl; normalization = :Dl)
460+
end

0 commit comments

Comments
 (0)