@@ -73,6 +73,10 @@ function last_step_failed(integrator::ODEIntegrator)
7373end
7474
7575function 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+
7680 if has_tstop (integrator)
7781 tdir_t = integrator. tdir * integrator. t
7882 tdir_tstop = first_tstop (integrator)
@@ -82,6 +86,7 @@ function modify_dt_for_tstops!(integrator)
8286 original_dt = abs (integrator. dt)
8387
8488 if integrator. opts. adaptive
89+ integrator. dtpropose = original_dt
8590 if original_dt < distance_to_tstop
8691 # Normal step, no tstop interference
8792 integrator. next_step_tstop = false
@@ -124,7 +129,7 @@ function handle_tstop_step!(integrator)
124129 perform_step! (integrator, integrator. cache)
125130 end
126131
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
128133end
129134
130135# Want to extend savevalues! for DDEIntegrator
@@ -186,7 +191,6 @@ function _savevalues!(integrator, force_save, reduce_size)::Tuple{Bool, Bool}
186191 end
187192 if force_save || (integrator. opts. save_everystep &&
188193 (isempty (integrator. sol. t) ||
189- (integrator. t != = integrator. sol. t[end ]) &&
190194 (integrator. opts. save_end || integrator. t != = integrator. sol. prob. tspan[2 ])
191195 ))
192196 integrator. saveiter += 1
@@ -311,12 +315,20 @@ function _loopfooter!(integrator)
311315 if integrator. accept_step # Accept
312316 increment_accept! (integrator. stats)
313317 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+
314328 dtnew = DiffEqBase. value (step_accept_controller! (integrator,
315329 integrator. alg,
316330 q)) *
317331 oneunit (integrator. dt)
318- integrator. tprev = integrator. t
319- integrator. t = fixed_t_for_floatingpoint_error! (integrator, ttmp)
320332 calc_dt_propose! (integrator, dtnew)
321333 handle_callbacks! (integrator)
322334 else # Reject
@@ -325,7 +337,7 @@ function _loopfooter!(integrator)
325337 elseif ! integrator. opts. adaptive # Not adaptive
326338 increment_accept! (integrator. stats)
327339 integrator. tprev = integrator. t
328- integrator. t = fixed_t_for_floatingpoint_error ! (integrator, ttmp)
340+ integrator. t = fixed_t_for_tstop_error ! (integrator, ttmp)
329341 integrator. last_stepfail = false
330342 integrator. accept_step = true
331343 integrator. dtpropose = integrator. dt
@@ -364,7 +376,7 @@ function log_step!(progress_name, progress_id, progress_message, dt, u, p, t, ts
364376 progress= (t- t1)/ (t2- t1))
365377end
366378
367- function fixed_t_for_floatingpoint_error ! (integrator, ttmp)
379+ function fixed_t_for_tstop_error ! (integrator, ttmp)
368380 # If we're in tstop snap mode, use exact tstop target
369381 if integrator. next_step_tstop
370382 # Reset the flag now that we're snapping to tstop
@@ -501,10 +513,7 @@ function handle_tstop!(integrator)
501513 tdir_t = integrator. tdir * integrator. t
502514 tdir_tstop = first_tstop (integrator)
503515 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)
508517 integrator. just_hit_tstop = true
509518 elseif tdir_t > tdir_tstop
510519 if ! integrator. dtchangeable
0 commit comments