xzackli / Bolt.jl

differentiable boltzmann code
MIT License
42 stars 5 forks source link

clean up background integration #43

Closed xzackli closed 2 years ago

xzackli commented 3 years ago

The background integration should basically be instant compared to the perturbation evolution. We should remove all the quadgk and replace it with fixed grid quadrature.

jmsull commented 3 years ago

I removed the quadgk from the background functions for conformal time and rho in d96a2825b59370153ac3ef840afaefb96ba41561 and replaced it with the same quadrature points and weights that are called once in the background and used for perturbations already (so there is only ever one call to quadrature). This is a little iffy for conformal time since we are calling quad upon quad, but I checked this for the splined results in dev_quad. This seems to result in about the same accuracy we were getting for the perturbation integrals for conformal time (1e-3) while \scrH(a) is always within 4e-6(!) of quadgk. We of course should probably drop these tolerances lower eventually, and we may want to make the background quadrature more accurate than perturbations (CLASS does this). And of course, my rough mapping back and forth to the unit interval in the log of the integration variables would be improved by a fancier treatment of the endpoints, but that was also true before.

I had to modify the \tau' function (in tau_functions) in IonizationHistory in ionization.jl and recfast.jl - it now takes an extra argument that is the \scrHa(a) function. \tau' is the only place in the whole code [outside of bg] where the "raw" \scrH(a) function is called instead of the spline. So either tau functions needs to be passed the quad points and weights, or it needs to use the splined H(a) - I opted for the latter since IonizationHistory already takes the background as an argument. Let me know if this sounds too problematic since I haven't yet familiarized myself with the details of what the ionization history is actually doing.

jmsull commented 3 years ago

Can we close this? Or want to do some more detailed timing?