Skip to content

Commit

Permalink
Merge pull request #347 from CliMA/kp/change-saveat
Browse files Browse the repository at this point in the history
Remove check for number in tstops_and_saveat_heaps
  • Loading branch information
ph-kev authored Feb 3, 2025
2 parents e5947e9 + ba91230 commit 207704b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 20 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ ClimaTimeSteppers.jl Release Notes

Main
-------
v0.8.2
- ![][badge-💥breaking] If saveat is a number, then it does not automatically expand to `tspan[1]:saveat:tspan[2]`. To fix this, update
`saveat`, which is a keyword in the integrator, to be an array. For example, if `saveat` is a scalar, replace it with
`[tspan[1]:saveat:tspan[2]..., tspan[2]]` to achieve the same behavior as before.

v0.7.18
-------
Expand Down
4 changes: 2 additions & 2 deletions docs/src/tutorials/diffusion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ prob = SciMLBase.ODEProblem(
# We use SSPKnoth for this example
algo = ClimaTimeSteppers.RosenbrockAlgorithm(ClimaTimeSteppers.tableau(ClimaTimeSteppers.SSPKnoth()));

# And here is the integrator, where we set `saveat = dt` to save a snapshot of
# And here is the integrator, where we set `saveat = t0:dt:t_end` to save a snapshot of
# the solution at every timestep.
integrator = SciMLBase.init(prob, algo; dt, saveat = dt);
integrator = SciMLBase.init(prob, algo; dt, saveat = t0:dt:t_end);

## Solution and visualization
#
Expand Down
17 changes: 4 additions & 13 deletions src/integrators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,17 @@ end


# helper function for setting up min/max heaps for tstops and saveat
function tstops_and_saveat_heaps(t0, tf, tstops, saveat)
function tstops_and_saveat_heaps(t0, tf, tstops, saveat = [])
FT = typeof(tf)
ordering = tf > t0 ? DataStructures.FasterForward : DataStructures.FasterReverse

# ensure that tstops includes tf and only has values ahead of t0
tstops = [filter(t -> t0 < t < tf || tf < t < t0, tstops)..., tf]
tstops = DataStructures.BinaryHeap{FT, ordering}(tstops)

if isnothing(saveat)
saveat = [t0, tf]
elseif saveat isa Number
saveat > zero(saveat) || error("saveat value must be positive")
saveat = tf > t0 ? saveat : -saveat
saveat = [t0:saveat:tf..., tf]
else
# We do not need to filter saveat like tstops because the saving
# callback will ignore any times that are not between t0 and tf.
saveat = collect(saveat)
end
saveat = DataStructures.BinaryHeap{FT, ordering}(saveat)
isnothing(saveat) && (saveat = [t0, tf])

saveat = DataStructures.BinaryHeap{FT, ordering}(collect(saveat))

return tstops, saveat
end
Expand Down
5 changes: 0 additions & 5 deletions test/integrator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,9 @@ include("problems.jl")

# testing non-interpolated saving (OrdinaryDiffEq interpolates when saving)
(false, (; saveat = save_dt_times), misaligned_saving_times),
(false, (; saveat = save_dt), [misaligned_saving_times..., tf]),

# testing tstops (tstops remove the need for interpolation when saving)
(true, (; saveat = save_dt_times, tstops = save_dt_times), save_dt_times),
(true, (; saveat = save_dt, tstops = save_dt_times), [save_dt_times..., tf]),

# testing add_tstops! and add_saveat!
(true, (; saveat = [tf], callback = adding_callback), [save_dt_times..., tf]),
Expand Down Expand Up @@ -136,9 +134,6 @@ end
((;), (; erase_sol = false), [t0, tf, t0′, tf′]),
((;), (; saveat = save_dt_times′, tstops = save_dt_times′), save_dt_times′),
((; saveat = save_dt_times′, tstops = save_dt_times′), (;), save_dt_times′),
((;), (; saveat = save_dt, tstops = save_dt_times′), [save_dt_times′..., tf′]),
((; saveat = save_dt, tstops = save_dt_times′), (;), [save_dt_times′..., tf′]),
((; saveat = save_dt, tstops = all_times), (; erase_sol = false), all_times),
)
integrator = init(deepcopy(prob), alg; dt, init_kwargs...)
@test !@any_reltype(integrator, (UnionAll, DataType))
Expand Down

0 comments on commit 207704b

Please sign in to comment.