Skip to content

Commit 859711f

Browse files
committed
Use setuppt/ptprobgen in adaptive source grid function
1 parent 2d84a6b commit 859711f

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/observables/fourier.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,12 @@ The options `bgopts` and `ptopts` are passed to the background and perturbation
262262
"""
263263
function source_grid_adaptive(prob::CosmologyProblem, Ss::AbstractVector, τs, ks; bgopts = (), ptopts = (), kwargs...)
264264
bgsol = solvebg(prob.bg; bgopts...)
265+
ptprob0, ptprobgen = setuppt(prob.pt, bgsol, prob.bgspline)
265266

266267
getSs = map(S -> getsym(prob.pt, S), Ss)
267268
function Sk(k)
268-
ptsols = solvept(prob.pt, bgsol, [k], prob.bgspline; saveat = τs, thread = false, ptopts...)
269-
ptsol = only(ptsols)
269+
ptprob = ptprobgen(ptprob0, k)
270+
ptsol = solvept(ptprob; saveat = τs, ptopts...)
270271
S = transpose(stack(map(getS -> getS(ptsol), getSs)))
271272
S[:, end] .= 0.0 # avoid NaN/Infs from 1/χ today; fine in LOS integration, since always weighted by 0-valued Bessel function # TODO: avoid
272273
return S

src/solve.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,27 @@ function solvept(ptprob::ODEProblem, bgsol::ODESolution, ks::AbstractArray, bgsp
427427
verbose && println()
428428
return ptsols
429429
end
430+
"""
431+
solvept(ptprob::ODEProblem; alg = DEFAULT_PTALG, reltol = 1e-8, abstol = 1e-8, kwargs...)
432+
433+
Solve the perturbation problem `ptprob` and return the solution.
434+
Its wavenumber and background spline must already be initialized, for example with `setuppt`.
435+
436+
# Examples
437+
438+
```julia
439+
# ...
440+
prob = CosmologyProblem(M, pars)
441+
bgsol = solvebg(prob.bg)
442+
ptprob0, ptprobgen = SymBoltz.setuppt(prob.pt, bgsol, prob.bgspline)
443+
k = 1.0
444+
ptprob = ptprobgen(ptprob0, k)
445+
ptsol = solvept(ptprob)
446+
```
447+
"""
448+
function solvept(ptprob::ODEProblem; alg = DEFAULT_PTALG, reltol = 1e-8, abstol = 1e-8, kwargs...)
449+
return solve(ptprob, alg; reltol, abstol, kwargs...)
450+
end
430451

431452
function time_today(prob::CosmologyProblem)
432453
getτ0 = SymBoltz.getsym(prob.bg, :τ0)

0 commit comments

Comments
 (0)