Skip to content

Commit

Permalink
clean code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
xzackli committed Aug 20, 2024
1 parent 674271b commit 8173950
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions scripts/dev_fd_quadrature.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ function ρPold(a,par::AbstractCosmoParams)
m = par.Σm_ν
qmin=1e-18
qmax=1e1
ρ = 4π * a^(-4) * quadgk(q -> q^2 * ( q^2 + (a*m)^2 ) * f0(q,par) ,qmin, qmax,rtol=1e-6)[1]
P = 4π/3 * a^(-4) * quadgk(q -> q^2 * q^2 /√( q^2 + (a*m)^2) * f0(q,par), qmin, qmax,rtol=1e-6)[1]
ρ = 4π * a^(-4) * quadgk(q -> q^2 * ( q^2 + (a*m)^2 ) * f0(q) ,qmin, qmax,rtol=1e-6)[1]
P = 4π/3 * a^(-4) * quadgk(q -> q^2 * q^2 /√( q^2 + (a*m)^2) * f0(q), qmin, qmax,rtol=1e-6)[1]
return ρ,P#,norm
end
H₀(par::AbstractCosmoParams) = par.h * km_s_Mpc_100
Expand Down
4 changes: 2 additions & 2 deletions src/perturbations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function boltsolve_rsa(hierarchy::Hierarchy{T}, ode_alg=KenCarp4(); reltol=1e-6,
x_grid = hierarchy.bg.x_grid
pertlen = 2(hierarchy.ℓᵧ+1)+(hierarchy.ℓ_ν+1)+(hierarchy.ℓ_mν+1)*hierarchy.nq+5
results=zeros(pertlen,length(x_grid))
for i in 1:length(x_grid) results[:,i] = perturb(x_grid[i]) end
for i in eachindex(x_grid) results[:,i] = perturb(x_grid[i]) end
#replace the late-time perts with RSA approx (assuming we don't change rsa switch)
#this_rsa_switch = x_grid[argmin(abs.(hierarchy.k .* hierarchy.bg.η.(x_grid) .- 45))]

Expand All @@ -102,7 +102,7 @@ function boltsolve_rsa(hierarchy::Hierarchy{T}, ode_alg=KenCarp4(); reltol=1e-6,
x_grid_rsa = x_grid[x_grid.>this_rsa_switch]
results_rsa = results[:,x_grid.>this_rsa_switch]
#(re)-compute the RSA perts so we can write them to the output vector
for i in 1:length(x_grid_rsa)
for i in eachindex(x_grid_rsa)
rsa_perts!(view(results_rsa,:,i),hierarchy,x_grid_rsa[i]) #to mutate need to use view...
end
results[:,x_grid.>this_rsa_switch] = results_rsa
Expand Down
14 changes: 7 additions & 7 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ end
class_eta = bg.η.(class_x)


TOL = 1e-3
@test all(abs.(itphibolt.(class_x) ./ itpphiclass.(class_x) .- 1) .< TOL)
@test all(abs.(-itdeltbbolt.(class_x) ./ itdeltbclass.(class_x) .- 1) .< TOL)
@test all(abs.(itpgambolt.(class_x) ./ itpgambolt.(class_x) .- 1) .< TOL)
reltol = 1e-3
@test all(abs.(itphibolt.(class_x) ./ itpphiclass.(class_x) .- 1) .< reltol)
@test all(abs.(-itdeltbbolt.(class_x) ./ itdeltbclass.(class_x) .- 1) .< reltol)
@test all(abs.(itpgambolt.(class_x) ./ itpgambolt.(class_x) .- 1) .< reltol)
end

@testset "cell_camb_1e-1" begin
Expand Down Expand Up @@ -177,9 +177,9 @@ end
itpee_b = LinearInterpolation(ℓs, @.(ℓfac * Cℓee))

#test line
TOL = 1.1e-1
reltol = 1.1e-1
#FIXME should really do this on the finer of the two grids but need to rerun...
@test all(abs.(itptt_b.(ℓs) ./ itptt.(ℓs) .- 1) .< TOL)
@test all(abs.(itptt_b.(ℓs) ./ itptt.(ℓs) .- 1) .< reltol)
# all(abs.(itpte_b.(ℓs) .- itpte.(ℓs) .- 1) .< TOL) # zero-crossing will be an issue here, do diff check
@test all(abs.(itpee_b.(ℓs) ./ itpee.(ℓs) .- 1) .< TOL)
@test all(abs.(itpee_b.(ℓs) ./ itpee.(ℓs) .- 1) .< reltol)
end

0 comments on commit 8173950

Please sign in to comment.