@@ -73,6 +73,10 @@ function last_step_failed(integrator::ODEIntegrator)
73
73
end
74
74
75
75
function modify_dt_for_tstops! (integrator)
76
+ integrator. t, integrator. dt
77
+ tdir_tstop = first_tstop (integrator)
78
+ distance_to_tstop = abs (tdir_tstop - integrator. tdir * integrator. t)
79
+
76
80
if has_tstop (integrator)
77
81
tdir_t = integrator. tdir * integrator. t
78
82
tdir_tstop = first_tstop (integrator)
@@ -82,6 +86,7 @@ function modify_dt_for_tstops!(integrator)
82
86
original_dt = abs (integrator. dt)
83
87
84
88
if integrator. opts. adaptive
89
+ integrator. dtpropose = original_dt
85
90
if original_dt < distance_to_tstop
86
91
# Normal step, no tstop interference
87
92
integrator. next_step_tstop = false
@@ -124,7 +129,7 @@ function handle_tstop_step!(integrator)
124
129
perform_step! (integrator, integrator. cache)
125
130
end
126
131
127
- # Flag will be reset in fixed_t_for_floatingpoint_error ! when t is updated
132
+ # Flag will be reset in fixed_t_for_tstop_error ! when t is updated
128
133
end
129
134
130
135
# Want to extend savevalues! for DDEIntegrator
@@ -186,7 +191,6 @@ function _savevalues!(integrator, force_save, reduce_size)::Tuple{Bool, Bool}
186
191
end
187
192
if force_save || (integrator. opts. save_everystep &&
188
193
(isempty (integrator. sol. t) ||
189
- (integrator. t != = integrator. sol. t[end ]) &&
190
194
(integrator. opts. save_end || integrator. t != = integrator. sol. prob. tspan[2 ])
191
195
))
192
196
integrator. saveiter += 1
@@ -311,12 +315,20 @@ function _loopfooter!(integrator)
311
315
if integrator. accept_step # Accept
312
316
increment_accept! (integrator. stats)
313
317
integrator. last_stepfail = false
318
+ integrator. tprev = integrator. t
319
+
320
+ if integrator. next_step_tstop
321
+ # Step controller dt is overly pessimistic, since dt = time to tstop
322
+ # For example, if super dense time, dt = eps(t), so the next step is tiny
323
+ # Thus if snap to tstop, let the step controller assume dt was the pre-fixed version
324
+ integrator. dt = integrator. dtpropose
325
+ end
326
+ integrator. t = fixed_t_for_tstop_error! (integrator, ttmp)
327
+
314
328
dtnew = DiffEqBase. value (step_accept_controller! (integrator,
315
329
integrator. alg,
316
330
q)) *
317
331
oneunit (integrator. dt)
318
- integrator. tprev = integrator. t
319
- integrator. t = fixed_t_for_floatingpoint_error! (integrator, ttmp)
320
332
calc_dt_propose! (integrator, dtnew)
321
333
handle_callbacks! (integrator)
322
334
else # Reject
@@ -325,7 +337,7 @@ function _loopfooter!(integrator)
325
337
elseif ! integrator. opts. adaptive # Not adaptive
326
338
increment_accept! (integrator. stats)
327
339
integrator. tprev = integrator. t
328
- integrator. t = fixed_t_for_floatingpoint_error ! (integrator, ttmp)
340
+ integrator. t = fixed_t_for_tstop_error ! (integrator, ttmp)
329
341
integrator. last_stepfail = false
330
342
integrator. accept_step = true
331
343
integrator. dtpropose = integrator. dt
@@ -364,7 +376,7 @@ function log_step!(progress_name, progress_id, progress_message, dt, u, p, t, ts
364
376
progress= (t- t1)/ (t2- t1))
365
377
end
366
378
367
- function fixed_t_for_floatingpoint_error ! (integrator, ttmp)
379
+ function fixed_t_for_tstop_error ! (integrator, ttmp)
368
380
# If we're in tstop snap mode, use exact tstop target
369
381
if integrator. next_step_tstop
370
382
# Reset the flag now that we're snapping to tstop
@@ -501,10 +513,7 @@ function handle_tstop!(integrator)
501
513
tdir_t = integrator. tdir * integrator. t
502
514
tdir_tstop = first_tstop (integrator)
503
515
if tdir_t == tdir_tstop
504
- while tdir_t == tdir_tstop # remove all redundant copies
505
- res = pop_tstop! (integrator)
506
- has_tstop (integrator) ? (tdir_tstop = first_tstop (integrator)) : break
507
- end
516
+ res = pop_tstop! (integrator)
508
517
integrator. just_hit_tstop = true
509
518
elseif tdir_t > tdir_tstop
510
519
if ! integrator. dtchangeable
0 commit comments