@@ -484,7 +484,7 @@ SolutionData IDAKLUSolverOpenMP<ExprSet>::solve(
484
484
}
485
485
486
486
if (hit_tinterp) {
487
- // Save the interpolated state at t_prev < t < t_val, for all t in t_interp
487
+ // Save the interpolated state at t_prev < t <= t_val, for all t in t_interp
488
488
SetStepInterp (
489
489
i_interp,
490
490
t_interp_next,
@@ -499,26 +499,15 @@ SolutionData IDAKLUSolverOpenMP<ExprSet>::solve(
499
499
i_save);
500
500
}
501
501
502
- if (hit_adaptive || hit_teval || hit_event || hit_final_time) {
503
- if (hit_tinterp) {
504
- // Reset the states and sensitivities at t = t_val
505
- CheckErrors (IDAGetDky (ida_mem, t_val, 0 , yy));
506
- if (sensitivity) {
507
- CheckErrors (IDAGetSensDky (ida_mem, t_val, 0 , yyS));
508
- }
502
+ // Check that we are not saving the same time point twice,
503
+ // which is possible if t_interp contains t_val.
504
+ if ((t_val != t[i_save-1 ]) && (hit_adaptive || hit_teval || hit_event || hit_final_time)) {
505
+ if (hit_adaptive) {
506
+ // Dynamically allocate memory for the adaptive step
507
+ ExtendAdaptiveArrays ();
509
508
}
510
509
511
- // Save the current state at t_val
512
- // First, check to make sure that the t_val is not equal to the current t value
513
- // If it is, we don't want to save the current state twice
514
- if (!hit_tinterp || t_val != t.back ()) {
515
- if (hit_adaptive) {
516
- // Dynamically allocate memory for the adaptive step
517
- ExtendAdaptiveArrays ();
518
- }
519
-
520
- SetStep (t_val, y_val, yp_val, yS_val, ypS_val, i_save);
521
- }
510
+ SetStep (t_val, y_val, yp_val, yS_val, ypS_val, i_save);
522
511
}
523
512
524
513
if (hit_final_time || hit_event) {
@@ -788,6 +777,12 @@ void IDAKLUSolverOpenMP<ExprSet>::SetStepInterp(
788
777
}
789
778
t_interp_next = t_interp[i_interp];
790
779
}
780
+
781
+ // Reset the states and sensitivities to t = t_val
782
+ CheckErrors (IDAGetDky (ida_mem, t_val, 0 , yy));
783
+ if (sensitivity) {
784
+ CheckErrors (IDAGetSensDky (ida_mem, t_val, 0 , yyS));
785
+ }
791
786
}
792
787
793
788
template <class ExprSet >
0 commit comments