Skip to content

Commit 2096a2a

Browse files
committed
Save only final times when evaluating matter power spectrum
1 parent 348080d commit 2096a2a

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/observables/fourier.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,14 @@ end
8080
Solve the problem `prob` with exact wavenumber(s) `k`, and then compute the power spectrum with the solution `sol`.
8181
"""
8282
function spectrum_matter(prob::CosmologyProblem, k, τ = nothing; species = [:c, :b, :h], kwargs...)
83-
sol = solve(prob, k; kwargs...) # TODO: just save endpoints
84-
τ = isnothing(τ) ? sol[prob.M.τ][end] : τ
83+
# save only the necessary time(s)
84+
if isnothing(τ)
85+
ptextraopts = (save_everystep = false, save_start = false, save_end = true)
86+
else
87+
ptextraopts = (saveat = [τ],)
88+
end
89+
sol = solve(prob, k; ptextraopts, kwargs...)
90+
τ = isnothing(τ) ? sol.bg.t[end] : τ
8591
return spectrum_matter(sol, k, τ; species)
8692
end
8793

src/solve.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,23 +280,23 @@ If `threads`, integration over independent perturbation modes are parallellized.
280280
"""
281281
function solve(
282282
prob::CosmologyProblem, ks::Union{Nothing, AbstractArray} = nothing;
283-
bgopts = (alg = DEFAULT_BGALG, reltol = 1e-9, abstol = 1e-9),
284-
ptopts = (alg = DEFAULT_PTALG, reltol = 1e-8, abstol = 1e-8),
283+
bgopts = (alg = DEFAULT_BGALG, reltol = 1e-9, abstol = 1e-9), bgextraopts = (),
284+
ptopts = (alg = DEFAULT_PTALG, reltol = 1e-8, abstol = 1e-8), ptextraopts = (),
285285
shootopts = (alg = DEFAULT_SHOOTALG, abstol = 1e-5),
286286
thread = true, verbose = false, kwargs...
287287
)
288288
if !isempty(prob.shoot)
289-
bgsol = solvebg(prob.bg, collect(prob.shoot), prob.conditions; shootopts, verbose, bgopts..., kwargs...)
289+
bgsol = solvebg(prob.bg, collect(prob.shoot), prob.conditions; shootopts, verbose, bgopts..., bgextraopts..., kwargs...)
290290
else
291-
bgsol = solvebg(prob.bg; verbose, bgopts..., kwargs...)
291+
bgsol = solvebg(prob.bg; verbose, bgopts..., bgextraopts..., kwargs...)
292292
end
293293

294294
if isnothing(ks) || isempty(ks)
295295
ks = nothing
296296
ptsol = nothing
297297
else
298298
ks = k_dimensionless.(ks, Ref(bgsol))
299-
ptsol = solvept(prob.pt, bgsol, ks, prob.bgspline; thread, verbose, ptopts..., kwargs...)
299+
ptsol = solvept(prob.pt, bgsol, ks, prob.bgspline; thread, verbose, ptopts..., ptextraopts..., kwargs...)
300300
end
301301

302302
return CosmologySolution(prob, bgsol, ks, ptsol)

0 commit comments

Comments
 (0)