Skip to content

Commit 207704b

Browse files
authored
Merge pull request #347 from CliMA/kp/change-saveat
Remove check for number in tstops_and_saveat_heaps
2 parents e5947e9 + ba91230 commit 207704b

File tree

4 files changed

+10
-20
lines changed

4 files changed

+10
-20
lines changed

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ ClimaTimeSteppers.jl Release Notes
33

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

711
v0.7.18
812
-------

docs/src/tutorials/diffusion.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ prob = SciMLBase.ODEProblem(
190190
# We use SSPKnoth for this example
191191
algo = ClimaTimeSteppers.RosenbrockAlgorithm(ClimaTimeSteppers.tableau(ClimaTimeSteppers.SSPKnoth()));
192192

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

197197
## Solution and visualization
198198
#

src/integrators.jl

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,17 @@ end
6666

6767

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

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

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

9081
return tstops, saveat
9182
end

test/integrator.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,9 @@ include("problems.jl")
7070

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

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

7977
# testing add_tstops! and add_saveat!
8078
(true, (; saveat = [tf], callback = adding_callback), [save_dt_times..., tf]),
@@ -136,9 +134,6 @@ end
136134
((;), (; erase_sol = false), [t0, tf, t0′, tf′]),
137135
((;), (; saveat = save_dt_times′, tstops = save_dt_times′), save_dt_times′),
138136
((; saveat = save_dt_times′, tstops = save_dt_times′), (;), save_dt_times′),
139-
((;), (; saveat = save_dt, tstops = save_dt_times′), [save_dt_times′..., tf′]),
140-
((; saveat = save_dt, tstops = save_dt_times′), (;), [save_dt_times′..., tf′]),
141-
((; saveat = save_dt, tstops = all_times), (; erase_sol = false), all_times),
142137
)
143138
integrator = init(deepcopy(prob), alg; dt, init_kwargs...)
144139
@test !@any_reltype(integrator, (UnionAll, DataType))

0 commit comments

Comments
 (0)